Alert if banned
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import { GuildMember, GuildTextBasedChannel } from 'discord.js';
|
import { Guild, GuildMember, GuildTextBasedChannel } from 'discord.js';
|
||||||
import { Database } from '../shared/Database';
|
import { Database } from '../shared/Database';
|
||||||
import { config } from '../config';
|
import { config } from '../config';
|
||||||
|
import { userIsBanned } from '../utils';
|
||||||
|
|
||||||
export async function handleMemberJoin(member: GuildMember) {
|
export async function handleMemberJoin(member: GuildMember) {
|
||||||
const guildSettings = await Database.getGuildSettings(member.guild.id);
|
const guildSettings = await Database.getGuildSettings(member.guild.id);
|
||||||
@@ -9,14 +10,14 @@ export async function handleMemberJoin(member: GuildMember) {
|
|||||||
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) {
|
||||||
const content = `${member.toString()}'s e621 and discord account(s):\n${await getE621Alts(member.id)}`;
|
const content = `${member.toString()}'s e621 and discord account(s):\n${await getE621Alts(member.id, member.guild)}`;
|
||||||
|
|
||||||
channel.send(content).catch(console.error);
|
channel.send(content).catch(console.error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getE621Alts(discordId: string, depth = 1, ignore: number[] = []): Promise<string> {
|
async function getE621Alts(discordId: string, guild: Guild, depth = 1, ignore: number[] = []): Promise<string> {
|
||||||
const e621UserIds = await Database.getE621Ids(discordId);
|
const e621UserIds = await Database.getE621Ids(discordId);
|
||||||
|
|
||||||
const toIgnore = ignore.concat(e621UserIds);
|
const toIgnore = ignore.concat(e621UserIds);
|
||||||
@@ -25,21 +26,28 @@ async function getE621Alts(discordId: string, depth = 1, ignore: number[] = []):
|
|||||||
|
|
||||||
for (const e621Id of e621UserIds) {
|
for (const e621Id of e621UserIds) {
|
||||||
if (ignore.includes(e621Id)) continue;
|
if (ignore.includes(e621Id)) continue;
|
||||||
content += `${'- '.repeat(depth)}${config.E621_BASE_URL}/users/${e621Id}\n${await getDiscordAlts(e621Id, depth + 1, toIgnore)}`;
|
|
||||||
|
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;
|
return content;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getDiscordAlts(e621Id: number, depth = 1, ignore: number[] = []): Promise<string> {
|
async function getDiscordAlts(e621Id: number, guild: Guild, depth = 1, ignore: number[] = []): Promise<string> {
|
||||||
const discordIds = await Database.getDiscordIds(e621Id);
|
const discordIds = await Database.getDiscordIds(e621Id);
|
||||||
|
|
||||||
let content = '';
|
let content = '';
|
||||||
|
|
||||||
for (const discordId of discordIds) {
|
for (const discordId of discordIds) {
|
||||||
const alts = await getE621Alts(discordId, depth + 1, ignore);
|
const alts = await getE621Alts(discordId, guild, depth + 1, ignore);
|
||||||
|
|
||||||
if (alts) content += `${'- '.repeat(depth)}<@${discordId}>\n${alts}`;
|
const banned = await guild.bans.fetch(discordId);
|
||||||
|
|
||||||
|
content += `${'- '.repeat(depth)}<@${discordId}>${banned ? ' [BANNED]' : ''}\n${alts}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
return content;
|
return content;
|
||||||
|
|||||||
@@ -58,3 +58,8 @@ export function getPostUrl(post: E621Post): string {
|
|||||||
if (post.rating == 's') return `${config.E926_BASE_URL}/post/${post.id}`;
|
if (post.rating == 's') return `${config.E926_BASE_URL}/post/${post.id}`;
|
||||||
return `${config.E621_BASE_URL}/post/${post.id}`;
|
return `${config.E621_BASE_URL}/post/${post.id}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function userIsBanned(idOrName: string | number): Promise<boolean> {
|
||||||
|
const user = await getE621User(idOrName);
|
||||||
|
return user?.is_banned ?? false;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user