master
Kit Kasune 3 years ago
parent a119e84a42
commit e3410aa97b
  1. 4
      bot.js
  2. 5
      commands/misc/help.js
  3. 25
      commands/music/clearqueue.js
  4. 31
      commands/music/newcontroller.js
  5. 22
      commands/music/pause.js
  6. 116
      commands/music/play.js
  7. 59
      commands/music/queue.js
  8. 44
      commands/music/skip.js
  9. 13
      events/messageReactionRemove.js
  10. 11
      events/ready.js
  11. 1585
      package-lock.json
  12. 2
      package.json
  13. 55
      util/actmusiccont.js
  14. 21
      util/updatecontroller.js

@ -27,7 +27,9 @@ client.misc = {
monners: {}
},
loggers: {},
neptune: '782727129414500374'
neptune: '782727129414500374',
queue: {},
attemptedQueue: []
};
//const config = require('./config.js');

@ -36,8 +36,8 @@ module.exports = {
helpSorted[category] = categorySorted;
}
let cat = await ask(message, "What would you like help with? (`Fun`|`Utility`|`Misc`|`Moderation`|`Social`|`Leveling`) or `all` if you'd like to browse all commands", 60000); if (!cat) {return;}
if (!['f', 'fun', 'u', 'util', 'utility', 'utilities', 'm', 'misc', 'miscellaneous', 'mod', 'moderation', 's', 'social', 'leveling', 'l', 'level', 'a', 'all'].includes(`${cat}`.trim().toLowerCase())) {return message.channel.send("That wasn't a valid response! Try again?");}
let cat = await ask(message, "What would you like help with? (`Fun`|`Utility`|`Misc`|`Moderation`|`Social`|`Leveling`|`Music`) or `all` if you'd like to browse all commands", 60000); if (!cat) {return;}
if (!['f', 'fun', 'u', 'util', 'utility', 'utilities', 'm', 'misc', 'miscellaneous', 'mod', 'moderation', 's', 'social', 'leveling', 'l', 'level', 'music', 'a', 'all'].includes(`${cat}`.trim().toLowerCase())) {return message.channel.send("That wasn't a valid response! Try again?");}
let pages;
if (['f', 'fun'].includes(`${cat}`.trim().toLowerCase())) {pages = helpSorted['Fun'];}
@ -47,6 +47,7 @@ module.exports = {
if (['mod', 'moderation'].includes(`${cat}`.trim().toLowerCase())) {pages = helpSorted['Moderation'];}
if (['s', 'social'].includes(`${cat}`.trim().toLowerCase())) {pages = helpSorted['Social'];}
if (['l', 'leveling', 'level'].includes(`${cat}`.trim().toLowerCase())) {pages = helpSorted['Leveling'];}
if (["music"].includes(`${cat}`.trim().toLowerCase())) {pages = helpSorted['Music'];}
if (['a', 'all'].includes(`${cat}`.trim().toLowerCase())) {pages = []; let c; for (c of Object.values(helpSorted)) {let h; for (h of c) {pages.push(h)}}}
await require('../../util/wait')(500);

@ -0,0 +1,25 @@
const Discord = require('discord.js');
module.exports = {
name: "clearqueue",
aliases: ['cq'],
meta: {
category: 'Music',
description: "Clear your music queue",
syntax: '`clearqueue`',
extra: null
},
help: "Clear your music queue",
async execute(message, msg, args, cmd, prefix, mention, client) {
if (!message.guild) {return message.channel.send("You must be in a server in order to use this command!");}
if (!client.misc.queue[message.guild.id]) {return message.channel.send("This server doesn't have any music playing!");}
if (!message.member.voice.channel || !message.member.voice.channel === client.misc.queue[message.guild.id].updates) {return message.channel.send("You're not in the music voice channel!");}
let ct = client.misc.queue[message.guild.id].queue[0];
client.misc.queue[message.guild.id].queue = [];
client.misc.queue[message.guild.id].queue.push(ct);
require('../../util/updatecontroller')(message, client);
message.channel.send("Queue cleared!");
}
};

@ -0,0 +1,31 @@
const Discord = require('discord.js');
const moment = require('moment');
require('moment-precise-range-plugin');
const activateControls = require('../../util/actmusiccont');
const updateController = require('../../util/updatecontroller');
module.exports = {
name: "newcontroller",
aliases: ['ncont', 'nc'],
meta: {
category: 'Music',
description: "Create a new music controller to replace the old one in case it gets buried in chat",
syntax: '`newcontroller`',
extra: null
},
help: "Create a new music controller to replace the old one in case it gets buried in chat",
async execute(message, msg, args, cmd, prefix, mention, client) {
if (!message.guild) {return message.channel.send("You must be in a server in order to use this command!");}
if (!client.misc.queue[message.guild.id]) {return message.channel.send("This server doesn't have any music playing!");}
if (!message.member.voice.channel || !message.member.voice.channel === client.misc.queue[message.guild.id].updates) {return message.channel.send("You're not in the music voice channel!");}
client.misc.queue[message.guild.id].controller = await message.channel.send("One moment...");
await require('../../util/wait')(500);
updateController(message, client);
let reactions = ['⏯', '⏭', '⏹', '🔁', '🔉', '🔊'];
for (let i = 0; i < reactions.length; i++) {await client.misc.queue[message.guild.id].controller.react(reactions[i]);}
activateControls(client.misc.queue[message.guild.id].controller, client);
}
};

@ -0,0 +1,22 @@
const Discord = require('discord.js');
module.exports = {
name: "pause",
aliases: ['pa', 'res', 'resume'],
meta: {
category: 'Music',
description: "Pause/play the current song",
syntax: '`pause`',
extra: null
},
help: "Pause/play the current song",
async execute(message, msg, args, cmd, prefix, mention, client) {
if (!message.guild) {return message.channel.send("You must be in a server in order to use this command!");}
if (!client.misc.queue[message.guild.id]) {return message.channel.send("This server doesn't have any music playing!");}
if (!message.member.voice.channel || !message.member.voice.channel === client.misc.queue[message.guild.id].updates) {return message.channel.send("You're not in the music voice channel!");}
await client.misc.queue[message.guild.id].player.pause(!client.misc.queue[message.guild.id].player.paused);
require('../../util/updatecontroller')(message, client);
return message.channel.send(`${client.misc.queue[message.guild.id].player.paused ? "Paused your music." : "Resuming the tunes <a:NC_happy:830701612426199040>"}`);
}
};

@ -0,0 +1,116 @@
const Discord = require('discord.js');
const axios = require('axios');
const moment = require('moment');
require('moment-precise-range-plugin');
const sw = require('swwrap');
const activateControls = require('../../util/actmusiccont');
const updateController = require('../../util/updatecontroller');
module.exports = {
name: "play",
aliases: ['p'],
meta: {
category: 'Music',
description: "Play a song!",
syntax: '`play <songName|songURL>`',
extra: null
},
help: new Discord.MessageEmbed()
.setTitle("Help -> Music Playing")
.setDescription("Plays a song by searching for it or using a URL you provide.")
.addField("Notice", "You must be in a voice channel in order to use this command!")
.addField("Syntax", "`play <songName|songURL>`"),
async execute(message, msg, args, cmd, prefix, mention, client) {
if (!message.guild) {return message.channel.send("You must be in a server in order to use this command.");}
if (!args.length) {return message.channel.send(`Syntax: \`${prefix}play <songName|songURL>\``);}
if (!message.member.voice.channel) {return message.channel.send("You have to be in a voice channel to play music, silly!");}
if (client.misc.queue[message.guild.id] && (client.misc.queue[message.guild.id].channel !== message.member.voice.channel.id)) {return message.channel.send("You're in a voice channel, but it's not the music voice channel. Since there's already music playing from me in this server, I can't join your channel.");}
if (client.misc.attemptedQueue.includes(message.guild.id)) {return message.channel.send("A wee too fast there!");}
client.misc.attemptedQueue.push(message.guild.id);
const swc = new sw.Client();
const node = client.lavacordManager.idealNodes[0];
const params = new URLSearchParams();
let search = args.join(' ');
let gotSpotify = false;
const checkSpotify = () => {return new Promise(resolve => {
if (search.match(/^https:\/\/open\.spotify\.com\/track\/\w+/gm)) {
swc.getTrack(search.replace(/^https:\/\/open\.spotify\.com\/track\//gm, '').replace(/\?si=.+/gm, ''))
.then(r => {gotSpotify = true; search = `${r.artist} - ${r.name}`; return resolve(undefined);})
.catch(() => {return resolve(undefined);});
} else {resolve(undefined);}
});}
await checkSpotify();
params.append('identifier', search.match(/^https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,4}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)$/g) ? search : `ytsearch:${search}`);
const data = await axios(`http://${node.host}:${node.port}/loadtracks?${params}`, {
headers: {
Authorization: node.password
}
});
let [song] = data.data.tracks;
client.misc.attemptedQueue.splice(client.misc.attemptedQueue.indexOf(message.guild.id), 1);
if (!song) {return message.channel.send("I couldn't find that song! Try again?");}
if (!client.misc.queue[message.guild.id]) {
let player = await client.lavacordManager.join({
guild: message.guild.id,
channel: message.member.voice.channel.id,
node: client.lavacordManager.idealNodes[0].id
}, {selfdeaf: true});
client.misc.queue[message.guild.id] = {
player: player,
queue: [{song: song, player: message.author.id}],
votes: [],
updates: message.channel.id,
channel: message.member.voice.channel.id,
volume: 50
};
player.on('end', async data => {
if (data.reason === "REPLACED" || data.reason === "STOPPED") return;
client.misc.queue[message.guild.id].queue.shift();
if (!client.misc.queue[message.guild.id].queue.length) {
await client.lavacordManager.leave(message.guild.id);
message.guild.channels.cache.get(client.misc.queue[message.guild.id].updates).send('Finished playing.');
return delete client.misc.queue[message.guild.id];
}
await player.play(client.misc.queue[message.guild.id].queue[0].song.track);
updateController(message, client);
});
await player.play(song.track);
await player.volume(50);
let tc = await message.channel.send(new Discord.MessageEmbed()
.setAuthor("Now Playing", message.author.avatarURL())
.setTitle(song.info.title)
.setThumbnail(`https://i.ytimg.com/vi/${song.info.identifier}/maxresdefault.jpg`)
.setDescription(`Channel: ${song.info.author}\n[Original video](${song.info.uri})`)
.addField("Queued By", `<@${message.author.id}>`, true)
.addField("Length", moment.preciseDiff(Date.now(), Date.now() + song.info.length), true)
.addField("Songs in Queue", `**1** Song\n${moment.preciseDiff(Date.now(), Date.now() + song.info.length)}`)
.addField("Settings", `Volume: **${client.misc.queue[message.guild.id].volume}**/**150**`)
.setColor('2c328ba89cb0')
.setFooter("Luno")
);
let reactions = ['⏯', '⏭', '⏹', '🔁', '🔉', '🔊'];
for (let i = 0; i < reactions.length; i++) {await tc.react(reactions[i]);}
client.misc.queue[message.guild.id].controller = tc;
activateControls(client.misc.queue[message.guild.id].controller, client);
} else {
if (client.misc.queue[message.guild.id].queue.length >= 100) {return message.channel.send("Your queue is too big! Add the song after this one has played.");}
client.misc.queue[message.guild.id].queue.push({song: song, player: message.author.id});
message.channel.send(`Queued **${song.info.title}** | **${client.misc.queue[message.guild.id].queue.length - 1} song${client.misc.queue[message.guild.id].queue.length - 1 > 1 ? 's' : ''}** remaining until it's played.`);
updateController(message, client);
}
}
};

@ -0,0 +1,59 @@
const Discord = require('discord.js');
const moment = require('moment');
require('moment-precise-range-plugin');
const {Pagination} = require('../../util/pagination');
module.exports = {
name: "queue",
aliases: ['q'],
meta: {
category: 'Music',
description: "View your music queue",
syntax: '`queue`',
extra: null
},
help: "View your music queue",
async execute(message, msg, args, cmd, prefix, mention, client) {
if (!message.guild) {return message.channel.send("You must be in a server in order to use this command!");}
if (!client.misc.queue[message.guild.id]) {return message.channel.send("This server doesn't have any music playing!");}
let queue = client.misc.queue[message.guild.id].queue;
if (queue.length > 10) {
let pages = [];
let x = 0;
while (true) {
let cond = false;
let page = '';
for (let i = 0; i < 10; i++) {
if (queue[(x * 10) + i] === undefined) {cond = true; break;}
page += `**${(x * 10) + i + 1}.** **${queue[(x * 10) + i].song.info.title}** - ${queue[(x * 10) + i].song.info.author}\n<@${queue[(x * 10) + i].player}> | ${moment.preciseDiff(Date.now(), Date.now() + queue[(x * 10) + i].song.info.length)}\n`;
if ((x * 10) + i >= queue.length) {cond = true; break;}
}
pages.push(new Discord.MessageEmbed()
.setTitle(`Server Music Queue [${(x * 10) + 1}-${(x * 10) + 10} of ${queue.length}]`)
.setThumbnail(message.guild.iconURL({size: 2048}))
.setDescription(page)
.setColor('2c9cb0')
.setFooter("Kit", client.user.avatarURL())
.setTimestamp()
);
if (cond) {break;}
x++;
}
let queueList = new Pagination(message.channel, pages, message, client, true);
return queueList.start({user: message.author.id, endTime: 60000});
} else {
let page = '';
for (let i = 0; i < queue.length; i++) {page += `**${i + 1}.** **${queue[i].song.info.title}** - ${queue[i].song.info.author}\n<@${queue[i].player}> | ${moment.preciseDiff(Date.now(), Date.now() + queue[i].song.info.length)}\n`;}
return message.channel.send(new Discord.MessageEmbed()
.setTitle(`Server Music Queue - ${queue.length}`)
.setThumbnail(message.guild.iconURL({size: 2048}))
.setDescription(page)
.setColor('2c9cb0')
.setFooter("Kit", client.user.avatarURL())
.setTimestamp()
);
}
}
};

@ -0,0 +1,44 @@
const Discord = require('discord.js');
const updateController = require('../../util/updatecontroller');
module.exports = {
name: "skip",
aliases: ['s'],
meta: {
category: 'Music',
description: "Skips the currently-playing song",
syntax: '`skip [count]`',
extra: null
},
help: "Skips the currently-playing song",
async execute(message, msg, args, cmd, prefix, mention, client) {
if (!message.guild) {return message.channel.send("You must be in a server in order to use this command!");}
if (!client.misc.queue[message.guild.id]) {return message.channel.send("This server doesn't have any music playing!");}
if (!message.member.voice.channel || !message.member.voice.channel === client.misc.queue[message.guild.id].updates) {return message.channel.send("You're not in the music voice channel!");}
let skips = 0;
async function skip() {
client.misc.queue[message.guild.id].queue.shift();
skips++;
if (!client.misc.queue[message.guild.id].queue.length) {
await client.lavacordManager.leave(message.guild.id);
message.guild.channels.cache.get(client.misc.queue[message.guild.id].updates).send('Finished playing.');
delete client.misc.queue[message.guild.id];
return false;
}
return true;
}
if (args[0] && (isNaN(Number(args[0])) || Number(args[0]) < 1)) {return message.channel.send("You must specify a positive number of songs to delete!");}
if (args[0] && Number(args[0]) > 50) {return message.channel.send("That's too big of a number!");}
let count = args[0] ? Number(args[0]) : 1;
for (let i=0; i < count; i++) {if (!skip()) {break;}}
await message.channel.send(`Skipped ${skips} song${skips === 1 ? '' : 's'}!`);
await client.misc.queue[message.guild.id].player.play(client.misc.queue[message.guild.id].queue[0].song.track);
await updateController(message, client);
}
};

@ -0,0 +1,13 @@
module.exports = async (client, reaction, user) => {
if (reaction.partial) {try {await reaction.fetch();} catch {return;}}
if (user.bot) {return;}
if (reaction.message.guild && client.misc.queue[reaction.message.guild.id]
&& reaction.message.guild.members.cache.get(user.id).voice.channel
&& reaction.message.guild.members.cache.get(user.id).voice.channel.id === client.misc.queue[reaction.message.guild.id].channel
&& reaction.message.id === client.misc.queue[reaction.message.guild.id].controller.id
&& reaction.emoji.name === '⏯') {
await client.misc.queue[reaction.message.guild.id].player.pause(false);
require('../util/updatecontroller')(reaction.message, client);
}
};

@ -3,6 +3,7 @@ const chalk = require('chalk');
const moment = require('moment');
const mongoose = require('mongoose');
const ora = require('ora');
const Lavalink = require('@lavacord/discord.js');
const GuildSettings = require('../models/guild');
const BotDataSchema = require('../models/bot');
@ -79,6 +80,16 @@ module.exports = async client => {
setInterval(() => localXPCacheClean(client), 150000);
client.lavacordManager = new Lavalink.Manager(client, client.config.lava.nodes, {user: client.user.id});
client.lavacordManager.on('error', (err, node) => {console.error(`\nAn error occurred on Lava node ${node.id}.`, err)});
await client.lavacordManager.connect()
.then(() => {
console.log(`${chalk.gray('\n[INFO]')} >> ${chalk.greenBright("Connected")} to Lavacord.`);
client.misc.lava = true;
})
.catch(e => {console.log(`${chalk.red('\n[ERROR]')} >> ${chalk.yellow("Occured while connecting to Lavacord:")}`); console.error(e);});
let botData = await BotDataSchema.findOne({finder: 'lel'})
? await BotDataSchema.findOne({finder: 'lel'})
: new BotDataSchema({

1585
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -5,6 +5,8 @@
"main": "bot.js",
"author": "LunoDev",
"dependencies": {
"@lavacord/discord.js": "^0.0.7",
"axios": "^0.21.1",
"canvas": "^2.6.1",
"chalk": "^4.1.0",
"dblapi.js": "^2.4.1",

@ -0,0 +1,55 @@
const Discord = require("discord.js");
const moment = require('moment');
require('moment-precise-range-plugin');
const updateController = require("./updatecontroller");
module.exports = async function activateControls(message, client) {
let col = await message.createReactionCollector((r) => ['⏯', '⏭', '⏹', '🔁', '🔉', '🔊'].includes(r.emoji.name), {time: 1000 * 60 * 30});
col.on('collect', async (r, u) => {
if (!r.message.guild.members.cache.get(u.id).voice.channel || !r.message.guild.members.cache.get(u.id).voice.channel === client.misc.queue[message.guild.id].channel) {return;}
let functions = {
'⏯': async () => {
await client.misc.queue[message.guild.id].player.pause(!client.misc.queue[message.guild.id].player.paused);
updateController(message, client);
},
'⏭': async () => {
client.misc.queue[message.guild.id].queue.shift();
if (!client.misc.queue[message.guild.id].queue.length) {
await client.lavacordManager.leave(message.guild.id);
message.guild.channels.cache.get(client.misc.queue[message.guild.id].updates).send('Finished playing.');
col.stop();
return delete client.misc.queue[message.guild.id];
}
await client.misc.queue[message.guild.id].player.play(client.misc.queue[message.guild.id].queue[0].song.track);
updateController(message, client);
},
'⏹': async () => {
await client.lavacordManager.leave(message.guild.id);
message.guild.channels.cache.get(client.misc.queue[message.guild.id].updates).send('Finished playing.');
col.stop();
return delete client.misc.queue[message.guild.id];
},
'🔁': () => {},
'🔉': async () => {
if (client.misc.queue[message.guild.id].volume <= 10) {return;}
client.misc.queue[message.guild.id].volume -= 10;
await client.misc.queue[message.guild.id].player.volume(client.misc.queue[message.guild.id].volume);
updateController(message, client);
},
'🔊': async () => {
if (client.misc.queue[message.guild.id].volume >= 150) {return;}
client.misc.queue[message.guild.id].volume += 10;
await client.misc.queue[message.guild.id].player.volume(client.misc.queue[message.guild.id].volume);
updateController(message, client);
}
};
return functions[r.emoji.name]();});
col.on('end', () => {
if (!client.misc.queue[message.guild.id]) {return;}
client.misc.queue[message.guild.id].controller.delete().catch(() => {});
if (client.misc.queue[message.guild.id].queue.length) {updateController(message, client);}
});
};

@ -0,0 +1,21 @@
const Discord = require("discord.js");
const moment = require('moment');
require('moment-precise-range-plugin');
module.exports = async (message, client) => {
let t = client.misc.queue[message.guild.id].queue[0];
let length = 0;
client.misc.queue[message.guild.id].queue.forEach(x => length += x.song.info.length);
await client.misc.queue[message.guild.id].controller.edit("", new Discord.MessageEmbed()
.setAuthor("Now Playing", client.users.cache.get(t.player).avatarURL())
.setTitle(t.song.info.title)
.setThumbnail(`https://i.ytimg.com/vi/${t.song.info.identifier}/maxresdefault.jpg`)
.setDescription(`Channel: ${t.song.info.author}\n[Original video](${t.song.info.uri})`)
.addField("Queued By", `<@${t.player}>`, true)
.addField("Length", moment.preciseDiff(Date.now(), Date.now() + t.song.info.length), true)
.addField("Songs in Queue", `**${client.misc.queue[message.guild.id].queue.length}** Song${client.misc.queue[message.guild.id].queue.length > 1 ? 's' : ''}\n${moment.preciseDiff(Date.now(), Date.now() + length)}${client.misc.queue[message.guild.id].queue.length > 1 ? `\n\nNext up: **${client.misc.queue[message.guild.id].queue[1].song.info.title}**` : ''}`)
.addField("Settings", `Volume: **${client.misc.queue[message.guild.id].volume}**/**150**${client.misc.queue[message.guild.id].player.paused ? '\n**Currently paused.**' : ''}`)
.setColor('328ba8')
.setFooter("Luno")
).catch(() => {});
};
Loading…
Cancel
Save