1
0
mirror of https://github.com/musix-org/musix-oss synced 2024-12-23 06:43:17 +00:00

Update V3.2.0

This commit is contained in:
MatteZ02 2020-04-19 20:00:16 +03:00
parent ce214a827f
commit ec07bdb5a3
33 changed files with 2319 additions and 659 deletions

View File

@ -5,6 +5,13 @@ module.exports = {
devToken: process.env.DEVTOKEN, devToken: process.env.DEVTOKEN,
dblKey: process.env.DBLKEY, dblKey: process.env.DBLKEY,
api_key: process.env.GOOGLE_API_KEY, api_key: process.env.GOOGLE_API_KEY,
genius_api_key: process.env.GENIUS_API_KEY,
soundCloud_api_key: process.env.SOUNDCLOUD_API_KEY,
spotify_access_key: process.env.SPOTIFY_ACCESS_KEY,
spotify_client_secret: process.env.SPOTIFY_CLIENT_SECRET,
spotify_client_id: process.env.SPOTIFY_CLIENT_ID,
port: 8888,
redirectUri: "http://localhost:8888/callback/",
testServer: "489111553321336832", testServer: "489111553321336832",
primary_test_channel: "617633098296721409", primary_test_channel: "617633098296721409",
secondary_test_channel: "570531724002328577", secondary_test_channel: "570531724002328577",
@ -13,7 +20,7 @@ module.exports = {
invite: invite:
"https://discordapp.com/oauth2/authorize?client_id=607266889537945605&permissions=3427328&scope=bot", "https://discordapp.com/oauth2/authorize?client_id=607266889537945605&permissions=3427328&scope=bot",
supportServer: "https://discord.gg/rvHuJtB", supportServer: "https://discord.gg/rvHuJtB",
devMode: false, devMode: true,
api: false, api: false,
saveDB: true, saveDB: true,
respawn: true, respawn: true,

View File

@ -1,4 +1,4 @@
const config = require("./src/struct/config/config.ts"); const config = require("./config/config.ts");
if (config.devMode) { if (config.devMode) {
console.log('- dev mode- '); console.log('- dev mode- ');
@ -6,8 +6,14 @@ if (config.devMode) {
config.shards = 1; config.shards = 1;
} }
const { ShardingManager } = require('discord.js'); const {
const manager = new ShardingManager('./src/bot.ts', { token: config.token, respawn: config.respawn, totalShards: config.shards }); ShardingManager
} = require('discord.js');
const manager = new ShardingManager('./src/bot.ts', {
token: config.token,
respawn: config.respawn,
totalShards: config.shards
});
console.log('- Launching shards -'); console.log('- Launching shards -');
manager.spawn(config.shards, config.shardDelay, config.shardTimeout); manager.spawn(config.shards, config.shardDelay, config.shardTimeout);

1233
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{ {
"name": "musix", "name": "musix",
"version": "3.1.1", "version": "3.2.0",
"description": "V3 for Musix the discord music bot", "description": "V3 for Musix the discord music bot",
"main": "./index.js", "main": "./index.js",
"scripts": { "scripts": {
@ -18,20 +18,26 @@
"homepage": "https://github.com/MatteZ02/Musix-V3#readme", "homepage": "https://github.com/MatteZ02/Musix-V3#readme",
"dependencies": { "dependencies": {
"bufferutil": "^4.0.1", "bufferutil": "^4.0.1",
"cookie-parser": "^1.4.5",
"cors": "^2.8.5",
"dblapi.js": "^2.4.0", "dblapi.js": "^2.4.0",
"discord.js": "^12.1.1", "discord.js": "^12.2.0",
"dotenv": "^8.2.0", "dotenv": "^8.2.0",
"erlpack": "github:discordapp/erlpack", "erlpack": "github:discordapp/erlpack",
"firebase": "^7.14.0", "express": "^4.17.1",
"firebase": "^7.14.1",
"firebase-admin": "^8.10.0", "firebase-admin": "^8.10.0",
"fs": "0.0.1-security", "fs": "0.0.1-security",
"genius-lyrics-api": "^2.0.3",
"he": "^1.2.0", "he": "^1.2.0",
"libsodium-wrappers": "^0.7.6", "libsodium-wrappers": "^0.7.6",
"ms": "^2.1.2", "ms": "^2.1.2",
"node-opus": "^0.3.3", "node-opus": "^0.3.3",
"node-spotify-api": "^1.1.1",
"prism-media": "github:hydrabolt/prism-media", "prism-media": "github:hydrabolt/prism-media",
"request": "^2.88.2", "request": "^2.88.2",
"simple-youtube-api": "^5.2.1", "simple-youtube-api": "^5.2.1",
"spotify-web-api-node": "^4.0.0",
"utf-8-validate": "^5.0.2", "utf-8-validate": "^5.0.2",
"video-thumbnail-url": "^1.0.1", "video-thumbnail-url": "^1.0.1",
"yt-search": "^1.1.2", "yt-search": "^1.1.2",

View File

@ -1,24 +1,35 @@
module.exports = { module.exports = {
name: 'bass', name: "bass",
description: 'Bassboost command.', description: "Bassboost command.",
alias: 'none', alias: "none",
usage: '<bass>', usage: "<bass>",
cooldown: 5, cooldown: 5,
onlyDev: false, onlyDev: false,
permission: 'MANAGE_MESSAGES', permission: "MANAGE_MESSAGES",
category: 'music', category: "music",
execute(msg, args, client, Discord, command) { execute(msg, args, client, Discord, command) {
const queue = client.queue.get(msg.guild.id); const queue = client.queue.get(msg.guild.id);
if (!args[1] && queue) return msg.channel.send(`${client.messages.currentBass}**${queue.bass}**`); if (!args[1] && queue)
return msg.channel.send(
`${client.messages.currentBass}**${queue.bass}**`
);
const bass = parseFloat(args[1]); const bass = parseFloat(args[1]);
if (client.funcs.check(client, msg, command)) { if (client.funcs.check(client, msg, command)) {
if (queue.nigthCore)
return msg.channel.send(client.messages.disableNigthCore);
if (isNaN(bass)) return msg.channel.send(client.messages.validNumber); if (isNaN(bass)) return msg.channel.send(client.messages.validNumber);
if (bass > 100) return msg.channel.send(client.messages.maxBass); if (bass > 100) return msg.channel.send(client.messages.maxBass);
if (bass < 0) return msg.channel.send(client.messages.positiveBass); if (bass < 0) return msg.channel.send(client.messages.positiveBass);
queue.bass = bass; queue.bass = bass;
client.funcs.end(
client,
msg,
(queue.connection.dispatcher.streamTime + queue.time) / 1000,
command
);
let message; let message;
message = client.messages.bassApplied.replace("%BASS%", bass); message = client.messages.bassApplied.replace("%BASS%", bass);
return msg.channel.send(message); return msg.channel.send(message);
} }
} },
}; };

33
src/commands/lyrics.ts Normal file
View File

@ -0,0 +1,33 @@
const { getLyrics } = require("genius-lyrics-api");
module.exports = {
name: "lyrics",
alias: "l",
usage: "<song>",
description: "see the lyrics for a song",
onlyDev: false,
permission: "none",
category: "util",
async execute(msg, args, client, Discord, prefix, command) {
const searchString = args.slice(1).join(" ");
const options = {
apiKey: client.config.genius_api_key,
title: searchString,
artist: "",
optimizeQuery: true,
};
const queue = client.queue.get(msg.guild.id);
if (queue && !args[1]) options.title = queue.songs[0].title;
if (!queue && !args[1])
return msg.channel.send(client.messages.lyricsUsage);
getLyrics(options).then((lyrics) => {
if (lyrics === null)
return msg.channel.send(client.messages.noResultsLyrics);
const embed = new Discord.MessageEmbed()
.setTitle(client.messages.lyricsTitle)
.setDescription(lyrics)
.setColor(client.config.embedColor);
msg.channel.send(embed);
});
},
};

View File

@ -6,7 +6,7 @@ module.exports = {
onlyDev: false, onlyDev: false,
permission: "MANAGE_MESSAGES", permission: "MANAGE_MESSAGES",
category: "music", category: "music",
async execute(msg, args, client, Discord, prefix, command) { async execute(msg, args, client, Discord, command) {
const queue = client.queue.get(msg.guild.id); const queue = client.queue.get(msg.guild.id);
if (!args[1] && queue) if (!args[1] && queue)
return msg.channel.send( return msg.channel.send(

View File

@ -1,32 +1,50 @@
module.exports = { module.exports = {
name: 'nowplaying', name: "nowplaying",
alias: 'np', alias: "np",
usage: '', usage: "",
description: 'See the currently playing song position and length.', description: "See the currently playing song position and length.",
onlyDev: false, onlyDev: false,
permission: 'none', permission: "none",
category: 'music', category: "music",
async execute(msg, args, client, Discord, command) { async execute(msg, args, client, Discord, command) {
const getThumb = require('video-thumbnail-url'); const getThumb = require("video-thumbnail-url");
const ytdl = require('ytdl-core'); const ytdl = require("ytdl-core");
const queue = client.queue.get(msg.guild.id); const queue = client.queue.get(msg.guild.id);
if (!queue) return msg.channel.send(client.messages.noServerQueue); if (!queue) return msg.channel.send(client.messages.noServerQueue);
let data = await Promise.resolve(ytdl.getInfo(queue.songs[0].url)); let data = await Promise.resolve(ytdl.getInfo(queue.songs[0].url));
let songtime = (data.length_seconds * 1000).toFixed(0); let songTime = (data.length_seconds * 1000).toFixed(0);
queue.time = queue.connection.dispatcher.streamTime; let completed = (
let completed = (queue.time.toFixed(0)); queue.connection.dispatcher.streamTime + queue.time
).toFixed(0);
let barlength = 30; let barlength = 30;
let completedpercent = ((completed / songtime) * barlength).toFixed(0); let completedpercent = ((completed / songTime) * barlength).toFixed(0);
let array = []; for (let i = 0; i < completedpercent - 1; i++) { array.push('⎯'); } array.push('⭗'); for (let i = 0; i < barlength - completedpercent - 1; i++) { array.push('⎯'); } let array = [];
for (let i = 0; i < completedpercent - 1; i++) {
array.push("⎯");
}
array.push("⭗");
for (let i = 0; i < barlength - completedpercent - 1; i++) {
array.push("⎯");
}
const thumbnail = getThumb(queue.songs[0].url); const thumbnail = getThumb(queue.songs[0].url);
const embed = new Discord.MessageEmbed() const embed = new Discord.MessageEmbed()
.setTitle(client.messages.nowPlaying) .setTitle(client.messages.nowPlaying)
.setDescription(`${client.messages.nowPlayingDesc} ${queue.songs[0].title}\n${array.join('')} | \`${client.funcs.msToTime(completed, "hh:mm:ss")} / ${client.funcs.msToTime(songtime, "hh:mm:ss")}\``) .setDescription(
`${client.messages.nowPlayingDesc} ${
queue.songs[0].title
}\n${array.join("")} | \`${client.funcs.msToTime(
completed,
"hh:mm:ss"
)} / ${client.funcs.msToTime(songTime, "hh:mm:ss")}\``
)
.setFooter(`Queued by ${queue.songs[0].author.tag}`) .setFooter(`Queued by ${queue.songs[0].author.tag}`)
.setURL(queue.songs[0].url) .setURL(queue.songs[0].url)
.setThumbnail(thumbnail._rejectionHandler0) .setThumbnail(thumbnail._rejectionHandler0)
.setColor(client.config.embedColor) .setColor(client.config.embedColor);
if (queue.nigthCore)
embed.setDescription(
`${client.messages.nowPlayingDesc} ${queue.songs[0].title}`
);
return msg.channel.send(embed); return msg.channel.send(embed);
} },
}; };

View File

@ -1,45 +1,168 @@
const YouTube = require("simple-youtube-api"); const YouTube = require("simple-youtube-api");
const search = require('yt-search'); const search = require("yt-search");
const SpotifyApi = require("spotify-web-api-node");
module.exports = { module.exports = {
name: 'play', name: "play",
alias: 'p', alias: "p",
usage: '<song name>', usage: "<song name>",
description: 'Play some music.', description: "Play some music.",
onlyDev: false, onlyDev: false,
permission: 'none', permission: "none",
category: 'music', category: "music",
async execute(msg, args, client, Discord, command) { async execute(msg, args, client, Discord, command) {
const spotify = new SpotifyApi({
id: client.config.spotify_client_id,
secret: client.config.spotify_client_secret,
});
spotify.setAccessToken(client.config.spotify_access_key);
const youtube = new YouTube(client.config.api_key); const youtube = new YouTube(client.config.api_key);
const searchString = args.slice(1).join(" "); const searchString = args.slice(1).join(" ");
const url = args[1] ? args[1].replace(/<(.+)>/g, "$1") : ""; const url = args[1] ? args[1].replace(/<(.+)>/g, "$1") : "";
const queue = client.queue.get(msg.guild.id); const queue = client.queue.get(msg.guild.id);
const voiceChannel = msg.member.voice.channel; const voiceChannel = msg.member.voice.channel;
if (
client.global.db.guilds[msg.guild.id].blacklist.includes(
msg.member.voice.channelID
)
)
return msg.channel.send(client.messages.blackListedVC);
if (!queue) { if (!queue) {
if (!msg.member.voice.channel) return msg.channel.send(client.messages.noVoiceChannel); if (!msg.member.voice.channel)
return msg.channel.send(client.messages.noVoiceChannel);
} else { } else {
if (voiceChannel !== queue.voiceChannel) return msg.channel.send(client.messages.wrongVoiceChannel); if (voiceChannel !== queue.voiceChannel)
return msg.channel.send(client.messages.wrongVoiceChannel);
} }
if (!args[1]) return msg.channel.send(client.messages.noQuery); if (!args[1]) return msg.channel.send(client.messages.noQuery);
if (voiceChannel.full) return msg.channel.send(client.messages.channelFull); if (voiceChannel.full) return msg.channel.send(client.messages.channelFull);
if (!voiceChannel.joinable) return msg.channel.send(client.messages.noPermsConnect); if (!voiceChannel.joinable)
if (!voiceChannel.speakable) return msg.channel.send(client.messages.noPermsSpeak); return msg.channel.send(client.messages.noPermsConnect);
if (url.match(/^https?:\/\/(www.youtube.com|youtube.com)\/playlist(.*)$/)) { if (!voiceChannel.speakable)
return msg.channel.send(client.messages.noPermsSpeak);
if (url.match(/^https?:\/\/(open.spotify.com|spotify.com)(.*)$/)) {
if (!client.global.db.guilds[msg.guild.id].premium)
return msg.channel.send(client.messages.notPremium);
const playlistId = url.split("/playlist/")[1].split("?")[0];
spotify.getPlaylist(playlistId).then(
async function (data) {
const lmsg = await msg.channel.send(client.messages.loadingSongs);
let failed = 0;
for (let i = 0; data.body.tracks.items.length > i; i++) {
const track = await data.body.tracks.items[i].track;
await client.funcs.sleep(250);
await search(
`${track.artists[0].name} ${track.name} audio`,
async function (err, res) {
if (err) return console.log(err);
if (res.videos.length === 0) {
await search(
`${track.artists[0].name} ${track.name} lyrics`,
async function (err, res) {
if (err) return console.log(err);
if (res.videos.length === 0) {
await search(
`${track.artists[0].name} ${track.name}`,
async function (err, res) {
if (err) return console.log(err);
if (res.videos.length === 0) {
failed++;
return;
}
await client.funcs.handleVideo(
res.videos[0],
msg,
voiceChannel,
client,
true,
"ytdl"
);
}
);
return;
}
await client.funcs.handleVideo(
res.videos[0],
msg,
voiceChannel,
client,
true,
"ytdl"
);
}
);
failed++;
return;
}
await client.funcs.handleVideo(
res.videos[0],
msg,
voiceChannel,
client,
true,
"ytdl"
);
}
);
}
let message;
if (failed === 0) {
message = client.messages.playlistAdded.replace(
"%TITLE%",
data.body.name
);
} else {
message = `${client.messages.playlistAdded.replace(
"%TITLE%",
data.body.name
)}\n${client.messages.failedToLoad + failed}`;
}
lmsg.edit(message);
},
function (err) {
console.log(err);
msg.channel.send(client.messages.noResults);
}
);
} else if (
url.match(/^https?:\/\/(www.youtube.com|youtube.com)\/playlist(.*)$/)
) {
const lmsg = await msg.channel.send(client.messages.loadingSongs); const lmsg = await msg.channel.send(client.messages.loadingSongs);
const playlist = await youtube.getPlaylist(url); const playlist = await youtube.getPlaylist(url);
const videos = await playlist.getVideos(); const videos = await playlist.getVideos();
for (const video of Object.values(videos)) { for (const video of Object.values(videos)) {
const video2 = await youtube.getVideoByID(video.id); const video2 = await youtube.getVideoByID(video.id);
await client.funcs.handleVideo(video2, msg, voiceChannel, client, true); await client.funcs.handleVideo(
video2,
msg,
voiceChannel,
client,
true,
"ytdl"
);
} }
client.messages.playlistAdded = client.messages.playlistAdded.replace("%TITLE%", playlist.title); let message;
return lmsg.edit(client.messages.playlistAdded); message = client.messages.playlistAdded.replace(
"%TITLE%",
playlist.title
);
return lmsg.edit(message);
} else { } else {
search(searchString, function (err, res) { search(searchString, function (err, res) {
if (err) return console.log(err); if (err) return console.log(err);
if (res.videos.length === 0) return msg.channel.send(client.messages.noResults); if (res.videos.length === 0)
client.funcs.handleVideo(res.videos[0], msg, voiceChannel, client, false); return msg.channel.send(client.messages.noResults);
}) client.funcs.handleVideo(
} res.videos[0],
msg,
voiceChannel,
client,
false,
"ytdl"
);
});
} }
},
}; };

View File

@ -1,11 +1,11 @@
module.exports = { module.exports = {
name: 'remove', name: "remove",
alias: 'rm', alias: "rm",
usage: '<song pos>', usage: "<song pos>",
description: 'Remove a song from the queue', description: "Remove a song from the queue",
onlyDev: false, onlyDev: false,
permission: 'MANAGE_MESSAGES', permission: "MANAGE_MESSAGES",
category: 'music', category: "music",
execute(msg, args, client, Discord, command) { execute(msg, args, client, Discord, command) {
const queue = client.queue.get(msg.guild.id); const queue = client.queue.get(msg.guild.id);
if (client.funcs.check(client, msg, command)) { if (client.funcs.check(client, msg, command)) {
@ -15,11 +15,17 @@ module.exports = {
if (pos < 1) return msg.channel.send(client.messages.noSongs); if (pos < 1) return msg.channel.send(client.messages.noSongs);
let message1; let message1;
let message2; let message2;
message1 = client.messages.queueLength.replace("%LENGTH%", queue.songs.length); message1 = client.messages.queueLength.replace(
"%LENGTH%",
queue.songs.length
);
if (pos > queue.songs.length) return msg.channel.send(message1); if (pos > queue.songs.length) return msg.channel.send(message1);
message2 = client.messages.removed.replace("%SONG%", queue.songs[pos].title); message2 = client.messages.removed.replace(
"%SONG%",
queue.songs[pos].title
);
msg.channel.send(message2); msg.channel.send(message2);
return queue.songs.splice(pos, 1); return queue.songs.splice(pos, 1);
} }
} },
}; };

View File

@ -1,29 +1,36 @@
module.exports = { module.exports = {
name: 'seek', name: "seek",
alias: 'none', alias: "none",
usage: '<point in song>', usage: "<point in song (seconds)>",
description: 'Seek to a specific point in the currently playing song.', description: "Seek to a specific point in the currently playing song.",
onlyDev: true, onlyDev: false,
permission: 'MANAGE_MESSAGES', permission: "MANAGE_MESSAGES",
category: 'music', category: "music",
async execute(msg, args, client, Discord, command) { async execute(msg, args, client, Discord, command) {
const ytdl = require('ytdl-core'); const ytdl = require("ytdl-core");
const queue = client.queue.get(msg.guild.id); const queue = client.queue.get(msg.guild.id);
if (client.funcs.check(client, msg, command)) { if (client.funcs.check(client, msg, command)) {
if (queue.nigthCore)
return msg.channel.send(client.messages.disableNigthCore);
let data = await Promise.resolve(ytdl.getInfo(queue.songs[0].url)); let data = await Promise.resolve(ytdl.getInfo(queue.songs[0].url));
if (!args[1]) return msg.channel.send(`${client.messages.correctUsage}\`${client.global.db.guilds[msg.guild.id].prefix}seek ${command.usage}\``); if (!args[1])
let point = args[1]; return msg.channel.send(
`${client.messages.correctUsage}\`${
client.global.db.guilds[msg.guild.id].prefix
}seek ${command.usage}\``
);
const pos = parseInt(args[1]); const pos = parseInt(args[1]);
if (isNaN(pos)) { if (isNaN(pos)) {
if (pos < 0) return msg.channel.send(client.messages.seekingPointPositive); if (pos < 0)
return msg.channel.send(client.messages.seekingPointPositive);
let message; let message;
message = client.messages.seekMax.replace("%LENGTH%", data.length_seconds); message = client.messages.seekMax.replace(
"%LENGTH%",
data.length_seconds
);
if (pos > data.length_seconds) return msg.channel.send(message); if (pos > data.length_seconds) return msg.channel.send(message);
point = pos;
}
queue.connection.dispatcher.end();
queue.endReason = "seek";
client.funcs.play(msg.guild, queue.songs[0], client, msg, point, false);
} }
client.funcs.end(client, msg, pos, command);
} }
},
}; };

View File

@ -1,32 +1,68 @@
module.exports = { module.exports = {
name: 'settings', name: "settings",
alias: 'pref', alias: "pref",
usage: '<setting> <value(opt)>', usage: "<setting> <value(opt)>",
description: 'Change the server settings for Musix.', description: "Change the server settings for Musix.",
onlyDev: false, onlyDev: false,
permission: 'MANAGE_GUILD', permission: "MANAGE_GUILD",
category: 'util', category: "util",
async execute(msg, args, client, Discord, command) { async execute(msg, args, client, Discord, command) {
let footer; let footer;
footer = client.messages.settingsFooter.replace("%PREFIX%", client.global.db.guilds[msg.guild.id].prefix); footer = client.messages.settingsFooter.replace(
"%PREFIX%",
client.global.db.guilds[msg.guild.id].prefix
);
const embed = new Discord.MessageEmbed() const embed = new Discord.MessageEmbed()
.setTitle(client.messages.settingsTitle) .setTitle(client.messages.settingsTitle)
.addField(client.messages.settingsPrefix, client.messages.settingsPrefixDesc, true) .addField(
.addField(client.messages.settingsVolume, client.messages.settingsVolumeDesc, true) client.messages.settingsPrefix,
.addField(client.messages.settingsPermissions, client.messages.settingsPermissionsDesc, true) client.messages.settingsPrefixDesc,
.addField(client.messages.settingsSetDj, client.messages.settingsSetDjDesc, true) true
.addField(client.messages.settingsAnnounceSongs, client.messages.settingsAnnounceSongsDesc) )
.addField(client.messages.settingsBass, client.messages.settingsBassDesc, true) .addField(
client.messages.settingsVolume,
client.messages.settingsVolumeDesc,
true
)
.addField(
client.messages.settingsBlacklist,
client.messages.settingsBlacklist,
true
)
.addField(
client.messages.settingsPermissions,
client.messages.settingsPermissionsDesc,
true
)
.addField(
client.messages.settingsSetDj,
client.messages.settingsSetDjDesc,
true
)
.addField(
client.messages.settingsAnnounceSongs,
client.messages.settingsAnnounceSongsDesc
)
.addField(
client.messages.settingsBass,
client.messages.settingsBassDesc,
true
)
.setFooter(footer) .setFooter(footer)
.setAuthor(client.user.username, client.user.displayAvatarURL) .setAuthor(client.user.username, client.user.displayAvatarURL)
.setColor(client.config.embedColor) .setColor(client.config.embedColor);
const permissions = msg.channel.permissionsFor(msg.author); const permissions = msg.channel.permissionsFor(msg.author);
if (msg.author.id !== client.config.devId) { if (msg.author.id !== client.config.devId) {
if (!permissions.has(command.permission)) return msg.channel.send(client.messages.noPermsManageSettings); if (!permissions.has(command.permission))
return msg.channel.send(client.messages.noPermsManageSettings);
} }
if (args[1]) { if (args[1]) {
const optionName = args[1].toLowerCase(); const optionName = args[1].toLowerCase();
const option = client.settingCmd.get(optionName) || client.settingCmd.find(cmd => cmd.aliases && cmd.aliases.includes(optionName)); const option =
client.settingCmd.get(optionName) ||
client.settingCmd.find(
(cmd) => cmd.aliases && cmd.aliases.includes(optionName)
);
if (!option) return msg.channel.send(embed); if (!option) return msg.channel.send(embed);
try { try {
option.execute(msg, args, client); option.execute(msg, args, client);
@ -34,9 +70,12 @@ module.exports = {
msg.reply(client.messages.errorExeOpt); msg.reply(client.messages.errorExeOpt);
const embed = new Discord.MessageEmbed() const embed = new Discord.MessageEmbed()
.setTitle(`Musix ${error.toString()}`) .setTitle(`Musix ${error.toString()}`)
.setDescription(error.stack.replace(/at /g, '**at **')) .setDescription(error.stack.replace(/at /g, "**at **"))
.setColor(client.config.embedColor); .setColor(client.config.embedColor);
client.fetchUser(client.config.devId).then(user => user.send(embed)).catch(console.error); client
.fetchUser(client.config.devId)
.then((user) => user.send(embed))
.catch(console.error);
client.users.cache.get(client.config.devId).send(embed); client.users.cache.get(client.config.devId).send(embed);
} }
} else { } else {

View File

@ -0,0 +1,109 @@
const discord = require("discord.js");
module.exports = {
name: "blacklist",
async execute(msg, args, client) {
if (args[2] === "add") {
if (msg.mentions.channels.first()) {
if (
client.global.db.guilds[msg.guild.id].blacklist.includes(
msg.mentions.channels.first().id
)
)
return msg.channel.send(client.messages.channelAlreadyBlackListed);
} else if (
client.global.db.guilds[msg.guild.id].blacklist.includes(args[3])
)
return msg.channel.send(client.messages.channelAlreadyBlackListed);
if (
!msg.guild.channels.cache.get(args[3]) &&
!msg.mentions.channels.first()
)
return msg.channel.send(client.messages.idOrMentionChannel);
if (msg.mentions.channels.first()) {
client.global.db.guilds[msg.guild.id].blacklist.push(
msg.mentions.channels.first().id
);
let message;
message = client.messages.channelAdded.replace(
"%CHANNEL%",
msg.mentions.channels.first().name
);
msg.channel.send(message);
} else {
client.global.db.guilds[msg.guild.id].blacklist.push(args[3]);
let message;
message = client.messages.channelAdded.replace(
"%CHANNEL%",
msg.guild.channels.cache.get(args[3]).name
);
msg.channel.send(message);
}
} else if (args[2] === "remove") {
if (msg.mentions.channels.first()) {
if (
!client.global.db.guilds[msg.guild.id].blacklist.includes(
msg.mentions.channels.first().id
)
)
return msg.channel.send(client.messages.channelNotBlackListed);
if (
client.global.db.guilds[msg.guild.id].blacklist.indexOf(
msg.mentions.channels.first().id
) !== -1
) {
client.global.db.guilds[msg.guild.id].blacklist.splice(
client.global.db.guilds[msg.guild.id].blacklist.indexOf(
msg.mentions.channels.first().id
),
1
);
let message;
message = client.messages.channelRemoved.replace(
"%CHANNEL%",
msg.mentions.channels.first().name
);
}
} else {
if (!client.global.db.guilds[msg.guild.id].blacklist.includes(args[3]))
return msg.channel.send(client.messages.channelNotBlackListed);
if (
client.global.db.guilds[msg.guild.id].blacklist.indexOf(args[3]) !==
-1
) {
client.global.db.guilds[msg.guild.id].blacklist.splice(
client.global.db.guilds[msg.guild.id].blacklist.indexOf(args[3]),
1
);
let message;
message = client.messages.channelRemoved.replace(
"%CHANNEL%",
msg.guild.channels.cache.get(args[3]).name
);
msg.channel.send(message);
}
}
} else if (args[2] === "list") {
const embed = new discord.MessageEmbed()
.setTitle(client.messages.blacklistTitle)
.setDescription(
`${client.global.db.guilds[msg.guild.id].blacklist
.map((c) => `**-** <#${c}>`)
.join("\n")}`
)
.setColor(client.config.embedColor);
msg.channel.send(embed);
} else {
const embed = new discord.MessageEmbed()
.setTitle(client.messages.blacklistTitle)
.addField("add", "Add a channel to the blacklist. (ID or mention)")
.addField(
"remove",
"Remove a channel from the blacklist. (ID or mention)"
)
.addField("list", "List the currently blacklisted channels.")
.setColor(client.config.embedColor);
msg.channel.send(embed);
}
},
};

View File

@ -0,0 +1,28 @@
module.exports = {
name: "premium",
async execute(msg, args, client) {
if (msg.member.id !== client.config.devId)
return msg.channel.send(client.messages.onlyDev);
if (!args[2])
return msg.channel.send(
`${client.messages.correctUsage} ${client.messages.premiumUsage}`
);
if (client.global.db.guilds[args[2]].premium === false) {
client.global.db.guilds[args[2]].premium = true;
let message;
message = client.messages.nowPremium.replace(
"%GUILD%",
client.guilds.cache.get(args[2]).name
);
msg.channel.send(message);
} else if (client.global.db.guilds[args[2]].premium === true) {
client.global.db.guilds[args[2]].premium = false;
let message;
message = client.messages.noMorePremium.replace(
"%GUILD%",
client.guilds.cache.get(args[2]).name
);
msg.channel.send(message);
}
},
};

View File

@ -1,19 +1,26 @@
module.exports = { module.exports = {
name: 'skip', name: "skip",
alias: 's', alias: "s",
usage: '', usage: "",
description: 'Skip the currently playing song.', description: "Skip the currently playing song.",
onlyDev: false, onlyDev: false,
permission: 'MANAGE_MESSAGES', permission: "MANAGE_MESSAGES",
category: 'music', category: "music",
execute(msg, args, client, Discord, command) { execute(msg, args, client, Discord, command) {
const queue = client.queue.get(msg.guild.id); const queue = client.queue.get(msg.guild.id);
const permissions = msg.channel.permissionsFor(msg.author); const permissions = msg.channel.permissionsFor(msg.author);
if (!queue || !queue.playing) return msg.channel.send(client.messages.noServerQueue); if (!queue || !queue.playing)
return msg.channel.send(client.messages.noServerQueue);
if (msg.author.id !== client.config.devId) { if (msg.author.id !== client.config.devId) {
if (msg.member.voice.channel !== queue.voiceChannel) return msg.channel.send(client.messages.wrongVoiceChannel); if (msg.member.voice.channel !== queue.voiceChannel)
return msg.channel.send(client.messages.wrongVoiceChannel);
if (client.global.db.guilds[msg.guild.id].permissions) { if (client.global.db.guilds[msg.guild.id].permissions) {
if (!msg.member.roles.cache.has(client.global.db.guilds[msg.guild.id].djrole) || !permissions.has(command.permission)) { if (
!msg.member.roles.cache.has(
client.global.db.guilds[msg.guild.id].djrole
) ||
!permissions.has(command.permission)
) {
return vote(queue, msg, client); return vote(queue, msg, client);
} else { } else {
return skipSong(queue, msg, client); return skipSong(queue, msg, client);
@ -24,18 +31,20 @@ module.exports = {
} else { } else {
return skipSong(queue, msg, client); return skipSong(queue, msg, client);
} }
} },
}; };
function skipSong(queue, msg, client) { function skipSong(queue, msg, client) {
msg.channel.send(client.messages.skipped); msg.channel.send(client.messages.skipped);
queue.endReason = "skip"; queue.endReason = "skip";
queue.time = 0;
queue.connection.dispatcher.end(); queue.connection.dispatcher.end();
}; }
function vote(queue, msg, client) { function vote(queue, msg, client) {
queue.votesNeeded = Math.floor(queue.voiceChannel.members.size / 2); queue.votesNeeded = Math.floor(queue.voiceChannel.members.size / 2);
queue.votesNeeded.toFixed(); queue.votesNeeded.toFixed();
if (queue.voiceChannel.members.size > 2) { if (queue.voiceChannel.members.size > 2) {
if (queue.voters.includes(msg.member.id)) return msg.channel.send(client.messages.alreadyVoted); if (queue.voters.includes(msg.member.id))
return msg.channel.send(client.messages.alreadyVoted);
queue.votes++; queue.votes++;
queue.voters.push(msg.member.id); queue.voters.push(msg.member.id);
if (queue.votes >= queue.votesNeeded) { if (queue.votes >= queue.votesNeeded) {
@ -43,8 +52,11 @@ function vote(queue, msg, client) {
queue.votes = 0; queue.votes = 0;
queue.votesNeeded = null; queue.votesNeeded = null;
return skipSong(queue, msg, client); return skipSong(queue, msg, client);
} else return msg.channel.send(`${client.messages.notEnoughVotes} ${queue.votes} / ${queue.votesNeeded}!`); } else
return msg.channel.send(
`${client.messages.notEnoughVotes} ${queue.votes} / ${queue.votesNeeded}!`
);
} else { } else {
return skipSong(queue, msg, client); return skipSong(queue, msg, client);
} }
}; }

View File

@ -1,25 +1,30 @@
module.exports = { module.exports = {
name: 'skipto', name: "skipto",
alias: 'st', alias: "st",
usage: '<point in queue>', usage: "<point in queue>",
description: 'Skip to a point in the queue', description: "Skip to a point in the queue",
onlyDev: false, onlyDev: false,
permission: 'MANAGE_MESSAGES', permission: "MANAGE_MESSAGES",
category: 'music', category: "music",
async execute(msg, args, client, Discord, command) { async execute(msg, args, client, Discord, command) {
const queue = client.queue.get(msg.guild.id); const queue = client.queue.get(msg.guild.id);
if (client.funcs.check(client, msg, command)) { if (client.funcs.check(client, msg, command)) {
if (!args[1]) return msg.channel.send(`${client.messages.correctUsage}\`${command.usage}\``); if (!args[1])
return msg.channel.send(
`${client.messages.correctUsage}\`${command.usage}\``
);
let point = parseInt(args[1]); let point = parseInt(args[1]);
point = point - 1; point = point - 1;
if (isNaN(point)) return msg.channel.send(client.messages.validNumber); if (isNaN(point)) return msg.channel.send(client.messages.validNumber);
if (point > queue.songs.size) return msg.channel.send(client.messages.noSongs); if (point > queue.songs.size)
return msg.channel.send(client.messages.noSongs);
if (point < 0) return msg.channel.send(client.messages.cantSkipToCurrent); if (point < 0) return msg.channel.send(client.messages.cantSkipToCurrent);
for (let i = 0; i < point; i++) { for (let i = 0; i < point; i++) {
queue.songs.shift(); queue.songs.shift();
} }
queue.endReason = "skipto"; queue.endReason = "skipto";
queue.time = 0;
queue.connection.dispatcher.end(); queue.connection.dispatcher.end();
} }
} },
}; };

View File

@ -0,0 +1,22 @@
module.exports = {
name: "soundcloud",
alias: "sc",
usage: "",
description: "",
onlyDev: true,
permission: "dev",
category: "music",
async execute(msg, args, client, Discord, prefix, command) {
const SoundCloud = require("soundcloud-api-client");
const key = client.config.soundCloud_api_key;
const soundcloud = new SoundCloud({ key });
const q = "live mix";
const genres = ["house", "tech-house", "techno"].join(",");
soundcloud
.get("/tracks", { q, genres })
.then((tracks) => console.log(tracks))
.catch((e) => console.error(e));
},
};

View File

@ -1,7 +1,7 @@
module.exports = { module.exports = {
name: 'guildcreate', name: "guildcreate",
async execute(client, guild) { async execute(client, guild) {
client.db.collection('guilds').doc(guild.id).set({ client.db.collection("guilds").doc(guild.id).set({
prefix: client.config.prefix, prefix: client.config.prefix,
defaultVolume: client.config.defaultVolume, defaultVolume: client.config.defaultVolume,
permissions: client.config.permissions, permissions: client.config.permissions,
@ -9,6 +9,8 @@ module.exports = {
djrole: client.config.djrole, djrole: client.config.djrole,
startPlaying: client.config.startPlaying, startPlaying: client.config.startPlaying,
bass: client.config.bass, bass: client.config.bass,
blacklist: [],
premium: false,
}); });
client.global.db.guilds[guild.id] = { client.global.db.guilds[guild.id] = {
prefix: client.config.prefix, prefix: client.config.prefix,
@ -18,6 +20,8 @@ module.exports = {
djrole: client.config.djrole, djrole: client.config.djrole,
startPlaying: client.config.startPlaying, startPlaying: client.config.startPlaying,
bass: client.config.bass, bass: client.config.bass,
blacklist: [],
premium: false,
};
},
}; };
}
}

View File

@ -1,48 +1,56 @@
const DBL = require("dblapi.js"); const DBL = require("dblapi.js");
module.exports = { module.exports = {
name: 'ready', name: "ready",
async execute(client, Discord) { async execute(client, Discord) {
const remoteMusixGuildsData = await client.funcs.dbget('guilds', null, client); const remoteMusixGuildsData = await client.funcs.dbget(
remoteMusixGuildsData.forEach(guildData => { "guilds",
null,
client
);
remoteMusixGuildsData.forEach((guildData) => {
client.global.db.guilds[guildData.id] = guildData.d; client.global.db.guilds[guildData.id] = guildData.d;
}); });
if (client.config.devMode) { if (client.config.devMode) {
client.guilds.cache.forEach(guild => { client.guilds.cache.forEach((guild) => {
client.global.db.guilds[guild.id] = { client.global.db.guilds[guild.id] = {
prefix: client.config.prefix, prefix: client.config.devPrefix,
defaultVolume: client.config.defaultVolume, defaultVolume: client.config.defaultVolume,
permissions: client.config.permissions, permissions: client.config.permissions,
dj: client.config.dj, dj: client.config.dj,
djrole: client.config.djrole, djrole: client.config.djrole,
startPlaying: client.config.startPlaying, startPlaying: client.config.startPlaying,
bass: client.config.bass, bass: client.config.bass,
blacklist: [],
}; };
}); });
} }
console.log(`- DB Set - Shard: ${client.shard.ids} -`); console.log(`- DB Set - Shard: ${client.shard.ids} -`);
client.user.setActivity(`@${client.user.username} help | 🎶`, { type: 'LISTENING' }); client.user.setActivity(`@${client.user.username} help | 🎶`, {
client.user.setStatus('online'); type: "LISTENING",
});
client.user.setStatus("online");
const dbl = new DBL(client.config.dblKey, client); const dbl = new DBL(client.config.dblKey, client);
if (client.config.dblApi && !client.config.devMode) { if (client.config.dblApi && !client.config.devMode) {
dbl.on('posted', () => { dbl.on("posted", () => {
console.log('Server count posted!'); console.log("Server count posted!");
}); });
dbl.on('error', error => { dbl.on("error", (error) => {
console.log('Error with DBL: ' + error); console.log("Error with DBL: " + error);
}); });
dbl.postStats(client.guilds.size); dbl.postStats(client.guilds.size);
} }
console.log(`- Activated - Shard: ${client.shard.ids} -`); console.log(`- Activated - Shard: ${client.shard.ids} -`);
setInterval(() => { setInterval(() => {
client.funcs.checkDB(client); if (!client.config.devMode) client.funcs.checkDB(client);
}, 60000); }, 60000);
setInterval(async () => { setInterval(async () => {
client.funcs.saveDB(client); client.funcs.saveDB(client);
if (client.config.dblApi && !client.config.devMode) dbl.postStats(client.guilds.cache.size); if (client.config.dblApi && !client.config.devMode)
dbl.postStats(client.guilds.cache.size);
}, 1800000); }, 1800000);
setInterval(() => { setInterval(() => {
client.funcs.ffmpeg(client, Discord); client.funcs.ffmpeg(client, Discord);
}, 7200000); }, 7200000);
} },
} };

View File

@ -2,7 +2,7 @@ module.exports = async function (client, reason, guild) {
const queue = client.queue.get(guild.id); const queue = client.queue.get(guild.id);
queue.playing = false; queue.playing = false;
if (reason === "seek") { if (reason === "seek") {
return queue.playing = true; return (queue.playing = true);
} }
if (!queue.songLooping) { if (!queue.songLooping) {
@ -10,6 +10,7 @@ module.exports = async function (client, reason, guild) {
queue.songs.push(queue.songs[0]); queue.songs.push(queue.songs[0]);
} }
queue.time = 0;
queue.votes = 0; queue.votes = 0;
queue.voters = []; queue.voters = [];
queue.songs.shift(); queue.songs.shift();

View File

@ -1,15 +1,15 @@
const { Client, Collection } = require('discord.js'); const { Client, Collection } = require("discord.js");
const admin = require('firebase-admin'); const admin = require("firebase-admin");
const serviceAccount = require('./config/serviceAccount.json'); const serviceAccount = require("./config/serviceAccount.json");
const fs = require('fs'); const fs = require("fs");
const path = require('path'); const path = require("path");
const events = require('../events/events.ts'); const events = require("../events/events.ts");
module.exports = class extends Client { module.exports = class extends Client {
constructor() { constructor() {
super({ super({
disableEveryone: true, disableEveryone: true,
disabledEvents: ['TYPING_START'] disabledEvents: ["TYPING_START"],
}); });
admin.initializeApp({ admin.initializeApp({
@ -21,30 +21,34 @@ module.exports = class extends Client {
this.queue = new Map(); this.queue = new Map();
this.funcs = {}; this.funcs = {};
this.dispatcher = {}; this.dispatcher = {};
this.config = require('./config/config.ts'); this.config = require("../../config/config.ts");
this.messages = require('./config/messages.ts'); this.messages = require("./config/messages.ts");
this.db = admin.firestore(); this.db = admin.firestore();
this.db.FieldValue = require('firebase-admin').firestore.FieldValue; this.db.FieldValue = require("firebase-admin").firestore.FieldValue;
this.dispatcher.finish = require('../events/dispatcherEvents/finish.ts'); this.dispatcher.finish = require("../events/dispatcherEvents/finish.ts");
this.dispatcher.error = require('../events/dispatcherEvents/error.ts'); this.dispatcher.error = require("../events/dispatcherEvents/error.ts");
this.global = { this.global = {
db: { db: {
guilds: {}, guilds: {},
}, },
}; };
fs.readdirSync(path.join(__dirname, 'funcs')).forEach(filename => { fs.readdirSync(path.join(__dirname, "funcs")).forEach((filename) => {
this.funcs[filename.slice(0, -3)] = require(`./funcs/${filename}`); this.funcs[filename.slice(0, -3)] = require(`./funcs/${filename}`);
}); });
const commandFiles = fs.readdirSync(path.join(path.dirname(__dirname), 'commands')).filter(f => f.endsWith('.ts')); const commandFiles = fs
.readdirSync(path.join(path.dirname(__dirname), "commands"))
.filter((f) => f.endsWith(".ts"));
for (const file of commandFiles) { for (const file of commandFiles) {
const command = require(`../commands/${file}`); const command = require(`../commands/${file}`);
command.uses = 0; command.uses = 0;
this.commands.set(command.name, command); this.commands.set(command.name, command);
this.commandAliases.set(command.alias, command); this.commandAliases.set(command.alias, command);
} }
const settingFiles = fs.readdirSync(path.join(path.dirname(__dirname), 'commands/settings')).filter(f => f.endsWith('.ts')); const settingFiles = fs
.readdirSync(path.join(path.dirname(__dirname), "commands/settings"))
.filter((f) => f.endsWith(".ts"));
for (const file of settingFiles) { for (const file of settingFiles) {
const option = require(`../commands/settings/${file}`); const option = require(`../commands/settings/${file}`);
this.settingCmd.set(option.name, option); this.settingCmd.set(option.name, option);
@ -55,6 +59,8 @@ module.exports = class extends Client {
events(this); events(this);
this.login(this.config.token).catch(err => console.log('Failed to login: ' + err)); this.login(this.config.token).catch((err) =>
console.log("Failed to login: " + err)
);
} }
}; };

View File

@ -9,15 +9,27 @@ module.exports = {
announceSongsTrue: announceSongsTrue:
emojis.green_check_mark + "announcesongs now set to `true`!", emojis.green_check_mark + "announcesongs now set to `true`!",
bassApplied: bassApplied:
emojis.volumeHigh + emojis.volumeHigh + "The bass level **%BASS%** has been applied!",
"The bass level **%BASS%** will be applied when the next song starts playing!",
bassFalse: emojis.green_check_mark + "Bass is now false!", bassFalse: emojis.green_check_mark + "Bass is now false!",
bassLevel: emojis.green_check_mark + "Bass level is now", bassLevel: emojis.green_check_mark + "Bass level is now",
blacklistTitle: "Currently blacklisted channels:",
blackListedVC:
emojis.redx +
"Your voiceChannel is blacklisted! Please choose another channel!",
boolean: emojis.redx + "Please define a boolean! (true/false)", boolean: emojis.redx + "Please define a boolean! (true/false)",
cancellingVideoSelection: emojis.redx + "Cancelling video selection", cancellingVideoSelection: emojis.redx + "Cancelling video selection",
cantSkipToCurrent: cantSkipToCurrent:
emojis.redx + "You can't skip to the song currently playing!", emojis.redx + "You can't skip to the song currently playing!",
channelAdded:
emojis.green_check_mark + "Channel %CHANNEL% added to the blacklist!",
channelAlreadyBlackListed:
emojis.redx + "That channel is already blacklisted!",
channelFull: emojis.redx + "Your voice channel is full!", channelFull: emojis.redx + "Your voice channel is full!",
channelNotBlackListed:
emojis.redx + "That channel is not blacklisted or does not exist!",
channelRemoved:
emojis.green_check_mark +
"Channel %CHANNEL% has been removed from the blacklist!",
cmdUsesFooter: "These statistics are from the current uptime.", cmdUsesFooter: "These statistics are from the current uptime.",
cmdUsesTitle: "Musix Command Usage During Current Uptime", cmdUsesTitle: "Musix Command Usage During Current Uptime",
correctUsage: emojis.redx + "correct usage: ", correctUsage: emojis.redx + "correct usage: ",
@ -38,6 +50,8 @@ module.exports = {
devMode: devMode:
emojis.redx + emojis.redx +
"Dev mode has been turned on! Commands are only available to developer(s)!", "Dev mode has been turned on! Commands are only available to developer(s)!",
disableNigthCore:
emojis.redx + "Please disable nigthCore in order to use this command!",
dispatcherError: "Error with the dispatcher: ", dispatcherError: "Error with the dispatcher: ",
djFalse: emojis.green_check_mark + "`DJ` now set to `false`", djFalse: emojis.green_check_mark + "`DJ` now set to `false`",
djRoleCreated: djRoleCreated:
@ -56,24 +70,34 @@ module.exports = {
errorExeOpt: errorExeOpt:
emojis.redx + "there was an error trying to execute that option!", emojis.redx + "there was an error trying to execute that option!",
evalTitle: "Evaluation Command", evalTitle: "Evaluation Command",
failedToLoad: emojis.redx + "Songs failed to load: ",
helpCmdFooter: "Command Alias:", helpCmdFooter: "Command Alias:",
helpFooter: helpFooter:
'"%PREFIX%help <command>" to see more information about a command.', '"%PREFIX%help <command>" to see more information about a command.',
helpTitle: "help", helpTitle: "help",
idOrMentionChannel:
emojis.redx + "Please provide a channel id or mention a channel!",
inviteTitle: "Invite Musix to your Discord server!", inviteTitle: "Invite Musix to your Discord server!",
joined: emojis.green_check_mark + "Joined", joined: emojis.green_check_mark + "Joined",
joinSupport: "Join the musix support server: ", joinSupport: "Join the musix support server: ",
loadingSongs: emojis.loading + "Loading song(s)", loadingSongs: emojis.loading + "Loading song(s)",
looping: emojis.repeat + "Looping the queue now!", looping: emojis.repeat + "Looping the queue now!",
loopingSong: emojis.repeatSong + "Looping **%TITLE%** now!", loopingSong: emojis.repeatSong + "Looping **%TITLE%** now!",
lyricsTitle: "Lyrics",
lyricsUsage: emojis.redx + "Provide a song to search for!",
maxBass: emojis.redx + "The max bass is `100`!", maxBass: emojis.redx + "The max bass is `100`!",
maxVolume: emojis.redx + "The max volume is `100`!", maxVolume: emojis.redx + "The max volume is `100`!",
mentionChannel: emojis.redx + "Please mention a channel!",
musicCommandsDisabled:
emojis.redx +
"This channels has been blacklisted! Music commands cannot be used here!",
nigthCoreApplied: nigthCoreApplied:
emojis.green_check_mark + emojis.green_check_mark +
"NigthCore is now **%BOOLEAN%** this will be applied when the next song starts playing!", "NigthCore is now **%BOOLEAN%** this will be applied when the next song starts playing!",
noDj: emojis.redx + "You need the `DJ` role to use this command!", noDj: emojis.redx + "You need the `DJ` role to use this command!",
noLooping: emojis.repeat + "No longer looping the queue!", noLooping: emojis.repeat + "No longer looping the queue!",
noLoopingSong: emojis.repeatSong + "No longer looping the song!", noLoopingSong: emojis.repeatSong + "No longer looping the song!",
noMorePremium: ":cry: Guild %GUILD% is no longer premium!",
noPerms: emojis.redx + `You need the %PERMS% permission to use this command!`, noPerms: emojis.redx + `You need the %PERMS% permission to use this command!`,
noPermsConnect: noPermsConnect:
emojis.redx + emojis.redx +
@ -95,8 +119,10 @@ module.exports = {
"I cannot use external emojis, make sure I have the proper permissions!", "I cannot use external emojis, make sure I have the proper permissions!",
noQuery: emojis.redx + "you need to use a link or search for a song!", noQuery: emojis.redx + "you need to use a link or search for a song!",
noResults: emojis.redx + "I could not obtain any search results!", noResults: emojis.redx + "I could not obtain any search results!",
noResultsLyrics: emojis.redx + "I could not obtain any results!",
noServerQueue: emojis.redx + "There is nothing playing!", noServerQueue: emojis.redx + "There is nothing playing!",
noSongs: emojis.redx + "That song does not exist!", noSongs: emojis.redx + "That song does not exist!",
notPremium: emojis.redx + "This is not a premium guild!",
nowPlayingDesc: emojis.notes + "**Now playing:**", nowPlayingDesc: emojis.notes + "**Now playing:**",
notAllowed: emojis.redx + "You are not allowed to do that!", notAllowed: emojis.redx + "You are not allowed to do that!",
notEnoughVotes: emojis.redx + "Not enough votes!", notEnoughVotes: emojis.redx + "Not enough votes!",
@ -105,6 +131,8 @@ module.exports = {
emojis.redx + emojis.redx +
"I'm sorry but you need to be in a voice channel to play music!", "I'm sorry but you need to be in a voice channel to play music!",
nowPlaying: "__Now playing__", nowPlaying: "__Now playing__",
nowPremium: ":tada: Guild %GUILD% is now premium!",
onlyDev: emojis.redx + "This command is only available for dev(s)!",
paused: emojis.pause + "Paused the music!", paused: emojis.pause + "Paused the music!",
permission: "🔒 Permission requirement:", permission: "🔒 Permission requirement:",
permissionsFalse: emojis.redx + "That value is already `false`!", permissionsFalse: emojis.redx + "That value is already `false`!",
@ -122,6 +150,7 @@ module.exports = {
prefixHere: "My prefix here is: ", prefixHere: "My prefix here is: ",
prefixMaxLength: "The prefix must be shorter or equal to 5 letters!", prefixMaxLength: "The prefix must be shorter or equal to 5 letters!",
prefixSet: emojis.green_check_mark + "New prefix set to:", prefixSet: emojis.green_check_mark + "New prefix set to:",
premiumUsage: emojis.redx + "`settings premium <guild id>`",
provideANumber: provideANumber:
"Please provide a number ranging from 1-10 to select one of the search results.", "Please provide a number ranging from 1-10 to select one of the search results.",
provideASong: provideASong:
@ -151,6 +180,9 @@ module.exports = {
"Whether to announce songs that start playing or not.", "Whether to announce songs that start playing or not.",
settingsBass: "bass", settingsBass: "bass",
settingsBassDesc: "Change the default bass level.", settingsBassDesc: "Change the default bass level.",
settingsBlacklist: "blacklist",
settingsBlacklistDesc:
"Blacklist channels that you wan't to block music commands to be executed on or block the bot from joining certain voiceChannels.",
settingsFooter: "how to use: %PREFIX%settings <Setting name> <value>", settingsFooter: "how to use: %PREFIX%settings <Setting name> <value>",
settingsPermissions: "permissions", settingsPermissions: "permissions",
settingsPermissionsDesc: settingsPermissionsDesc:

View File

@ -1,7 +1,7 @@
module.exports = { module.exports = {
ytdlOptions: { filter: "audio", highWaterMark: 1 << 20, volume: false }, ytdlOptions: { filter: "audio", highWaterMark: 1 << 25, volume: false },
options: { options: {
seek: 0, seek: null,
bitrate: 1024, bitrate: 1024,
volume: 1, volume: 1,
type: "converted", type: "converted",

View File

@ -12,13 +12,20 @@ module.exports = function (client, msg, command) {
} }
if (client.global.db.guilds[msg.guild.id].permissions === true) { if (client.global.db.guilds[msg.guild.id].permissions === true) {
if (client.global.db.guilds[msg.guild.id].dj) { if (client.global.db.guilds[msg.guild.id].dj) {
if (!msg.member.roles.cache.has(client.global.db.guilds[msg.guild.id].djrole)) { if (
!msg.member.roles.cache.has(
client.global.db.guilds[msg.guild.id].djrole
)
) {
msg.channel.send(client.messages.noDj); msg.channel.send(client.messages.noDj);
return false; return false;
} else return true; } else return true;
} else if (!permissions.has(command.permission)) { } else if (!permissions.has(command.permission)) {
let message let message;
message = client.messages.noPerms.replace("%PERMS%", command.permissions); message = client.messages.noPerms.replace(
"%PERMS%",
command.permissions
);
msg.channel.send(message); msg.channel.send(message);
return false; return false;
} else return true; } else return true;

View File

@ -1,11 +1,22 @@
module.exports = async function (client) { module.exports = async function (client) {
client.guilds.cache.forEach(guild => { client.guilds.cache.forEach((guild) => {
if (client.global.db.guilds[guild.id].prefix === undefined) client.global.db.guilds[guild.id].prefix = client.config.prefix; if (client.global.db.guilds[guild.id].prefix === undefined)
if (client.global.db.guilds[guild.id].defaultVolume === undefined) client.global.db.guilds[guild.id].defaultVolume = client.config.defaultVolume; client.global.db.guilds[guild.id].prefix = client.config.prefix;
if (client.global.db.guilds[guild.id].permissions === undefined) client.global.db.guilds[guild.id].permissions = client.config.permissions; if (client.global.db.guilds[guild.id].defaultVolume === undefined)
if (client.global.db.guilds[guild.id].dj === undefined) client.global.db.guilds[guild.id].dj = client.config.dj; client.global.db.guilds[guild.id].defaultVolume =
if (client.global.db.guilds[guild.id].djrole === undefined) client.global.db.guilds[guild.id].djrole = client.config.djrole; client.config.defaultVolume;
if (client.global.db.guilds[guild.id].startPlaying === undefined) client.global.db.guilds[guild.id].startPlaying = client.config.startPlaying; if (client.global.db.guilds[guild.id].permissions === undefined)
if (client.global.db.guilds[guild.id].bass === undefined) client.global.db.guilds[guild.id].bass = client.config.bass; client.global.db.guilds[guild.id].permissions = client.config.permissions;
if (client.global.db.guilds[guild.id].dj === undefined)
client.global.db.guilds[guild.id].dj = client.config.dj;
if (client.global.db.guilds[guild.id].djrole === undefined)
client.global.db.guilds[guild.id].djrole = client.config.djrole;
if (client.global.db.guilds[guild.id].startPlaying === undefined)
client.global.db.guilds[guild.id].startPlaying =
client.config.startPlaying;
if (client.global.db.guilds[guild.id].bass === undefined)
client.global.db.guilds[guild.id].bass = client.config.bass;
if (client.global.db.guilds[guild.id].blacklsit === undefined)
client.global.db.guilds[guild.id].blacklist = [];
}); });
}; };

12
src/struct/funcs/end.ts Normal file
View File

@ -0,0 +1,12 @@
module.exports = async function (client, msg, pos, command) {
const seek = parseInt(pos);
const queue = client.queue.get(msg.guild.id);
if (command.name === "seek") {
queue.time = pos * 1000;
} else {
queue.time = queue.connection.dispatcher.streamTime + queue.time;
}
queue.connection.dispatcher.end();
queue.endReason = "seek";
client.funcs.play(msg.guild, queue.songs[0], client, seek, false);
};

View File

@ -1,7 +1,14 @@
module.exports = function (msg, args, client, Discord, command) { module.exports = function (msg, args, client, Discord, command) {
const permissions = msg.channel.permissionsFor(msg.client.user); const permissions = msg.channel.permissionsFor(msg.client.user);
if (!permissions.has('EMBED_LINKS')) return msg.channel.send(client.messages.noPermsEmbed); if (!permissions.has("EMBED_LINKS"))
if (!permissions.has('USE_EXTERNAL_EMOJIS')) return msg.channel.send(client.noPermsUseExternalEmojis); return msg.channel.send(client.messages.noPermsEmbed);
if (!permissions.has("USE_EXTERNAL_EMOJIS"))
return msg.channel.send(client.noPermsUseExternalEmojis);
if (
command.category === "music" &&
client.global.db.guilds[msg.guild.id].blacklist.includes(msg.channel.id)
)
return msg.channel.send(client.messages.musicCommandsDisabled);
try { try {
command.uses++; command.uses++;
command.execute(msg, args, client, Discord, command); command.execute(msg, args, client, Discord, command);
@ -10,10 +17,12 @@ module.exports = function (msg, args, client, Discord, command) {
msg.reply(client.messages.errorExe); msg.reply(client.messages.errorExe);
const embed = new Discord.MessageEmbed() const embed = new Discord.MessageEmbed()
.setTitle(`Musix ${error.toString()}`) .setTitle(`Musix ${error.toString()}`)
.setDescription(error.stack.replace(/at /g, '**at **')) .setDescription(error.stack.replace(/at /g, "**at **"))
.setFooter(`guild: ${msg.guild.id} (${msg.guild.name}), user: ${msg.member.id} (${msg.member.displayName}), channel: ${msg.channel.id} (${msg.channel.name}), date: ${date}, Shard: ${client.shard.ids}`) .setFooter(
.setColor('#b50002'); `guild: ${msg.guild.id} (${msg.guild.name}), user: ${msg.member.id} (${msg.member.displayName}), channel: ${msg.channel.id} (${msg.channel.name}), date: ${date}, Shard: ${client.shard.ids}`
client.users.cache.get(client.devId).send(embed); )
.setColor("#b50002");
client.users.cache.get(client.config.devId).send(embed);
console.error(error); console.error(error);
} }
}; };

View File

@ -1,15 +1,17 @@
module.exports = async function ( module.exports = async function (
video, resource,
msg, msg,
voiceChannel, voiceChannel,
client, client,
playlist = false playlist,
type
) { ) {
const Discord = require("discord.js"); const Discord = require("discord.js");
const song = { const song = {
title: Discord.Util.escapeMarkdown(video.title), title: Discord.Util.escapeMarkdown(resource.title),
url: video.url, url: resource.url,
author: msg.author, author: msg.author,
type: type,
}; };
const queue = client.queue.get(msg.guild.id); const queue = client.queue.get(msg.guild.id);
@ -24,12 +26,12 @@ module.exports = async function (
} }
const construct = { const construct = {
textChannel: null, textChannel: msg.channel,
voiceChannel: null, voiceChannel: voiceChannel,
connection: null, connection: null,
songs: [], songs: [],
volume: null, volume: client.global.db.guilds[msg.guild.id].defaultVolume,
bass: null, bass: client.global.db.guilds[msg.guild.id].bass,
nigthCore: false, nigthCore: false,
playing: false, playing: false,
paused: false, paused: false,
@ -42,11 +44,6 @@ module.exports = async function (
endReason: null, endReason: null,
}; };
construct.textChannel = msg.channel;
construct.voiceChannel = voiceChannel;
construct.volume = client.global.db.guilds[msg.guild.id].defaultVolume;
construct.bass = client.global.db.guilds[msg.guild.id].bass;
construct.songs.push(song); construct.songs.push(song);
client.queue.set(msg.guild.id, construct); client.queue.set(msg.guild.id, construct);

View File

@ -1,10 +1,9 @@
module.exports = async function (guild, song, client, seek, play) { module.exports = async function (guild, song, client, seek, play) {
const { Readable: ReadableStream } = require("stream");
const Discord = require("discord.js"); const Discord = require("discord.js");
const ytdl = require("ytdl-core"); const ytdl = require("ytdl-core");
const streamConfig = require("../config/streamConfig.ts"); const streamConfig = require("../config/streamConfig.ts");
const getThumb = require("video-thumbnail-url");
const prism = require("prism-media"); const prism = require("prism-media");
const queue = client.queue.get(guild.id); const queue = client.queue.get(guild.id);
if (!song) { if (!song) {
queue.voiceChannel.leave(); queue.voiceChannel.leave();
@ -14,6 +13,9 @@ module.exports = async function (guild, song, client, seek, play) {
streamConfig.options.seek = seek; streamConfig.options.seek = seek;
let input = song.url;
if (song.type === "ytdl") input = ytdl(song.url, streamConfig.ytdlOptions);
const ffmpegArgs = [ const ffmpegArgs = [
"-analyzeduration", "-analyzeduration",
"0", "0",
@ -28,38 +30,43 @@ module.exports = async function (guild, song, client, seek, play) {
"-af", "-af",
`bass=g=${queue.bass}`, `bass=g=${queue.bass}`,
]; ];
client.funcs.sleep(500);
if (queue.nigthCore) { if (queue.nigthCore) {
ffmpegArgs.push("-af"); ffmpegArgs.push("-af");
ffmpegArgs.push("asetrate=52920"); ffmpegArgs.push("asetrate=52920");
} }
const transcoder = new prism.FFmpeg({ args: ffmpegArgs }); const isStream = input instanceof ReadableStream;
const args = isStream ? ffmpegArgs.slice() : ["-i", input, ...ffmpegArgs];
args.unshift("-ss", String(seek));
const transcoder = new prism.FFmpeg({ args: args });
const stream = input.pipe(transcoder);
const dispatcher = queue.connection const dispatcher = queue.connection
.play( .play(stream, streamConfig.options)
ytdl(song.url, streamConfig.ytdlOptions).pipe(transcoder),
streamConfig.options
)
.on("finish", () => { .on("finish", () => {
client.dispatcher.finish(client, queue.endReason, guild); client.dispatcher.finish(client, queue.endReason, guild);
}) })
.on("start", () => { .on("start", () => {
queue.endReason = null;
dispatcher.player.streamingData.pausedTime = 0; dispatcher.player.streamingData.pausedTime = 0;
}) })
.on("error", (error) => { .on("error", (error) => {
client.dispatcher.error(client, error, guild); client.dispatcher.error(client, error, guild);
}); });
dispatcher.setVolume(queue.volume / 10); dispatcher.setVolume(queue.volume / 10);
if (client.global.db.guilds[guild.id].startPlaying || play) { if ((client.global.db.guilds[guild.id].startPlaying && play) || play) {
if (song.type !== "ytdl") return;
const data = await Promise.resolve(ytdl.getInfo(queue.songs[0].url)); const data = await Promise.resolve(ytdl.getInfo(queue.songs[0].url));
const songtime = (data.length_seconds * 1000).toFixed(0); const songtime = (data.length_seconds * 1000).toFixed(0);
const thumbnail = getThumb(queue.songs[0].url);
const embed = new Discord.MessageEmbed() const embed = new Discord.MessageEmbed()
.setTitle(`${client.messages.startPlaying}**${song.title}**`) .setTitle(`${client.messages.startPlaying}**${song.title}**`)
.setDescription( .setDescription(
`Song duration: \`${client.funcs.msToTime(songtime, "hh:mm:ss")}\`` `Song duration: \`${client.funcs.msToTime(songtime, "hh:mm:ss")}\``
) )
.setThumbnail(thumbnail._rejectionHandler0)
.setColor(client.config.embedColor); .setColor(client.config.embedColor);
queue.textChannel.send(embed); queue.textChannel.send(embed);
} }

View File

@ -1,8 +1,8 @@
module.exports = async function (client) { module.exports = async function (client) {
if (client.config.saveDB && !client.config.devMode) { if (client.config.saveDB && !client.config.devMode) {
//console.log('DB saved'); //console.log('DB saved');
client.guilds.cache.forEach(guild => { client.guilds.cache.forEach((guild) => {
client.db.collection('guilds').doc(guild.id).set({ client.db.collection("guilds").doc(guild.id).set({
prefix: client.global.db.guilds[guild.id].prefix, prefix: client.global.db.guilds[guild.id].prefix,
defaultVolume: client.global.db.guilds[guild.id].defaultVolume, defaultVolume: client.global.db.guilds[guild.id].defaultVolume,
permissions: client.global.db.guilds[guild.id].permissions, permissions: client.global.db.guilds[guild.id].permissions,
@ -10,7 +10,9 @@ module.exports = async function (client) {
djrole: client.global.db.guilds[guild.id].djrole, djrole: client.global.db.guilds[guild.id].djrole,
startPlaying: client.global.db.guilds[guild.id].startPlaying, startPlaying: client.global.db.guilds[guild.id].startPlaying,
bass: client.global.db.guilds[guild.id].bass, bass: client.global.db.guilds[guild.id].bass,
blacklist: client.global.db.guilds[guild.id].blacklist,
premium: client.global.db.guilds[guild.id].premium,
}); });
}); });
} }
} };

View File

@ -0,0 +1,3 @@
module.exports = function (milliseconds) {
return new Promise((resolve) => setTimeout(resolve, milliseconds));
};

153
web/app.js Normal file
View File

@ -0,0 +1,153 @@
const config = require("../config/config.ts");
const express = require("express"); // Express web server framework
const request = require("request"); // "Request" library
const cors = require("cors");
const querystring = require("querystring");
const cookieParser = require("cookie-parser");
const http = require("http");
const client_id = config.spotify_client_id;
const client_secret = config.spotify_client_secret;
const redirect_uri = config.redirectUri;
const scope = "user-read-private user-read-email";
console.log(config);
/**
* Generates a random string containing numbers and letters
* @param {number} length The length of the string
* @return {string} The generated string
*/
var generateRandomString = function (length) {
var text = "";
var possible =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for (var i = 0; i < length; i++) {
text += possible.charAt(Math.floor(Math.random() * possible.length));
}
return text;
};
var stateKey = "spotify_auth_state";
var app = express();
app
.use(express.static(__dirname + "/public"))
.use(cors())
.use(cookieParser());
app.get("/login", function (req, res) {
var state = generateRandomString(16);
res.cookie(stateKey, state);
res.redirect(
"https://accounts.spotify.com/authorize?" +
querystring.stringify({
response_type: "code",
client_id: client_id,
scope: scope,
redirect_uri: redirect_uri,
state: state,
})
);
});
app.get("/callback", function (req, res) {
// your application requests refresh and access tokens
// after checking the state parameter
var code = req.query.code || null;
var state = req.query.state || null;
var storedState = req.cookies ? req.cookies[stateKey] : null;
if (state === null || state !== storedState) {
res.redirect(
"/#" +
querystring.stringify({
error: "state_mismatch",
})
);
} else {
res.clearCookie(stateKey);
var authOptions = {
url: "https://accounts.spotify.com/api/token",
form: {
code: code,
redirect_uri: redirect_uri,
grant_type: "authorization_code",
},
headers: {
Authorization:
"Basic " +
new Buffer(client_id + ":" + client_secret).toString("base64"),
},
json: true,
};
request.post(authOptions, function (error, response, body) {
if (!error && response.statusCode === 200) {
var access_token = body.access_token,
refresh_token = body.refresh_token;
var options = {
url: "https://api.spotify.com/v1/me",
headers: {
Authorization: "Bearer " + access_token,
},
json: true,
};
// use the access token to access the Spotify Web API
request.get(options, function (error, response, body) {
console.log(body);
});
// we can also pass the token to the browser to make requests from there
res.redirect(
"/#" +
querystring.stringify({
access_token: access_token,
refresh_token: refresh_token,
})
);
} else {
res.redirect(
"/#" +
querystring.stringify({
error: "invalid_token",
})
);
}
});
}
});
app.get("/refresh_token", function (req, res) {
// requesting access token from refresh token
var refresh_token = req.query.refresh_token;
var authOptions = {
url: "https://accounts.spotify.com/api/token",
headers: {
Authorization:
"Basic " +
new Buffer(client_id + ":" + client_secret).toString("base64"),
},
form: {
grant_type: "refresh_token",
refresh_token: refresh_token,
},
json: true,
};
request.post(authOptions, function (error, response, body) {
if (!error && response.statusCode === 200) {
var access_token = body.access_token;
res.send({
access_token: access_token,
});
}
});
});
console.log("Listening on " + config.port);
app.listen(config.port);

145
web/public/index.html Normal file
View File

@ -0,0 +1,145 @@
<!doctype html>
<html>
<head>
<title>Example of the Authorization Code flow with Spotify</title>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
<style type="text/css">
#login,
#loggedin {
display: none;
}
.text-overflow {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
width: 500px;
}
</style>
</head>
<body>
<div class="container">
<div id="login">
<h1>This is an example of the Authorization Code flow</h1>
<a href="/login" class="btn btn-primary">Log in with Spotify</a>
</div>
<div id="loggedin">
<div id="user-profile">
</div>
<div id="oauth">
</div>
<button class="btn btn-default" id="obtain-new-token">Obtain new token using the refresh token</button>
</div>
</div>
<script id="user-profile-template" type="text/x-handlebars-template">
<h1>Logged in as {{display_name}}</h1>
<div class="media">
<div class="pull-left">
<img class="media-object" width="150" src="{{images.0.url}}" />
</div>
<div class="media-body">
<dl class="dl-horizontal">
<dt>Display name</dt><dd class="clearfix">{{display_name}}</dd>
<dt>Id</dt><dd>{{id}}</dd>
<dt>Email</dt><dd>{{email}}</dd>
<dt>Spotify URI</dt><dd><a href="{{external_urls.spotify}}">{{external_urls.spotify}}</a></dd>
<dt>Link</dt><dd><a href="{{href}}">{{href}}</a></dd>
<dt>Profile Image</dt><dd class="clearfix"><a href="{{images.0.url}}">{{images.0.url}}</a></dd>
<dt>Country</dt><dd>{{country}}</dd>
</dl>
</div>
</div>
</script>
<script id="oauth-template" type="text/x-handlebars-template">
<h2>oAuth info</h2>
<dl class="dl-horizontal">
<dt>Access token</dt><dd class="text-overflow">{{access_token}}</dd>
<dt>Refresh token</dt><dd class="text-overflow">{{refresh_token}}</dd>
</dl>
</script>
<script src="//cdnjs.cloudflare.com/ajax/libs/handlebars.js/2.0.0-alpha.1/handlebars.min.js"></script>
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script>
(function () {
/**
* Obtains parameters from the hash of the URL
* @return Object
*/
function getHashParams() {
var hashParams = {};
var e, r = /([^&;=]+)=?([^&;]*)/g,
q = window.location.hash.substring(1);
while (e = r.exec(q)) {
hashParams[e[1]] = decodeURIComponent(e[2]);
}
return hashParams;
}
var userProfileSource = document.getElementById('user-profile-template').innerHTML,
userProfileTemplate = Handlebars.compile(userProfileSource),
userProfilePlaceholder = document.getElementById('user-profile');
var oauthSource = document.getElementById('oauth-template').innerHTML,
oauthTemplate = Handlebars.compile(oauthSource),
oauthPlaceholder = document.getElementById('oauth');
var params = getHashParams();
var access_token = params.access_token,
refresh_token = params.refresh_token,
error = params.error;
if (error) {
alert('There was an error during the authentication: ' + error);
} else {
if (access_token) {
// render oauth info
oauthPlaceholder.innerHTML = oauthTemplate({
access_token: access_token,
refresh_token: refresh_token
});
$.ajax({
url: 'https://api.spotify.com/v1/me',
headers: {
'Authorization': 'Bearer ' + access_token
},
success: function (response) {
userProfilePlaceholder.innerHTML = userProfileTemplate(response);
$('#login').hide();
$('#loggedin').show();
}
});
} else {
// render initial screen
$('#login').show();
$('#loggedin').hide();
}
document.getElementById('obtain-new-token').addEventListener('click', function () {
$.ajax({
url: '/refresh_token',
data: {
'refresh_token': refresh_token
}
}).done(function (data) {
access_token = data.access_token;
oauthPlaceholder.innerHTML = oauthTemplate({
access_token: access_token,
refresh_token: refresh_token
});
});
}, false);
}
})();
</script>
</body>
</html>