diff options
author | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-06-14 22:51:48 -0400 |
---|---|---|
committer | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-06-14 22:51:48 -0400 |
commit | d055e0dbb86ef7fd4ee96a1531b51181e825fb4b (patch) | |
tree | e2ed9e956f2d8167e7f225383f9917e66d2a2803 /src/commands | |
parent | 335f7c30994fc8c4e787f407dfd4c2de63b400e3 (diff) | |
download | tanzanite-d055e0dbb86ef7fd4ee96a1531b51181e825fb4b.tar.gz tanzanite-d055e0dbb86ef7fd4ee96a1531b51181e825fb4b.tar.bz2 tanzanite-d055e0dbb86ef7fd4ee96a1531b51181e825fb4b.zip |
made a few changes
Diffstat (limited to 'src/commands')
-rw-r--r-- | src/commands/dev/eval.ts | 213 | ||||
-rw-r--r-- | src/commands/dev/reload.ts | 10 | ||||
-rw-r--r-- | src/commands/dev/setLevel.ts | 13 | ||||
-rw-r--r-- | src/commands/info/botInfo.ts | 13 | ||||
-rw-r--r-- | src/commands/info/help.ts | 14 | ||||
-rw-r--r-- | src/commands/info/ping.ts | 19 | ||||
-rw-r--r-- | src/commands/info/pronouns.ts | 36 | ||||
-rw-r--r-- | src/commands/moderation/ban.ts | 16 | ||||
-rw-r--r-- | src/commands/moderation/kick.ts | 12 | ||||
-rw-r--r-- | src/commands/moderation/modlog.ts | 79 | ||||
-rw-r--r-- | src/commands/moderation/role.ts | 52 | ||||
-rw-r--r-- | src/commands/moulberry-bush/capePerms.ts | 19 | ||||
-rw-r--r-- | src/commands/moulberry-bush/giveawayPing.ts | 19 | ||||
-rw-r--r-- | src/commands/moulberry-bush/level.ts | 10 | ||||
-rw-r--r-- | src/commands/moulberry-bush/rule.ts | 26 | ||||
-rw-r--r-- | src/commands/server-config/prefix.ts | 5 |
16 files changed, 329 insertions, 227 deletions
diff --git a/src/commands/dev/eval.ts b/src/commands/dev/eval.ts index bab5f8e..2f1d45d 100644 --- a/src/commands/dev/eval.ts +++ b/src/commands/dev/eval.ts @@ -1,15 +1,16 @@ /* eslint-disable @typescript-eslint/no-unused-vars */ -import { BushCommand } from '../../lib/extensions/BushCommand'; -import { MessageEmbed, Message } from 'discord.js'; -import { inspect, promisify } from 'util'; import { exec } from 'child_process'; +import { Constants } from 'discord-akairo'; +import { Message, MessageEmbed, MessageEmbedOptions, Util } from 'discord.js'; +import { transpile } from 'typescript'; +import { inspect, promisify } from 'util'; +import { BushCommand } from '../../lib/extensions/BushCommand'; const clean = (text) => { - if (typeof text === 'string') - return text.replace(/`/g, '`' + String.fromCharCode(8203)).replace(/@/g, '@' + String.fromCharCode(8203)); - else return text; + if (typeof text === 'string') { + return (text = Util.cleanCodeBlockContent(text)); + } else return text; }; - export default class EvalCommand extends BushCommand { public constructor() { super('eval', { @@ -17,29 +18,54 @@ export default class EvalCommand extends BushCommand { category: 'dev', description: { content: 'Use the command to eval stuff in the bot.', - usage: 'eval <code> [--silent] [--depth #]', + usage: 'eval [--depth #] <code> [--sudo] [--silent] [--delete] [--proto] [--hidden] [--ts]', examples: ['eval message.guild.name', 'eval this.client.ownerID'] }, args: [ { - id: 'depth', - match: 'option', - type: 'number', + id: 'selDepth', + match: Constants.ArgumentMatches.OPTION, + type: Constants.ArgumentTypes.NUMBER, flag: '--depth', default: 0 }, { + id: 'sudo', + match: Constants.ArgumentMatches.FLAG, + flag: '--sudo' + }, + { + id: 'deleteMSG', + match: Constants.ArgumentMatches.FLAG, + flag: '--delete' + }, + { id: 'silent', - match: 'flag', + match: Constants.ArgumentMatches.FLAG, flag: '--silent' }, { + id: 'typescript', + match: Constants.ArgumentMatches.FLAG, + flag: '--ts' + }, + { + id: 'hidden', + match: Constants.ArgumentMatches.FLAG, + flag: '--hidden' + }, + { + id: 'showProto', + match: Constants.ArgumentMatches.FLAG, + flag: '--proto' + }, + { id: 'code', - match: 'rest', - type: 'string', + match: Constants.ArgumentMatches.REST, + type: Constants.ArgumentTypes.STRING, prompt: { start: 'What would you like to eval?', - retry: 'Invalid code to eval. What would you like to eval?' + retry: '{error} Invalid code to eval.' } } ], @@ -48,11 +74,62 @@ export default class EvalCommand extends BushCommand { }); } + private redactCredentials(old: string) { + const mapping = { + ['token']: 'Token', + ['devToken']: 'Dev Token', + ['MongoDB']: 'MongoDB URI', + ['hypixelApiKey']: 'Hypixel Api Key', + ['webhookID']: 'Webhook ID', + ['webhookToken']: 'Webhook Token' + }; + return mapping[old] || old; + } + public async exec( message: Message, - { depth, code, silent }: { depth: number; code: string; silent: boolean } - ): Promise<void> { + { + selDepth, + code: codeArg, + sudo, + silent, + deleteMSG, + typescript, + hidden, + showProto + }: { + selDepth: number; + code: string; + sudo: boolean; + silent: boolean; + deleteMSG: boolean; + typescript: boolean; + hidden: boolean; + showProto: boolean; + } + ): Promise<unknown> { + if (!this.client.config.owners.includes(message.author.id)) + return await message.channel.send(`${this.client.util.emojis.error} Only my developers can run this command.`); + const code: { js?: string | null; ts?: string | null; lang?: 'js' | 'ts' } = {}; + codeArg = codeArg.replace(/[ββ]/g, '"'); + codeArg = codeArg.replace(/```/g, ''); + if (typescript) { + code.ts = codeArg; + code.js = transpile(codeArg); + code.lang = 'ts'; + } else { + code.ts = null; + code.js = codeArg; + code.lang = 'js'; + } + const embed: MessageEmbed = new MessageEmbed(); + const bad_phrases: string[] = ['delete', 'destroy']; + if (bad_phrases.some((p) => code[code.lang].includes(p)) && !sudo) { + return await message.util.send(`${this.client.util.emojis.error} This eval was blocked by smooth brain protectionβ’.`); + } + const embeds: (MessageEmbed | MessageEmbedOptions)[] = [new MessageEmbed()]; + embeds.some((embed) => embed); try { let output; @@ -62,59 +139,85 @@ export default class EvalCommand extends BushCommand { guild = message.guild, channel = message.channel, config = this.client.config, + members = message.guild.members, + roles = message.guild.roles, sh = promisify(exec), models = this.client.db.models, got = require('got'); // eslint-disable-line @typescript-eslint/no-var-requires - output = eval(code); - output = await output; - if (typeof output !== 'string') output = inspect(output, { depth }); - output = output.replace(new RegExp(this.client.token, 'g'), '[token omitted]'); + if (code[code.lang].replace(/ /g, '').includes('9+10' || '10+9')) { + output = 21; + } else { + output = eval(code.js); + output = await output; + } + let proto, outputProto; + if (showProto) { + proto = Object.getPrototypeOf(output); + outputProto = clean(inspect(proto, { depth: 1, getters: true, showHidden: true })); + } + if (typeof output !== 'string') + output = inspect(output, { depth: selDepth, showHidden: hidden, getters: true, showProxy: true }); + for (const credentialName in this.client.config.credentials) { + const credential = this.client.config.credentials[credentialName]; + const newCredential = this.redactCredentials(credentialName); + output = output.replace( + new RegExp(credential.toString().replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'g'), + `[${newCredential} Omitted]` + ); + output = output.replace( + new RegExp([...credential.toString().replace(/[.*+?^${}()|[\]\\]/g, '\\$&')].reverse().join(''), 'g'), + `[${newCredential} Omitted]` + ); + } + output = clean(output); + const inputJS = clean(code.js); + embed - .setTitle('β
Evaled code successfully') - .addField( - 'π₯ Input', - code.length > 1012 - ? 'Too large to display. Hastebin: ' + (await this.client.util.haste(code)) - : '```js\n' + code + '```' - ) - .addField( - 'π€ Output', - output.length > 1012 - ? 'Too large to display. Hastebin: ' + (await this.client.util.haste(output)) - : '```js\n' + output + '```' - ) - .setColor('#66FF00') - .setFooter(message.author.username, message.author.displayAvatarURL({ dynamic: true })) + .setTitle(`${this.client.util.emojis.successFull} Evaled code successfully`) + .setColor(this.client.util.colors.success) + .setFooter(message.author.tag, message.author.displayAvatarURL({ dynamic: true })) .setTimestamp(); + if (code.lang === 'ts') { + const inputTS = clean(code.ts); + embed + .addField('π₯ Input (typescript)', await this.client.util.codeblock(inputTS, 1024, 'ts')) + .addField('π₯ Input (transpiled javascript)', await this.client.util.codeblock(inputJS, 1024, 'js')); + } else { + embed.addField('π₯ Input', await this.client.util.codeblock(inputJS, 1024, 'js')); + } + embed.addField('π€ Output', await this.client.util.codeblock(output, 1024, 'js')); + if (showProto) embed.addField('βοΈ Proto', await this.client.util.codeblock(outputProto, 1024, 'js')); } catch (e) { + const inputJS = clean(code.js); embed - .setTitle('β Code was not able to be evaled') - .addField( - 'π₯ Input', - code.length > 1012 - ? 'Too large to display. Hastebin: ' + (await this.client.util.haste(code)) - : '```js\n' + code + '```' - ) - .addField( - 'π€ Output', - e.length > 1012 - ? 'Too large to display. Hastebin: ' + (await this.client.util.haste(e)) - : '```js\n' + e + '```Full stack:' + (await this.client.util.haste(e.stack)) - ) - .setColor('#FF0000') - .setFooter(message.author.username, message.author.displayAvatarURL({ dynamic: true })) + .setTitle(`${this.client.util.emojis.errorFull} Code was not able to be evaled.`) + .setColor(this.client.util.colors.error) + .setFooter(message.author.tag, message.author.displayAvatarURL({ dynamic: true })) .setTimestamp(); + if (code.lang === 'ts') { + const inputTS = clean(code.ts); + embed + .addField('π₯ Input (typescript)', await this.client.util.codeblock(inputTS, 1024, 'ts')) + .addField('π₯ Input (transpiled javascript)', await this.client.util.codeblock(inputJS, 1024, 'js')); + } else { + embed.addField('π₯ Input', await this.client.util.codeblock(inputJS, 1024, 'js')); + } + embed.addField('π€ Output', await this.client.util.codeblock(e?.stack, 1024, 'js')); } if (!silent) { - await message.util.send(embed); + await message.util.reply({ embeds: [embed] }); } else { try { - await message.author.send(embed); - await message.react('<a:Check_Mark:790373952760971294>'); + await message.author.send({ embeds: [embed] }); + if (!deleteMSG) await message.react(this.client.util.emojis.successFull); } catch (e) { - await message.react('β'); + if (!deleteMSG) await message.react(this.client.util.emojis.errorFull); } } + + if (deleteMSG && message.deletable) { + await message.delete(); + } } } diff --git a/src/commands/dev/reload.ts b/src/commands/dev/reload.ts index 0cf32ce..3194ce2 100644 --- a/src/commands/dev/reload.ts +++ b/src/commands/dev/reload.ts @@ -1,9 +1,9 @@ -import { BushCommand } from '../../lib/extensions/BushCommand'; import { stripIndent } from 'common-tags'; +import { ApplicationCommandOptionType } from 'discord-api-types'; import { Message } from 'discord.js'; -import { CommandInteraction } from 'discord.js'; +import { BushCommand } from '../../lib/extensions/BushCommand'; +import { BushInteractionMessage } from '../../lib/extensions/BushInteractionMessage'; import { SlashCommandOption } from '../../lib/extensions/Util'; -import { ApplicationCommandOptionType } from 'discord-api-types'; export default class ReloadCommand extends BushCommand { constructor() { @@ -55,7 +55,7 @@ export default class ReloadCommand extends BushCommand { await message.util.send(await this.getResponse(fast)); } - public async execSlash(message: CommandInteraction, { fast }: { fast: SlashCommandOption<boolean> }): Promise<void> { - await message.reply(await this.getResponse(fast?.value)); + public async execSlash(message: BushInteractionMessage, { fast }: { fast: SlashCommandOption<boolean> }): Promise<void> { + await message.interaction.reply(await this.getResponse(fast?.value)); } } diff --git a/src/commands/dev/setLevel.ts b/src/commands/dev/setLevel.ts index e57e2f8..7401699 100644 --- a/src/commands/dev/setLevel.ts +++ b/src/commands/dev/setLevel.ts @@ -1,8 +1,7 @@ import { ApplicationCommandOptionType } from 'discord-api-types'; -import { CommandInteraction } from 'discord.js'; -import { User } from 'discord.js'; -import { Message } from 'discord.js'; +import { Message, User } from 'discord.js'; import { BushCommand } from '../../lib/extensions/BushCommand'; +import { BushInteractionMessage } from '../../lib/extensions/BushInteractionMessage'; import { SlashCommandOption } from '../../lib/extensions/Util'; import { Level } from '../../lib/models'; import AllowedMentions from '../../lib/utils/AllowedMentions'; @@ -68,16 +67,18 @@ export default class SetLevelCommand extends BushCommand { } async exec(message: Message, { user, level }: { user: User; level: number }): Promise<void> { - await message.util.send(await this.setLevel(user, level), { + await message.util.send({ + content: await this.setLevel(user, level), allowedMentions: AllowedMentions.none() }); } async execSlash( - message: CommandInteraction, + message: BushInteractionMessage, { user, level }: { user: SlashCommandOption<void>; level: SlashCommandOption<number> } ): Promise<void> { - await message.reply(await this.setLevel(user.user, level.value), { + await message.interaction.reply({ + content: await this.setLevel(user.user, level.value), allowedMentions: AllowedMentions.none() }); } diff --git a/src/commands/info/botInfo.ts b/src/commands/info/botInfo.ts index ebbd0c9..66bf5af 100644 --- a/src/commands/info/botInfo.ts +++ b/src/commands/info/botInfo.ts @@ -1,6 +1,7 @@ -import { MessageEmbed, Message, CommandInteraction } from 'discord.js'; -import { BushCommand } from '../../lib/extensions/BushCommand'; +import { Message, MessageEmbed } from 'discord.js'; import { duration } from 'moment'; +import { BushCommand } from '../../lib/extensions/BushCommand'; +import { BushInteractionMessage } from '../../lib/extensions/BushInteractionMessage'; export default class BotInfoCommand extends BushCommand { constructor() { @@ -33,7 +34,7 @@ export default class BotInfoCommand extends BushCommand { }, { name: 'User count', - value: this.client.users.cache.size, + value: this.client.users.cache.size.toString(), inline: true }, { @@ -46,10 +47,10 @@ export default class BotInfoCommand extends BushCommand { } public async exec(message: Message): Promise<void> { - await message.util.send(await this.generateEmbed()); + await message.util.send({ embeds: [await this.generateEmbed()] }); } - public async execSlash(message: CommandInteraction): Promise<void> { - await message.reply(await this.generateEmbed()); + public async execSlash(message: BushInteractionMessage): Promise<void> { + await message.interaction.reply({ embeds: [await this.generateEmbed()] }); } } diff --git a/src/commands/info/help.ts b/src/commands/info/help.ts index 0629bf1..317091e 100644 --- a/src/commands/info/help.ts +++ b/src/commands/info/help.ts @@ -1,8 +1,8 @@ -import { Message, MessageEmbed } from 'discord.js'; -import { BushCommand } from '../../lib/extensions/BushCommand'; import { stripIndent } from 'common-tags'; import { ApplicationCommandOptionType } from 'discord-api-types'; -import { CommandInteraction } from 'discord.js'; +import { Message, MessageEmbed } from 'discord.js'; +import { BushCommand } from '../../lib/extensions/BushCommand'; +import { BushInteractionMessage } from '../../lib/extensions/BushInteractionMessage'; import { SlashCommandOption } from '../../lib/extensions/Util'; export default class HelpCommand extends BushCommand { @@ -72,14 +72,14 @@ export default class HelpCommand extends BushCommand { } public async exec(message: Message, { command }: { command: BushCommand }): Promise<void> { - await message.util.send(this.generateEmbed(command)); + await message.util.send({ embeds: [this.generateEmbed(command)] }); } - public async execSlash(message: CommandInteraction, { command }: { command: SlashCommandOption<string> }): Promise<void> { + public async execSlash(message: BushInteractionMessage, { command }: { command: SlashCommandOption<string> }): Promise<void> { if (command) { - await message.reply(this.generateEmbed(this.handler.findCommand(command.value) as BushCommand)); + await message.interaction.reply({ embeds: [this.generateEmbed(this.handler.findCommand(command.value) as BushCommand)] }); } else { - await message.reply(this.generateEmbed()); + await message.interaction.reply({ embeds: [this.generateEmbed()] }); } } } diff --git a/src/commands/info/ping.ts b/src/commands/info/ping.ts index b130e6d..feb48ad 100644 --- a/src/commands/info/ping.ts +++ b/src/commands/info/ping.ts @@ -1,7 +1,6 @@ -import { CommandInteraction } from 'discord.js'; -import { Message } from 'discord.js'; -import { MessageEmbed } from 'discord.js'; +import { Message, MessageEmbed } from 'discord.js'; import { BushCommand } from '../../lib/extensions/BushCommand'; +import { BushInteractionMessage } from '../../lib/extensions/BushInteractionMessage'; export default class PingCommand extends BushCommand { constructor() { @@ -29,23 +28,23 @@ export default class PingCommand extends BushCommand { .setTimestamp(); await sentMessage.edit({ content: null, - embed + embeds: [embed] }); } - public async execSlash(message: CommandInteraction): Promise<void> { - const timestamp1 = message.createdTimestamp; - await message.reply('Pong!'); - const timestamp2 = await message.fetchReply().then((m) => (m as Message).createdTimestamp); + public async execSlash(message: BushInteractionMessage): Promise<void> { + const timestamp1 = message.interaction.createdTimestamp; + await message.interaction.reply('Pong!'); + const timestamp2 = await message.interaction.fetchReply().then((m) => (m as Message).createdTimestamp); const botLatency = `\`\`\`\n ${Math.floor(timestamp2 - timestamp1)}ms \`\`\``; const apiLatency = `\`\`\`\n ${Math.round(this.client.ws.ping)}ms \`\`\``; const embed = new MessageEmbed() .setTitle('Pong! π') .addField('Bot Latency', botLatency, true) .addField('API Latency', apiLatency, true) - .setFooter(message.user.username, message.user.displayAvatarURL({ dynamic: true })) + .setFooter(message.interaction.user.username, message.interaction.user.displayAvatarURL({ dynamic: true })) .setTimestamp(); - await message.editReply({ + await message.interaction.editReply({ content: null, embeds: [embed] }); diff --git a/src/commands/info/pronouns.ts b/src/commands/info/pronouns.ts index 740eb68..faf3aa2 100644 --- a/src/commands/info/pronouns.ts +++ b/src/commands/info/pronouns.ts @@ -1,8 +1,8 @@ -import { BushCommand } from '../../lib/extensions/BushCommand'; -import { User, Message, MessageEmbed } from 'discord.js'; -import got, { HTTPError } from 'got'; -import { CommandInteraction } from 'discord.js'; import { ApplicationCommandOptionType } from 'discord-api-types'; +import { CommandInteraction, Message, MessageEmbed, User } from 'discord.js'; +import got, { HTTPError } from 'got'; +import { BushCommand } from '../../lib/extensions/BushCommand'; +import { BushInteractionMessage } from '../../lib/extensions/BushInteractionMessage'; import { SlashCommandOption } from '../../lib/extensions/Util'; export const pronounMapping = { @@ -56,7 +56,7 @@ export default class PronounsCommand extends BushCommand { required: false } ], - slashEmphemeral: true // I'll add dynamic checking to this later + slashEphemeral: true // I'll add dynamic checking to this later }); } async sendResponse(message: Message | CommandInteraction, user: User, author: boolean): Promise<void> { @@ -65,15 +65,17 @@ export default class PronounsCommand extends BushCommand { .get(`https://pronoundb.org/api/v1/lookup?platform=discord&id=${user.id}`) .json(); if (message instanceof Message) { - message.reply( - new MessageEmbed({ - title: `${author ? 'Your' : `${user.tag}'s`} pronouns:`, - description: pronounMapping[apiRes.pronouns], - footer: { - text: 'Data provided by https://pronoundb.org/' - } - }) - ); + message.reply({ + embeds: [ + new MessageEmbed({ + title: `${author ? 'Your' : `${user.tag}'s`} pronouns:`, + description: pronounMapping[apiRes.pronouns], + footer: { + text: 'Data provided by https://pronoundb.org/' + } + }) + ] + }); } else { message.reply({ embeds: [ @@ -105,8 +107,8 @@ export default class PronounsCommand extends BushCommand { const u = user || message.author; await this.sendResponse(message, u, u.id === message.author.id); } - async execSlash(message: CommandInteraction, { user }: { user?: SlashCommandOption<void> }): Promise<void> { - const u = user?.user || message.user; - await this.sendResponse(message, u, u.id === message.user.id); + async execSlash(message: BushInteractionMessage, { user }: { user?: SlashCommandOption<void> }): Promise<void> { + const u = user?.user || message.author; + await this.sendResponse(message.interaction, u, u.id === message.author.id); } } diff --git a/src/commands/moderation/ban.ts b/src/commands/moderation/ban.ts index 0d57203..f843ac4 100644 --- a/src/commands/moderation/ban.ts +++ b/src/commands/moderation/ban.ts @@ -1,12 +1,10 @@ -import { User } from 'discord.js'; -import { Guild } from '../../lib/models'; -import { BushCommand } from '../../lib/extensions/BushCommand'; -import { Ban, Modlog, ModlogType } from '../../lib/models'; +import { ApplicationCommandOptionType } from 'discord-api-types'; +import { CommandInteraction, Message, User } from 'discord.js'; import moment from 'moment'; -import { Message } from 'discord.js'; -import { CommandInteraction } from 'discord.js'; +import { BushCommand } from '../../lib/extensions/BushCommand'; +import { BushInteractionMessage } from '../../lib/extensions/BushInteractionMessage'; import { SlashCommandOption } from '../../lib/extensions/Util'; -import { ApplicationCommandOptionType } from 'discord-api-types'; +import { Ban, Guild, Modlog, ModlogType } from '../../lib/models'; const durationAliases: Record<string, string[]> = { weeks: ['w', 'weeks', 'week', 'wk', 'wks'], @@ -170,7 +168,7 @@ export default class BanCommand extends BushCommand { } async execSlash( - message: CommandInteraction, + message: BushInteractionMessage, { user, reason, @@ -181,7 +179,7 @@ export default class BanCommand extends BushCommand { time: SlashCommandOption<string>; } ): Promise<void> { - for await (const response of this.genResponses(message, user.user, reason?.value, time?.value)) { + for await (const response of this.genResponses(message.interaction, user.user, reason?.value, time?.value)) { await message.reply(response); } } diff --git a/src/commands/moderation/kick.ts b/src/commands/moderation/kick.ts index c5581f6..eed0122 100644 --- a/src/commands/moderation/kick.ts +++ b/src/commands/moderation/kick.ts @@ -1,8 +1,8 @@ +import { ApplicationCommandOptionType } from 'discord-api-types'; +import { CommandInteraction, GuildMember, Message } from 'discord.js'; import { BushCommand } from '../../lib/extensions/BushCommand'; +import { BushInteractionMessage } from '../../lib/extensions/BushInteractionMessage'; import { Guild, Modlog, ModlogType } from '../../lib/models'; -import { GuildMember, Message } from 'discord.js'; -import { ApplicationCommandOptionType } from 'discord-api-types'; -import { CommandInteraction } from 'discord.js'; export default class KickCommand extends BushCommand { constructor() { @@ -100,9 +100,9 @@ export default class KickCommand extends BushCommand { } } - async execSlash(message: CommandInteraction, { user, reason }: { user: GuildMember; reason?: string }): Promise<void> { - for await (const response of this.genResponses(message, user, reason)) { - await message.reply(response); + async execSlash(message: BushInteractionMessage, { user, reason }: { user: GuildMember; reason?: string }): Promise<void> { + for await (const response of this.genResponses(message.interaction, user, reason)) { + await message.interaction.reply(response); } } } diff --git a/src/commands/moderation/modlog.ts b/src/commands/moderation/modlog.ts index 806c00a..862a26d 100644 --- a/src/commands/moderation/modlog.ts +++ b/src/commands/moderation/modlog.ts @@ -1,10 +1,9 @@ -import { BushCommand } from '../../lib/extensions/BushCommand'; -import { Message } from 'discord.js'; -import { Modlog } from '../../lib/models'; -import { MessageEmbed } from 'discord.js'; -import moment from 'moment'; import { stripIndent } from 'common-tags'; import { Argument } from 'discord-akairo'; +import { Message, MessageEmbed } from 'discord.js'; +import moment from 'moment'; +import { BushCommand } from '../../lib/extensions/BushCommand'; +import { Modlog } from '../../lib/models'; export default class ModlogCommand extends BushCommand { constructor() { @@ -87,10 +86,10 @@ export default class ModlogCommand extends BushCommand { }) ); if (page) { - await message.util.send(embedPages[page - 1]); + await message.util.send({ embeds: [embedPages[page - 1]] }); return; } else { - await message.util.send(embedPages[0]); + await message.util.send({ embeds: [embedPages[0]] }); return; } } else if (search) { @@ -99,38 +98,40 @@ export default class ModlogCommand extends BushCommand { await message.util.send('That modlog does not exist.'); return; } - await message.util.send( - new MessageEmbed({ - title: `Modlog ${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 - } - ] - }) - ); + await message.util.send({ + embeds: [ + new MessageEmbed({ + title: `Modlog ${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 + } + ] + }) + ] + }); } } } diff --git a/src/commands/moderation/role.ts b/src/commands/moderation/role.ts index b01d578..8951560 100644 --- a/src/commands/moderation/role.ts +++ b/src/commands/moderation/role.ts @@ -1,8 +1,8 @@ /* eslint-disable @typescript-eslint/no-empty-function */ +import { ApplicationCommandOptionType } from 'discord-api-types'; +import { GuildMember, Message, Role } from 'discord.js'; import { BushCommand } from '../../lib/extensions/BushCommand'; import AllowedMentions from '../../lib/utils/AllowedMentions'; -import { Message, Role, GuildMember } from 'discord.js'; -import { ApplicationCommandOptionType } from 'discord-api-types'; export default class RoleCommand extends BushCommand { private roleWhitelist: Record<string, string[]> = { @@ -77,43 +77,39 @@ export default class RoleCommand extends BushCommand { if (!message.member.permissions.has('MANAGE_ROLES') && !this.client.ownerID.includes(message.author.id)) { const mappedRole = this.client.util.moulberryBushRoleMap.find((m) => m.id === role.id); if (!mappedRole || !this.roleWhitelist[mappedRole.name]) { - return message.util.reply( - `<:error:837123021016924261> <@&${role.id}> is not whitelisted, and you do not have manage roles permission.`, - { - allowedMentions: AllowedMentions.none() - } - ); + return message.util.reply({ + content: `<:error:837123021016924261> <@&${role.id}> is not whitelisted, and you do not have manage roles permission.`, + allowedMentions: AllowedMentions.none() + }); } const allowedRoles = this.roleWhitelist[mappedRole.name].map((r) => { return this.client.util.moulberryBushRoleMap.find((m) => m.name === r).id; }); if (!message.member.roles.cache.some((role) => allowedRoles.includes(role.id))) { - return message.util.reply( - `<:error:837123021016924261> <@&${role.id}> is whitelisted, but you do not have any of the roles required to manage it.`, - { - allowedMentions: AllowedMentions.none() - } - ); + return message.util.reply({ + content: `<:error:837123021016924261> <@&${role.id}> is whitelisted, but you do not have any of the roles required to manage it.`, + allowedMentions: AllowedMentions.none() + }); } } if (!this.client.ownerID.includes(message.author.id)) { if (role.comparePositionTo(message.member.roles.highest) >= 0) { - return message.util.reply(`<:error:837123021016924261> <@&${role.id}> is higher or equal to your highest role.`, { + return message.util.reply({ + content: `<:error:837123021016924261> <@&${role.id}> is higher or equal to your highest role.`, allowedMentions: AllowedMentions.none() }); } if (role.comparePositionTo(message.guild.me.roles.highest) >= 0) { - return message.util.reply(`<:error:837123021016924261> <@&${role.id}> is higher or equal to my highest role.`, { + return message.util.reply({ + content: `<:error:837123021016924261> <@&${role.id}> is higher or equal to my highest role.`, allowedMentions: AllowedMentions.none() }); } if (role.managed) { - await message.util.reply( - `<:error:837123021016924261> <@&${role.id}> is managed by an integration and cannot be managed.`, - { - allowedMentions: AllowedMentions.none() - } - ); + await message.util.reply({ + content: `<:error:837123021016924261> <@&${role.id}> is managed by an integration and cannot be managed.`, + allowedMentions: AllowedMentions.none() + }); } } // No checks if the user has MANAGE_ROLES @@ -121,22 +117,26 @@ export default class RoleCommand extends BushCommand { try { await user.roles.remove(role.id); } catch { - return message.util.reply(`<:error:837123021016924261> Could not remove <@&${role.id}> from <@${user.id}>.`, { + return message.util.reply({ + content: `<:error:837123021016924261> Could not remove <@&${role.id}> from <@${user.id}>.`, allowedMentions: AllowedMentions.none() }); } - return message.util.reply(`<:checkmark:837109864101707807> Successfully removed <@&${role.id}> from <@${user.id}>!`, { + return message.util.reply({ + content: `<:checkmark:837109864101707807> Successfully removed <@&${role.id}> from <@${user.id}>!`, allowedMentions: AllowedMentions.none() }); } else { try { await user.roles.add(role.id); } catch { - return message.util.reply(`<:error:837123021016924261> Could not add <@&${role.id}> to <@${user.id}>.`, { + return message.util.reply({ + content: `<:error:837123021016924261> Could not add <@&${role.id}> to <@${user.id}>.`, allowedMentions: AllowedMentions.none() }); } - return message.util.reply(`<:checkmark:837109864101707807> Successfully added <@&${role.id}> to <@${user.id}>!`, { + return message.util.reply({ + content: `<:checkmark:837109864101707807> Successfully added <@&${role.id}> to <@${user.id}>!`, allowedMentions: AllowedMentions.none() }); } diff --git a/src/commands/moulberry-bush/capePerms.ts b/src/commands/moulberry-bush/capePerms.ts index a0edf8c..7eb90c5 100644 --- a/src/commands/moulberry-bush/capePerms.ts +++ b/src/commands/moulberry-bush/capePerms.ts @@ -1,9 +1,8 @@ import { ApplicationCommandOptionType } from 'discord-api-types'; -import { MessageEmbed } from 'discord.js'; -import { CommandInteraction } from 'discord.js'; -import { Message } from 'discord.js'; +import { Message, MessageEmbed } from 'discord.js'; import got from 'got'; import { BushCommand } from '../../lib/extensions/BushCommand'; +import { BushInteractionMessage } from '../../lib/extensions/BushInteractionMessage'; import { SlashCommandOption } from '../../lib/extensions/Util'; interface Capeperms { @@ -75,12 +74,12 @@ export default class CapePermissionsCommand extends BushCommand { ] }); } - private async getResponse(user: string): Promise<string | MessageEmbed> { + private async getResponse(user: string): Promise<{ content?: string; embeds?: MessageEmbed[] }> { let capeperms: Capeperms, uuid: string; try { uuid = await this.client.util.mcUUID(user); } catch (e) { - return `<:error:837123021016924261> \`${user}\` doesn't appear to be a valid username.`; + return { content: `<:error:837123021016924261> \`${user}\` doesn't appear to be a valid username.` }; } try { @@ -89,19 +88,19 @@ export default class CapePermissionsCommand extends BushCommand { capeperms = null; } if (capeperms == null) { - return `<:error:837123021016924261> There was an error finding cape perms for \`${user}\`.`; + return { content: `<:error:837123021016924261> There was an error finding cape perms for \`${user}\`.` }; } else { if (capeperms?.perms) { const foundUser = capeperms.perms.find((u) => u._id === uuid); - if (foundUser == null) return `<:error:837123021016924261> \`${user}\` does not appear to have any capes.`; + if (foundUser == null) return { content: `<:error:837123021016924261> \`${user}\` does not appear to have any capes.` }; const userPerm: string[] = foundUser.perms; const embed = this.client.util .createEmbed(this.client.util.colors.default) .setTitle(`${user}'s Capes`) .setDescription(userPerm.join('\n')); - return embed; + return { embeds: [embed] }; } else { - return `<:error:837123021016924261> There was an error finding cape perms for ${user}.`; + return { content: `<:error:837123021016924261> There was an error finding cape perms for ${user}.` }; } } } @@ -109,7 +108,7 @@ export default class CapePermissionsCommand extends BushCommand { await message.reply(await this.getResponse(user)); } - public async execSlash(message: CommandInteraction, { user }: { user: SlashCommandOption<string> }): Promise<void> { + public async execSlash(message: BushInteractionMessage, { user }: { user: SlashCommandOption<string> }): Promise<void> { await message.reply(await this.getResponse(user.value)); } } diff --git a/src/commands/moulberry-bush/giveawayPing.ts b/src/commands/moulberry-bush/giveawayPing.ts index 34de257..9a03140 100644 --- a/src/commands/moulberry-bush/giveawayPing.ts +++ b/src/commands/moulberry-bush/giveawayPing.ts @@ -1,8 +1,6 @@ +import { Message, NewsChannel, TextChannel, WebhookClient } from 'discord.js'; import { BushCommand } from '../../lib/extensions/BushCommand'; import AllowedMentions from '../../lib/utils/AllowedMentions'; -import { Message, WebhookClient } from 'discord.js'; -import { TextChannel } from 'discord.js'; -import { NewsChannel } from 'discord.js'; export default class GiveawayPingCommand extends BushCommand { constructor() { @@ -39,13 +37,12 @@ export default class GiveawayPingCommand extends BushCommand { const webhook = webhooks.first(); webhookClient = new WebhookClient(webhook.id, webhook.token); } - return webhookClient.send( - 'π <@&767782793261875210> Giveaway.\n\n<:mad:783046135392239626> Spamming, line breaking, gibberish etc. disqualifies you from winning. We can and will ban you from giveaways. Winners will all be checked and rerolled if needed.', - { - username: `${message.member.nickname || message.author.username}`, - avatarURL: message.author.avatarURL({ dynamic: true }), - allowedMentions: AllowedMentions.roles() - } - ); + return webhookClient.send({ + content: + 'π <@&767782793261875210> Giveaway.\n\n<:mad:783046135392239626> Spamming, line breaking, gibberish etc. disqualifies you from winning. We can and will ban you from giveaways. Winners will all be checked and rerolled if needed.', + username: `${message.member.nickname || message.author.username}`, + avatarURL: message.author.avatarURL({ dynamic: true }), + allowedMentions: AllowedMentions.roles() + }); } } diff --git a/src/commands/moulberry-bush/level.ts b/src/commands/moulberry-bush/level.ts index 0375fd8..f53aa64 100644 --- a/src/commands/moulberry-bush/level.ts +++ b/src/commands/moulberry-bush/level.ts @@ -1,9 +1,7 @@ import { ApplicationCommandOptionType } from 'discord-api-types'; -import { Message } from 'discord.js'; -import { CommandInteractionOption } from 'discord.js'; -import { CommandInteraction } from 'discord.js'; -import { User } from 'discord.js'; +import { CommandInteractionOption, Message, User } from 'discord.js'; import { BushCommand } from '../../lib/extensions/BushCommand'; +import { BushInteractionMessage } from '../../lib/extensions/BushInteractionMessage'; import { Level } from '../../lib/models'; /* import canvas from 'canvas'; @@ -150,13 +148,13 @@ export default class LevelCommand extends BushCommand { // ); await message.reply(await this.getResponse(user || message.author)); } - async execSlash(message: CommandInteraction, { user }: { user?: CommandInteractionOption }): Promise<void> { + async execSlash(message: BushInteractionMessage, { user }: { user?: CommandInteractionOption }): Promise<void> { // await message.reply( // new MessageAttachment( // await this.getImage(user?.user || message.user), // 'lel.png' // ) // ); - await message.reply(await this.getResponse(user?.user || message.user)); + await message.reply(await this.getResponse(user?.user || message.author)); } } diff --git a/src/commands/moulberry-bush/rule.ts b/src/commands/moulberry-bush/rule.ts index ba4f9e6..b71b42f 100644 --- a/src/commands/moulberry-bush/rule.ts +++ b/src/commands/moulberry-bush/rule.ts @@ -1,8 +1,8 @@ import { Argument } from 'discord-akairo'; -import { Message, MessageEmbed, User } from 'discord.js'; -import { BushCommand } from '../../lib/extensions/BushCommand'; import { ApplicationCommandOptionType } from 'discord-api-types'; -import { CommandInteraction } from 'discord.js'; +import { CommandInteraction, Message, MessageEmbed, User } from 'discord.js'; +import { BushCommand } from '../../lib/extensions/BushCommand'; +import { BushInteractionMessage } from '../../lib/extensions/BushInteractionMessage'; import { SlashCommandOption } from '../../lib/extensions/Util'; export default class RuleCommand extends BushCommand { @@ -118,12 +118,12 @@ export default class RuleCommand extends BushCommand { message: Message | CommandInteraction, rule?: number, user?: User - ): string | MessageEmbed | [string, MessageEmbed] { + ): { content?: string; embeds?: MessageEmbed[] } | [string, MessageEmbed] { if ( message.guild.id !== '516977525906341928' && !this.client.ownerID.includes(message instanceof Message ? message.author.id : message.user.id) ) { - return "<:no:787549684196704257> This command can only be run in Moulberry's Bush."; + return { content: "<:no:787549684196704257> This command can only be run in Moulberry's Bush." }; } let rulesEmbed = new MessageEmbed().setColor('ef3929'); if (message instanceof Message) { @@ -138,7 +138,7 @@ export default class RuleCommand extends BushCommand { } } if (!user) { - return rulesEmbed; + return { embeds: [rulesEmbed] }; } else { return [`<@!${user.id}>`, rulesEmbed]; } @@ -146,8 +146,9 @@ export default class RuleCommand extends BushCommand { public async exec(message: Message, { rule, user }: { rule?: number; user?: User }): Promise<void> { const response = this.getResponse(message, rule, user); if (Array.isArray(response)) { - await message.util.send(response[0], { - embed: response[1] + await message.util.send({ + content: response[0], + embeds: [response[1]] }); } else { await message.util.send(response); @@ -156,16 +157,17 @@ export default class RuleCommand extends BushCommand { } public async execSlash( - message: CommandInteraction, + message: BushInteractionMessage, { rule, user }: { rule?: SlashCommandOption<number>; user?: SlashCommandOption<void> } ): Promise<void> { - const response = this.getResponse(message, rule?.value, user?.user); + const response = this.getResponse(message.interaction, rule?.value, user?.user); if (Array.isArray(response)) { - await message.reply(response[0], { + await message.interaction.reply({ + content: response[0], embeds: [response[1]] }); } else { - await message.reply(response); + await message.interaction.reply(response); } } } diff --git a/src/commands/server-config/prefix.ts b/src/commands/server-config/prefix.ts index c60f8fb..9cdc331 100644 --- a/src/commands/server-config/prefix.ts +++ b/src/commands/server-config/prefix.ts @@ -1,6 +1,7 @@ import { ApplicationCommandOptionType } from 'discord-api-types'; -import { CommandInteraction, Message, Guild as DiscordGuild } from 'discord.js'; +import { Guild as DiscordGuild, Message } from 'discord.js'; import { BushCommand } from '../../lib/extensions/BushCommand'; +import { BushInteractionMessage } from '../../lib/extensions/BushInteractionMessage'; import { SlashCommandOption } from '../../lib/extensions/Util'; import { Guild } from '../../lib/models'; @@ -57,7 +58,7 @@ export default class PrefixCommand extends BushCommand { } } - async execSlash(message: CommandInteraction, { prefix }: { prefix?: SlashCommandOption<string> }): Promise<void> { + async execSlash(message: BushInteractionMessage, { prefix }: { prefix?: SlashCommandOption<string> }): Promise<void> { await this.changePrefix(message.guild, prefix?.value); if (prefix) { await message.reply(`Sucessfully set prefix to \`${prefix.value}\``); |