Make finduser and whois recursive as well
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
import { Guild } from 'discord.js';
|
||||
import { Database } from '../shared/Database';
|
||||
import { userIsBanned } from './e621-utils';
|
||||
import { config } from '../config';
|
||||
|
||||
export async function getE621Alts(discordId: string, guild: Guild, depth = 1, ignore: number[] = []): Promise<string> {
|
||||
const e621UserIds = await Database.getE621Ids(discordId);
|
||||
|
||||
const toIgnore = ignore.concat(e621UserIds);
|
||||
|
||||
let content = '';
|
||||
|
||||
for (const e621Id of e621UserIds) {
|
||||
if (ignore.includes(e621Id)) continue;
|
||||
|
||||
const alts = await getDiscordAlts(e621Id, guild, depth + 1, toIgnore);
|
||||
|
||||
const banned = await userIsBanned(e621Id);
|
||||
|
||||
content += `${'- '.repeat(depth)}${config.E621_BASE_URL}/users/${e621Id}${banned ? ' [BANNED]' : ''}\n${alts}`;
|
||||
}
|
||||
|
||||
return content;
|
||||
}
|
||||
|
||||
export async function getDiscordAlts(e621Id: number, guild: Guild, depth = 1, ignore: number[] = []): Promise<string> {
|
||||
const discordIds = await Database.getDiscordIds(e621Id);
|
||||
|
||||
let content = '';
|
||||
|
||||
for (const discordId of discordIds) {
|
||||
const alts = await getE621Alts(discordId, guild, depth + 1, ignore);
|
||||
|
||||
let banned = false;
|
||||
|
||||
// It's either this or fetch all the bans and sift through them for every discord alt.
|
||||
try {
|
||||
banned = !!(await guild.bans.fetch(discordId));
|
||||
} catch (e) { }
|
||||
|
||||
if (alts || banned) content += `${'- '.repeat(depth)}<@${discordId}>${banned ? ' [BANNED]' : ''}\n${alts}`;
|
||||
}
|
||||
|
||||
return content;
|
||||
}
|
||||
+2
-1
@@ -1,3 +1,4 @@
|
||||
export * from './alt-utils';
|
||||
export * from './array-utils';
|
||||
export * from './audit-log-utils';
|
||||
export * from './channel-utils';
|
||||
@@ -6,9 +7,9 @@ export * from './e621-utils';
|
||||
export * from './message-logger';
|
||||
export * from './message-utils';
|
||||
export * from './ms-to-human';
|
||||
export * from './note-utils';
|
||||
export * from './refresh-commands';
|
||||
export * from './string-utils';
|
||||
export * from './ticket-utils';
|
||||
export * from './wait';
|
||||
export * from './note-utils';
|
||||
export * from './whois';
|
||||
|
||||
+4
-24
@@ -1,35 +1,15 @@
|
||||
import { CommandInteraction, MessageFlags } from 'discord.js';
|
||||
import { config } from '../config';
|
||||
import { Database } from '../shared/Database';
|
||||
import { getE621Alts } from './alt-utils';
|
||||
|
||||
export async function handleWhoIsInteraction(interaction: CommandInteraction, idToUse: string, ephemeral = false) {
|
||||
if (ephemeral) await interaction.deferReply({ flags: [MessageFlags.Ephemeral] });
|
||||
else await interaction.deferReply();
|
||||
|
||||
const results = await Database.getE621Ids(idToUse);
|
||||
if (!interaction.guild) return interaction.editReply('This command must be used in a server');
|
||||
|
||||
if (results.length > 0) {
|
||||
const mappedResults = results.map(e => `- ${config.E621_BASE_URL}/users/${e}\n`);
|
||||
const content = await getE621Alts(idToUse, interaction.guild!);
|
||||
|
||||
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.editReply(content);
|
||||
} else {
|
||||
interaction.editReply('No e621 accounts found for this user');
|
||||
}
|
||||
interaction.editReply(`<@${idToUse}>'s e621 and discord account(s):\n${content}`);
|
||||
}
|
||||
Reference in New Issue
Block a user