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/moulberry-bush/rule.ts | |
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/moulberry-bush/rule.ts')
-rw-r--r-- | src/commands/moulberry-bush/rule.ts | 86 |
1 files changed, 62 insertions, 24 deletions
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); + } + } } |