Squashed commit of the following:
commite8a57468deAuthor: Tarrgon <61888458+Tarrgon@users.noreply.github.com> Date: Sat May 31 11:10:56 2025 -0400 Add record command commit5a8ca6bb54Author: Tarrgon <61888458+Tarrgon@users.noreply.github.com> Date: Sat May 31 11:10:30 2025 -0400 Move context menus to their own folder commit2d7c14ed7aMerge:33a6ba85107759Author: Tarrgon <61888458+Tarrgon@users.noreply.github.com> Date: Sat May 31 10:54:27 2025 -0400 Merge branch 'alt-data' into records commit5107759923Author: Tarrgon <61888458+Tarrgon@users.noreply.github.com> Date: Fri May 30 15:26:21 2025 -0400 Recursive alt lookup data
This commit is contained in:
@@ -3,6 +3,14 @@ import { Database } from '../shared/Database';
|
||||
import { userIsBanned } from './e621-utils';
|
||||
import { config } from '../config';
|
||||
|
||||
type AltData = {
|
||||
type: 'e621' | 'discord'
|
||||
thisId: number | string
|
||||
banned: boolean
|
||||
alts: AltData[]
|
||||
};
|
||||
|
||||
|
||||
export async function getE621Alts(discordId: string, guild: Guild, depth = 1, ignore: number[] = []): Promise<string> {
|
||||
const e621UserIds = await Database.getE621Ids(discordId);
|
||||
|
||||
@@ -42,4 +50,57 @@ export async function getDiscordAlts(e621Id: number, guild: Guild, depth = 1, ig
|
||||
}
|
||||
|
||||
return content;
|
||||
}
|
||||
|
||||
export async function comprehensiveAltLookupFromDiscord(discordId: string, guild: Guild): Promise<AltData> {
|
||||
return getE621AltData(discordId, guild);
|
||||
}
|
||||
|
||||
export async function comprehensiveAltLookupFromE621(e621Id: number, guild: Guild): Promise<AltData> {
|
||||
return getDiscordAltData(e621Id, guild);
|
||||
}
|
||||
|
||||
async function getE621AltData(discordId: string, guild: Guild, depth = 1, ignore: number[] = []): Promise<AltData> {
|
||||
const e621UserIds = await Database.getE621Ids(discordId);
|
||||
|
||||
const toIgnore = ignore.concat(e621UserIds);
|
||||
|
||||
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) { }
|
||||
|
||||
const data: AltData = { type: 'discord', thisId: discordId, banned, alts: [] };
|
||||
|
||||
for (const e621Id of e621UserIds) {
|
||||
if (ignore.includes(e621Id)) continue;
|
||||
|
||||
data.alts.push(await getDiscordAltData(e621Id, guild, depth + 1, toIgnore));
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
async function getDiscordAltData(e621Id: number, guild: Guild, depth = 1, ignore: number[] = []): Promise<AltData> {
|
||||
const discordIds = await Database.getDiscordIds(e621Id);
|
||||
|
||||
const data: AltData = { type: 'e621', thisId: e621Id, banned: await userIsBanned(e621Id), alts: [] };
|
||||
|
||||
for (const discordId of discordIds) {
|
||||
data.alts.push(await getE621AltData(discordId, guild, depth + 1, ignore));
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
export function e621IdsFromAltData(altData: AltData, data: number[] = []) {
|
||||
if (altData.type == 'e621' && !data.includes(altData.thisId as number)) data.push(altData.thisId as number);
|
||||
|
||||
for (const alt of altData.alts) {
|
||||
e621IdsFromAltData(alt, data);
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
Reference in New Issue
Block a user