SameVC inhibitor
This commit is contained in:
parent
7bf2510235
commit
671623dca7
9
@types/DiscordClient.d.ts
vendored
9
@types/DiscordClient.d.ts
vendored
@ -19,7 +19,7 @@ export type ClientOptions = {
|
|||||||
music: MusicPlayerOptions
|
music: MusicPlayerOptions
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ComponentType = 'command' | 'module' | 'observer' | 'inhibitor' | 'setting';
|
export type ComponentType = 'command' | 'module' | 'observer' | 'inhibitor' | 'setting' | 'downloader';
|
||||||
|
|
||||||
export type ComponentOptions = {
|
export type ComponentOptions = {
|
||||||
type: ComponentType,
|
type: ComponentType,
|
||||||
@ -35,7 +35,8 @@ export type CommandDefinition = {
|
|||||||
guildOnly?: boolean,
|
guildOnly?: boolean,
|
||||||
help?: string,
|
help?: string,
|
||||||
limited?: Snowflake[],
|
limited?: Snowflake[],
|
||||||
showUsage?: boolean
|
showUsage?: boolean,
|
||||||
|
sameVc?: boolean
|
||||||
} & Omit<ComponentOptions, 'type'>
|
} & Omit<ComponentOptions, 'type'>
|
||||||
|
|
||||||
export type ObserverOptions = {
|
export type ObserverOptions = {
|
||||||
@ -48,6 +49,10 @@ export type InhibitorOptions = {
|
|||||||
silent?: boolean
|
silent?: boolean
|
||||||
} & Omit<ComponentOptions, 'type'>
|
} & Omit<ComponentOptions, 'type'>
|
||||||
|
|
||||||
|
export type DownloaderOptions = {
|
||||||
|
//
|
||||||
|
} & Omit<ComponentOptions, 'type'>
|
||||||
|
|
||||||
export type InhibitorResponse<T extends boolean = boolean> = {
|
export type InhibitorResponse<T extends boolean = boolean> = {
|
||||||
error: T,
|
error: T,
|
||||||
inhibitor: Inhibitor,
|
inhibitor: Inhibitor,
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { Message } from 'discord.js';
|
import { Message } from 'discord.js';
|
||||||
import Command from '../../../interfaces/Command.js';
|
import Command from '../../../interfaces/Command.js';
|
||||||
import DiscordClient from '../../DiscordClient.js';
|
import DiscordClient from '../../DiscordClient.js';
|
||||||
import { CommandOpts } from '@navy.gif/commandparser';
|
import { CommandOpts, OptionType } from '@navy.gif/commandparser';
|
||||||
|
|
||||||
class QueueCommand extends Command
|
class QueueCommand extends Command
|
||||||
{
|
{
|
||||||
@ -9,14 +9,16 @@ class QueueCommand extends Command
|
|||||||
{
|
{
|
||||||
super(client, {
|
super(client, {
|
||||||
name: 'queue',
|
name: 'queue',
|
||||||
showUsage: true,
|
|
||||||
options: [{
|
options: [{
|
||||||
name: 'artist',
|
name: 'artist',
|
||||||
flag: true
|
flag: true
|
||||||
}, {
|
}, {
|
||||||
name: 'song',
|
name: 'id',
|
||||||
required: true
|
flag: true,
|
||||||
}]
|
type: OptionType.INTEGER
|
||||||
|
}, {
|
||||||
|
name: 'song'
|
||||||
|
}],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -24,16 +26,30 @@ class QueueCommand extends Command
|
|||||||
{
|
{
|
||||||
const { member, guild } = message;
|
const { member, guild } = message;
|
||||||
const { me } = guild.members;
|
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)
|
if (!member?.voice || member.voice.channelId !== me?.voice.channelId)
|
||||||
return 'Only vc participants can queue songs';
|
return 'Only vc participants can queue songs';
|
||||||
|
|
||||||
const query = {
|
const query = {
|
||||||
title: args.song!.value as string,
|
title: args.song?.value as string | undefined,
|
||||||
artist: args.artist?.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)
|
if (!result)
|
||||||
return 'Query yielded no results';
|
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, {
|
super(client, {
|
||||||
name: 'skip',
|
name: 'skip',
|
||||||
guildOnly: true,
|
guildOnly: true,
|
||||||
restricted: true
|
restricted: true,
|
||||||
|
sameVc: true
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async execute (message: Message<true>)
|
async execute (message: Message<true>)
|
||||||
{
|
{
|
||||||
const { member, author, guild } = message;
|
const { author } = message;
|
||||||
const { me } = guild.members;
|
|
||||||
if (!member?.voice || member.voice.channelId !== me?.voice.channelId)
|
|
||||||
return 'Only vc participants can adjust volume';
|
|
||||||
|
|
||||||
this.logger.info(`${author.username} (${author.id}) skipped a song`);
|
this.logger.info(`${author.username} (${author.id}) skipped a song`);
|
||||||
this.client.musicPlayer.playNext();
|
this.client.musicPlayer.playNext();
|
||||||
return 'Song skipped';
|
return 'Song skipped';
|
||||||
|
@ -19,7 +19,8 @@ class VolumeCommand extends Command
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
guildOnly: true,
|
guildOnly: true,
|
||||||
restricted: true
|
restricted: true,
|
||||||
|
sameVc: true,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -29,11 +30,7 @@ class VolumeCommand extends Command
|
|||||||
if (!volume)
|
if (!volume)
|
||||||
return `Volume is currently at ${this.client.musicPlayer.volume}`;
|
return `Volume is currently at ${this.client.musicPlayer.volume}`;
|
||||||
|
|
||||||
const { member, author, guild } = message;
|
const { author } = message;
|
||||||
const { me } = guild.members;
|
|
||||||
if (!member?.voice || member.voice.channelId !== me?.voice.channelId)
|
|
||||||
return 'Only vc participants can adjust volume';
|
|
||||||
|
|
||||||
this.logger.info(`${author.username} (${author.id}) is adjusting volume to ${volume.value}`);
|
this.logger.info(`${author.username} (${author.id}) is adjusting volume to ${volume.value}`);
|
||||||
this.client.musicPlayer.volume = (volume.value as number);
|
this.client.musicPlayer.volume = (volume.value as number);
|
||||||
return `Volume set to ${volume.value}`;
|
return `Volume set to ${volume.value}`;
|
||||||
|
@ -9,7 +9,8 @@ class GuildOnlyInhibitor extends Inhibitor
|
|||||||
constructor (client: DiscordClient)
|
constructor (client: DiscordClient)
|
||||||
{
|
{
|
||||||
super(client, {
|
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