From fe5f9cf9a7df3b9cc42d7165ca8566e36fa70039 Mon Sep 17 00:00:00 2001 From: Hellyson Rodrigo Parteka Date: Fri, 12 Nov 2021 16:30:18 -0300 Subject: feat: discord.js v13 --- src/commands/config.ts | 9 +++++---- src/commands/help.ts | 12 ++++++++---- src/commands/queue.ts | 2 +- src/commands/shortcuts.ts | 4 ++-- 4 files changed, 16 insertions(+), 11 deletions(-) (limited to 'src/commands') 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/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/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; } -- cgit v1.2.3 From 5a74115bebb42df2eac3a277478f69ef706c4e83 Mon Sep 17 00:00:00 2001 From: DrunkenToast Date: Sat, 20 Nov 2021 21:10:39 +0100 Subject: feat: remove from queue + fix typo queuecommand --- src/commands/play.ts | 1 + src/commands/remove.ts | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 src/commands/remove.ts (limited to 'src/commands') diff --git a/src/commands/play.ts b/src/commands/play.ts index a907a40..3bf19a4 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 { const [targetVoiceChannel] = getMemberVoiceChannel(msg.member!) ?? getMostPopularVoiceChannel(msg.guild!); diff --git a/src/commands/remove.ts b/src/commands/remove.ts new file mode 100644 index 0000000..8f2931f --- /dev/null +++ b/src/commands/remove.ts @@ -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 { + 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:'); + } +} -- cgit v1.2.3 From fe233cb98ce460dccb5d799de00671b6a57f2202 Mon Sep 17 00:00:00 2001 From: DrunkenToast Date: Sat, 20 Nov 2021 21:19:34 +0100 Subject: fix: range and q size check --- src/commands/remove.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/commands') diff --git a/src/commands/remove.ts b/src/commands/remove.ts index 8f2931f..e098484 100644 --- a/src/commands/remove.ts +++ b/src/commands/remove.ts @@ -48,8 +48,13 @@ export default class implements Command { return; } + if (range[1] > player.queueSize()) { + await res.stop(errorMsg('queue isn\'t THAT big')); + return; + } + if (range[0] < range[1]) { - player.removeFromQueue(range[0], range[0] - range[1]); + player.removeFromQueue(range[0], range[1] - range[0] + 1); } else { await res.stop(errorMsg('range is backwards, just like you')); return; -- cgit v1.2.3 From 7538a2ebb8bc111bd974eab7d037e8a4a558a10a Mon Sep 17 00:00:00 2001 From: DrunkenToast Date: Sat, 20 Nov 2021 21:34:56 +0100 Subject: fix: loading message isn't required --- src/commands/remove.ts | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) (limited to 'src/commands') diff --git a/src/commands/remove.ts b/src/commands/remove.ts index e098484..bdca944 100644 --- a/src/commands/remove.ts +++ b/src/commands/remove.ts @@ -1,9 +1,8 @@ -import {Message, TextChannel} from 'discord.js'; +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 LoadingMessage from '../utils/loading-message.js'; import errorMsg from '../utils/error-msg.js'; @injectable() @@ -24,11 +23,8 @@ export default class implements Command { public async execute(msg: Message, args: string []): Promise { 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'); + await msg.channel.send('atleast give me a clue for which song you want to remove'); return; } @@ -36,7 +32,7 @@ export default class implements Command { const match = reg.exec(args[0]); if (match === null) { - await res.stop(errorMsg('incorrect format, just an index or start-end format')); + await msg.channel.send(errorMsg('incorrect format, just an index or start-end format')); return; } @@ -44,19 +40,19 @@ export default class implements Command { const range = [parseInt(match[1], 10), parseInt(match[2], 10)]; if (range[0] < 1) { - await res.stop(errorMsg('you start counting with 1')); + await msg.channel.send(errorMsg('you start counting with 1')); return; } if (range[1] > player.queueSize()) { - await res.stop(errorMsg('queue isn\'t THAT big')); + await msg.channel.send(errorMsg('queue isn\'t THAT big')); return; } if (range[0] < range[1]) { player.removeFromQueue(range[0], range[1] - range[0] + 1); } else { - await res.stop(errorMsg('range is backwards, just like you')); + await msg.channel.send(errorMsg('range is backwards, just like you')); return; } @@ -65,18 +61,18 @@ export default class implements Command { const index = parseInt(match[3], 10); if (index < 1) { - await res.stop(errorMsg('it\'s got be bigger than 0, chief')); + await msg.channel.send(errorMsg('it\'s got be bigger than 0, chief')); return; } if (index > player.queueSize()) { - await res.stop(errorMsg('queue isn\'t THAT big')); + await msg.channel.send(errorMsg('queue isn\'t THAT big')); return; } player.removeFromQueue(index, 1); } - await res.stop('to the trash it goes :wastebasket:'); + await msg.channel.send('to the trash it goes :wastebasket:'); } } -- cgit v1.2.3 From 490b082587e6ff7428ea119b0071d8d50d92bd97 Mon Sep 17 00:00:00 2001 From: Max Isom Date: Sat, 20 Nov 2021 18:58:40 -0500 Subject: Update strings --- src/commands/play.ts | 1 - src/commands/remove.ts | 22 ++++++++++------------ 2 files changed, 10 insertions(+), 13 deletions(-) (limited to 'src/commands') diff --git a/src/commands/play.ts b/src/commands/play.ts index 3bf19a4..0582ebe 100644 --- a/src/commands/play.ts +++ b/src/commands/play.ts @@ -131,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/remove.ts b/src/commands/remove.ts index bdca944..9c40a71 100644 --- a/src/commands/remove.ts +++ b/src/commands/remove.ts @@ -10,8 +10,8 @@ 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'], + ['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; @@ -24,7 +24,7 @@ export default class implements Command { const player = this.playerManager.get(msg.guild!.id); if (args.length === 0) { - await msg.channel.send('atleast give me a clue for which song you want to remove'); + await msg.channel.send(errorMsg('missing song position or range')); return; } @@ -32,7 +32,7 @@ export default class implements Command { const match = reg.exec(args[0]); if (match === null) { - await msg.channel.send(errorMsg('incorrect format, just an index or start-end format')); + await msg.channel.send(errorMsg('incorrect format')); return; } @@ -40,39 +40,37 @@ export default class implements Command { const range = [parseInt(match[1], 10), parseInt(match[2], 10)]; if (range[0] < 1) { - await msg.channel.send(errorMsg('you start counting with 1')); + await msg.channel.send(errorMsg('position must be greater than 0')); return; } if (range[1] > player.queueSize()) { - await msg.channel.send(errorMsg('queue isn\'t THAT big')); + 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, just like you')); + await msg.channel.send(errorMsg('range is backwards')); return; } - - console.log(range); } else { // 3rd group exists -> just one song const index = parseInt(match[3], 10); if (index < 1) { - await msg.channel.send(errorMsg('it\'s got be bigger than 0, chief')); + await msg.channel.send(errorMsg('position must be greater than 0')); return; } if (index > player.queueSize()) { - await msg.channel.send(errorMsg('queue isn\'t THAT big')); + await msg.channel.send(errorMsg('position is outside of the queue\'s range')); return; } player.removeFromQueue(index, 1); } - await msg.channel.send('to the trash it goes :wastebasket:'); + await msg.channel.send(':wastebasket: removed'); } } -- cgit v1.2.3