SameVC inhibitor
This commit is contained in:
parent
7bf2510235
commit
671623dca7
11
@types/DiscordClient.d.ts
vendored
11
@types/DiscordClient.d.ts
vendored
@ -19,7 +19,7 @@ export type ClientOptions = {
|
||||
music: MusicPlayerOptions
|
||||
}
|
||||
|
||||
export type ComponentType = 'command' | 'module' | 'observer' | 'inhibitor' | 'setting';
|
||||
export type ComponentType = 'command' | 'module' | 'observer' | 'inhibitor' | 'setting' | 'downloader';
|
||||
|
||||
export type ComponentOptions = {
|
||||
type: ComponentType,
|
||||
@ -35,7 +35,8 @@ export type CommandDefinition = {
|
||||
guildOnly?: boolean,
|
||||
help?: string,
|
||||
limited?: Snowflake[],
|
||||
showUsage?: boolean
|
||||
showUsage?: boolean,
|
||||
sameVc?: boolean
|
||||
} & Omit<ComponentOptions, 'type'>
|
||||
|
||||
export type ObserverOptions = {
|
||||
@ -46,7 +47,11 @@ export type ObserverOptions = {
|
||||
export type InhibitorOptions = {
|
||||
priority?: number,
|
||||
silent?: boolean
|
||||
}& Omit<ComponentOptions, 'type'>
|
||||
} & Omit<ComponentOptions, 'type'>
|
||||
|
||||
export type DownloaderOptions = {
|
||||
//
|
||||
} & Omit<ComponentOptions, 'type'>
|
||||
|
||||
export type InhibitorResponse<T extends boolean = boolean> = {
|
||||
error: T,
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { Message } from 'discord.js';
|
||||
import Command from '../../../interfaces/Command.js';
|
||||
import DiscordClient from '../../DiscordClient.js';
|
||||
import { CommandOpts } from '@navy.gif/commandparser';
|
||||
import { CommandOpts, OptionType } from '@navy.gif/commandparser';
|
||||
|
||||
class QueueCommand extends Command
|
||||
{
|
||||
@ -9,14 +9,16 @@ class QueueCommand extends Command
|
||||
{
|
||||
super(client, {
|
||||
name: 'queue',
|
||||
showUsage: true,
|
||||
options: [{
|
||||
name: 'artist',
|
||||
flag: true
|
||||
}, {
|
||||
name: 'song',
|
||||
required: true
|
||||
}]
|
||||
name: 'id',
|
||||
flag: true,
|
||||
type: OptionType.INTEGER
|
||||
}, {
|
||||
name: 'song'
|
||||
}],
|
||||
});
|
||||
}
|
||||
|
||||
@ -24,16 +26,30 @@ class QueueCommand extends Command
|
||||
{
|
||||
const { member, guild } = message;
|
||||
const { me } = guild.members;
|
||||
|
||||
if (!Object.keys(args).length)
|
||||
{
|
||||
const { queue } = this.client.musicPlayer;
|
||||
if (!queue.length)
|
||||
return 'Queue empty';
|
||||
return `
|
||||
**Music queue:**\n${queue.map(entry => `\t\\- **${entry.title}** by ${entry.artist}`).join('\n')}
|
||||
`;
|
||||
}
|
||||
|
||||
if (!member?.voice || member.voice.channelId !== me?.voice.channelId)
|
||||
return 'Only vc participants can queue songs';
|
||||
|
||||
const query = {
|
||||
title: args.song!.value as string,
|
||||
title: args.song?.value as string | undefined,
|
||||
artist: args.artist?.value as string | undefined,
|
||||
id: args.id?.value as number | undefined
|
||||
};
|
||||
const result = this.client.musicPlayer.queue(query);
|
||||
|
||||
const result = this.client.musicPlayer.queueSong(query);
|
||||
if (!result)
|
||||
return 'Query yielded no results';
|
||||
return `Song **${result.title}** by ${result.arist} queued`;
|
||||
return `Song **${result.title}** by ${result.artist} queued`;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,17 +9,14 @@ class SkipCommand extends Command
|
||||
super(client, {
|
||||
name: 'skip',
|
||||
guildOnly: true,
|
||||
restricted: true
|
||||
restricted: true,
|
||||
sameVc: true
|
||||
});
|
||||
}
|
||||
|
||||
async execute (message: Message<true>)
|
||||
{
|
||||
const { member, author, guild } = message;
|
||||
const { me } = guild.members;
|
||||
if (!member?.voice || member.voice.channelId !== me?.voice.channelId)
|
||||
return 'Only vc participants can adjust volume';
|
||||
|
||||
const { author } = message;
|
||||
this.logger.info(`${author.username} (${author.id}) skipped a song`);
|
||||
this.client.musicPlayer.playNext();
|
||||
return 'Song skipped';
|
||||
|
@ -19,7 +19,8 @@ class VolumeCommand extends Command
|
||||
}
|
||||
],
|
||||
guildOnly: true,
|
||||
restricted: true
|
||||
restricted: true,
|
||||
sameVc: true,
|
||||
});
|
||||
}
|
||||
|
||||
@ -29,11 +30,7 @@ class VolumeCommand extends Command
|
||||
if (!volume)
|
||||
return `Volume is currently at ${this.client.musicPlayer.volume}`;
|
||||
|
||||
const { member, author, guild } = message;
|
||||
const { me } = guild.members;
|
||||
if (!member?.voice || member.voice.channelId !== me?.voice.channelId)
|
||||
return 'Only vc participants can adjust volume';
|
||||
|
||||
const { author } = message;
|
||||
this.logger.info(`${author.username} (${author.id}) is adjusting volume to ${volume.value}`);
|
||||
this.client.musicPlayer.volume = (volume.value as number);
|
||||
return `Volume set to ${volume.value}`;
|
||||
|
@ -9,7 +9,8 @@ class GuildOnlyInhibitor extends Inhibitor
|
||||
constructor (client: DiscordClient)
|
||||
{
|
||||
super(client, {
|
||||
name: 'GuildOnly'
|
||||
name: 'GuildOnly',
|
||||
priority: 4
|
||||
});
|
||||
}
|
||||
|
||||
|
29
src/client/components/inhibitors/SameVC.ts
Normal file
29
src/client/components/inhibitors/SameVC.ts
Normal file
@ -0,0 +1,29 @@
|
||||
import { Message } from 'discord.js';
|
||||
import Inhibitor from '../../../interfaces/Inhibitor.js';
|
||||
import DiscordClient from '../../DiscordClient.js';
|
||||
import { InhibitorResponse } from '../../../../@types/DiscordClient.js';
|
||||
|
||||
class SameVCInhibitor extends Inhibitor
|
||||
{
|
||||
constructor (client: DiscordClient)
|
||||
{
|
||||
super(client, {
|
||||
name: 'SameVC',
|
||||
});
|
||||
}
|
||||
|
||||
override async execute (message: Message<true>): Promise<InhibitorResponse>
|
||||
{
|
||||
const { member, guild } = message;
|
||||
if (!guild)
|
||||
return super._fail('This command cannot be executed outside of a server');
|
||||
|
||||
const { me } = guild.members;
|
||||
if (!member?.voice || member.voice.channelId !== me?.voice.channelId)
|
||||
super._fail('Only vc participants can queue songs');
|
||||
return super._succeed();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default SameVCInhibitor;
|
Loading…
Reference in New Issue
Block a user