Recursive alt check
This commit is contained in:
@@ -6,23 +6,41 @@ export async function handleMemberJoin(member: GuildMember) {
|
|||||||
const guildSettings = await Database.getGuildSettings(member.guild.id);
|
const guildSettings = await Database.getGuildSettings(member.guild.id);
|
||||||
|
|
||||||
if (guildSettings?.new_member_channel_id) {
|
if (guildSettings?.new_member_channel_id) {
|
||||||
const e621UserIds = await Database.getE621Ids(member.id);
|
|
||||||
const channel = await member.guild.channels.fetch(guildSettings.new_member_channel_id) as GuildTextBasedChannel;
|
const channel = await member.guild.channels.fetch(guildSettings.new_member_channel_id) as GuildTextBasedChannel;
|
||||||
|
|
||||||
if (channel) {
|
if (channel) {
|
||||||
let content = `${member.toString()}'s e621 and discord account(s):\n`;
|
const content = `${member.toString()}'s e621 and discord account(s):\n${await getE621Alts(member.id)}`;
|
||||||
|
|
||||||
for (const e621Id of e621UserIds) {
|
|
||||||
content += `- ${config.E621_BASE_URL}/users/${e621Id}\n`;
|
|
||||||
|
|
||||||
const discordIds = await Database.getDiscordIds(e621Id);
|
|
||||||
|
|
||||||
for (const discordId of discordIds) {
|
|
||||||
content += `- - <@${discordId}>\n`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
channel.send(content).catch(console.error);
|
channel.send(content).catch(console.error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function getE621Alts(discordId: string, 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;
|
||||||
|
content += `${'- '.repeat(depth)}${config.E621_BASE_URL}/users/${e621Id}\n${await getDiscordAlts(e621Id, depth + 1, toIgnore)}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getDiscordAlts(e621Id: number, depth = 1, ignore: number[] = []): Promise<string> {
|
||||||
|
const discordIds = await Database.getDiscordIds(e621Id);
|
||||||
|
|
||||||
|
let content = '';
|
||||||
|
|
||||||
|
for (const discordId of discordIds) {
|
||||||
|
const alts = await getE621Alts(discordId, depth + 1, ignore);
|
||||||
|
|
||||||
|
if (alts) content += `${'- '.repeat(depth)}<@${discordId}>\n${alts}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return content;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user