diff options
author | TymanWasTaken <tyman@tyman.tech> | 2021-05-17 14:06:24 -0400 |
---|---|---|
committer | TymanWasTaken <tyman@tyman.tech> | 2021-05-17 14:06:24 -0400 |
commit | 9aee8c80067530b178612f1261c38b83683f266d (patch) | |
tree | 2ac52f719bdd77ef0265da2de02336f0759deaba /src/commands | |
parent | 4d63c4af57a7391dd61106b79874b8e83c14971a (diff) | |
download | tanzanite-9aee8c80067530b178612f1261c38b83683f266d.tar.gz tanzanite-9aee8c80067530b178612f1261c38b83683f266d.tar.bz2 tanzanite-9aee8c80067530b178612f1261c38b83683f266d.zip |
probably works idk what all I did
Diffstat (limited to 'src/commands')
-rw-r--r-- | src/commands/admin/prefix.ts | 14 | ||||
-rw-r--r-- | src/commands/info/help.ts | 57 | ||||
-rw-r--r-- | src/commands/moderation/ban.ts | 112 | ||||
-rw-r--r-- | src/commands/moulberry-bush/capeperms.ts | 50 | ||||
-rw-r--r-- | src/commands/moulberry-bush/giveawayping.ts | 12 | ||||
-rw-r--r-- | src/commands/moulberry-bush/level.ts | 10 | ||||
-rw-r--r-- | src/commands/moulberry-bush/rule.ts | 86 | ||||
-rw-r--r-- | src/commands/owner/eval.ts | 2 |
8 files changed, 233 insertions, 110 deletions
diff --git a/src/commands/admin/prefix.ts b/src/commands/admin/prefix.ts index 6d0273b..112f6b8 100644 --- a/src/commands/admin/prefix.ts +++ b/src/commands/admin/prefix.ts @@ -1,6 +1,7 @@ import { ApplicationCommandOptionType } from 'discord-api-types'; import { CommandInteraction, Message, Guild as DiscordGuild } from 'discord.js'; import { BotCommand } from '../../lib/extensions/BotCommand'; +import { SlashCommandOption } from '../../lib/extensions/Util'; import { Guild } from '../../lib/models'; export default class PrefixCommand extends BotCommand { @@ -53,14 +54,13 @@ export default class PrefixCommand extends BotCommand { } } - async execSlash(message: CommandInteraction): Promise<void> { - const prefix = message.options.find((o) => o.name === 'prefix')?.value as - | string - | undefined; - - await this.changePrefix(message.guild, prefix); + async execSlash( + message: CommandInteraction, + { prefix }: { prefix?: SlashCommandOption<string> } + ): Promise<void> { + await this.changePrefix(message.guild, prefix?.value); if (prefix) { - await message.reply(`Sucessfully set prefix to \`${prefix}\``); + await message.reply(`Sucessfully set prefix to \`${prefix.value}\``); } else { await message.reply( `Sucessfully reset prefix to \`${this.client.config.prefix}\`` diff --git a/src/commands/info/help.ts b/src/commands/info/help.ts index cdddb51..116669c 100644 --- a/src/commands/info/help.ts +++ b/src/commands/info/help.ts @@ -3,6 +3,7 @@ import { BotCommand } from '../../lib/extensions/BotCommand'; import { stripIndent } from 'common-tags'; import { ApplicationCommandOptionType } from 'discord-api-types'; import { CommandInteraction } from 'discord.js'; +import { SlashCommandOption } from '../../lib/extensions/Util'; export default class HelpCommand extends BotCommand { constructor() { @@ -57,29 +58,29 @@ export default class HelpCommand extends BotCommand { ); } return embed; - } - - const embed = new MessageEmbed() - .setColor([155, 200, 200]) - .setTitle( - `\`${command.description.usage ? command.description.usage : ''}\`` - ) - .addField( - 'Description', - `${command.description.content ? command.description.content : ''} ${ - command.ownerOnly ? '\n__Owner Only__' : '' - }` - ); + } else { + const embed = new MessageEmbed() + .setColor([155, 200, 200]) + .setTitle( + `\`${command.description.usage ? command.description.usage : ''}\`` + ) + .addField( + 'Description', + `${command.description.content ? command.description.content : ''} ${ + command.ownerOnly ? '\n__Owner Only__' : '' + }` + ); - if (command.aliases.length > 1) - embed.addField('Aliases', `\`${command.aliases.join('` `')}\``, true); - if (command.description.examples && command.description.examples.length) - embed.addField( - 'Examples', - `\`${command.description.examples.join('`\n`')}\``, - true - ); - return embed; + if (command.aliases.length > 1) + embed.addField('Aliases', `\`${command.aliases.join('` `')}\``, true); + if (command.description.examples && command.description.examples.length) + embed.addField( + 'Examples', + `\`${command.description.examples.join('`\n`')}\``, + true + ); + return embed; + } } public async exec( @@ -89,13 +90,15 @@ export default class HelpCommand extends BotCommand { await message.util.send(this.generateEmbed(command)); } - public async execSlash(message: CommandInteraction): Promise<void> { - const command = message.options.find((o) => o.name === 'command')?.value as - | string - | undefined; + public async execSlash( + message: CommandInteraction, + { command }: { command: SlashCommandOption<string> } + ): Promise<void> { if (command) { await message.reply( - this.generateEmbed(this.handler.findCommand(command) as BotCommand) + this.generateEmbed( + this.handler.findCommand(command.value) as BotCommand + ) ); } else { await message.reply(this.generateEmbed()); diff --git a/src/commands/moderation/ban.ts b/src/commands/moderation/ban.ts index 3858290..107de9d 100644 --- a/src/commands/moderation/ban.ts +++ b/src/commands/moderation/ban.ts @@ -4,6 +4,9 @@ import { BotCommand } from '../../lib/extensions/BotCommand'; import { Ban, Modlog, ModlogType } from '../../lib/models'; import moment from 'moment'; import { Message } from 'discord.js'; +import { CommandInteraction } from 'discord.js'; +// import { SlashCommandOption } from '../../lib/extensions/Util'; +// import { ApplicationCommandOptionType } from 'discord-api-types'; const durationAliases: Record<string, string[]> = { weeks: ['w', 'weeks', 'week', 'wk', 'wks'], @@ -12,7 +15,8 @@ const durationAliases: Record<string, string[]> = { 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; +const durationRegex = + /(?:(\d+)(d(?:ays?)?|h(?:ours?|rs?)?|m(?:inutes?|ins?)?|mo(?:nths?)?|w(?:eeks?|ks?)?)(?: |$))/g; export default class PrefixCommand extends BotCommand { constructor() { @@ -48,12 +52,35 @@ export default class PrefixCommand extends BotCommand { 'ban @Tyman being cool --time 7days' ] } + // slashCommandOptions: [ + // { + // type: ApplicationCommandOptionType.USER, + // name: 'user', + // description: 'The user to ban', + // required: true + // }, + // { + // type: ApplicationCommandOptionType.STRING, + // name: 'reason', + // description: 'The reason to show in modlogs and audit log', + // required: false + // }, + // { + // type: ApplicationCommandOptionType.STRING, + // name: 'time', + // description: + // 'The time the user should be banned for (default permanent)', + // required: false + // } + // ] }); } - async exec( - message: Message, - { user, reason, time }: { user: User; reason?: string; time?: string } - ): Promise<void> { + async *genResponses( + message: Message | CommandInteraction, + user: User, + reason?: string, + time?: string + ): AsyncIterable<string> { const duration = moment.duration(); let modlogEnry: Modlog; let banEntry: Ban; @@ -72,7 +99,7 @@ export default class PrefixCommand extends BotCommand { if (time) { const parsed = [...time.matchAll(durationRegex)]; if (parsed.length < 1) { - await message.util.send('Invalid time.'); + yield 'Invalid time.'; return; } for (const part of parsed) { @@ -91,7 +118,10 @@ export default class PrefixCommand extends BotCommand { reason, type: ModlogType.TEMPBAN, duration: duration.asMilliseconds(), - moderator: message.author.id + moderator: + message instanceof CommandInteraction + ? message.user.id + : message.author.id }); banEntry = Ban.build({ user: user.id, @@ -106,7 +136,10 @@ export default class PrefixCommand extends BotCommand { guild: message.guild.id, reason, type: ModlogType.BAN, - moderator: message.author.id + moderator: + message instanceof CommandInteraction + ? message.user.id + : message.author.id }); banEntry = Ban.build({ user: user.id, @@ -119,9 +152,7 @@ export default class PrefixCommand extends BotCommand { await banEntry.save(); } catch (e) { console.error(e); - await message.util.send( - 'Error saving to database. Please report this to a developer.' - ); + yield 'Error saving to database. Please report this to a developer.'; return; } try { @@ -133,25 +164,60 @@ export default class PrefixCommand extends BotCommand { } with reason \`${reason || 'No reason given'}\`` ); } catch (e) { - await message.channel.send('Error sending message to user'); + yield 'Error sending message to user'; } await message.guild.members.ban(user, { - reason: `Banned by ${message.author.tag} with ${ - reason ? `reason ${reason}` : 'no reason' - }` + reason: `Banned by ${ + message instanceof CommandInteraction + ? message.user.tag + : message.author.tag + } with ${reason ? `reason ${reason}` : 'no reason'}` }); - await message.util.send( - `Banned <@!${user.id}> ${ - translatedTime.length >= 1 - ? `for ${translatedTime.join(', ')}` - : 'permanently' - } with reason \`${reason || 'No reason given'}\`` - ); + yield `Banned <@!${user.id}> ${ + translatedTime.length >= 1 + ? `for ${translatedTime.join(', ')}` + : 'permanently' + } with reason \`${reason || 'No reason given'}\``; } catch { - await message.util.send('Error banning :/'); + yield 'Error banning :/'; await banEntry.destroy(); await modlogEnry.destroy(); return; } } + async exec( + message: Message, + { user, reason, time }: { user: User; reason?: string; time?: string } + ): Promise<void> { + for await (const response of this.genResponses( + message, + user, + reason, + time + )) { + await message.util.send(response); + } + } + + // async execSlash( + // message: CommandInteraction, + // { + // user, + // reason, + // time + // }: { + // user: SlashCommandOption<undefined>; + // reason: SlashCommandOption<string>; + // time: SlashCommandOption<string>; + // } + // ): Promise<void> { + // for await (const response of this.genResponses( + // message, + // user.user, + // reason?.value, + // time?.value + // )) { + // await message.reply(response); + // } + // } } diff --git a/src/commands/moulberry-bush/capeperms.ts b/src/commands/moulberry-bush/capeperms.ts index 0588696..7a79666 100644 --- a/src/commands/moulberry-bush/capeperms.ts +++ b/src/commands/moulberry-bush/capeperms.ts @@ -1,3 +1,6 @@ +import { ApplicationCommandOptionType } from 'discord-api-types'; +import { MessageEmbed } from 'discord.js'; +import { CommandInteraction } from 'discord.js'; import { Message } from 'discord.js'; import got from 'got'; import { BotCommand } from '../../lib/extensions/BotCommand'; @@ -61,20 +64,24 @@ export default class CapePermsCommand extends BotCommand { } ], clientPermissions: ['EMBED_LINKS', 'SEND_MESSAGES'], - channel: 'guild' + channel: 'guild', + slashCommandOptions: [ + { + type: ApplicationCommandOptionType.STRING, + name: 'user', + description: + 'The username of the player to see the cape permissions of', + required: true + } + ] }); } - public async exec( - message: Message, - { user }: { user: string } - ): Promise<Message> { + private async getResponse(user: string): Promise<string | MessageEmbed> { let capeperms: Capeperms, uuid: string; try { uuid = await this.client.util.mcUUID(user); } catch (e) { - return message.util.reply( - `<:error:837123021016924261> \`${user}\` doesn't appear to be a valid username.` - ); + return `<:error:837123021016924261> \`${user}\` doesn't appear to be a valid username.`; } try { @@ -85,27 +92,34 @@ export default class CapePermsCommand extends BotCommand { capeperms = null; } if (capeperms == null) { - return message.util.reply( - `<:error:837123021016924261> There was an error finding cape perms for \`${user}\`.` - ); + return `<: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 message.util.reply( - `<:error:837123021016924261> \`${user}\` does not appear to have any capes.` - ); + return `<: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')); - await message.util.reply(embed); + return embed; } else { - return message.util.reply( - `<:error:837123021016924261> There was an error finding cape perms for ${user}.` - ); + return `<:error:837123021016924261> There was an error finding cape perms for ${user}.`; } } } + public async exec( + message: Message, + { user }: { user: string } + ): Promise<void> { + await message.reply(await this.getResponse(user)); + } + + public async execSlash( + message: CommandInteraction, + { user }: { user: string } + ): Promise<void> { + await message.reply(await this.getResponse(user)); + } } diff --git a/src/commands/moulberry-bush/giveawayping.ts b/src/commands/moulberry-bush/giveawayping.ts index e96b073..d99f475 100644 --- a/src/commands/moulberry-bush/giveawayping.ts +++ b/src/commands/moulberry-bush/giveawayping.ts @@ -43,14 +43,14 @@ export default class GiveawayPingCommand extends BotCommand { '<:error:837123021016924261> This command may only be run in giveaway channels.' ); await message.delete().catch(() => undefined); - const webhooks = await (message.channel as - | TextChannel - | NewsChannel).fetchWebhooks(); + const webhooks = await ( + message.channel as TextChannel | NewsChannel + ).fetchWebhooks(); let webhookClient: WebhookClient; if (webhooks.size < 1) { - const webhook = await (message.channel as - | TextChannel - | NewsChannel).createWebhook('Giveaway ping webhook'); + const webhook = await ( + message.channel as TextChannel | NewsChannel + ).createWebhook('Giveaway ping webhook'); webhookClient = new WebhookClient(webhook.id, webhook.token); } else { const webhook = webhooks.first(); diff --git a/src/commands/moulberry-bush/level.ts b/src/commands/moulberry-bush/level.ts index ab41f42..ab08361 100644 --- a/src/commands/moulberry-bush/level.ts +++ b/src/commands/moulberry-bush/level.ts @@ -1,5 +1,6 @@ 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 { BotCommand } from '../../lib/extensions/BotCommand'; @@ -51,9 +52,10 @@ export default class LevelCommand extends BotCommand { async exec(message: Message, { user }: { user?: User }): Promise<void> { await message.reply(await this.getResponse(user || message.author)); } - async execSlash(message: CommandInteraction): Promise<void> { - const user = - message.options.find((o) => o.name === 'user')?.user || message.user; - await message.reply(await this.getResponse(user)); + async execSlash( + message: CommandInteraction, + { user }: { user?: CommandInteractionOption } + ): Promise<void> { + await message.reply(await this.getResponse(user?.user || message.user)); } } diff --git a/src/commands/moulberry-bush/rule.ts b/src/commands/moulberry-bush/rule.ts index 4eac580..a9414ea 100644 --- a/src/commands/moulberry-bush/rule.ts +++ b/src/commands/moulberry-bush/rule.ts @@ -1,7 +1,9 @@ import { Argument } from 'discord-akairo'; import { Message, MessageEmbed, User } from 'discord.js'; -import AllowedMentions from '../../lib/utils/AllowedMentions'; import { BotCommand } from '../../lib/extensions/BotCommand'; +import { ApplicationCommandOptionType } from 'discord-api-types'; +import { CommandInteraction } from 'discord.js'; +import { SlashCommandOption } from '../../lib/extensions/Util'; export default class RuleCommand extends BotCommand { private rules = [ @@ -98,28 +100,43 @@ export default class RuleCommand extends BotCommand { } ], clientPermissions: ['EMBED_LINKS', 'SEND_MESSAGES'], - channel: 'guild' + channel: 'guild', + slashCommandOptions: [ + { + type: ApplicationCommandOptionType.STRING, + name: 'rule', + description: 'The rule to show', + required: false + }, + { + type: ApplicationCommandOptionType.USER, + name: 'user', + description: 'The user to ping', + required: false + } + ] }); } - public async exec( - message: Message, - { rule, user }: { rule: undefined | number; user: User } - ): Promise<unknown> { + private getResponse( + message: Message | CommandInteraction, + rule?: number, + user?: User + ): string | MessageEmbed | [string, MessageEmbed] { if ( message.guild.id !== '516977525906341928' && - !this.client.ownerID.includes(message.author.id) + !this.client.ownerID.includes( + message instanceof Message ? message.author.id : message.user.id + ) ) { - return message.util.reply( - "<:no:787549684196704257> This command can only be run in Moulberry's Bush." - ); + return "<:no:787549684196704257> This command can only be run in Moulberry's Bush."; } - const rulesEmbed = new MessageEmbed() - .setColor('ef3929') - .setFooter( + let rulesEmbed = new MessageEmbed().setColor('ef3929'); + if (message instanceof Message) { + rulesEmbed = rulesEmbed.setFooter( `Triggered by ${message.author.tag}`, message.author.avatarURL({ dynamic: true }) ); - + } if (rule) { const foundRule = this.rules[rule]; rulesEmbed.addField(foundRule.title, foundRule.description); @@ -129,19 +146,40 @@ export default class RuleCommand extends BotCommand { } } if (!user) { - return ( - // If the original message was a reply -> imamate it - message.util.send({ - embed: rulesEmbed, - allowedMentions: AllowedMentions.users() - }) - ); + return rulesEmbed; } else { - await message.util.send(`<@!${user.id}>`, { - embed: rulesEmbed, - allowedMentions: AllowedMentions.users() + return [`<@!${user.id}>`, rulesEmbed]; + } + } + 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] }); + } else { + await message.util.send(response); } await message.delete().catch(() => undefined); } + + public async execSlash( + message: CommandInteraction, + { + rule, + user + }: { rule?: SlashCommandOption<number>; user?: SlashCommandOption<void> } + ): Promise<void> { + const response = this.getResponse(message, rule?.value, user?.user); + if (Array.isArray(response)) { + await message.reply(response[0], { + embeds: [response[1]] + }); + } else { + await message.reply(response); + } + } } diff --git a/src/commands/owner/eval.ts b/src/commands/owner/eval.ts index 44326b2..2d5eb2d 100644 --- a/src/commands/owner/eval.ts +++ b/src/commands/owner/eval.ts @@ -19,7 +19,7 @@ export default class EvalCommand extends BotCommand { category: 'dev', description: { content: 'Use the command to eval stuff in the bot.', - usage: 'eval [--depth #] <code> [--sudo] [--silent] [--delete]', + usage: 'eval <code> [--silent] [--depth #]', examples: ['eval message.guild.name', 'eval this.client.ownerID'] }, args: [ |