From 34f0d1d3ff3e2a90193c9a4d4de29d8335160d6a Mon Sep 17 00:00:00 2001 From: IRONM00N <64110067+IRONM00N@users.noreply.github.com> Date: Fri, 2 Jul 2021 19:33:29 -0400 Subject: started restructuring moderation commands, note: nothing currently works :flushed: --- src/commands/moderation/ban.ts | 224 ++++++++++++++++------------------ src/commands/moderation/kick.ts | 125 ++++++++++--------- src/commands/moderation/modlog.ts | 137 +++++++-------------- src/commands/moderation/mute.ts | 246 +++++++++++++++++++++----------------- src/commands/moderation/warn.ts | 5 +- 5 files changed, 346 insertions(+), 391 deletions(-) (limited to 'src/commands/moderation') 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 = { - 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 { - 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 { + // 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 { - 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 { + 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); + // } } } diff --git a/src/commands/moderation/kick.ts b/src/commands/moderation/kick.ts index 09d6abf..df538bc 100644 --- a/src/commands/moderation/kick.ts +++ b/src/commands/moderation/kick.ts @@ -1,7 +1,5 @@ -import { CommandInteraction, GuildMember, Message } from 'discord.js'; +import { GuildMember, Message } from 'discord.js'; import { BushCommand } from '../../lib/extensions/discord-akairo/BushCommand'; -import { BushSlashMessage } from '../../lib/extensions/discord-akairo/BushSlashMessage'; -import { Guild, ModLog, ModLogType } from '../../lib/models'; export default class KickCommand extends BushCommand { public constructor() { @@ -20,7 +18,12 @@ export default class KickCommand extends BushCommand { { id: 'reason', type: 'string', - match: 'restContent' + match: 'restContent', + prompt: { + start: 'Why would you like to kick this user?', + retry: '{error} Choose a valid user to kick.', + optional: true + } } ], clientPermissions: ['KICK_MEMBERS'], @@ -28,19 +31,19 @@ export default class KickCommand extends BushCommand { description: { content: 'Kick a member from the server.', usage: 'kick ', - examples: ['kick @Tyman being cool'] + examples: ['kick @user bad'] }, slashOptions: [ { type: 'USER', name: 'user', - description: 'The user to kick', + description: 'What user would you like to kick?', required: true }, { type: 'STRING', name: 'reason', - description: 'The reason to show in modlogs and audit log', + description: 'Why would you like to kick this user?', required: false } ], @@ -48,63 +51,59 @@ export default class KickCommand extends BushCommand { }); } - private async *genResponses( - message: Message | CommandInteraction, - user: GuildMember, - reason?: string - ): AsyncIterable { - let modlogEnry: ModLog; - // 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 { - modlogEnry = ModLog.build({ - user: user.id, - guild: message.guild.id, - moderator: message instanceof Message ? message.author.id : message.user.id, - type: ModLogType.KICK, - reason - }); - await modlogEnry.save(); - } catch (e) { - this.client.console.error(`KickCommand`, `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 kicked in ${message.guild.name} with reason \`${reason || 'No reason given'}\``); - } catch (e) { - yield `${this.client.util.emojis.warn} Unable to dm user`; - } - try { - await user.kick( - `Kicked by ${message instanceof Message ? message.author.tag : message.user.tag} with ${ - reason ? `reason ${reason}` : 'no reason' - }` - ); - } catch { - yield `${this.client.util.emojis.error} Error kicking :/`; - await modlogEnry.destroy(); - return; - } - yield `${this.client.util.emojis.success} Kicked <@!${user.id}> with reason \`${reason || 'No reason given'}\``; - } + // private async *genResponses( + // message: Message | CommandInteraction, + // user: GuildMember, + // reason?: string + // ): AsyncIterable { + // let modlogEnry: ModLog; + // // 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 { + // modlogEnry = ModLog.build({ + // user: user.id, + // guild: message.guild.id, + // moderator: message instanceof Message ? message.author.id : message.user.id, + // type: ModLogType.KICK, + // reason + // }); + // await modlogEnry.save(); + // } catch (e) { + // this.client.console.error(`KickCommand`, `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 kicked in ${message.guild.name} with reason \`${reason || 'No reason given'}\``); + // } catch (e) { + // yield `${this.client.util.emojis.warn} Unable to dm user`; + // } + // try { + // await user.kick( + // `Kicked by ${message instanceof Message ? message.author.tag : message.user.tag} with ${ + // reason ? `reason ${reason}` : 'no reason' + // }` + // ); + // } catch { + // yield `${this.client.util.emojis.error} Error kicking :/`; + // await modlogEnry.destroy(); + // return; + // } + // yield `${this.client.util.emojis.success} Kicked <@!${user.id}> with reason \`${reason || 'No reason given'}\``; + // } - async exec(message: Message, { user, reason }: { user: GuildMember; reason?: string }): Promise { - for await (const response of this.genResponses(message, user, reason)) { - await message.util.send(response); - } - } + async exec(message: Message, { user, reason }: { user: GuildMember; reason?: string }): Promise { + return message.util.reply(`${this.client.util.emojis.error} This command is not finished.`); - async execSlash(message: BushSlashMessage, { user, reason }: { user: GuildMember; reason?: string }): Promise { - for await (const response of this.genResponses(message.interaction, user, reason)) { - await message.interaction.reply(response); - } + // for await (const response of this.genResponses(message, user, reason)) { + // await message.util.send(response); + // } } } diff --git a/src/commands/moderation/modlog.ts b/src/commands/moderation/modlog.ts index d094885..2f7601b 100644 --- a/src/commands/moderation/modlog.ts +++ b/src/commands/moderation/modlog.ts @@ -1,8 +1,8 @@ -import { stripIndent } from 'common-tags'; import { Argument } from 'discord-akairo'; -import { Message, MessageEmbed } from 'discord.js'; +import { MessageEmbed } from 'discord.js'; import moment from 'moment'; import { BushCommand } from '../../lib/extensions/discord-akairo/BushCommand'; +import { BushMessage } from '../../lib/extensions/discord.js/BushMessage'; import { ModLog } from '../../lib/models'; export default class ModlogCommand extends BushCommand { @@ -10,50 +10,47 @@ export default class ModlogCommand extends BushCommand { super('modlog', { aliases: ['modlog', 'modlogs'], category: 'moderation', + description: { + content: "View a user's modlogs, or view a specific case.", + usage: 'modlogs ', + examples: ['modlogs @Tyman'] + }, args: [ { id: 'search', + type: Argument.union('user', 'string'), prompt: { - start: 'What modlog id or user would you like to see?' + start: 'What case id or user would you like to see?', + retry: '{error} Choose a valid case id or user.' } - }, - { - id: 'page', - type: 'number' } ], userPermissions: ['MANAGE_MESSAGES'], - description: { - content: "View a user's modlogs, or view a specific modlog entry", - usage: 'warn [page]', - examples: ['modlogs @Tyman', 'modlogs @Tyman 3'] - } + slash: true, + slashOptions: [ + { + name: 'search', + description: 'What case id or user would you like to see?', + type: 'STRING', + required: true + } + ] }); } - *args(): unknown { - const search = yield { - id: 'search', - type: Argument.union('user', 'string'), - prompt: { - start: 'What modlog id or user would you like to see?', - retry: '{error} Choose a valid modlog id or user.' - } - }; - if (typeof search === 'string') return { search, page: null }; - else { - const page = yield { - id: 'page', - type: 'number', - prompt: { - start: 'What page?', - retry: '{error} Choose a valid page to view.', - optional: true - } - }; - return { search, page }; - } + + private generateModlogInfo(log: ModLog) { + const modLog = [ + `**Case ID**: ${log.id}`, + `**Type**: ${log.type.toLowerCase()}`, + `**User**: <@!${log.user}> (${log.user})`, + `**Moderator**: <@!${log.moderator}> (${log.moderator})` + ]; + if (log.duration) modLog.push(`**Duration**: ${moment.duration(log.duration, 'milliseconds').humanize()}`); + modLog.push(`**Reason**: ${log.reason || 'No Reason Specified.'}`); + return modLog.join(`\n`); } - async exec(message: Message, { search, page }: { search: string; page: number }): Promise { + + async exec(message: BushMessage, { search }: { search: string }): Promise { const foundUser = await this.client.util.resolveUserAsync(search); if (foundUser) { const logs = await ModLog.findAll({ @@ -65,75 +62,27 @@ export default class ModlogCommand extends BushCommand { }); const niceLogs: string[] = []; for (const log of logs) { - niceLogs.push(stripIndent` - **Case ID**: ${log.id} - **Type**: ${log.type.toLowerCase()} - **User**: <@!${log.user}> (${log.user}) - **Moderator**: <@!${log.moderator}> (${log.moderator}) - **Duration**: ${log.duration ? moment.duration(log.duration, 'milliseconds').humanize() : 'N/A'} - **Reason**: ${log.reason || 'None given'} - **${this.client.util.ordinal(logs.indexOf(log) + 1)}** action - `); + niceLogs.push(this.generateModlogInfo(log)); } const chunked: string[][] = this.client.util.chunk(niceLogs, 3); const embedPages = chunked.map( - (e, i) => + (chunk) => new MessageEmbed({ - title: foundUser.tag, - description: e.join('\n**---------------------------**\n'), - footer: { - text: `Page ${i + 1}/${chunked.length}` - }, + title: `${foundUser.tag}'s Mod Logs`, + description: chunk.join('\n**―――――――――――――――――――――――――――**\n'), color: this.client.util.colors.default }) ); - if (page) { - await message.util.send({ embeds: [embedPages[page - 1]] }); - return; - } else { - await message.util.send({ embeds: [embedPages[0]] }); - return; - } + this.client.util.buttonPaginate(message, embedPages, '', true); } else if (search) { const entry = await ModLog.findByPk(search); - if (!entry) { - await message.util.send(`${this.client.util.emojis.error} That modlog does not exist.`); - return; - } - await message.util.send({ - embeds: [ - new MessageEmbed({ - title: `${entry.id}`, - fields: [ - { - name: 'Type', - value: entry.type.toLowerCase(), - inline: true - }, - { - name: 'Duration', - value: `${entry.duration ? moment.duration(entry.duration, 'milliseconds').humanize() : 'N/A'}`, - inline: true - }, - { - name: 'Reason', - value: `${entry.reason || 'None given'}`, - inline: true - }, - { - name: 'Moderator', - value: `<@!${entry.moderator}> (${entry.moderator})`, - inline: true - }, - { - name: 'User', - value: `<@!${entry.user}> (${entry.user})`, - inline: true - } - ] - }) - ] + if (!entry) return message.util.send(`${this.client.util.emojis.error} That modlog does not exist.`); + const embed = new MessageEmbed({ + title: `Case ${entry.id}`, + description: this.generateModlogInfo(entry), + color: this.client.util.colors.default }); + return await this.client.util.buttonPaginate(message, [embed]); } } } 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 { - 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 { + // 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 { - this.client.console.debug(reason); + message: BushMessage, + { user, reason }: { user: BushUser; reason?: { duration: number; contentWithoutTime: string } } + ): Promise { + 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')}.` + ); } } } diff --git a/src/commands/moderation/warn.ts b/src/commands/moderation/warn.ts index c146db0..d70c9f0 100644 --- a/src/commands/moderation/warn.ts +++ b/src/commands/moderation/warn.ts @@ -15,6 +15,7 @@ export default class WarnCommand extends BushCommand { }, { id: 'reason', + type: 'contentWithDuration', match: 'rest' } ], @@ -25,7 +26,9 @@ export default class WarnCommand extends BushCommand { } }); } - public async exec(message: Message, { member, reason }: { member: GuildMember; reason: string }): Promise { + public async exec(message: Message, { member, reason }: { member: GuildMember; reason: string }): Promise { + return message.util.reply(`${this.client.util.emojis.error} This command is not finished.`); + // Create guild entry so postgres doesn't get mad when I try and add a modlog entry await Guild.findOrCreate({ where: { -- cgit