1
0
mirror of https://github.com/musix-org/musix-oss synced 2024-09-20 01:21:56 +00:00

One letter commands

This commit is contained in:
MatteZ02 2019-08-02 15:14:45 +03:00
parent e6c55a6fd8
commit fd1d99fbfb
5 changed files with 123 additions and 4 deletions

View File

@ -5,14 +5,14 @@ module.exports = {
execute(message, args, client, RichEmbed) { execute(message, args, client, RichEmbed) {
const embed = new RichEmbed() const embed = new RichEmbed()
.setTitle('Commands for Musix!') .setTitle('Commands for Musix!')
.addField('```-play```', 'Play a song.', true) .addField('```-play | -p```', 'Play a song.', true)
.addField('```-queue```', 'Display the queue.', true) .addField('```-queue | -q```', 'Display the queue.', true)
.addField('```-np```', 'Display whats currently playing.', true) .addField('```-nowplaying | -np```', 'Display whats currently playing.', true)
.addField('```-volume```', 'Change or check the volume.', true) .addField('```-volume```', 'Change or check the volume.', true)
.addField('```-pause```', 'Pause the music.', true) .addField('```-pause```', 'Pause the music.', true)
.addField('```-resume```', 'Resume the music.', true) .addField('```-resume```', 'Resume the music.', true)
.addField('```-stop```', 'Stop the music, Clear the queue and leave the current voice channel.', true) .addField('```-stop```', 'Stop the music, Clear the queue and leave the current voice channel.', true)
.addField('```-skip```', 'Skip a song.', true) .addField('```-skip | -s```', 'Skip a song.', true)
.addField('```-invite```', 'Invite Musix.', true) .addField('```-invite```', 'Invite Musix.', true)
.addField('```-ping```', 'See the current ping for Musix', true) .addField('```-ping```', 'See the current ping for Musix', true)
.addField('```-info```', 'Display info and instructions.', true) .addField('```-info```', 'Display info and instructions.', true)

10
commands/nowplaying.js Normal file
View File

@ -0,0 +1,10 @@
module.exports = {
name: 'nowplaying',
description: 'Now playing command.',
cooldown: 5,
execute(message, args, client, RichEmbed) {
const serverQueue = client.queue.get(message.guild.id);
if (!serverQueue) return message.channel.send(':x: There is nothing playing.');
return message.channel.send(`🎶 Now playing: **${serverQueue.songs[0].title}**`);
}
};

64
commands/p.js Normal file
View File

@ -0,0 +1,64 @@
const YouTube = require("simple-youtube-api");
const youtube = new YouTube("AIzaSyBPFfx6Kq2Nvn9lpB_M2T2Y6V2N-8K9Uvo");
module.exports = {
name: 'p',
description: 'Play command.',
usage: '[song name]',
args: true,
cooldown: 3,
async execute(message, args, client, RichEmbed) {
const searchString = args.slice(1).join(" ");
const url = args[1] ? args[1].replace(/<(.+)>/g, "$1") : "";
const serverQueue = client.queue.get(message.guild.id);
const voiceChannel = message.member.voiceChannel;
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')) {
return message.channel.send(':x: I cannot connect to your voice channel, make sure I have the proper permissions!');
}
if (!permissions.has('SPEAK')) {
return message.channel.send(':x: I cannot speak in this voice channel, make sure I have the proper permissions!');
}
if (url.match(/^https?:\/\/(www.youtube.com|youtube.com)\/playlist(.*)$/)) {
const playlist = await youtube.getPlaylist(url);
const videos = await playlist.getVideos();
for (const video of Object.values(videos)) {
const video2 = await youtube.getVideoByID(video.id);
await client.handleVideo(video2, message, voiceChannel, true);
}
return message.channel.send(`:white_check_mark: Playlist: **${playlist.title}** has been added to the queue!`);
} else {
try {
var video = await youtube.getVideo(url);
} catch (error) {
try {
var videos = await youtube.searchVideos(searchString, 10);
let index = 0;
const embed = new RichEmbed()
.setTitle("__Song Selection__")
.setDescription(`${videos.map(video2 => `**${++index}** \`${video2.title}\` `).join('\n')}`)
.setFooter("Please provide a number ranging from __1-10__ to select one of the search results.")
.setColor("#2780cd")
message.channel.send(embed);
try {
var response = await message.channel.awaitMessages(message2 => message2.content > 0 && message2.content < 11, {
maxMatches: 1,
time: 10000,
errors: ['time']
});
} catch (err) {
console.error(err);
return Message.channel.send(':x: Cancelling video selection.');
}
const videoIndex = parseInt(response.first().content);
var video = await youtube.getVideoByID(videos[videoIndex - 1].id);
} catch (err) {
console.error(err);
return message.channel.send(':x: I could not obtain any search results.');
}
}
return client.handleVideo(video, message, voiceChannel);
}
}
};

30
commands/q.js Normal file
View File

@ -0,0 +1,30 @@
module.exports = {
name: 'q',
description: 'Queue command.',
cooldown: 5,
async execute(message, args, client, RichEmbed) {
const serverQueue = client.queue.get(message.guild.id);
if (!serverQueue) return message.channel.send(':x: There is nothing playing.');
let page = parseInt(args[1]);
if (!page) page = 1;
let queuesongs = serverQueue.songs.slice((page - 1) * 10 + 1, page * 20 + 1);
let queuemessage = `${queuesongs.map(song => `**#** ${song.title}`).join('\n')}`
if (queuemessage.length >= 1972) {
let finalQueuemessage = queuemessage.slice(0, 1972).split('**#**').slice(0, -1).join('**#**');
const overflowSongsAmount = queuemessage.replace(finalQueuemessage, '').split('**#**').length;
finalQueuemessage += `\nI could not display all the songs at once. ${overflowSongsAmount} songs were not displayed here.`;
queuemessage = finalQueuemessage;
}
const hashs = queuemessage.split('**#**').length;
for (let i = 0; i < hashs; i++) {
queuemessage = queuemessage.replace('**#**', `**${i + 1}**`);
}
const embed = new RichEmbed()
.setTitle("__Song queue__")
.setDescription(queuemessage)
.setFooter(`🎶 **Now playing:** ${serverQueue.songs[0].title}`)
.setColor("#2780cd")
return message.channel.send(embed);
}
};

15
commands/s.js Normal file
View File

@ -0,0 +1,15 @@
module.exports = {
name: 's',
description: 'Skip command.',
cooldown: 5,
execute(message, args, client, RichEmbed) {
const { voiceChannel } = message.member;
const serverQueue = client.queue.get(message.guild.id);
const permissions = message.channel.permissionsFor(message.author);
if (!voiceChannel) return message.channel.send(':x: I\'m sorry but you need to be in a voice channel to skip songs!');
if (!serverQueue) return message.channel.send(':x: There is nothing playing that I could skip for you.');
if (!permissions.has('MANAGE_MESSAGES')) return message.channel.send(':x: You need the `MANAGE_MESSAGES` permission to skip songs!');
message.channel.send(':fast_forward: Skipped the song for you!');
serverQueue.connection.dispatcher.end('Skip command has been used!');
}
};