mirror of
https://github.com/BluemediaDev/muse.git
synced 2025-04-19 21:03:56 +02:00
feat: remove from queue
+ fix typo queuecommand
This commit is contained in:
parent
46701a8aab
commit
5a74115beb
4 changed files with 86 additions and 2 deletions
|
@ -37,6 +37,7 @@ export default class implements Command {
|
||||||
this.getSongs = getSongs;
|
this.getSongs = getSongs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line complexity
|
||||||
public async execute(msg: Message, args: string[]): Promise<void> {
|
public async execute(msg: Message, args: string[]): Promise<void> {
|
||||||
const [targetVoiceChannel] = getMemberVoiceChannel(msg.member!) ?? getMostPopularVoiceChannel(msg.guild!);
|
const [targetVoiceChannel] = getMemberVoiceChannel(msg.member!) ?? getMostPopularVoiceChannel(msg.guild!);
|
||||||
|
|
||||||
|
|
77
src/commands/remove.ts
Normal file
77
src/commands/remove.ts
Normal file
|
@ -0,0 +1,77 @@
|
||||||
|
import {Message, TextChannel} from 'discord.js';
|
||||||
|
import {inject, injectable} from 'inversify';
|
||||||
|
import {TYPES} from '../types.js';
|
||||||
|
import PlayerManager from '../managers/player.js';
|
||||||
|
import Command from '.';
|
||||||
|
import LoadingMessage from '../utils/loading-message.js';
|
||||||
|
import errorMsg from '../utils/error-msg.js';
|
||||||
|
|
||||||
|
@injectable()
|
||||||
|
export default class implements Command {
|
||||||
|
public name = 'remove';
|
||||||
|
public aliases = ['rm'];
|
||||||
|
public examples = [
|
||||||
|
['remove 1', 'removes the first song in the queue (not the one thats playing, just skip it dummy)'],
|
||||||
|
['rm 6-9', 'removes the every song in range [6-9] from the queue'],
|
||||||
|
];
|
||||||
|
|
||||||
|
private readonly playerManager: PlayerManager;
|
||||||
|
|
||||||
|
constructor(@inject(TYPES.Managers.Player) playerManager: PlayerManager) {
|
||||||
|
this.playerManager = playerManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async execute(msg: Message, args: string []): Promise<void> {
|
||||||
|
const player = this.playerManager.get(msg.guild!.id);
|
||||||
|
|
||||||
|
const res = new LoadingMessage(msg.channel as TextChannel);
|
||||||
|
await res.start();
|
||||||
|
|
||||||
|
if (args.length === 0) {
|
||||||
|
await res.stop('atleast give me a clue for which song you want to remove');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const reg = /^(\d+)-(\d+)$|^(\d+)$/g; // Expression has 3 groups: x-y or z. x-y is range, z is a single digit.
|
||||||
|
const match = reg.exec(args[0]);
|
||||||
|
|
||||||
|
if (match === null) {
|
||||||
|
await res.stop(errorMsg('incorrect format, just an index or start-end format'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (match[3] === undefined) { // 3rd group (z) doesn't exist -> a range
|
||||||
|
const range = [parseInt(match[1], 10), parseInt(match[2], 10)];
|
||||||
|
|
||||||
|
if (range[0] < 1) {
|
||||||
|
await res.stop(errorMsg('you start counting with 1'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (range[0] < range[1]) {
|
||||||
|
player.removeFromQueue(range[0], range[0] - range[1]);
|
||||||
|
} else {
|
||||||
|
await res.stop(errorMsg('range is backwards, just like you'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(range);
|
||||||
|
} else { // 3rd group exists -> just one song
|
||||||
|
const index = parseInt(match[3], 10);
|
||||||
|
|
||||||
|
if (index < 1) {
|
||||||
|
await res.stop(errorMsg('it\'s got be bigger than 0, chief'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (index > player.queueSize()) {
|
||||||
|
await res.stop(errorMsg('queue isn\'t THAT big'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
player.removeFromQueue(index, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
await res.stop('to the trash it goes :wastebasket:');
|
||||||
|
}
|
||||||
|
}
|
|
@ -21,7 +21,8 @@ import ForwardSeek from './commands/fseek.js';
|
||||||
import Help from './commands/help.js';
|
import Help from './commands/help.js';
|
||||||
import Pause from './commands/pause.js';
|
import Pause from './commands/pause.js';
|
||||||
import Play from './commands/play.js';
|
import Play from './commands/play.js';
|
||||||
import QueueCommad from './commands/queue.js';
|
import QueueCommand from './commands/queue.js';
|
||||||
|
import Remove from './commands/remove.js';
|
||||||
import Seek from './commands/seek.js';
|
import Seek from './commands/seek.js';
|
||||||
import Shortcuts from './commands/shortcuts.js';
|
import Shortcuts from './commands/shortcuts.js';
|
||||||
import Shuffle from './commands/shuffle.js';
|
import Shuffle from './commands/shuffle.js';
|
||||||
|
@ -60,7 +61,8 @@ container.bind<NaturalLanguage>(TYPES.Services.NaturalLanguage).to(NaturalLangua
|
||||||
Help,
|
Help,
|
||||||
Pause,
|
Pause,
|
||||||
Play,
|
Play,
|
||||||
QueueCommad,
|
QueueCommand,
|
||||||
|
Remove,
|
||||||
Seek,
|
Seek,
|
||||||
Shortcuts,
|
Shortcuts,
|
||||||
Shuffle,
|
Shuffle,
|
||||||
|
|
|
@ -271,6 +271,10 @@ export default class {
|
||||||
this.queue = newQueue;
|
this.queue = newQueue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
removeFromQueue(index: number, amount = 1): void {
|
||||||
|
this.queue.splice(this.queuePosition + index, amount);
|
||||||
|
}
|
||||||
|
|
||||||
removeCurrent(): void {
|
removeCurrent(): void {
|
||||||
this.queue = [...this.queue.slice(0, this.queuePosition), ...this.queue.slice(this.queuePosition + 1)];
|
this.queue = [...this.queue.slice(0, this.queuePosition), ...this.queue.slice(this.queuePosition + 1)];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue