Add a context menu command for whois
This commit is contained in:
@@ -0,0 +1,17 @@
|
|||||||
|
import { ApplicationIntegrationType, Client, InteractionContextType, MessageFlags, PermissionFlagsBits, ContextMenuCommandBuilder, ApplicationCommandType, ContextMenuCommandInteraction, UserContextMenuCommandInteraction } from 'discord.js';
|
||||||
|
import { handleWhoIsInteraction } from '../utils';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'whois',
|
||||||
|
data: new ContextMenuCommandBuilder()
|
||||||
|
.setName('whois')
|
||||||
|
.setIntegrationTypes(ApplicationIntegrationType.GuildInstall)
|
||||||
|
.setContexts(InteractionContextType.Guild)
|
||||||
|
.setDefaultMemberPermissions(PermissionFlagsBits.BanMembers)
|
||||||
|
.setType(ApplicationCommandType.User),
|
||||||
|
handler: async function (client: Client, interaction: UserContextMenuCommandInteraction) {
|
||||||
|
const idToUse = interaction.targetUser.id;
|
||||||
|
|
||||||
|
handleWhoIsInteraction(interaction, idToUse, true);
|
||||||
|
}
|
||||||
|
};
|
||||||
+2
-29
@@ -1,7 +1,5 @@
|
|||||||
import { ApplicationIntegrationType, ChatInputCommandInteraction, Client, InteractionContextType, MessageFlags, PermissionFlagsBits, SlashCommandBuilder } from 'discord.js';
|
import { ApplicationIntegrationType, ChatInputCommandInteraction, Client, InteractionContextType, MessageFlags, PermissionFlagsBits, SlashCommandBuilder } from 'discord.js';
|
||||||
import { Database } from '../shared/Database';
|
import { handleWhoIsInteraction } from '../utils';
|
||||||
import { getE621User } from '../utils';
|
|
||||||
import { config } from '../config';
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'whois',
|
name: 'whois',
|
||||||
@@ -33,31 +31,6 @@ export default {
|
|||||||
|
|
||||||
const idToUse = (user?.id ?? id) as string;
|
const idToUse = (user?.id ?? id) as string;
|
||||||
|
|
||||||
const results = await Database.getE621Ids(idToUse);
|
handleWhoIsInteraction(interaction, idToUse);
|
||||||
|
|
||||||
if (results.length > 0) {
|
|
||||||
const mappedResults = results.map(e => `- ${config.E621_BASE_URL}/users/${e}\n`);
|
|
||||||
|
|
||||||
const alts: string[] = [];
|
|
||||||
|
|
||||||
for (const e621Id of results) {
|
|
||||||
const discordIds = await Database.getDiscordIds(e621Id);
|
|
||||||
|
|
||||||
for (const discordId of discordIds) {
|
|
||||||
if (discordId != idToUse && !alts.includes(discordId)) alts.push(discordId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let content = `<@${idToUse}>'s e621 account(s):\n${mappedResults}`;
|
|
||||||
|
|
||||||
if (alts.length > 0) {
|
|
||||||
const mappedAlts = alts.map(id => `- <@${id}>\n`);
|
|
||||||
content += `\n\nDiscord alts found:\n${mappedAlts}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
interaction.reply(content);
|
|
||||||
} else {
|
|
||||||
interaction.reply('No e621 accounts found for this user');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -8,4 +8,6 @@ export * from './message-utils';
|
|||||||
export * from './ms-to-human';
|
export * from './ms-to-human';
|
||||||
export * from './refresh-commands';
|
export * from './refresh-commands';
|
||||||
export * from './string-utils';
|
export * from './string-utils';
|
||||||
|
export * from './ticket-utils';
|
||||||
export * from './wait';
|
export * from './wait';
|
||||||
|
export * from './whois';
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
import { CommandInteraction, MessageFlags } from 'discord.js';
|
||||||
|
import { config } from '../config';
|
||||||
|
import { Database } from '../shared/Database';
|
||||||
|
|
||||||
|
export async function handleWhoIsInteraction(interaction: CommandInteraction, idToUse: string, ephemeral = false) {
|
||||||
|
const results = await Database.getE621Ids(idToUse);
|
||||||
|
|
||||||
|
if (results.length > 0) {
|
||||||
|
const mappedResults = results.map(e => `- ${config.E621_BASE_URL}/users/${e}\n`);
|
||||||
|
|
||||||
|
const alts: string[] = [];
|
||||||
|
|
||||||
|
for (const e621Id of results) {
|
||||||
|
const discordIds = await Database.getDiscordIds(e621Id);
|
||||||
|
|
||||||
|
for (const discordId of discordIds) {
|
||||||
|
if (discordId != idToUse && !alts.includes(discordId)) alts.push(discordId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let content = `<@${idToUse}>'s e621 account(s):\n${mappedResults}`;
|
||||||
|
|
||||||
|
if (alts.length > 0) {
|
||||||
|
const mappedAlts = alts.map(id => `- <@${id}>\n`);
|
||||||
|
content += `\n\nDiscord alts found:\n${mappedAlts}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ephemeral) interaction.reply({ content, flags: [MessageFlags.Ephemeral] });
|
||||||
|
else interaction.reply(content);
|
||||||
|
} else {
|
||||||
|
if (ephemeral) interaction.reply({ content: 'No e621 accounts found for this user', flags: [MessageFlags.Ephemeral] });
|
||||||
|
else interaction.reply('No e621 accounts found for this user');
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user