diff options
author | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-07-02 19:33:29 -0400 |
---|---|---|
committer | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-07-02 19:33:29 -0400 |
commit | 34f0d1d3ff3e2a90193c9a4d4de29d8335160d6a (patch) | |
tree | f5a069b332b649f510aac741ae2484e853efc6a2 /src/commands/moderation/ban.ts | |
parent | 6c3ab0e2e4239a2122d1d8ce8ed7bc9673fdde6a (diff) | |
download | tanzanite-34f0d1d3ff3e2a90193c9a4d4de29d8335160d6a.tar.gz tanzanite-34f0d1d3ff3e2a90193c9a4d4de29d8335160d6a.tar.bz2 tanzanite-34f0d1d3ff3e2a90193c9a4d4de29d8335160d6a.zip |
started restructuring moderation commands,
note: nothing currently works :flushed:
Diffstat (limited to 'src/commands/moderation/ban.ts')
-rw-r--r-- | src/commands/moderation/ban.ts | 224 |
1 files changed, 103 insertions, 121 deletions
diff --git a/src/commands/moderation/ban.ts b/src/commands/moderation/ban.ts index 29dc8a6..f3cc1e2 100644 --- a/src/commands/moderation/ban.ts +++ b/src/commands/moderation/ban.ts @@ -1,17 +1,5 @@ -import { Argument } from 'discord-akairo'; -import { CommandInteraction, Message, User } from 'discord.js'; -import moment from 'moment'; +import { Message, User } from 'discord.js'; import { BushCommand } from '../../lib/extensions/discord-akairo/BushCommand'; -import { Ban, Guild, ModLog, ModLogType } from '../../lib/models'; - -/* const durationAliases: Record<string, string[]> = { - weeks: ['w', 'weeks', 'week', 'wk', 'wks'], - days: ['d', 'days', 'day'], - hours: ['h', 'hours', 'hour', 'hr', 'hrs'], - minutes: ['m', 'min', 'mins', 'minutes', 'minute'], - months: ['mo', 'month', 'months'] -}; -const durationRegex = /(?:(\d+)(d(?:ays?)?|h(?:ours?|rs?)?|m(?:inutes?|ins?)?|mo(?:nths?)?|w(?:eeks?|ks?)?)(?: |$))/g; */ export default class BanCommand extends BushCommand { public constructor() { @@ -29,18 +17,13 @@ export default class BanCommand extends BushCommand { }, { id: 'reason', + type: 'contentWithDuration', match: 'restContent', prompt: { start: 'Why would you like to ban this user?', retry: '{error} Choose a ban reason.', optional: true } - }, - { - id: 'time', - type: 'duration', - match: 'option', - flag: '--time' } ], clientPermissions: ['BAN_MEMBERS'], @@ -62,113 +45,112 @@ export default class BanCommand extends BushCommand { name: 'reason', description: 'Why are they getting banned?', required: false - }, - { - type: 'STRING', - name: 'time', - description: 'How long should they be banned for?', - required: false } ], slash: true }); } - async *genResponses( - message: Message | CommandInteraction, - user: User, - reason?: string, - time?: number - ): AsyncIterable<string> { - const duration = moment.duration(); - let modLogEntry: ModLog; - let banEntry: Ban; - // const translatedTime: string[] = []; - // Create guild entry so postgres doesn't get mad when I try and add a modlog entry - await Guild.findOrCreate({ - where: { - id: message.guild.id - }, - defaults: { - id: message.guild.id - } - }); - try { - if (time) { - duration.add(time); - /* const parsed = [...time.matchAll(durationRegex)]; - if (parsed.length < 1) { - yield `${this.client.util.emojis.error} Invalid time.`; - return; - } - for (const part of parsed) { - const translated = Object.keys(durationAliases).find((k) => durationAliases[k].includes(part[2])); - translatedTime.push(part[1] + ' ' + translated); - duration.add(Number(part[1]), translated as 'weeks' | 'days' | 'hours' | 'months' | 'minutes'); - } */ - modLogEntry = ModLog.build({ - user: user.id, - guild: message.guild.id, - reason, - type: ModLogType.TEMP_BAN, - duration: duration.asMilliseconds(), - moderator: message instanceof CommandInteraction ? message.user.id : message.author.id - }); - banEntry = Ban.build({ - user: user.id, - guild: message.guild.id, - reason, - expires: new Date(new Date().getTime() + duration.asMilliseconds()), - modlog: modLogEntry.id - }); - } else { - modLogEntry = ModLog.build({ - user: user.id, - guild: message.guild.id, - reason, - type: ModLogType.BAN, - moderator: message instanceof CommandInteraction ? message.user.id : message.author.id - }); - banEntry = Ban.build({ - user: user.id, - guild: message.guild.id, - reason, - modlog: modLogEntry.id - }); - } - await modLogEntry.save(); - await banEntry.save(); + // async *genResponses( + // message: Message | CommandInteraction, + // user: User, + // reason?: string, + // time?: number + // ): AsyncIterable<string> { + // const duration = moment.duration(); + // let modLogEntry: ModLog; + // let banEntry: Ban; + // // const translatedTime: string[] = []; + // // Create guild entry so postgres doesn't get mad when I try and add a modlog entry + // await Guild.findOrCreate({ + // where: { + // id: message.guild.id + // }, + // defaults: { + // id: message.guild.id + // } + // }); + // try { + // if (time) { + // duration.add(time); + // /* const parsed = [...time.matchAll(durationRegex)]; + // if (parsed.length < 1) { + // yield `${this.client.util.emojis.error} Invalid time.`; + // return; + // } + // for (const part of parsed) { + // const translated = Object.keys(durationAliases).find((k) => durationAliases[k].includes(part[2])); + // translatedTime.push(part[1] + ' ' + translated); + // duration.add(Number(part[1]), translated as 'weeks' | 'days' | 'hours' | 'months' | 'minutes'); + // } */ + // modLogEntry = ModLog.build({ + // user: user.id, + // guild: message.guild.id, + // reason, + // type: ModLogType.TEMP_BAN, + // duration: duration.asMilliseconds(), + // moderator: message instanceof CommandInteraction ? message.user.id : message.author.id + // }); + // banEntry = Ban.build({ + // user: user.id, + // guild: message.guild.id, + // reason, + // expires: new Date(new Date().getTime() + duration.asMilliseconds()), + // modlog: modLogEntry.id + // }); + // } else { + // modLogEntry = ModLog.build({ + // user: user.id, + // guild: message.guild.id, + // reason, + // type: ModLogType.BAN, + // moderator: message instanceof CommandInteraction ? message.user.id : message.author.id + // }); + // banEntry = Ban.build({ + // user: user.id, + // guild: message.guild.id, + // reason, + // modlog: modLogEntry.id + // }); + // } + // await modLogEntry.save(); + // await banEntry.save(); - try { - await user.send( - `You were banned in ${message.guild.name} ${duration ? duration.humanize() : 'permanently'} with reason \`${ - reason || 'No reason given' - }\`` - ); - } catch { - yield `${this.client.util.emojis.warn} Unable to dm user`; - } - await message.guild.members.ban(user, { - reason: `Banned by ${message instanceof CommandInteraction ? message.user.tag : message.author.tag} with ${ - reason ? `reason ${reason}` : 'no reason' - }` - }); - yield `${this.client.util.emojis.success} Banned <@!${user.id}> ${ - duration ? duration.humanize() : 'permanently' - } with reason \`${reason || 'No reason given'}\``; - } catch { - yield `${this.client.util.emojis.error} Error banning :/`; - await banEntry.destroy(); - await modLogEntry.destroy(); - return; - } - } - async exec(message: Message, { user, reason, time }: { user: User; reason?: string; time?: number | string }): Promise<void> { - if (typeof time === 'string') { - time = (await Argument.cast('duration', this.client.commandHandler.resolver, message, time)) as number; - //// time = this.client.commandHandler.resolver.type('duration') - } - for await (const response of this.genResponses(message, user, reason, time)) { - await message.util.send(response); - } + // try { + // await user.send( + // `You were banned in ${message.guild.name} ${duration ? duration.humanize() : 'permanently'} with reason \`${ + // reason || 'No reason given' + // }\`` + // ); + // } catch { + // yield `${this.client.util.emojis.warn} Unable to dm user`; + // } + // await message.guild.members.ban(user, { + // reason: `Banned by ${message instanceof CommandInteraction ? message.user.tag : message.author.tag} with ${ + // reason ? `reason ${reason}` : 'no reason' + // }` + // }); + // yield `${this.client.util.emojis.success} Banned <@!${user.id}> ${ + // duration ? duration.humanize() : 'permanently' + // } with reason \`${reason || 'No reason given'}\``; + // } catch { + // yield `${this.client.util.emojis.error} Error banning :/`; + // await banEntry.destroy(); + // await modLogEntry.destroy(); + // return; + // } + // } + async exec( + message: Message, + { user, reason, time }: { user: User; reason?: string; time?: number | string } + ): Promise<unknown> { + return message.util.reply(`${this.client.util.emojis.error} This command is not finished.`); + + // if (typeof time === 'string') { + // time = (await Argument.cast('duration', this.client.commandHandler.resolver, message, time)) as number; + // //// time = this.client.commandHandler.resolver.type('duration') + // } + // for await (const response of this.genResponses(message, user, reason, time)) { + // await message.util.send(response); + // } } } |