mirror of
https://github.com/BluemediaDev/muse.git
synced 2025-04-19 12:53:56 +02:00
Add queue clear command
This commit is contained in:
parent
9e1d656e52
commit
d70bd16797
3 changed files with 45 additions and 4 deletions
22
src/commands/clear.ts
Normal file
22
src/commands/clear.ts
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
import {Message} from 'discord.js';
|
||||||
|
import {TYPES} from '../types';
|
||||||
|
import {inject, injectable} from 'inversify';
|
||||||
|
import Queue from '../services/queue';
|
||||||
|
import Command from '.';
|
||||||
|
|
||||||
|
@injectable()
|
||||||
|
export default class implements Command {
|
||||||
|
public name = 'clear';
|
||||||
|
public description = 'clears all songs in queue (except currently playing)';
|
||||||
|
private readonly queue: Queue;
|
||||||
|
|
||||||
|
constructor(@inject(TYPES.Services.Queue) queue: Queue) {
|
||||||
|
this.queue = queue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async execute(msg: Message, _: string []): Promise<void> {
|
||||||
|
this.queue.clear(msg.guild!.id);
|
||||||
|
|
||||||
|
await msg.channel.send('cleared');
|
||||||
|
}
|
||||||
|
}
|
|
@ -21,6 +21,7 @@ import Player from './services/player';
|
||||||
|
|
||||||
// Comands
|
// Comands
|
||||||
import Command from './commands';
|
import Command from './commands';
|
||||||
|
import Clear from './commands/clear';
|
||||||
import Config from './commands/config';
|
import Config from './commands/config';
|
||||||
import Play from './commands/play';
|
import Play from './commands/play';
|
||||||
import QueueCommad from './commands/queue';
|
import QueueCommad from './commands/queue';
|
||||||
|
@ -38,6 +39,7 @@ container.bind<Player>(TYPES.Services.Player).to(Player).inSingletonScope();
|
||||||
container.bind<Queue>(TYPES.Services.Queue).to(Queue).inSingletonScope();
|
container.bind<Queue>(TYPES.Services.Queue).to(Queue).inSingletonScope();
|
||||||
|
|
||||||
// Commands
|
// Commands
|
||||||
|
container.bind<Command>(TYPES.Command).to(Clear).inSingletonScope();
|
||||||
container.bind<Command>(TYPES.Command).to(Config).inSingletonScope();
|
container.bind<Command>(TYPES.Command).to(Config).inSingletonScope();
|
||||||
container.bind<Command>(TYPES.Command).to(Play).inSingletonScope();
|
container.bind<Command>(TYPES.Command).to(Play).inSingletonScope();
|
||||||
container.bind<Command>(TYPES.Command).to(QueueCommad).inSingletonScope();
|
container.bind<Command>(TYPES.Command).to(QueueCommad).inSingletonScope();
|
||||||
|
|
|
@ -56,10 +56,7 @@ export default class {
|
||||||
}
|
}
|
||||||
|
|
||||||
add(guildId: string, song: QueuedSong): void {
|
add(guildId: string, song: QueuedSong): void {
|
||||||
if (!this.guildQueues.get(guildId)) {
|
this.initQueue(guildId);
|
||||||
this.guildQueues.set(guildId, []);
|
|
||||||
this.queuePositions.set(guildId, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (song.playlist) {
|
if (song.playlist) {
|
||||||
// Add to end of queue
|
// Add to end of queue
|
||||||
|
@ -95,7 +92,27 @@ export default class {
|
||||||
this.guildQueues.set(guildId, [queue[0], ...shuffle(queue.slice(1))]);
|
this.guildQueues.set(guildId, [queue[0], ...shuffle(queue.slice(1))]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
clear(guildId: string): void {
|
||||||
|
this.initQueue(guildId);
|
||||||
|
const queue = this.guildQueues.get(guildId);
|
||||||
|
|
||||||
|
const newQueue = [];
|
||||||
|
|
||||||
|
if (queue!.length > 0) {
|
||||||
|
newQueue.push(queue![0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.guildQueues.set(guildId, newQueue);
|
||||||
|
}
|
||||||
|
|
||||||
size(guildId: string): number {
|
size(guildId: string): number {
|
||||||
return this.get(guildId).length;
|
return this.get(guildId).length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private initQueue(guildId: string): void {
|
||||||
|
if (!this.guildQueues.get(guildId)) {
|
||||||
|
this.guildQueues.set(guildId, []);
|
||||||
|
this.queuePositions.set(guildId, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue