diff options
| author | Kevin Kendzia <[email protected]> | 2022-05-14 02:44:14 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-05-13 19:44:14 -0500 |
| commit | eb2885b2061708415e46929d21bc5991724ce441 (patch) | |
| tree | e77496a2d2fdd249cc505ca1e06d7b17cce957ac /src/commands | |
| parent | 1ef05aba9d2e692ef365721f725be2d2a4e464d9 (diff) | |
| download | muse-eb2885b2061708415e46929d21bc5991724ce441.tar.xz muse-eb2885b2061708415e46929d21bc5991724ce441.zip | |
fix command permission handling and push discord to v10 (#640)
Co-authored-by: Max Isom <[email protected]>
Diffstat (limited to 'src/commands')
| -rw-r--r-- | src/commands/clear.ts | 4 | ||||
| -rw-r--r-- | src/commands/config.ts | 29 | ||||
| -rw-r--r-- | src/commands/disconnect.ts | 4 | ||||
| -rw-r--r-- | src/commands/favorites.ts | 16 | ||||
| -rw-r--r-- | src/commands/fseek.ts | 4 | ||||
| -rw-r--r-- | src/commands/index.ts | 6 | ||||
| -rw-r--r-- | src/commands/move.ts | 4 | ||||
| -rw-r--r-- | src/commands/now-playing.ts | 4 | ||||
| -rw-r--r-- | src/commands/pause.ts | 4 | ||||
| -rw-r--r-- | src/commands/play.ts | 5 | ||||
| -rw-r--r-- | src/commands/queue.ts | 4 | ||||
| -rw-r--r-- | src/commands/remove.ts | 4 | ||||
| -rw-r--r-- | src/commands/resume.ts | 5 | ||||
| -rw-r--r-- | src/commands/seek.ts | 4 | ||||
| -rw-r--r-- | src/commands/shuffle.ts | 4 | ||||
| -rw-r--r-- | src/commands/skip.ts | 4 | ||||
| -rw-r--r-- | src/commands/stop.ts | 4 | ||||
| -rw-r--r-- | src/commands/unskip.ts | 4 |
18 files changed, 46 insertions, 67 deletions
diff --git a/src/commands/clear.ts b/src/commands/clear.ts index 2b258cb..8de8764 100644 --- a/src/commands/clear.ts +++ b/src/commands/clear.ts @@ -1,5 +1,5 @@ import {inject, injectable} from 'inversify'; -import {CommandInteraction} from 'discord.js'; +import {ChatInputCommandInteraction} from 'discord.js'; import {SlashCommandBuilder} from '@discordjs/builders'; import {TYPES} from '../types.js'; import PlayerManager from '../managers/player.js'; @@ -19,7 +19,7 @@ export default class implements Command { this.playerManager = playerManager; } - public async execute(interaction: CommandInteraction) { + public async execute(interaction: ChatInputCommandInteraction) { this.playerManager.get(interaction.guild!.id).clear(); await interaction.reply('clearer than a field after a fresh harvest'); diff --git a/src/commands/config.ts b/src/commands/config.ts index 5ed286f..55dab71 100644 --- a/src/commands/config.ts +++ b/src/commands/config.ts @@ -1,8 +1,7 @@ import {SlashCommandBuilder} from '@discordjs/builders'; -import {CommandInteraction, MessageEmbed} from 'discord.js'; +import {ChatInputCommandInteraction, EmbedBuilder, PermissionFlagsBits} from 'discord.js'; import {injectable} from 'inversify'; import {prisma} from '../utils/db.js'; -import updatePermissionsForGuild from '../utils/update-permissions-for-guild.js'; import Command from './index.js'; @injectable() @@ -10,6 +9,7 @@ export default class implements Command { public readonly slashCommand = new SlashCommandBuilder() .setName('config') .setDescription('configure bot settings') + .setDefaultMemberPermissions(PermissionFlagsBits.ManageGuild.toString() as any) .addSubcommand(subcommand => subcommand .setName('set-playlist-limit') .setDescription('set the maximum number of tracks that can be added from a playlist') @@ -43,10 +43,10 @@ export default class implements Command { .setName('get') .setDescription('show all settings')); - async execute(interaction: CommandInteraction) { + async execute(interaction: ChatInputCommandInteraction) { switch (interaction.options.getSubcommand()) { case 'set-playlist-limit': { - const limit = interaction.options.getInteger('limit')!; + const limit: number = interaction.options.getInteger('limit')!; if (limit < 1) { throw new Error('invalid limit'); @@ -66,25 +66,6 @@ export default class implements Command { break; } - case 'set-role': { - const role = interaction.options.getRole('role')!; - - await prisma.setting.update({ - where: { - guildId: interaction.guild!.id, - }, - data: { - roleId: role.id, - }, - }); - - await updatePermissionsForGuild(interaction.guild!); - - await interaction.reply('👍 role updated'); - - break; - } - case 'set-wait-after-queue-empties': { const delay = interaction.options.getInteger('delay')!; @@ -120,7 +101,7 @@ export default class implements Command { } case 'get': { - const embed = new MessageEmbed().setTitle('Config'); + const embed = new EmbedBuilder().setTitle('Config'); const config = await prisma.setting.findUnique({where: {guildId: interaction.guild!.id}}); diff --git a/src/commands/disconnect.ts b/src/commands/disconnect.ts index fd6b984..d9f025a 100644 --- a/src/commands/disconnect.ts +++ b/src/commands/disconnect.ts @@ -1,4 +1,4 @@ -import {CommandInteraction} from 'discord.js'; +import {ChatInputCommandInteraction} from 'discord.js'; import {SlashCommandBuilder} from '@discordjs/builders'; import {TYPES} from '../types.js'; import {inject, injectable} from 'inversify'; @@ -19,7 +19,7 @@ export default class implements Command { this.playerManager = playerManager; } - public async execute(interaction: CommandInteraction) { + public async execute(interaction: ChatInputCommandInteraction) { const player = this.playerManager.get(interaction.guild!.id); if (!player.voiceConnection) { diff --git a/src/commands/favorites.ts b/src/commands/favorites.ts index 31b1f79..3cfd716 100644 --- a/src/commands/favorites.ts +++ b/src/commands/favorites.ts @@ -1,5 +1,5 @@ import {SlashCommandBuilder} from '@discordjs/builders'; -import {AutocompleteInteraction, CommandInteraction, MessageEmbed} from 'discord.js'; +import {AutocompleteInteraction, ChatInputCommandInteraction, EmbedBuilder} from 'discord.js'; import {inject, injectable} from 'inversify'; import Command from '.'; import AddQueryToQueue from '../services/add-query-to-queue.js'; @@ -56,9 +56,9 @@ export default class implements Command { constructor(@inject(TYPES.Services.AddQueryToQueue) private readonly addQueryToQueue: AddQueryToQueue) {} - requiresVC = (interaction: CommandInteraction) => interaction.options.getSubcommand() === 'use'; + requiresVC = (interaction: ChatInputCommandInteraction) => interaction.options.getSubcommand() === 'use'; - async execute(interaction: CommandInteraction) { + async execute(interaction: ChatInputCommandInteraction) { switch (interaction.options.getSubcommand()) { case 'use': await this.use(interaction); @@ -100,7 +100,7 @@ export default class implements Command { }))); } - private async use(interaction: CommandInteraction) { + private async use(interaction: ChatInputCommandInteraction) { const name = interaction.options.getString('name')!.trim(); const favorite = await prisma.favoriteQuery.findFirst({ @@ -123,7 +123,7 @@ export default class implements Command { }); } - private async list(interaction: CommandInteraction) { + private async list(interaction: ChatInputCommandInteraction) { const favorites = await prisma.favoriteQuery.findMany({ where: { guildId: interaction.guild!.id, @@ -135,7 +135,7 @@ export default class implements Command { return; } - const embed = new MessageEmbed().setTitle('Favorites'); + const embed = new EmbedBuilder().setTitle('Favorites'); let description = ''; for (const favorite of favorites) { @@ -149,7 +149,7 @@ export default class implements Command { }); } - private async create(interaction: CommandInteraction) { + private async create(interaction: ChatInputCommandInteraction) { const name = interaction.options.getString('name')!.trim(); const query = interaction.options.getString('query')!.trim(); @@ -174,7 +174,7 @@ export default class implements Command { await interaction.reply('👍 favorite created'); } - private async remove(interaction: CommandInteraction) { + private async remove(interaction: ChatInputCommandInteraction) { const name = interaction.options.getString('name')!.trim(); const favorite = await prisma.favoriteQuery.findFirst({where: { diff --git a/src/commands/fseek.ts b/src/commands/fseek.ts index 7d0e553..c469948 100644 --- a/src/commands/fseek.ts +++ b/src/commands/fseek.ts @@ -1,4 +1,4 @@ -import {CommandInteraction} from 'discord.js'; +import {ChatInputCommandInteraction} from 'discord.js'; import {SlashCommandBuilder} from '@discordjs/builders'; import {TYPES} from '../types.js'; import {inject, injectable} from 'inversify'; @@ -25,7 +25,7 @@ export default class implements Command { this.playerManager = playerManager; } - public async execute(interaction: CommandInteraction): Promise<void> { + public async execute(interaction: ChatInputCommandInteraction): Promise<void> { const player = this.playerManager.get(interaction.guild!.id); const currentSong = player.getCurrent(); diff --git a/src/commands/index.ts b/src/commands/index.ts index 02349d2..60cf6ce 100644 --- a/src/commands/index.ts +++ b/src/commands/index.ts @@ -1,11 +1,11 @@ import {SlashCommandBuilder, SlashCommandSubcommandsOnlyBuilder} from '@discordjs/builders'; -import {AutocompleteInteraction, ButtonInteraction, CommandInteraction} from 'discord.js'; +import {AutocompleteInteraction, ButtonInteraction, ChatInputCommandInteraction} from 'discord.js'; export default interface Command { readonly slashCommand: Partial<SlashCommandBuilder | SlashCommandSubcommandsOnlyBuilder> & Pick<SlashCommandBuilder, 'toJSON'>; readonly handledButtonIds?: readonly string[]; - readonly requiresVC?: boolean | ((interaction: CommandInteraction) => boolean); - execute: (interaction: CommandInteraction) => Promise<void>; + readonly requiresVC?: boolean | ((interaction: ChatInputCommandInteraction) => boolean); + execute: (interaction: ChatInputCommandInteraction) => Promise<void>; handleButtonInteraction?: (interaction: ButtonInteraction) => Promise<void>; handleAutocompleteInteraction?: (interaction: AutocompleteInteraction) => Promise<void>; } diff --git a/src/commands/move.ts b/src/commands/move.ts index 9855c59..9063473 100644 --- a/src/commands/move.ts +++ b/src/commands/move.ts @@ -1,4 +1,4 @@ -import {CommandInteraction} from 'discord.js'; +import {ChatInputCommandInteraction} from 'discord.js'; import {inject, injectable} from 'inversify'; import {TYPES} from '../types.js'; import PlayerManager from '../managers/player.js'; @@ -26,7 +26,7 @@ export default class implements Command { this.playerManager = playerManager; } - public async execute(interaction: CommandInteraction): Promise<void> { + public async execute(interaction: ChatInputCommandInteraction): Promise<void> { const player = this.playerManager.get(interaction.guild!.id); const from = interaction.options.getInteger('from') ?? 1; diff --git a/src/commands/now-playing.ts b/src/commands/now-playing.ts index 999bb69..55060ed 100644 --- a/src/commands/now-playing.ts +++ b/src/commands/now-playing.ts @@ -1,4 +1,4 @@ -import {CommandInteraction} from 'discord.js'; +import {ChatInputCommandInteraction} from 'discord.js'; import {TYPES} from '../types.js'; import {inject, injectable} from 'inversify'; import PlayerManager from '../managers/player.js'; @@ -18,7 +18,7 @@ export default class implements Command { this.playerManager = playerManager; } - public async execute(interaction: CommandInteraction): Promise<void> { + public async execute(interaction: ChatInputCommandInteraction): Promise<void> { const player = this.playerManager.get(interaction.guild!.id); if (!player.getCurrent()) { diff --git a/src/commands/pause.ts b/src/commands/pause.ts index 7b9d295..b0381ae 100644 --- a/src/commands/pause.ts +++ b/src/commands/pause.ts @@ -1,4 +1,4 @@ -import {CommandInteraction} from 'discord.js'; +import {ChatInputCommandInteraction} from 'discord.js'; import {SlashCommandBuilder} from '@discordjs/builders'; import {TYPES} from '../types.js'; import {inject, injectable} from 'inversify'; @@ -20,7 +20,7 @@ export default class implements Command { this.playerManager = playerManager; } - public async execute(interaction: CommandInteraction) { + public async execute(interaction: ChatInputCommandInteraction) { const player = this.playerManager.get(interaction.guild!.id); if (player.status !== STATUS.PLAYING) { diff --git a/src/commands/play.ts b/src/commands/play.ts index ca23d61..d6149c4 100644 --- a/src/commands/play.ts +++ b/src/commands/play.ts @@ -1,4 +1,4 @@ -import {AutocompleteInteraction, CommandInteraction} from 'discord.js'; +import {AutocompleteInteraction, ChatInputCommandInteraction} from 'discord.js'; import {URL} from 'url'; import {SlashCommandBuilder} from '@discordjs/builders'; import {inject, injectable} from 'inversify'; @@ -43,8 +43,7 @@ export default class implements Command { this.addQueryToQueue = addQueryToQueue; } - // eslint-disable-next-line complexity - public async execute(interaction: CommandInteraction): Promise<void> { + public async execute(interaction: ChatInputCommandInteraction): Promise<void> { const query = interaction.options.getString('query')!; await this.addQueryToQueue.addToQueue({ diff --git a/src/commands/queue.ts b/src/commands/queue.ts index 4d75d42..9115ee6 100644 --- a/src/commands/queue.ts +++ b/src/commands/queue.ts @@ -1,4 +1,4 @@ -import {CommandInteraction} from 'discord.js'; +import {ChatInputCommandInteraction} from 'discord.js'; import {SlashCommandBuilder} from '@discordjs/builders'; import {inject, injectable} from 'inversify'; import {TYPES} from '../types.js'; @@ -22,7 +22,7 @@ export default class implements Command { this.playerManager = playerManager; } - public async execute(interaction: CommandInteraction) { + public async execute(interaction: ChatInputCommandInteraction) { const player = this.playerManager.get(interaction.guild!.id); const embed = buildQueueEmbed(player, interaction.options.getInteger('page') ?? 1); diff --git a/src/commands/remove.ts b/src/commands/remove.ts index 55c416f..5b470c6 100644 --- a/src/commands/remove.ts +++ b/src/commands/remove.ts @@ -1,4 +1,4 @@ -import {CommandInteraction} from 'discord.js'; +import {ChatInputCommandInteraction} from 'discord.js'; import {inject, injectable} from 'inversify'; import {TYPES} from '../types.js'; import PlayerManager from '../managers/player.js'; @@ -26,7 +26,7 @@ export default class implements Command { this.playerManager = playerManager; } - public async execute(interaction: CommandInteraction): Promise<void> { + public async execute(interaction: ChatInputCommandInteraction): Promise<void> { const player = this.playerManager.get(interaction.guild!.id); const position = interaction.options.getInteger('position') ?? 1; diff --git a/src/commands/resume.ts b/src/commands/resume.ts index eddc762..42758f2 100644 --- a/src/commands/resume.ts +++ b/src/commands/resume.ts @@ -6,7 +6,7 @@ import PlayerManager from '../managers/player.js'; import {STATUS} from '../services/player.js'; import {buildPlayingMessageEmbed} from '../utils/build-embed.js'; import {getMemberVoiceChannel, getMostPopularVoiceChannel} from '../utils/channels.js'; -import {CommandInteraction, GuildMember} from 'discord.js'; +import {ChatInputCommandInteraction, GuildMember} from 'discord.js'; @injectable() export default class implements Command { @@ -22,8 +22,7 @@ export default class implements Command { this.playerManager = playerManager; } - // eslint-disable-next-line complexity - public async execute(interaction: CommandInteraction): Promise<void> { + public async execute(interaction: ChatInputCommandInteraction): Promise<void> { const player = this.playerManager.get(interaction.guild!.id); const [targetVoiceChannel] = getMemberVoiceChannel(interaction.member as GuildMember) ?? getMostPopularVoiceChannel(interaction.guild!); if (player.status === STATUS.PLAYING) { diff --git a/src/commands/seek.ts b/src/commands/seek.ts index 00e9c2e..4be51a2 100644 --- a/src/commands/seek.ts +++ b/src/commands/seek.ts @@ -1,4 +1,4 @@ -import {CommandInteraction} from 'discord.js'; +import {ChatInputCommandInteraction} from 'discord.js'; import {TYPES} from '../types.js'; import {inject, injectable} from 'inversify'; import PlayerManager from '../managers/player.js'; @@ -26,7 +26,7 @@ export default class implements Command { this.playerManager = playerManager; } - public async execute(interaction: CommandInteraction): Promise<void> { + public async execute(interaction: ChatInputCommandInteraction): Promise<void> { const player = this.playerManager.get(interaction.guild!.id); const currentSong = player.getCurrent(); diff --git a/src/commands/shuffle.ts b/src/commands/shuffle.ts index 819c01c..a4a1497 100644 --- a/src/commands/shuffle.ts +++ b/src/commands/shuffle.ts @@ -1,4 +1,4 @@ -import {CommandInteraction} from 'discord.js'; +import {ChatInputCommandInteraction} from 'discord.js'; import {TYPES} from '../types.js'; import {inject, injectable} from 'inversify'; import PlayerManager from '../managers/player.js'; @@ -19,7 +19,7 @@ export default class implements Command { this.playerManager = playerManager; } - public async execute(interaction: CommandInteraction): Promise<void> { + public async execute(interaction: ChatInputCommandInteraction): Promise<void> { const player = this.playerManager.get(interaction.guild!.id); if (player.isQueueEmpty()) { diff --git a/src/commands/skip.ts b/src/commands/skip.ts index eb2746a..d8be5d8 100644 --- a/src/commands/skip.ts +++ b/src/commands/skip.ts @@ -1,4 +1,4 @@ -import {CommandInteraction} from 'discord.js'; +import {ChatInputCommandInteraction} from 'discord.js'; import {TYPES} from '../types.js'; import {inject, injectable} from 'inversify'; import PlayerManager from '../managers/player.js'; @@ -24,7 +24,7 @@ export default class implements Command { this.playerManager = playerManager; } - public async execute(interaction: CommandInteraction): Promise<void> { + public async execute(interaction: ChatInputCommandInteraction): Promise<void> { const numToSkip = interaction.options.getInteger('number') ?? 1; if (numToSkip < 1) { diff --git a/src/commands/stop.ts b/src/commands/stop.ts index 3c32c7f..71b33db 100644 --- a/src/commands/stop.ts +++ b/src/commands/stop.ts @@ -1,4 +1,4 @@ -import {CommandInteraction} from 'discord.js'; +import {ChatInputCommandInteraction} from 'discord.js'; import {SlashCommandBuilder} from '@discordjs/builders'; import {TYPES} from '../types.js'; import {inject, injectable} from 'inversify'; @@ -20,7 +20,7 @@ export default class implements Command { this.playerManager = playerManager; } - public async execute(interaction: CommandInteraction) { + public async execute(interaction: ChatInputCommandInteraction) { const player = this.playerManager.get(interaction.guild!.id); if (!player.voiceConnection) { diff --git a/src/commands/unskip.ts b/src/commands/unskip.ts index 936f4ef..31805d3 100644 --- a/src/commands/unskip.ts +++ b/src/commands/unskip.ts @@ -1,4 +1,4 @@ -import {CommandInteraction} from 'discord.js'; +import {ChatInputCommandInteraction} from 'discord.js'; import {TYPES} from '../types.js'; import {inject, injectable} from 'inversify'; import PlayerManager from '../managers/player.js'; @@ -20,7 +20,7 @@ export default class implements Command { this.playerManager = playerManager; } - public async execute(interaction: CommandInteraction): Promise<void> { + public async execute(interaction: ChatInputCommandInteraction): Promise<void> { const player = this.playerManager.get(interaction.guild!.id); try { |
