mirror of
https://github.com/BluemediaGER/muse.git
synced 2024-11-23 09:15:29 +01:00
Migrate disconnect command
This commit is contained in:
parent
c5e4c4b5cf
commit
c33526b8b7
|
@ -1,81 +0,0 @@
|
||||||
import {TextChannel, Message, GuildChannel, ThreadChannel} from 'discord.js';
|
|
||||||
import {injectable} from 'inversify';
|
|
||||||
import {Settings} from '../models/index.js';
|
|
||||||
import errorMsg from '../utils/error-msg.js';
|
|
||||||
import Command from '.';
|
|
||||||
|
|
||||||
@injectable()
|
|
||||||
export default class implements Command {
|
|
||||||
public name = 'config';
|
|
||||||
public aliases = [];
|
|
||||||
public examples = [
|
|
||||||
['config prefix !', 'set the prefix to !'],
|
|
||||||
['config channel music-commands', 'bind the bot to the music-commands channel'],
|
|
||||||
];
|
|
||||||
|
|
||||||
public async execute(msg: Message, args: string []): Promise<void> {
|
|
||||||
if (args.length === 0) {
|
|
||||||
// Show current settings
|
|
||||||
const settings = await Settings.findByPk(msg.guild!.id);
|
|
||||||
|
|
||||||
if (settings) {
|
|
||||||
let response = `prefix: \`${settings.prefix}\`\n`;
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-base-to-string
|
|
||||||
response += `channel: ${msg.guild!.channels.cache.get(settings.channel)!.toString()}`;
|
|
||||||
|
|
||||||
await msg.channel.send(response);
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const setting = args[0];
|
|
||||||
|
|
||||||
if (args.length !== 2) {
|
|
||||||
await msg.channel.send(errorMsg('incorrect number of arguments'));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (msg.author.id !== msg.guild!.ownerId) {
|
|
||||||
await msg.channel.send(errorMsg('not authorized'));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (setting) {
|
|
||||||
case 'prefix': {
|
|
||||||
const newPrefix = args[1];
|
|
||||||
|
|
||||||
await Settings.update({prefix: newPrefix}, {where: {guildId: msg.guild!.id}});
|
|
||||||
|
|
||||||
await msg.channel.send(`👍 prefix updated to \`${newPrefix}\``);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case 'channel': {
|
|
||||||
let channel: GuildChannel | ThreadChannel | undefined;
|
|
||||||
|
|
||||||
if (args[1].includes('<#') && args[1].includes('>')) {
|
|
||||||
channel = msg.guild!.channels.cache.find(c => c.id === args[1].slice(2, args[1].indexOf('>')));
|
|
||||||
} else {
|
|
||||||
channel = msg.guild!.channels.cache.find(c => c.name === args[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (channel && channel.type === 'GUILD_TEXT') {
|
|
||||||
await Settings.update({channel: channel.id}, {where: {guildId: msg.guild!.id}});
|
|
||||||
|
|
||||||
await Promise.all([
|
|
||||||
(channel as TextChannel).send('hey apparently I\'m bound to this channel now'),
|
|
||||||
msg.react('👍'),
|
|
||||||
]);
|
|
||||||
} else {
|
|
||||||
await msg.channel.send(errorMsg('either that channel doesn\'t exist or you want me to become sentient and listen to a voice channel'));
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
default:
|
|
||||||
await msg.channel.send(errorMsg('I\'ve never met this setting in my life'));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,4 +1,5 @@
|
||||||
import {Message} from 'discord.js';
|
import {CommandInteraction} from 'discord.js';
|
||||||
|
import {SlashCommandBuilder} from '@discordjs/builders';
|
||||||
import {TYPES} from '../types.js';
|
import {TYPES} from '../types.js';
|
||||||
import {inject, injectable} from 'inversify';
|
import {inject, injectable} from 'inversify';
|
||||||
import PlayerManager from '../managers/player.js';
|
import PlayerManager from '../managers/player.js';
|
||||||
|
@ -7,11 +8,9 @@ import Command from '.';
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export default class implements Command {
|
export default class implements Command {
|
||||||
public name = 'disconnect';
|
public readonly slashCommand = new SlashCommandBuilder()
|
||||||
public aliases = ['dc'];
|
.setName('disconnect')
|
||||||
public examples = [
|
.setDescription('pauses and disconnects player');
|
||||||
['disconnect', 'pauses and disconnects player'],
|
|
||||||
];
|
|
||||||
|
|
||||||
public requiresVC = true;
|
public requiresVC = true;
|
||||||
|
|
||||||
|
@ -21,16 +20,20 @@ export default class implements Command {
|
||||||
this.playerManager = playerManager;
|
this.playerManager = playerManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async execute(msg: Message, _: string []): Promise<void> {
|
public async executeFromInteraction(interaction: CommandInteraction) {
|
||||||
const player = this.playerManager.get(msg.guild!.id);
|
const player = this.playerManager.get(interaction.guild!.id);
|
||||||
|
|
||||||
if (!player.voiceConnection) {
|
if (!player.voiceConnection) {
|
||||||
await msg.channel.send(errorMsg('not connected'));
|
await interaction.reply({
|
||||||
|
content: errorMsg('not connected'),
|
||||||
|
ephemeral: true,
|
||||||
|
});
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
player.disconnect();
|
player.disconnect();
|
||||||
|
|
||||||
await msg.channel.send('u betcha');
|
await interaction.reply('u betcha');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ export default interface Command {
|
||||||
name?: string;
|
name?: string;
|
||||||
aliases?: string[];
|
aliases?: string[];
|
||||||
examples?: string[][];
|
examples?: string[][];
|
||||||
slashCommand?: Partial<SlashCommandBuilder> & Pick<SlashCommandBuilder, 'toJSON'>;
|
readonly slashCommand?: Partial<SlashCommandBuilder> & Pick<SlashCommandBuilder, 'toJSON'>;
|
||||||
requiresVC?: boolean;
|
requiresVC?: boolean;
|
||||||
executeFromInteraction?: (interaction: CommandInteraction) => Promise<void>;
|
executeFromInteraction?: (interaction: CommandInteraction) => Promise<void>;
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,6 @@ import NaturalLanguage from './services/natural-language-commands.js';
|
||||||
// Comands
|
// Comands
|
||||||
import Command from './commands';
|
import Command from './commands';
|
||||||
import Clear from './commands/clear.js';
|
import Clear from './commands/clear.js';
|
||||||
import Config from './commands/config.js';
|
|
||||||
import Disconnect from './commands/disconnect.js';
|
import Disconnect from './commands/disconnect.js';
|
||||||
import ForwardSeek from './commands/fseek.js';
|
import ForwardSeek from './commands/fseek.js';
|
||||||
import Pause from './commands/pause.js';
|
import Pause from './commands/pause.js';
|
||||||
|
@ -55,7 +54,6 @@ container.bind<NaturalLanguage>(TYPES.Services.NaturalLanguage).to(NaturalLangua
|
||||||
// Commands
|
// Commands
|
||||||
[
|
[
|
||||||
Clear,
|
Clear,
|
||||||
Config,
|
|
||||||
Disconnect,
|
Disconnect,
|
||||||
ForwardSeek,
|
ForwardSeek,
|
||||||
Pause,
|
Pause,
|
||||||
|
|
Loading…
Reference in a new issue