Skip to content
This repository has been archived by the owner on Oct 17, 2024. It is now read-only.

Commit

Permalink
音楽のスキップに権限を要求
Browse files Browse the repository at this point in the history
  • Loading branch information
takejohn committed Jun 28, 2024
1 parent 5e45ffa commit 4040cbd
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
10 changes: 9 additions & 1 deletion packages/player/PlayerCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class PlayerCommand implements Command {
constructor(
data: SlashCommandBuilder,
action: (
interaction: ChatInputCommandInteraction,
interaction: ChatInputCommandInteraction<'cached'>,
queue: GuildQueue<QueueMetadata>,
voiceChannelId: string,
) => Promise<void>,
Expand All @@ -33,6 +33,14 @@ export class PlayerCommand implements Command {
* @param interaction
*/
async execute(interaction: ChatInputCommandInteraction) {
if (!interaction.inCachedGuild()) {
await interaction.reply({
content: LANG.common.message.useCommandInGuild,
ephemeral: true,
});
return;
}

const voiceChannelId = getPlayableVoiceChannelId(interaction);
if (voiceChannelId == null) {
await interaction.reply({
Expand Down
11 changes: 11 additions & 0 deletions packages/player/commands/skip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import assert from 'assert';
import { SlashCommandBuilder } from 'discord.js';
import { LANG, strFormat } from 'core';
import { PlayerCommand } from '../PlayerCommand';
import { feature as perms } from 'perms';

perms.registerPermission('dj', '/skip コマンドの使用');

module.exports = new PlayerCommand(
new SlashCommandBuilder()
Expand All @@ -18,6 +21,14 @@ module.exports = new PlayerCommand(
return;
}

if (!perms.hasPermission(interaction.member, 'dj')) {
await interaction.reply({
content: LANG.common.message.noPermission,
ephemeral: true,
});
return;
}

try {
queue.node.skip();
const currentTrack = queue.currentTrack;
Expand Down
3 changes: 2 additions & 1 deletion packages/player/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
} from './players';
import { Client } from 'discord.js';
import * as db from 'db';
import { feature as perms } from 'perms';

class PlayerFeature extends Feature {
#player: Player | null = null;
Expand All @@ -17,7 +18,7 @@ class PlayerFeature extends Feature {

enabled = Config.features?.player ?? true;

dependencies = [db.feature];
dependencies = [db.feature, perms];

private deletePromise?: Promise<void>;

Expand Down

0 comments on commit 4040cbd

Please sign in to comment.