aboutsummaryrefslogtreecommitdiff
path: root/src/commands
diff options
context:
space:
mode:
authorMax Isom <[email protected]>2021-12-12 12:59:19 -0500
committerMax Isom <[email protected]>2021-12-12 12:59:19 -0500
commitf833b3b7569b3151963cfcede76d73533f716f0f (patch)
tree893181d0403e1394233a987b3d962bc0df81f0b6 /src/commands
parent3924c8007c08fa62b71303333d3563671e3c3db1 (diff)
parentf146a2a57c83aa37b4601cf093acb1cfa700a41e (diff)
downloadmuse-f833b3b7569b3151963cfcede76d73533f716f0f.tar.xz
muse-f833b3b7569b3151963cfcede76d73533f716f0f.zip
Merge branch 'master' into play-behavior-fix-gpg
Diffstat (limited to 'src/commands')
-rw-r--r--src/commands/config.ts9
-rw-r--r--src/commands/help.ts12
-rw-r--r--src/commands/play.ts2
-rw-r--r--src/commands/queue.ts2
-rw-r--r--src/commands/remove.ts76
-rw-r--r--src/commands/shortcuts.ts4
6 files changed, 93 insertions, 12 deletions
diff --git a/src/commands/config.ts b/src/commands/config.ts
index 0e5728a..8f3e0aa 100644
--- a/src/commands/config.ts
+++ b/src/commands/config.ts
@@ -1,4 +1,4 @@
-import {TextChannel, Message, GuildChannel} from 'discord.js';
+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';
@@ -20,6 +20,7 @@ export default class implements Command {
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);
@@ -35,7 +36,7 @@ export default class implements Command {
return;
}
- if (msg.author.id !== msg.guild!.owner!.id) {
+ if (msg.author.id !== msg.guild!.ownerId) {
await msg.channel.send(errorMsg('not authorized'));
return;
}
@@ -51,7 +52,7 @@ export default class implements Command {
}
case 'channel': {
- let channel: GuildChannel | undefined;
+ 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('>')));
@@ -59,7 +60,7 @@ export default class implements Command {
channel = msg.guild!.channels.cache.find(c => c.name === args[1]);
}
- if (channel && channel.type === 'text') {
+ if (channel && channel.type === 'GUILD_TEXT') {
await Settings.update({channel: channel.id}, {where: {guildId: msg.guild!.id}});
await Promise.all([
diff --git a/src/commands/help.ts b/src/commands/help.ts
index f150c54..7058efd 100644
--- a/src/commands/help.ts
+++ b/src/commands/help.ts
@@ -1,4 +1,4 @@
-import {Message} from 'discord.js';
+import {Message, Util} from 'discord.js';
import {injectable} from 'inversify';
import Command from '.';
import {TYPES} from '../types.js';
@@ -29,7 +29,7 @@ export default class implements Command {
const {prefix} = settings;
- const res = this.commands.sort((a, b) => a.name.localeCompare(b.name)).reduce((content, command) => {
+ const res = Util.splitMessage(this.commands.sort((a, b) => a.name.localeCompare(b.name)).reduce((content, command) => {
const aliases = command.aliases.reduce((str, alias, i) => {
str += alias;
@@ -53,9 +53,13 @@ export default class implements Command {
content += '\n';
return content;
- }, '');
+ }, ''));
+
+ for (const r of res) {
+ // eslint-disable-next-line no-await-in-loop
+ await msg.author.send(r);
+ }
- await msg.author.send(res, {split: true});
await msg.react('🇩');
await msg.react('🇲');
}
diff --git a/src/commands/play.ts b/src/commands/play.ts
index a0e5bb6..8fb5775 100644
--- a/src/commands/play.ts
+++ b/src/commands/play.ts
@@ -37,6 +37,7 @@ export default class implements Command {
this.getSongs = getSongs;
}
+ // eslint-disable-next-line complexity
public async execute(msg: Message, args: string[]): Promise<void> {
const [targetVoiceChannel] = getMemberVoiceChannel(msg.member!) ?? getMostPopularVoiceChannel(msg.guild!);
@@ -130,7 +131,6 @@ export default class implements Command {
if (song) {
newSongs.push(song);
} else {
- console.log(_);
await res.stop(errorMsg('that doesn\'t exist'));
return;
}
diff --git a/src/commands/queue.ts b/src/commands/queue.ts
index 85420e8..1c0735c 100644
--- a/src/commands/queue.ts
+++ b/src/commands/queue.ts
@@ -74,7 +74,7 @@ export default class implements Command {
embed.addField('Page', `${queuePage} out of ${maxQueuePage}`, false);
- await msg.channel.send(embed);
+ await msg.channel.send({embeds: [embed]});
} else {
await msg.channel.send('queue empty');
}
diff --git a/src/commands/remove.ts b/src/commands/remove.ts
new file mode 100644
index 0000000..9c40a71
--- /dev/null
+++ b/src/commands/remove.ts
@@ -0,0 +1,76 @@
+import {Message} from 'discord.js';
+import {inject, injectable} from 'inversify';
+import {TYPES} from '../types.js';
+import PlayerManager from '../managers/player.js';
+import Command from '.';
+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 next song in the queue'],
+ ['rm 5-7', 'remove every song in range 5 - 7 (inclusive) 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);
+
+ if (args.length === 0) {
+ await msg.channel.send(errorMsg('missing song position or range'));
+ 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 msg.channel.send(errorMsg('incorrect 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 msg.channel.send(errorMsg('position must be greater than 0'));
+ return;
+ }
+
+ if (range[1] > player.queueSize()) {
+ await msg.channel.send(errorMsg('position is outside of the queue\'s range'));
+ return;
+ }
+
+ if (range[0] < range[1]) {
+ player.removeFromQueue(range[0], range[1] - range[0] + 1);
+ } else {
+ await msg.channel.send(errorMsg('range is backwards'));
+ return;
+ }
+ } else { // 3rd group exists -> just one song
+ const index = parseInt(match[3], 10);
+
+ if (index < 1) {
+ await msg.channel.send(errorMsg('position must be greater than 0'));
+ return;
+ }
+
+ if (index > player.queueSize()) {
+ await msg.channel.send(errorMsg('position is outside of the queue\'s range'));
+ return;
+ }
+
+ player.removeFromQueue(index, 1);
+ }
+
+ await msg.channel.send(':wastebasket: removed');
+ }
+}
diff --git a/src/commands/shortcuts.ts b/src/commands/shortcuts.ts
index 109d5fc..929a5c1 100644
--- a/src/commands/shortcuts.ts
+++ b/src/commands/shortcuts.ts
@@ -55,7 +55,7 @@ export default class implements Command {
const newShortcut = {shortcut: shortcutName, command, guildId: msg.guild!.id, authorId: msg.author.id};
if (shortcut) {
- if (shortcut.authorId !== msg.author.id && msg.author.id !== msg.guild!.owner!.id) {
+ if (shortcut.authorId !== msg.author.id && msg.author.id !== msg.guild!.ownerId) {
await msg.channel.send(errorMsg('you do\'nt have permission to do that'));
return;
}
@@ -80,7 +80,7 @@ export default class implements Command {
}
// Check permissions
- if (shortcut.authorId !== msg.author.id && msg.author.id !== msg.guild!.owner!.id) {
+ if (shortcut.authorId !== msg.author.id && msg.author.id !== msg.guild!.ownerId) {
await msg.channel.send(errorMsg('you don\'t have permission to do that'));
return;
}