diff options
Diffstat (limited to 'src/listeners')
-rw-r--r-- | src/listeners/bush/appealListener.ts | 87 |
1 files changed, 46 insertions, 41 deletions
diff --git a/src/listeners/bush/appealListener.ts b/src/listeners/bush/appealListener.ts index 3ed8861..9f6b166 100644 --- a/src/listeners/bush/appealListener.ts +++ b/src/listeners/bush/appealListener.ts @@ -1,5 +1,9 @@ /* eslint-disable no-control-regex */ import { BushListener, ModLog, type BushClientEvents } from '#lib'; +import assert from 'assert'; +import { Embed } from 'discord.js'; +import UserInfoCommand from '../../commands/info/userInfo.js'; +import ModlogCommand from '../../commands/moderation/modlog.js'; export default class AppealListener extends BushListener { public constructor() { @@ -10,66 +14,67 @@ export default class AppealListener extends BushListener { }); } - public override async exec(...[message]: BushClientEvents['messageCreate']): Promise<void> { + public override async exec(...[message]: BushClientEvents['messageCreate']): Promise<any> { + if (!message.inGuild() || message.guildId !== client.consts.mappings.guilds.bush) return; if (message.author.id !== '855446927688335370' || message.embeds.length < 1) return; + const userId = message.embeds[0].fields?.find?.((f) => f.name === 'What is your discord ID?')?.value; if (!userId) return; + assert(message.embeds[0].fields); + const thread = await message.startThread({ - name: `${message.embeds[0].fields!.find((f) => f.name === 'What type of punishment are you appealing?')!.value} appeal` + name: `${message.embeds[0].fields.find((f) => f.name === 'What type of punishment are you appealing?')?.value} appeal` }); - const user = await this.client.users.fetch(userId).catch(() => null); - if (!user) { - await thread.send({ + + const user = await client.users.fetch(userId).catch(() => null); + if (!user) + return await thread.send({ embeds: [ - this.client.util - .embed() + new Embed() + .setTimestamp() + .setColor(util.colors.error) .setTitle( `${message.embeds[0].fields!.find((f) => f.name === 'What type of punishment are you appealing?')!.value} appeal` ) .addFields({ - name: 'Author', + name: '» User Information', value: 'Unable to fetch author, ID was likely invalid' }) ] }); - } else { - const latestModlog = await ModLog.findOne({ + + const latestModlogs = ( + await ModLog.findAll({ where: { user: user.id, guild: message.guildId }, order: [['createdAt', 'DESC']] - }); - await thread.send({ - embeds: [ - this.client.util - .embed() - .setTitle( - `${message.embeds[0].fields!.find((f) => f.name === 'What type of punishment are you appealing?')!.value} appeal` - ) - .addField({ - name: 'Author', - value: `${user} (${user.tag})` - }) - .addField({ - name: 'Latest modlog', - value: latestModlog - ? ` - Case ID: ${latestModlog.id} - Moderator: <@${latestModlog.moderator}> (${ - (await this.client.users - .fetch(latestModlog.moderator) - .then((u) => u.tag) - .catch(() => null)) ?? latestModlog.moderator - }) - Reason: ${latestModlog.reason} - Type: ${latestModlog.type} - Evidence: ${latestModlog.evidence} - `.replace(/\x09/g, '') - : 'No modlogs found' - }) - ] - }); + }) + ) + .slice(0, 3) + .reverse(); + + const embed = new Embed() + .setTimestamp() + .setColor(util.colors.default) + .setTitle(`${message.embeds[0].fields!.find((f) => f.name === 'What type of punishment are you appealing?')!.value} appeal`) + .setThumbnail(user.displayAvatarURL()); + + await UserInfoCommand.generateGeneralInfoField(embed, user, '» User Information'); + + member: { + if (!message.guild.members.cache.has(user.id)) break member; + const member = message.guild.members.cache.get(user.id)!; + UserInfoCommand.generateServerInfoField(embed, member); + if (member.roles.cache.size > 1) UserInfoCommand.generateRolesField(embed, member); } + + embed.addFields({ + name: '» Latest Modlogs', + value: latestModlogs.map((ml) => ModlogCommand.generateModlogInfo(ml, false)).join('\n') ?? 'No Modlogs Found' + }); + + await thread.send({ embeds: [embed] }); } } |