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/mute.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/mute.ts')
-rw-r--r-- | src/commands/moderation/mute.ts | 246 |
1 files changed, 134 insertions, 112 deletions
diff --git a/src/commands/moderation/mute.ts b/src/commands/moderation/mute.ts index 3496489..ffad432 100644 --- a/src/commands/moderation/mute.ts +++ b/src/commands/moderation/mute.ts @@ -1,8 +1,8 @@ import { Argument } from 'discord-akairo'; -import { CommandInteraction, Message, User } from 'discord.js'; -import moment from 'moment'; import { BushCommand } from '../../lib/extensions/discord-akairo/BushCommand'; -import { Guild, ModLog, ModLogType, Mute } from '../../lib/models'; +import { BushGuildMember } from '../../lib/extensions/discord.js/BushGuildMember'; +import { BushMessage } from '../../lib/extensions/discord.js/BushMessage'; +import { BushUser } from '../../lib/extensions/discord.js/BushUser'; export default class MuteCommand extends BushCommand { public constructor() { @@ -20,18 +20,13 @@ export default class MuteCommand extends BushCommand { }, { id: 'reason', - match: 'separate', + type: 'contentWithDuration', + match: 'rest', prompt: { start: 'Why would you like to mute this user?', - retry: '{error} Choose a mute reason.', + retry: '{error} Choose a mute reason and duration.', optional: true } - }, - { - id: 'time', - type: 'duration', - match: 'option', - flag: '--time' } ], clientPermissions: ['MANAGE_ROLES'], @@ -51,116 +46,143 @@ export default class MuteCommand extends BushCommand { { type: 'STRING', name: 'reason', - description: 'Why the user is getting muted.', - required: false - }, - { - type: 'STRING', - name: 'time', - description: 'How long the user should be muted for.', + description: 'Why is the user is getting muted, and how long should they be muted for?', required: false } ], slash: true }); } - async *genResponses( - message: Message | CommandInteraction, - user: User, - reason?: string, - time?: number - ): AsyncIterable<string> { - const duration = moment.duration(time); - let modlogEnry: ModLog; - let muteEntry: Mute; - // 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 { - const muteRole = (await Guild.findByPk(message.guild.id)).get('muteRole'); - try { - if (time) { - modlogEnry = ModLog.build({ - user: user.id, - guild: message.guild.id, - reason, - type: ModLogType.TEMP_MUTE, - duration: duration.asMilliseconds(), - moderator: message instanceof CommandInteraction ? message.user.id : message.author.id - }); - muteEntry = Mute.build({ - user: user.id, - guild: message.guild.id, - reason, - expires: new Date(new Date().getTime() + duration.asMilliseconds()), - modlog: modlogEnry.id - }); - } else { - modlogEnry = ModLog.build({ - user: user.id, - guild: message.guild.id, - reason, - type: ModLogType.MUTE, - moderator: message instanceof CommandInteraction ? message.user.id : message.author.id - }); - muteEntry = Mute.build({ - user: user.id, - guild: message.guild.id, - reason, - modlog: modlogEnry.id - }); - } - await modlogEnry.save(); - await muteEntry.save(); - } catch (e) { - this.client.console.error(`MuteCommand`, `Error saving to database. ${e?.stack}`); - yield `${this.client.util.emojis.error} Error saving to database. Please report this to a developer.`; - return; - } - try { - await user.send( - `You were muted in ${message.guild.name} ${time ? `for ${duration.humanize()}` : 'permanently'} with reason \`${ - reason || 'No reason given' - }\`` - ); - } catch (e) { - yield `${this.client.util.emojis.warn} Unable to dm user`; - } - await ( - await message.guild.members.fetch(user) - ).roles.add( - muteRole, - `Muted by ${message instanceof CommandInteraction ? message.user.tag : message.author.tag} with ${ - reason ? `reason ${reason}` : 'no reason' - }` - ); - yield `${this.client.util.emojis.success} muted <@!${user.id}> ${ - time ? `for ${duration.humanize()}` : 'permanently' - } with reason \`${reason || 'No reason given'}\``; - } catch { - yield `${this.client.util.emojis.error} Error muting :/`; - await muteEntry.destroy(); - await modlogEnry.destroy(); - return; - } - } + // async *genResponses( + // message: Message | CommandInteraction, + // user: User, + // reason?: string, + // time?: number + // ): AsyncIterable<string> { + // const duration = moment.duration(time); + // let modlogEnry: ModLog; + // let muteEntry: Mute; + // // 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 { + // const muteRole = (await Guild.findByPk(message.guild.id)).get('muteRole'); + // try { + // if (time) { + // modlogEnry = ModLog.build({ + // user: user.id, + // guild: message.guild.id, + // reason, + // type: ModLogType.TEMP_MUTE, + // duration: duration.asMilliseconds(), + // moderator: message instanceof CommandInteraction ? message.user.id : message.author.id + // }); + // muteEntry = Mute.build({ + // user: user.id, + // guild: message.guild.id, + // reason, + // expires: new Date(new Date().getTime() + duration.asMilliseconds()), + // modlog: modlogEnry.id + // }); + // } else { + // modlogEnry = ModLog.build({ + // user: user.id, + // guild: message.guild.id, + // reason, + // type: ModLogType.MUTE, + // moderator: message instanceof CommandInteraction ? message.user.id : message.author.id + // }); + // muteEntry = Mute.build({ + // user: user.id, + // guild: message.guild.id, + // reason, + // modlog: modlogEnry.id + // }); + // } + // await modlogEnry.save(); + // await muteEntry.save(); + // } catch (e) { + // this.client.console.error(`MuteCommand`, `Error saving to database. ${e?.stack}`); + // yield `${this.client.util.emojis.error} Error saving to database. Please report this to a developer.`; + // return; + // } + // try { + // await user.send( + // `You were muted in ${message.guild.name} ${time ? `for ${duration.humanize()}` : 'permanently'} with reason \`${ + // reason || 'No reason given' + // }\`` + // ); + // } catch (e) { + // yield `${this.client.util.emojis.warn} Unable to dm user`; + // } + // await ( + // await message.guild.members.fetch(user) + // ).roles.add( + // muteRole, + // `Muted by ${message instanceof CommandInteraction ? message.user.tag : message.author.tag} with ${ + // reason ? `reason ${reason}` : 'no reason' + // }` + // ); + // yield `${this.client.util.emojis.success} muted <@!${user.id}> ${ + // time ? `for ${duration.humanize()}` : 'permanently' + // } with reason \`${reason || 'No reason given'}\``; + // } catch { + // yield `${this.client.util.emojis.error} Error muting :/`; + // await muteEntry.destroy(); + // await modlogEnry.destroy(); + // return; + // } + // } async exec( - message: Message, - { user, reason, time }: { user: User; reason?: string[]; time?: string | number } - ): Promise<void> { - this.client.console.debug(reason); + message: BushMessage, + { user, reason }: { user: BushUser; reason?: { duration: number; contentWithoutTime: string } } + ): Promise<unknown> { + return message.util.reply(`${this.client.util.emojis.error} This command is not finished.`); + // this.client.console.debug(reason); - if (typeof time === 'string') { - time = (await Argument.cast('duration', this.client.commandHandler.resolver, message, time)) as number; + // if (typeof time === 'string') { + // time = (await Argument.cast('duration', this.client.commandHandler.resolver, message, time)) as number; + // } + // for await (const response of this.genResponses(message, user, reason.join(' '), time)) { + // await message.util.sendNew(response); + // } + + const member = message.guild.members.cache.get(user.id) as BushGuildMember; + if (!this.client.util.moderatorCanModerateUser(message.member, member)) { + return message.util.reply({ + content: `${this.client.util.emojis.error} You cannot mute **${member.user.tag}**.` + }); } - for await (const response of this.genResponses(message, user, reason.join(' '), time)) { - await message.util.sendNew(response); + + const time = + typeof reason === 'string' + ? //@ts-ignore: you are unreachable bitch + await Argument.cast('duration', this.client.commandHandler.resolver, message, reason) + : reason.duration; + const parsedReason = reason.contentWithoutTime; + + const response = await member.mute({ + reason: parsedReason, + moderator: message.author, + duration: time, + createModLogEntry: true + }); + + switch (response) { + case 'success': + return message.util.reply(`${this.client.util.emojis.success} Successfully muted **${member.user.tag}**.`); + case 'no mute role': + return message.util.reply( + `${this.client.util.emojis.error} Could not mute **${ + member.user.tag + }**, you must set a mute role with ${message.guild.getSetting('prefix')}.` + ); } } } |