diff options
author | TymanWasTaken <tyman@tyman.tech> | 2021-06-19 11:31:36 -0600 |
---|---|---|
committer | TymanWasTaken <tyman@tyman.tech> | 2021-06-19 11:31:36 -0600 |
commit | 873123996889c824c7d52785b7cf2903372b71a5 (patch) | |
tree | 00e811e9e9a43f030d6edc6e67f7064b04e37bc1 /src | |
parent | d055e0dbb86ef7fd4ee96a1531b51181e825fb4b (diff) | |
download | tanzanite-873123996889c824c7d52785b7cf2903372b71a5.tar.gz tanzanite-873123996889c824c7d52785b7cf2903372b71a5.tar.bz2 tanzanite-873123996889c824c7d52785b7cf2903372b71a5.zip |
fix: Use latest features of akairo fork
Diffstat (limited to 'src')
-rw-r--r-- | src/commands/dev/reload.ts | 8 | ||||
-rw-r--r-- | src/commands/dev/setLevel.ts | 10 | ||||
-rw-r--r-- | src/commands/info/botInfo.ts | 3 | ||||
-rw-r--r-- | src/commands/info/help.ts | 8 | ||||
-rw-r--r-- | src/commands/info/ping.ts | 3 | ||||
-rw-r--r-- | src/commands/info/pronouns.ts | 8 | ||||
-rw-r--r-- | src/commands/moderation/ban.ts | 12 | ||||
-rw-r--r-- | src/commands/moderation/kick.ts | 10 | ||||
-rw-r--r-- | src/commands/moulberry-bush/capePerms.ts | 8 | ||||
-rw-r--r-- | src/commands/moulberry-bush/level.ts | 8 | ||||
-rw-r--r-- | src/commands/moulberry-bush/rule.ts | 10 | ||||
-rw-r--r-- | src/commands/server-config/prefix.ts | 8 | ||||
-rw-r--r-- | src/lib/extensions/BushClient.ts | 3 | ||||
-rw-r--r-- | src/lib/extensions/BushCommandHandler.ts | 2 | ||||
-rw-r--r-- | src/lib/extensions/BushTaskHandler.ts | 2 | ||||
-rw-r--r-- | src/lib/extensions/Util.ts | 73 | ||||
-rw-r--r-- | src/lib/models/Modlog.ts | 3 | ||||
-rw-r--r-- | src/listeners/client/syncSlashCommands.ts | 19 |
18 files changed, 56 insertions, 142 deletions
diff --git a/src/commands/dev/reload.ts b/src/commands/dev/reload.ts index 3194ce2..4d6cc23 100644 --- a/src/commands/dev/reload.ts +++ b/src/commands/dev/reload.ts @@ -1,5 +1,4 @@ import { stripIndent } from 'common-tags'; -import { ApplicationCommandOptionType } from 'discord-api-types'; import { Message } from 'discord.js'; import { BushCommand } from '../../lib/extensions/BushCommand'; import { BushInteractionMessage } from '../../lib/extensions/BushInteractionMessage'; @@ -24,14 +23,15 @@ export default class ReloadCommand extends BushCommand { ], ownerOnly: true, typing: true, - slashCommandOptions: [ + slashOptions: [ { - type: ApplicationCommandOptionType.BOOLEAN, + type: 'BOOLEAN', name: 'fast', description: 'Wheather to use esbuild for fast compiling or not', required: false } - ] + ], + slash: true }); } diff --git a/src/commands/dev/setLevel.ts b/src/commands/dev/setLevel.ts index 7401699..83545b2 100644 --- a/src/commands/dev/setLevel.ts +++ b/src/commands/dev/setLevel.ts @@ -1,4 +1,3 @@ -import { ApplicationCommandOptionType } from 'discord-api-types'; import { Message, User } from 'discord.js'; import { BushCommand } from '../../lib/extensions/BushCommand'; import { BushInteractionMessage } from '../../lib/extensions/BushInteractionMessage'; @@ -35,20 +34,21 @@ export default class SetLevelCommand extends BushCommand { } ], ownerOnly: true, - slashCommandOptions: [ + slashOptions: [ { - type: ApplicationCommandOptionType.USER, + type: 'USER', name: 'user', description: 'The user to change the level of', required: true }, { - type: ApplicationCommandOptionType.INTEGER, + type: 'INTEGER', name: 'level', description: 'The level to set the user to', required: true } - ] + ], + slash: true }); } diff --git a/src/commands/info/botInfo.ts b/src/commands/info/botInfo.ts index 66bf5af..406ea2d 100644 --- a/src/commands/info/botInfo.ts +++ b/src/commands/info/botInfo.ts @@ -12,7 +12,8 @@ export default class BotInfoCommand extends BushCommand { content: 'Shows information about the bot', usage: 'botinfo', examples: ['botinfo'] - } + }, + slash: true }); } diff --git a/src/commands/info/help.ts b/src/commands/info/help.ts index 317091e..4073f74 100644 --- a/src/commands/info/help.ts +++ b/src/commands/info/help.ts @@ -1,5 +1,4 @@ import { stripIndent } from 'common-tags'; -import { ApplicationCommandOptionType } from 'discord-api-types'; import { Message, MessageEmbed } from 'discord.js'; import { BushCommand } from '../../lib/extensions/BushCommand'; import { BushInteractionMessage } from '../../lib/extensions/BushInteractionMessage'; @@ -22,14 +21,15 @@ export default class HelpCommand extends BushCommand { type: 'commandAlias' } ], - slashCommandOptions: [ + slashOptions: [ { - type: ApplicationCommandOptionType.STRING, + type: 'STRING', name: 'command', description: 'The command to get help for', required: false } - ] + ], + slash: true }); } diff --git a/src/commands/info/ping.ts b/src/commands/info/ping.ts index feb48ad..9b3b67b 100644 --- a/src/commands/info/ping.ts +++ b/src/commands/info/ping.ts @@ -11,7 +11,8 @@ export default class PingCommand extends BushCommand { content: 'Gets the latency of the bot', usage: 'ping', examples: ['ping'] - } + }, + slash: true }); } diff --git a/src/commands/info/pronouns.ts b/src/commands/info/pronouns.ts index faf3aa2..58b9580 100644 --- a/src/commands/info/pronouns.ts +++ b/src/commands/info/pronouns.ts @@ -1,4 +1,3 @@ -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'; @@ -48,15 +47,16 @@ export default class PronounsCommand extends BushCommand { } ], clientPermissions: ['SEND_MESSAGES'], - slashCommandOptions: [ + slashOptions: [ { - type: ApplicationCommandOptionType.USER, + type: 'USER', name: 'user', description: 'The user to get pronouns for', required: false } ], - slashEphemeral: true // I'll add dynamic checking to this later + slashEphemeral: true, // I'll add dynamic checking to this later + slash: true }); } async sendResponse(message: Message | CommandInteraction, user: User, author: boolean): Promise<void> { diff --git a/src/commands/moderation/ban.ts b/src/commands/moderation/ban.ts index f843ac4..e67bd6a 100644 --- a/src/commands/moderation/ban.ts +++ b/src/commands/moderation/ban.ts @@ -1,4 +1,3 @@ -import { ApplicationCommandOptionType } from 'discord-api-types'; import { CommandInteraction, Message, User } from 'discord.js'; import moment from 'moment'; import { BushCommand } from '../../lib/extensions/BushCommand'; @@ -46,26 +45,27 @@ export default class BanCommand extends BushCommand { usage: 'ban <member> <reason> [--time]', examples: ['ban @Tyman being cool', 'ban @Tyman being cool --time 7days'] }, - slashCommandOptions: [ + slashOptions: [ { - type: ApplicationCommandOptionType.USER, + type: 'USER', name: 'user', description: 'The user to ban', required: true }, { - type: ApplicationCommandOptionType.STRING, + type: 'STRING', name: 'reason', description: 'The reason to show in modlogs and audit log', required: false }, { - type: ApplicationCommandOptionType.STRING, + type: 'STRING', name: 'time', description: 'The time the user should be banned for (default permanent)', required: false } - ] + ], + slash: true }); } async *genResponses( diff --git a/src/commands/moderation/kick.ts b/src/commands/moderation/kick.ts index eed0122..3e2e8d1 100644 --- a/src/commands/moderation/kick.ts +++ b/src/commands/moderation/kick.ts @@ -1,4 +1,3 @@ -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'; @@ -29,20 +28,21 @@ export default class KickCommand extends BushCommand { usage: 'kick <member> <reason>', examples: ['kick @Tyman being cool'] }, - slashCommandOptions: [ + slashOptions: [ { - type: ApplicationCommandOptionType.USER, + type: 'USER', name: 'user', description: 'The user to kick', required: true }, { - type: ApplicationCommandOptionType.STRING, + type: 'STRING', name: 'reason', description: 'The reason to show in modlogs and audit log', required: false } - ] + ], + slash: true }); } diff --git a/src/commands/moulberry-bush/capePerms.ts b/src/commands/moulberry-bush/capePerms.ts index 7eb90c5..42e0d77 100644 --- a/src/commands/moulberry-bush/capePerms.ts +++ b/src/commands/moulberry-bush/capePerms.ts @@ -1,4 +1,3 @@ -import { ApplicationCommandOptionType } from 'discord-api-types'; import { Message, MessageEmbed } from 'discord.js'; import got from 'got'; import { BushCommand } from '../../lib/extensions/BushCommand'; @@ -64,14 +63,15 @@ export default class CapePermissionsCommand extends BushCommand { ], clientPermissions: ['EMBED_LINKS', 'SEND_MESSAGES'], channel: 'guild', - slashCommandOptions: [ + slashOptions: [ { - type: ApplicationCommandOptionType.STRING, + type: 'STRING', name: 'user', description: 'The username of the player to see the cape permissions of', required: true } - ] + ], + slash: true }); } private async getResponse(user: string): Promise<{ content?: string; embeds?: MessageEmbed[] }> { diff --git a/src/commands/moulberry-bush/level.ts b/src/commands/moulberry-bush/level.ts index f53aa64..64d6dad 100644 --- a/src/commands/moulberry-bush/level.ts +++ b/src/commands/moulberry-bush/level.ts @@ -1,4 +1,3 @@ -import { ApplicationCommandOptionType } from 'discord-api-types'; import { CommandInteractionOption, Message, User } from 'discord.js'; import { BushCommand } from '../../lib/extensions/BushCommand'; import { BushInteractionMessage } from '../../lib/extensions/BushInteractionMessage'; @@ -32,14 +31,15 @@ export default class LevelCommand extends BushCommand { } } ], - slashCommandOptions: [ + slashOptions: [ { - type: ApplicationCommandOptionType.USER, + type: 'USER', name: 'user', description: 'The user to get the level of', required: false } - ] + ], + slash: true }); } diff --git a/src/commands/moulberry-bush/rule.ts b/src/commands/moulberry-bush/rule.ts index b71b42f..c11c5d2 100644 --- a/src/commands/moulberry-bush/rule.ts +++ b/src/commands/moulberry-bush/rule.ts @@ -1,5 +1,4 @@ import { Argument } from 'discord-akairo'; -import { ApplicationCommandOptionType } from 'discord-api-types'; import { CommandInteraction, Message, MessageEmbed, User } from 'discord.js'; import { BushCommand } from '../../lib/extensions/BushCommand'; import { BushInteractionMessage } from '../../lib/extensions/BushInteractionMessage'; @@ -98,20 +97,21 @@ export default class RuleCommand extends BushCommand { ], clientPermissions: ['EMBED_LINKS', 'SEND_MESSAGES'], channel: 'guild', - slashCommandOptions: [ + slashOptions: [ { - type: ApplicationCommandOptionType.INTEGER, + type: 'INTEGER', name: 'rule', description: 'The rule to show', required: false }, { - type: ApplicationCommandOptionType.USER, + type: 'USER', name: 'user', description: 'The user to ping', required: false } - ] + ], + slash: true }); } private getResponse( diff --git a/src/commands/server-config/prefix.ts b/src/commands/server-config/prefix.ts index 9cdc331..28f8496 100644 --- a/src/commands/server-config/prefix.ts +++ b/src/commands/server-config/prefix.ts @@ -1,4 +1,3 @@ -import { ApplicationCommandOptionType } from 'discord-api-types'; import { Guild as DiscordGuild, Message } from 'discord.js'; import { BushCommand } from '../../lib/extensions/BushCommand'; import { BushInteractionMessage } from '../../lib/extensions/BushInteractionMessage'; @@ -21,14 +20,15 @@ export default class PrefixCommand extends BushCommand { usage: 'prefix [prefix]', examples: ['prefix', 'prefix +'] }, - slashCommandOptions: [ + slashOptions: [ { - type: ApplicationCommandOptionType.STRING, + type: 'STRING', name: 'prefix', description: 'The prefix to set for this server', required: false } - ] + ], + slash: true }); } diff --git a/src/lib/extensions/BushClient.ts b/src/lib/extensions/BushClient.ts index e2e889b..a173804 100644 --- a/src/lib/extensions/BushClient.ts +++ b/src/lib/extensions/BushClient.ts @@ -80,7 +80,8 @@ export class BushClient extends AkairoClient { }, ignorePermissions: this.config.owners, ignoreCooldown: this.config.owners, - automateCategories: true + automateCategories: true, + autoRegisterSlashCommands: true }); this.util = new BushUtil(this); diff --git a/src/lib/extensions/BushCommandHandler.ts b/src/lib/extensions/BushCommandHandler.ts index 6ef44d7..52e4665 100644 --- a/src/lib/extensions/BushCommandHandler.ts +++ b/src/lib/extensions/BushCommandHandler.ts @@ -3,7 +3,7 @@ import { Collection } from 'discord.js'; import { BushClient } from './BushClient'; import { BushCommand } from './BushCommand'; -export interface BushCommandHandlerOptions extends CommandHandlerOptions {} +export type BushCommandHandlerOptions = CommandHandlerOptions; export class BushCommandHandler extends CommandHandler { public constructor(client: BushClient, options: BushCommandHandlerOptions) { diff --git a/src/lib/extensions/BushTaskHandler.ts b/src/lib/extensions/BushTaskHandler.ts index f783eb3..923e42b 100644 --- a/src/lib/extensions/BushTaskHandler.ts +++ b/src/lib/extensions/BushTaskHandler.ts @@ -1,7 +1,7 @@ import { AkairoHandlerOptions, TaskHandler } from 'discord-akairo'; import { BushClient } from './BushClient'; -export interface BushTaskHandlerOptions extends AkairoHandlerOptions {} +export type BushTaskHandlerOptions = AkairoHandlerOptions; export class BushTaskHandler extends TaskHandler { public constructor(client: BushClient, options: BushTaskHandlerOptions) { diff --git a/src/lib/extensions/Util.ts b/src/lib/extensions/Util.ts index 3913437..4a4ccef 100644 --- a/src/lib/extensions/Util.ts +++ b/src/lib/extensions/Util.ts @@ -1,6 +1,5 @@ -import chalk from 'chalk'; import { exec } from 'child_process'; -import { ClientUtil, Command } from 'discord-akairo'; +import { ClientUtil } from 'discord-akairo'; import { APIInteractionDataResolvedChannel, APIInteractionDataResolvedGuildMember, @@ -11,7 +10,6 @@ import { ButtonInteraction, CommandInteractionOption, Constants, - Guild, GuildChannel, GuildMember, MessageActionRow, @@ -260,73 +258,6 @@ export class BushUtil extends ClientUtil { return apiRes.uuid.replace(/-/g, ''); } - public async syncSlashCommands(force = false, guild?: Snowflake): Promise<void> { - let fetchedGuild: Guild; - if (guild) fetchedGuild = this.client.guilds.cache.get(guild); - try { - const registered = - guild === undefined ? await this.client.application.commands.fetch() : await fetchedGuild.commands.fetch(); - for (const [, registeredCommand] of registered) { - if (!this.client.commandHandler.modules.find((cmd) => cmd.id == registeredCommand.name)?.execSlash || force) { - guild === undefined - ? await this.client.application.commands.delete(registeredCommand.id) - : await fetchedGuild.commands.delete(registeredCommand.id); - this.client.logger.verbose( - chalk`{red Deleted slash command ${registeredCommand.name}${ - guild !== undefined ? ` in guild ${fetchedGuild.name}` : '' - }}` - ); - } - } - - for (const [, botCommand] of this.client.commandHandler.modules) { - if (botCommand.execSlash) { - const found = registered.find((i) => i.name == botCommand.id); - Command; - const slashdata = { - name: botCommand.id, - description: botCommand.description.content, - options: botCommand.options.slashCommandOptions - }; - botCommand; - - if (found?.id && !force) { - if (slashdata.description !== found.description) { - guild === undefined - ? await this.client.application.commands.edit(found.id, slashdata) - : fetchedGuild.commands.edit(found.id, slashdata); - this.client.logger.verbose( - chalk`{yellow Edited slash command ${botCommand.id}${ - guild !== undefined ? ` in guild ${fetchedGuild.name}` : '' - }}` - ); - } - } else { - guild === undefined - ? await this.client.application.commands.create(slashdata) - : fetchedGuild.commands.create(slashdata); - this.client.logger.verbose( - chalk`{green Created slash command ${botCommand.id}${ - guild !== undefined ? ` in guild ${fetchedGuild.name}` : '' - }}` - ); - } - } - } - - return this.client.logger.log( - chalk.green(`Slash commands registered${guild !== undefined ? ` in guild ${fetchedGuild.name}` : ''}`) - ); - } catch (e) { - console.log(chalk.red(e.stack)); - return this.client.logger.error( - chalk`{red Slash commands not registered${ - guild !== undefined ? ` in guild ${fetchedGuild.name}` : '' - }, see above error.}` - ); - } - } - public moulberryBushRoleMap = [ { name: '*', id: '792453550768390194' }, { name: 'Admin Perms', id: '746541309853958186' }, @@ -424,7 +355,7 @@ export class BushUtil extends ClientUtil { }); collector.on('end', async () => { - await msg.edit({ content: text, embeds: [embeds[curPage]], components: [getPaginationRow(true)] }).catch(() => {}); + await msg.edit({ content: text, embeds: [embeds[curPage]], components: [getPaginationRow(true)] }).catch(() => undefined); }); async function edit(interaction: MessageComponentInteraction): Promise<void> { diff --git a/src/lib/models/Modlog.ts b/src/lib/models/Modlog.ts index 3917a88..5a2cb69 100644 --- a/src/lib/models/Modlog.ts +++ b/src/lib/models/Modlog.ts @@ -1,7 +1,6 @@ import { DataTypes, Sequelize } from 'sequelize'; -import { BaseModel } from './BaseModel'; import { v4 as uuidv4 } from 'uuid'; -import * as Models from './'; +import { BaseModel } from './BaseModel'; export enum ModlogType { BAN = 'BAN', diff --git a/src/listeners/client/syncSlashCommands.ts b/src/listeners/client/syncSlashCommands.ts deleted file mode 100644 index 69b91bc..0000000 --- a/src/listeners/client/syncSlashCommands.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { BushListener } from '../../lib/extensions/BushListener'; - -export default class SyncSlashCommandsListener extends BushListener { - constructor() { - super('syncslashcommands', { - emitter: 'client', - event: 'ready' - }); - } - async exec(): Promise<void> { - if (this.client.config.dev && this.client.config.devGuild) { - // Use guild slash commands for instant registration in dev - await this.client.util.syncSlashCommands(false, this.client.config.devGuild); - } else { - // Use global in production - await this.client.util.syncSlashCommands(); - } - } -} |