aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTymanWasTaken <32660892+TymanWasTaken@users.noreply.github.com>2022-03-07 20:44:54 -0700
committerGitHub <noreply@github.com>2022-03-07 22:44:54 -0500
commit18ed79d5ee2b79988eba61b3f87c7698c53b25e7 (patch)
tree41eef74395527ea435310479dcb4a5febaa2b70d
parent6231a857f6ec263f06598bafb3cc3a3a2511bcb3 (diff)
downloadtanzanite-18ed79d5ee2b79988eba61b3f87c7698c53b25e7.tar.gz
tanzanite-18ed79d5ee2b79988eba61b3f87c7698c53b25e7.tar.bz2
tanzanite-18ed79d5ee2b79988eba61b3f87c7698c53b25e7.zip
Appeal listener (#57)
-rw-r--r--src/listeners/bush/appealListener.ts75
1 files changed, 75 insertions, 0 deletions
diff --git a/src/listeners/bush/appealListener.ts b/src/listeners/bush/appealListener.ts
new file mode 100644
index 0000000..3ed8861
--- /dev/null
+++ b/src/listeners/bush/appealListener.ts
@@ -0,0 +1,75 @@
+/* eslint-disable no-control-regex */
+import { BushListener, ModLog, type BushClientEvents } from '#lib';
+
+export default class AppealListener extends BushListener {
+ public constructor() {
+ super('appealListener', {
+ emitter: 'client',
+ event: 'messageCreate',
+ category: 'bush'
+ });
+ }
+
+ public override async exec(...[message]: BushClientEvents['messageCreate']): Promise<void> {
+ 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;
+ const thread = await message.startThread({
+ 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({
+ embeds: [
+ this.client.util
+ .embed()
+ .setTitle(
+ `${message.embeds[0].fields!.find((f) => f.name === 'What type of punishment are you appealing?')!.value} appeal`
+ )
+ .addFields({
+ name: 'Author',
+ value: 'Unable to fetch author, ID was likely invalid'
+ })
+ ]
+ });
+ } else {
+ const latestModlog = await ModLog.findOne({
+ 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'
+ })
+ ]
+ });
+ }
+ }
+}