mirror of
https://github.com/BluemediaDev/muse.git
synced 2025-05-12 20:41:37 +02:00
Merge branch 'master' into playlist-limit-config
This commit is contained in:
commit
d8086be5cf
31 changed files with 1214 additions and 753 deletions
|
@ -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';
|
||||
|
@ -21,6 +21,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()}\n`;
|
||||
response += `playlist-limit: ${settings.playlistLimit}`;
|
||||
|
||||
|
@ -37,7 +38,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;
|
||||
}
|
||||
|
@ -53,7 +54,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('>')));
|
||||
|
@ -61,7 +62,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([
|
||||
|
|
|
@ -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('🇲');
|
||||
}
|
||||
|
|
|
@ -38,6 +38,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!);
|
||||
const settings = await Settings.findByPk(msg.guild!.id);
|
||||
|
@ -134,7 +135,6 @@ export default class implements Command {
|
|||
if (song) {
|
||||
newSongs.push(song);
|
||||
} else {
|
||||
console.log(_);
|
||||
await res.stop(errorMsg('that doesn\'t exist'));
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -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');
|
||||
}
|
||||
|
|
76
src/commands/remove.ts
Normal file
76
src/commands/remove.ts
Normal file
|
@ -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');
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue