mirror of
https://github.com/BluemediaGER/muse.git
synced 2024-11-23 01:05:30 +01:00
Add disconnect command
This commit is contained in:
parent
6a02088b04
commit
8340f9b95a
27
src/commands/disconnect.ts
Normal file
27
src/commands/disconnect.ts
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
import {Message} from 'discord.js';
|
||||||
|
import {TYPES} from '../types';
|
||||||
|
import {inject, injectable} from 'inversify';
|
||||||
|
import PlayerManager from '../managers/player';
|
||||||
|
import Command from '.';
|
||||||
|
|
||||||
|
@injectable()
|
||||||
|
export default class implements Command {
|
||||||
|
public name = 'disconnect';
|
||||||
|
public examples = [
|
||||||
|
['disconnect', 'pauses and disconnects player']
|
||||||
|
];
|
||||||
|
|
||||||
|
private readonly playerManager: PlayerManager;
|
||||||
|
|
||||||
|
constructor(@inject(TYPES.Managers.Player) playerManager: PlayerManager) {
|
||||||
|
this.playerManager = playerManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async execute(msg: Message, _: string []): Promise<void> {
|
||||||
|
const player = this.playerManager.get(msg.guild!.id);
|
||||||
|
|
||||||
|
player.disconnect();
|
||||||
|
|
||||||
|
await msg.channel.send('u betcha');
|
||||||
|
}
|
||||||
|
}
|
|
@ -57,7 +57,7 @@ export default class implements Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Must be resuming play
|
// Must be resuming play
|
||||||
if (queue.get().length === 0) {
|
if (queue.get().length === 0 && !queue.getCurrent()) {
|
||||||
await res.stop(errorMsg('nothing to play'));
|
await res.stop(errorMsg('nothing to play'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@ import NaturalLanguage from './services/natural-language-commands';
|
||||||
import Command from './commands';
|
import Command from './commands';
|
||||||
import Clear from './commands/clear';
|
import Clear from './commands/clear';
|
||||||
import Config from './commands/config';
|
import Config from './commands/config';
|
||||||
|
import Disconnect from './commands/disconnect';
|
||||||
import ForwardSeek from './commands/fseek';
|
import ForwardSeek from './commands/fseek';
|
||||||
import Help from './commands/help';
|
import Help from './commands/help';
|
||||||
import Pause from './commands/pause';
|
import Pause from './commands/pause';
|
||||||
|
@ -53,18 +54,23 @@ container.bind<GetSongs>(TYPES.Services.GetSongs).to(GetSongs).inSingletonScope(
|
||||||
container.bind<NaturalLanguage>(TYPES.Services.NaturalLanguage).to(NaturalLanguage).inSingletonScope();
|
container.bind<NaturalLanguage>(TYPES.Services.NaturalLanguage).to(NaturalLanguage).inSingletonScope();
|
||||||
|
|
||||||
// Commands
|
// Commands
|
||||||
container.bind<Command>(TYPES.Command).to(Clear).inSingletonScope();
|
[
|
||||||
container.bind<Command>(TYPES.Command).to(Config).inSingletonScope();
|
Clear,
|
||||||
container.bind<Command>(TYPES.Command).to(ForwardSeek).inSingletonScope();
|
Config,
|
||||||
container.bind<Command>(TYPES.Command).to(Help).inSingletonScope();
|
Disconnect,
|
||||||
container.bind<Command>(TYPES.Command).to(Pause).inSingletonScope();
|
ForwardSeek,
|
||||||
container.bind<Command>(TYPES.Command).to(Play).inSingletonScope();
|
Help,
|
||||||
container.bind<Command>(TYPES.Command).to(QueueCommad).inSingletonScope();
|
Pause,
|
||||||
container.bind<Command>(TYPES.Command).to(Seek).inSingletonScope();
|
Play,
|
||||||
container.bind<Command>(TYPES.Command).to(Shortcuts).inSingletonScope();
|
QueueCommad,
|
||||||
container.bind<Command>(TYPES.Command).to(Shuffle).inSingletonScope();
|
Seek,
|
||||||
container.bind<Command>(TYPES.Command).to(Skip).inSingletonScope();
|
Shortcuts,
|
||||||
container.bind<Command>(TYPES.Command).to(Unskip).inSingletonScope();
|
Shuffle,
|
||||||
|
Skip,
|
||||||
|
Unskip
|
||||||
|
].forEach(command => {
|
||||||
|
container.bind<Command>(TYPES.Command).to(command).inSingletonScope();
|
||||||
|
});
|
||||||
|
|
||||||
// Config values
|
// Config values
|
||||||
container.bind<string>(TYPES.Config.DISCORD_TOKEN).toConstantValue(DISCORD_TOKEN);
|
container.bind<string>(TYPES.Config.DISCORD_TOKEN).toConstantValue(DISCORD_TOKEN);
|
||||||
|
|
|
@ -45,7 +45,6 @@ export default class {
|
||||||
this.voiceConnection.disconnect();
|
this.voiceConnection.disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.positionInSeconds = 0;
|
|
||||||
this.voiceConnection = null;
|
this.voiceConnection = null;
|
||||||
this.dispatcher = null;
|
this.dispatcher = null;
|
||||||
}
|
}
|
||||||
|
@ -97,10 +96,15 @@ export default class {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Resume from paused state
|
// Resume from paused state
|
||||||
if (this.status === STATUS.PAUSED && this.getPosition() !== 0 && this.dispatcher && currentSong.url === this.nowPlaying?.url) {
|
if (this.status === STATUS.PAUSED && this.getPosition() !== 0 && currentSong.url === this.nowPlaying?.url) {
|
||||||
this.dispatcher.resume();
|
if (this.dispatcher) {
|
||||||
this.status = STATUS.PLAYING;
|
this.dispatcher.resume();
|
||||||
return;
|
this.status = STATUS.PLAYING;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Was disconnected, need to recreate stream
|
||||||
|
return this.seek(this.getPosition());
|
||||||
}
|
}
|
||||||
|
|
||||||
const stream = await this.getStream(currentSong.url);
|
const stream = await this.getStream(currentSong.url);
|
||||||
|
|
Loading…
Reference in a new issue