1
0
mirror of https://github.com/musix-org/musix-oss synced 2025-08-01 17:44:35 +00:00

Fix code to work on this decade 1/x

This commit is contained in:
Christer Warén
2024-02-09 11:53:30 +02:00
parent d609687957
commit 9049a5e6b8
53 changed files with 2455 additions and 1704 deletions

View File

@@ -1,12 +1,13 @@
const YouTube = require("simple-youtube-api");
const he = require('he');
const { EmbedBuilder } = require("discord.js");
module.exports = {
name: 'add',
async execute(message, args, client, Discord, prefix) {
async execute(message, args, client, prefix) {
if (client.global.db.playlists[message.guild.id].saved) {
const serverQueue = client.queue.get(message.guild.id);
const youtube = new YouTube(client.config.api_key);
const youtube = new YouTube(client.config.youtube_api_key);
const searchString = args.slice(2).join(" ");
const url = args[2] ? args[2].replace(/<(.+)>/g, "$1") : "";
if (!args[2]) return message.channel.send(':x: You need to use a link or search for a song!');
@@ -16,15 +17,16 @@ module.exports = {
try {
var videos = await youtube.searchVideos(searchString, 10);
let index = 0;
const embed = new Discord.RichEmbed()
const embed = new EmbedBuilder()
.setTitle("__Song Selection__")
.setDescription(`${videos.map(video2 => `**${++index}** ${he.decode(video2.title)} `).join('\n')}`)
.setFooter("Please provide a number ranging from 1-10 to select one of the search results.")
.setFooter({ text: "Please provide a number ranging from 1-10 to select one of the search results." })
.setColor("#b50002")
message.channel.send(embed);
message.channel.send({ embeds: [embed] });
try {
var response = await message.channel.awaitMessages(message2 => message2.content > 0 && message2.content < 11, {
maxMatches: 1,
var response = await message.channel.awaitMessages({
filter: message2 => message2.content > 0 && message2.content < 11,
max: 1,
time: 10000,
errors: ['time']
});
@@ -41,11 +43,11 @@ module.exports = {
}
let song = {
id: video.id,
title: Discord.Util.escapeMarkdown(video.title),
title: video.title,
url: `https://www.youtube.com/watch?v=${video.id}`
}
client.global.db.playlists[message.guild.id].songs.push(song);
message.channel.send(`:white_check_mark: ${song.title} added to the playlist!`);
} else return message.channel.send(':x: There is no playlist saved! Start by using the save option!');
}
};
};

View File

@@ -1,6 +1,6 @@
module.exports = {
name: 'delete',
async execute(message, args, client, Discord, prefix) {
async execute(message, args, client, prefix) {
client.global.db.playlists[message.guild.id] = {
songs: [],
firstSong: undefined,
@@ -8,4 +8,4 @@ module.exports = {
};
message.channel.send(':wastebasket: Deleted the playlist.');
}
};
};

View File

@@ -1,6 +1,8 @@
const { EmbedBuilder } = require("discord.js");
module.exports = {
name: 'list',
async execute(message, args, client, Discord, prefix) {
async execute(message, args, client, prefix) {
if (args[2]) {
if (isNaN(args[2])) return msg.channel.send(':x: I\'m sorry, But you need to enter a valid __number__.');
}
@@ -13,10 +15,10 @@ module.exports = {
for (let i = 0; i < hashs; i++) {
queuemessage = queuemessage.replace('**#**', `**${i + 1}**`);
}
const embed = new Discord.RichEmbed()
const embed = new EmbedBuilder()
.setTitle("__playlist queue__")
.setDescription(`${pagetext}\n${queuemessage}`)
.setColor("#b50002")
return message.channel.send(embed);
return message.channel.send({ embeds: [embed] });
}
};
};

View File

@@ -1,14 +1,17 @@
const { PermissionFlagsBits } = require("discord.js");
const { createAudioPlayer, getVoiceConnection, joinVoiceChannel, NoSubscriberBehavior } = require("@discordjs/voice");
module.exports = {
name: 'play',
async execute(message, args, client, Discord, prefix) {
async execute(message, args, client, prefix) {
const serverQueue = client.queue.get(message.guild.id);
const voiceChannel = message.member.voiceChannel;
const voiceChannel = message.member.voice.channel;
if (!voiceChannel) return message.channel.send(':x: I\'m sorry but you need to be in a voice channel to play music!');
const permissions = voiceChannel.permissionsFor(message.client.user);
if (!permissions.has('CONNECT')) {
if (!permissions.has(PermissionFlagsBits.Connect)) {
return message.channel.send(':x: I cannot connect to your voice channel, make sure I have the proper permissions!');
}
if (!permissions.has('SPEAK')) {
if (!permissions.has(PermissionFlagsBits.Speak)) {
return message.channel.send(':x: I cannot speak in your voice channel, make sure I have the proper permissions!');
}
let songs;
@@ -24,8 +27,13 @@ module.exports = {
if (!serverQueue) {
const construct = {
textChannel: message.channel,
voiceChannel: message.member.voiceChannel,
voiceChannel: message.member.voice.channel,
connection: null,
audioPlayer: createAudioPlayer({
behaviors: {
noSubscriber: NoSubscriberBehavior.Play,
}
}),
songs: [...songs],
volume: client.global.db.guilds[message.guild.id].defaultVolume,
playing: false,
@@ -38,7 +46,13 @@ module.exports = {
client.queue.set(message.guild.id, construct);
message.channel.send(":white_check_mark: Queue set!");
try {
var connection = await message.member.voiceChannel.join();
const connection =
getVoiceConnection(voiceChannel.guild.id) ??
joinVoiceChannel({
channelId: voiceChannel.id,
guildId: voiceChannel.guild.id,
adapterCreator: voiceChannel.guild.voiceAdapterCreator
});
construct.connection = connection;
client.funcs.play(message.guild, construct.songs[0], client, message, 0, false);
} catch (error) {
@@ -46,10 +60,10 @@ module.exports = {
return message.channel.send(`:x: An error occured: ${error}`);
}
} else {
serverQueue.connection.dispatcher.end("queue set");
serverQueue.audioPlayer.stop();
serverQueue.songs = [...client.global.db.playlists[message.guild.id].songs];
message.channel.send(":white_check_mark: Queue set!");
}
} else return message.channel.send(':x: There is no queue set for this server!')
}
};
};

View File

@@ -1,6 +1,6 @@
module.exports = {
name: 'remove',
async execute(message, args, client, Discord, prefix) {
async execute(message, args, client, prefix) {
if (client.global.db.playlists[message.guild.id].saved) {
if (!args[2]) return message.channel.send(':x: Please provide a number on the position of the song that you wan\'t to remove!');
const songNum = parseInt(args[2]) - 1;
@@ -10,4 +10,4 @@ module.exports = {
return client.global.db.playlists[message.guild.id].songs.splice(songNum, 1);
} else return message.channel.send(':x: There is no playlist saved! Start by using the save option!');
}
};
};

View File

@@ -1,6 +1,6 @@
module.exports = {
name: 'save',
async execute(message, args, client, Discord, prefix) {
async execute(message, args, client, prefix) {
const serverQueue = client.queue.get(message.guild.id);
if (!serverQueue) return message.channel.send(':x: There is nothing playing!');
client.global.db.playlists[message.guild.id] = {
@@ -10,4 +10,4 @@ module.exports = {
};
message.channel.send(":white_check_mark: Queue saved!");
}
};
};