mirror of
https://github.com/BluemediaDev/muse.git
synced 2025-07-03 12:02:42 +02:00
Merge branch 'master' into feature/slash-commands
This commit is contained in:
commit
ed4e7b5ceb
36 changed files with 1464 additions and 1665 deletions
|
@ -2,6 +2,7 @@ import {CommandInteraction, GuildMember} from 'discord.js';
|
|||
import {URL} from 'url';
|
||||
import {Except} from 'type-fest';
|
||||
import {SlashCommandBuilder} from '@discordjs/builders';
|
||||
import shuffle from 'array-shuffle';
|
||||
import {inject, injectable} from 'inversify';
|
||||
import Command from '.';
|
||||
import {TYPES} from '../types.js';
|
||||
|
@ -10,7 +11,7 @@ import PlayerManager from '../managers/player.js';
|
|||
import {getMostPopularVoiceChannel, getMemberVoiceChannel} from '../utils/channels.js';
|
||||
import errorMsg from '../utils/error-msg.js';
|
||||
import GetSongs from '../services/get-songs.js';
|
||||
import Settings from '../models/settings.js';
|
||||
import {prisma} from '../utils/db.js';
|
||||
|
||||
@injectable()
|
||||
export default class implements Command {
|
||||
|
@ -23,7 +24,10 @@ export default class implements Command {
|
|||
.setDescription('YouTube URL, Spotify URL, or search query'))
|
||||
.addBooleanOption(option => option
|
||||
.setName('immediate')
|
||||
.setDescription('adds track to the front of the queue'));
|
||||
.setDescription('adds track to the front of the queue'))
|
||||
.addBooleanOption(option => option
|
||||
.setName('shuffle')
|
||||
.setDescription('shuffles the input if it\'s a playlist'));
|
||||
|
||||
public requiresVC = true;
|
||||
|
||||
|
@ -39,8 +43,13 @@ export default class implements Command {
|
|||
public async executeFromInteraction(interaction: CommandInteraction): Promise<void> {
|
||||
const [targetVoiceChannel] = getMemberVoiceChannel(interaction.member as GuildMember) ?? getMostPopularVoiceChannel(interaction.guild!);
|
||||
|
||||
const settings = await Settings.findByPk(interaction.guild!.id);
|
||||
const {playlistLimit} = settings!;
|
||||
const settings = await prisma.setting.findUnique({where: {guildId: interaction.guild!.id}});
|
||||
|
||||
if (!settings) {
|
||||
throw new Error('Could not find settings for guild');
|
||||
}
|
||||
|
||||
const {playlistLimit} = settings;
|
||||
|
||||
const player = this.playerManager.get(interaction.guild!.id);
|
||||
const wasPlayingSong = player.getCurrent() !== null;
|
||||
|
@ -67,8 +76,9 @@ export default class implements Command {
|
|||
}
|
||||
|
||||
const addToFrontOfQueue = interaction.options.getBoolean('immediate');
|
||||
const shuffleAdditions = interaction.options.getBoolean('shuffle');
|
||||
|
||||
const newSongs: Array<Except<QueuedSong, 'addedInChannelId'>> = [];
|
||||
let newSongs: Array<Except<QueuedSong, 'addedInChannelId'>> = [];
|
||||
let extraMsg = '';
|
||||
|
||||
await interaction.deferReply();
|
||||
|
@ -139,6 +149,10 @@ export default class implements Command {
|
|||
return;
|
||||
}
|
||||
|
||||
if (shuffleAdditions) {
|
||||
newSongs = shuffle(newSongs);
|
||||
}
|
||||
|
||||
newSongs.forEach(song => {
|
||||
player.add({...song, addedInChannelId: interaction.channel?.id}, {immediate: addToFrontOfQueue ?? false});
|
||||
});
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import {Message} from 'discord.js';
|
||||
import {injectable} from 'inversify';
|
||||
import {Shortcut, Settings} from '../models/index.js';
|
||||
import errorMsg from '../utils/error-msg.js';
|
||||
import Command from '.';
|
||||
import {prisma} from '../utils/db.js';
|
||||
|
||||
@injectable()
|
||||
export default class implements Command {
|
||||
|
@ -18,7 +18,11 @@ export default class implements Command {
|
|||
public async execute(msg: Message, args: string []): Promise<void> {
|
||||
if (args.length === 0) {
|
||||
// Get shortcuts for guild
|
||||
const shortcuts = await Shortcut.findAll({where: {guildId: msg.guild!.id}});
|
||||
const shortcuts = await prisma.shortcut.findMany({
|
||||
where: {
|
||||
guildId: msg.guild!.id,
|
||||
},
|
||||
});
|
||||
|
||||
if (shortcuts.length === 0) {
|
||||
await msg.channel.send('no shortcuts exist');
|
||||
|
@ -26,7 +30,11 @@ export default class implements Command {
|
|||
}
|
||||
|
||||
// Get prefix for guild
|
||||
const settings = await Settings.findOne({where: {guildId: msg.guild!.id}});
|
||||
const settings = await prisma.setting.findUnique({
|
||||
where: {
|
||||
guildId: msg.guild!.id,
|
||||
},
|
||||
});
|
||||
|
||||
if (!settings) {
|
||||
return;
|
||||
|
@ -48,7 +56,12 @@ export default class implements Command {
|
|||
|
||||
switch (action) {
|
||||
case 'set': {
|
||||
const shortcut = await Shortcut.findOne({where: {guildId: msg.guild!.id, shortcut: shortcutName}});
|
||||
const shortcut = await prisma.shortcut.findFirst({
|
||||
where: {
|
||||
guildId: msg.guild!.id,
|
||||
shortcut: shortcutName,
|
||||
},
|
||||
});
|
||||
|
||||
const command = args.slice(2).join(' ');
|
||||
|
||||
|
@ -60,10 +73,15 @@ export default class implements Command {
|
|||
return;
|
||||
}
|
||||
|
||||
await shortcut.update(newShortcut);
|
||||
await prisma.shortcut.update({
|
||||
where: {
|
||||
id: shortcut.id,
|
||||
},
|
||||
data: newShortcut,
|
||||
});
|
||||
await msg.channel.send('shortcut updated');
|
||||
} else {
|
||||
await Shortcut.create(newShortcut);
|
||||
await prisma.shortcut.create({data: newShortcut});
|
||||
await msg.channel.send('shortcut created');
|
||||
}
|
||||
|
||||
|
@ -72,7 +90,12 @@ export default class implements Command {
|
|||
|
||||
case 'delete': {
|
||||
// Check if shortcut exists
|
||||
const shortcut = await Shortcut.findOne({where: {guildId: msg.guild!.id, shortcut: shortcutName}});
|
||||
const shortcut = await prisma.shortcut.findFirst({
|
||||
where: {
|
||||
guildId: msg.guild!.id,
|
||||
shortcut: shortcutName,
|
||||
},
|
||||
});
|
||||
|
||||
if (!shortcut) {
|
||||
await msg.channel.send(errorMsg('shortcut doesn\'t exist'));
|
||||
|
@ -85,7 +108,11 @@ export default class implements Command {
|
|||
return;
|
||||
}
|
||||
|
||||
await shortcut.destroy();
|
||||
await prisma.shortcut.delete({
|
||||
where: {
|
||||
id: shortcut.id,
|
||||
},
|
||||
});
|
||||
|
||||
await msg.channel.send('shortcut deleted');
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue