mirror of
https://github.com/musix-org/musix-oss
synced 2024-12-22 21:13:18 +00:00
Update V3.2.0
This commit is contained in:
parent
ce214a827f
commit
ec07bdb5a3
@ -5,6 +5,13 @@ module.exports = {
|
||||
devToken: process.env.DEVTOKEN,
|
||||
dblKey: process.env.DBLKEY,
|
||||
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",
|
||||
primary_test_channel: "617633098296721409",
|
||||
secondary_test_channel: "570531724002328577",
|
||||
@ -13,7 +20,7 @@ module.exports = {
|
||||
invite:
|
||||
"https://discordapp.com/oauth2/authorize?client_id=607266889537945605&permissions=3427328&scope=bot",
|
||||
supportServer: "https://discord.gg/rvHuJtB",
|
||||
devMode: false,
|
||||
devMode: true,
|
||||
api: false,
|
||||
saveDB: true,
|
||||
respawn: true,
|
12
index.js
12
index.js
@ -1,4 +1,4 @@
|
||||
const config = require("./src/struct/config/config.ts");
|
||||
const config = require("./config/config.ts");
|
||||
|
||||
if (config.devMode) {
|
||||
console.log('- dev mode- ');
|
||||
@ -6,8 +6,14 @@ if (config.devMode) {
|
||||
config.shards = 1;
|
||||
}
|
||||
|
||||
const { ShardingManager } = require('discord.js');
|
||||
const manager = new ShardingManager('./src/bot.ts', { token: config.token, respawn: config.respawn, totalShards: config.shards });
|
||||
const {
|
||||
ShardingManager
|
||||
} = require('discord.js');
|
||||
const manager = new ShardingManager('./src/bot.ts', {
|
||||
token: config.token,
|
||||
respawn: config.respawn,
|
||||
totalShards: config.shards
|
||||
});
|
||||
|
||||
console.log('- Launching shards -');
|
||||
manager.spawn(config.shards, config.shardDelay, config.shardTimeout);
|
||||
|
1233
package-lock.json
generated
1233
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
12
package.json
12
package.json
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "musix",
|
||||
"version": "3.1.1",
|
||||
"version": "3.2.0",
|
||||
"description": "V3 for Musix the discord music bot",
|
||||
"main": "./index.js",
|
||||
"scripts": {
|
||||
@ -18,20 +18,26 @@
|
||||
"homepage": "https://github.com/MatteZ02/Musix-V3#readme",
|
||||
"dependencies": {
|
||||
"bufferutil": "^4.0.1",
|
||||
"cookie-parser": "^1.4.5",
|
||||
"cors": "^2.8.5",
|
||||
"dblapi.js": "^2.4.0",
|
||||
"discord.js": "^12.1.1",
|
||||
"discord.js": "^12.2.0",
|
||||
"dotenv": "^8.2.0",
|
||||
"erlpack": "github:discordapp/erlpack",
|
||||
"firebase": "^7.14.0",
|
||||
"express": "^4.17.1",
|
||||
"firebase": "^7.14.1",
|
||||
"firebase-admin": "^8.10.0",
|
||||
"fs": "0.0.1-security",
|
||||
"genius-lyrics-api": "^2.0.3",
|
||||
"he": "^1.2.0",
|
||||
"libsodium-wrappers": "^0.7.6",
|
||||
"ms": "^2.1.2",
|
||||
"node-opus": "^0.3.3",
|
||||
"node-spotify-api": "^1.1.1",
|
||||
"prism-media": "github:hydrabolt/prism-media",
|
||||
"request": "^2.88.2",
|
||||
"simple-youtube-api": "^5.2.1",
|
||||
"spotify-web-api-node": "^4.0.0",
|
||||
"utf-8-validate": "^5.0.2",
|
||||
"video-thumbnail-url": "^1.0.1",
|
||||
"yt-search": "^1.1.2",
|
||||
|
@ -1,24 +1,35 @@
|
||||
module.exports = {
|
||||
name: 'bass',
|
||||
description: 'Bassboost command.',
|
||||
alias: 'none',
|
||||
usage: '<bass>',
|
||||
cooldown: 5,
|
||||
onlyDev: false,
|
||||
permission: 'MANAGE_MESSAGES',
|
||||
category: 'music',
|
||||
execute(msg, args, client, Discord, command) {
|
||||
const queue = client.queue.get(msg.guild.id);
|
||||
if (!args[1] && queue) return msg.channel.send(`${client.messages.currentBass}**${queue.bass}**`);
|
||||
const bass = parseFloat(args[1]);
|
||||
if (client.funcs.check(client, msg, command)) {
|
||||
if (isNaN(bass)) return msg.channel.send(client.messages.validNumber);
|
||||
if (bass > 100) return msg.channel.send(client.messages.maxBass);
|
||||
if (bass < 0) return msg.channel.send(client.messages.positiveBass);
|
||||
queue.bass = bass;
|
||||
let message;
|
||||
message = client.messages.bassApplied.replace("%BASS%", bass);
|
||||
return msg.channel.send(message);
|
||||
}
|
||||
name: "bass",
|
||||
description: "Bassboost command.",
|
||||
alias: "none",
|
||||
usage: "<bass>",
|
||||
cooldown: 5,
|
||||
onlyDev: false,
|
||||
permission: "MANAGE_MESSAGES",
|
||||
category: "music",
|
||||
execute(msg, args, client, Discord, command) {
|
||||
const queue = client.queue.get(msg.guild.id);
|
||||
if (!args[1] && queue)
|
||||
return msg.channel.send(
|
||||
`${client.messages.currentBass}**${queue.bass}**`
|
||||
);
|
||||
const bass = parseFloat(args[1]);
|
||||
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 (bass > 100) return msg.channel.send(client.messages.maxBass);
|
||||
if (bass < 0) return msg.channel.send(client.messages.positiveBass);
|
||||
queue.bass = bass;
|
||||
client.funcs.end(
|
||||
client,
|
||||
msg,
|
||||
(queue.connection.dispatcher.streamTime + queue.time) / 1000,
|
||||
command
|
||||
);
|
||||
let message;
|
||||
message = client.messages.bassApplied.replace("%BASS%", bass);
|
||||
return msg.channel.send(message);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
33
src/commands/lyrics.ts
Normal file
33
src/commands/lyrics.ts
Normal 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);
|
||||
});
|
||||
},
|
||||
};
|
@ -6,7 +6,7 @@ module.exports = {
|
||||
onlyDev: false,
|
||||
permission: "MANAGE_MESSAGES",
|
||||
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);
|
||||
if (!args[1] && queue)
|
||||
return msg.channel.send(
|
||||
|
@ -1,32 +1,50 @@
|
||||
module.exports = {
|
||||
name: 'nowplaying',
|
||||
alias: 'np',
|
||||
usage: '',
|
||||
description: 'See the currently playing song position and length.',
|
||||
onlyDev: false,
|
||||
permission: 'none',
|
||||
category: 'music',
|
||||
async execute(msg, args, client, Discord, command) {
|
||||
const getThumb = require('video-thumbnail-url');
|
||||
const ytdl = require('ytdl-core');
|
||||
const queue = client.queue.get(msg.guild.id);
|
||||
if (!queue) return msg.channel.send(client.messages.noServerQueue);
|
||||
let data = await Promise.resolve(ytdl.getInfo(queue.songs[0].url));
|
||||
let songtime = (data.length_seconds * 1000).toFixed(0);
|
||||
queue.time = queue.connection.dispatcher.streamTime;
|
||||
let completed = (queue.time.toFixed(0));
|
||||
let barlength = 30;
|
||||
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('⎯'); }
|
||||
const thumbnail = getThumb(queue.songs[0].url);
|
||||
const embed = new Discord.MessageEmbed()
|
||||
.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")}\``)
|
||||
.setFooter(`Queued by ${queue.songs[0].author.tag}`)
|
||||
.setURL(queue.songs[0].url)
|
||||
.setThumbnail(thumbnail._rejectionHandler0)
|
||||
.setColor(client.config.embedColor)
|
||||
return msg.channel.send(embed);
|
||||
name: "nowplaying",
|
||||
alias: "np",
|
||||
usage: "",
|
||||
description: "See the currently playing song position and length.",
|
||||
onlyDev: false,
|
||||
permission: "none",
|
||||
category: "music",
|
||||
async execute(msg, args, client, Discord, command) {
|
||||
const getThumb = require("video-thumbnail-url");
|
||||
const ytdl = require("ytdl-core");
|
||||
const queue = client.queue.get(msg.guild.id);
|
||||
if (!queue) return msg.channel.send(client.messages.noServerQueue);
|
||||
let data = await Promise.resolve(ytdl.getInfo(queue.songs[0].url));
|
||||
let songTime = (data.length_seconds * 1000).toFixed(0);
|
||||
let completed = (
|
||||
queue.connection.dispatcher.streamTime + queue.time
|
||||
).toFixed(0);
|
||||
let barlength = 30;
|
||||
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("⎯");
|
||||
}
|
||||
const thumbnail = getThumb(queue.songs[0].url);
|
||||
const embed = new Discord.MessageEmbed()
|
||||
.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")}\``
|
||||
)
|
||||
.setFooter(`Queued by ${queue.songs[0].author.tag}`)
|
||||
.setURL(queue.songs[0].url)
|
||||
.setThumbnail(thumbnail._rejectionHandler0)
|
||||
.setColor(client.config.embedColor);
|
||||
if (queue.nigthCore)
|
||||
embed.setDescription(
|
||||
`${client.messages.nowPlayingDesc} ${queue.songs[0].title}`
|
||||
);
|
||||
return msg.channel.send(embed);
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -1,45 +1,168 @@
|
||||
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 = {
|
||||
name: 'play',
|
||||
alias: 'p',
|
||||
usage: '<song name>',
|
||||
description: 'Play some music.',
|
||||
onlyDev: false,
|
||||
permission: 'none',
|
||||
category: 'music',
|
||||
async execute(msg, args, client, Discord, command) {
|
||||
const youtube = new YouTube(client.config.api_key);
|
||||
const searchString = args.slice(1).join(" ");
|
||||
const url = args[1] ? args[1].replace(/<(.+)>/g, "$1") : "";
|
||||
const queue = client.queue.get(msg.guild.id);
|
||||
const voiceChannel = msg.member.voice.channel;
|
||||
if (!queue) {
|
||||
if (!msg.member.voice.channel) return msg.channel.send(client.messages.noVoiceChannel);
|
||||
} else {
|
||||
if (voiceChannel !== queue.voiceChannel) return msg.channel.send(client.messages.wrongVoiceChannel);
|
||||
}
|
||||
if (!args[1]) return msg.channel.send(client.messages.noQuery);
|
||||
if (voiceChannel.full) return msg.channel.send(client.messages.channelFull);
|
||||
if (!voiceChannel.joinable) return msg.channel.send(client.messages.noPermsConnect);
|
||||
if (!voiceChannel.speakable) return msg.channel.send(client.messages.noPermsSpeak);
|
||||
if (url.match(/^https?:\/\/(www.youtube.com|youtube.com)\/playlist(.*)$/)) {
|
||||
const lmsg = await msg.channel.send(client.messages.loadingSongs);
|
||||
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.funcs.handleVideo(video2, msg, voiceChannel, client, true);
|
||||
}
|
||||
client.messages.playlistAdded = client.messages.playlistAdded.replace("%TITLE%", playlist.title);
|
||||
return lmsg.edit(client.messages.playlistAdded);
|
||||
} else {
|
||||
search(searchString, function (err, res) {
|
||||
if (err) return console.log(err);
|
||||
if (res.videos.length === 0) return msg.channel.send(client.messages.noResults);
|
||||
client.funcs.handleVideo(res.videos[0], msg, voiceChannel, client, false);
|
||||
})
|
||||
}
|
||||
}
|
||||
name: "play",
|
||||
alias: "p",
|
||||
usage: "<song name>",
|
||||
description: "Play some music.",
|
||||
onlyDev: false,
|
||||
permission: "none",
|
||||
category: "music",
|
||||
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 searchString = args.slice(1).join(" ");
|
||||
const url = args[1] ? args[1].replace(/<(.+)>/g, "$1") : "";
|
||||
const queue = client.queue.get(msg.guild.id);
|
||||
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 (!msg.member.voice.channel)
|
||||
return msg.channel.send(client.messages.noVoiceChannel);
|
||||
} else {
|
||||
if (voiceChannel !== queue.voiceChannel)
|
||||
return msg.channel.send(client.messages.wrongVoiceChannel);
|
||||
}
|
||||
if (!args[1]) return msg.channel.send(client.messages.noQuery);
|
||||
if (voiceChannel.full) return msg.channel.send(client.messages.channelFull);
|
||||
if (!voiceChannel.joinable)
|
||||
return msg.channel.send(client.messages.noPermsConnect);
|
||||
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 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.funcs.handleVideo(
|
||||
video2,
|
||||
msg,
|
||||
voiceChannel,
|
||||
client,
|
||||
true,
|
||||
"ytdl"
|
||||
);
|
||||
}
|
||||
let message;
|
||||
message = client.messages.playlistAdded.replace(
|
||||
"%TITLE%",
|
||||
playlist.title
|
||||
);
|
||||
return lmsg.edit(message);
|
||||
} else {
|
||||
search(searchString, function (err, res) {
|
||||
if (err) return console.log(err);
|
||||
if (res.videos.length === 0)
|
||||
return msg.channel.send(client.messages.noResults);
|
||||
client.funcs.handleVideo(
|
||||
res.videos[0],
|
||||
msg,
|
||||
voiceChannel,
|
||||
client,
|
||||
false,
|
||||
"ytdl"
|
||||
);
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
|
@ -1,25 +1,31 @@
|
||||
module.exports = {
|
||||
name: 'remove',
|
||||
alias: 'rm',
|
||||
usage: '<song pos>',
|
||||
description: 'Remove a song from the queue',
|
||||
onlyDev: false,
|
||||
permission: 'MANAGE_MESSAGES',
|
||||
category: 'music',
|
||||
execute(msg, args, client, Discord, command) {
|
||||
const queue = client.queue.get(msg.guild.id);
|
||||
if (client.funcs.check(client, msg, command)) {
|
||||
if (!args[1]) return msg.channel.send(client.messages.provideASong);
|
||||
const pos = parseInt(args[1]);
|
||||
if (isNaN(pos)) return msg.channel.send(client.messages.validNumber);
|
||||
if (pos < 1) return msg.channel.send(client.messages.noSongs);
|
||||
let message1;
|
||||
let message2;
|
||||
message1 = client.messages.queueLength.replace("%LENGTH%", queue.songs.length);
|
||||
if (pos > queue.songs.length) return msg.channel.send(message1);
|
||||
message2 = client.messages.removed.replace("%SONG%", queue.songs[pos].title);
|
||||
msg.channel.send(message2);
|
||||
return queue.songs.splice(pos, 1);
|
||||
}
|
||||
name: "remove",
|
||||
alias: "rm",
|
||||
usage: "<song pos>",
|
||||
description: "Remove a song from the queue",
|
||||
onlyDev: false,
|
||||
permission: "MANAGE_MESSAGES",
|
||||
category: "music",
|
||||
execute(msg, args, client, Discord, command) {
|
||||
const queue = client.queue.get(msg.guild.id);
|
||||
if (client.funcs.check(client, msg, command)) {
|
||||
if (!args[1]) return msg.channel.send(client.messages.provideASong);
|
||||
const pos = parseInt(args[1]);
|
||||
if (isNaN(pos)) return msg.channel.send(client.messages.validNumber);
|
||||
if (pos < 1) return msg.channel.send(client.messages.noSongs);
|
||||
let message1;
|
||||
let message2;
|
||||
message1 = client.messages.queueLength.replace(
|
||||
"%LENGTH%",
|
||||
queue.songs.length
|
||||
);
|
||||
if (pos > queue.songs.length) return msg.channel.send(message1);
|
||||
message2 = client.messages.removed.replace(
|
||||
"%SONG%",
|
||||
queue.songs[pos].title
|
||||
);
|
||||
msg.channel.send(message2);
|
||||
return queue.songs.splice(pos, 1);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
@ -1,29 +1,36 @@
|
||||
module.exports = {
|
||||
name: 'seek',
|
||||
alias: 'none',
|
||||
usage: '<point in song>',
|
||||
description: 'Seek to a specific point in the currently playing song.',
|
||||
onlyDev: true,
|
||||
permission: 'MANAGE_MESSAGES',
|
||||
category: 'music',
|
||||
async execute(msg, args, client, Discord, command) {
|
||||
const ytdl = require('ytdl-core');
|
||||
const queue = client.queue.get(msg.guild.id);
|
||||
if (client.funcs.check(client, msg, command)) {
|
||||
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}\``);
|
||||
let point = args[1];
|
||||
const pos = parseInt(args[1]);
|
||||
if (isNaN(pos)) {
|
||||
if (pos < 0) return msg.channel.send(client.messages.seekingPointPositive);
|
||||
let message;
|
||||
message = client.messages.seekMax.replace("%LENGTH%", data.length_seconds);
|
||||
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);
|
||||
}
|
||||
name: "seek",
|
||||
alias: "none",
|
||||
usage: "<point in song (seconds)>",
|
||||
description: "Seek to a specific point in the currently playing song.",
|
||||
onlyDev: false,
|
||||
permission: "MANAGE_MESSAGES",
|
||||
category: "music",
|
||||
async execute(msg, args, client, Discord, command) {
|
||||
const ytdl = require("ytdl-core");
|
||||
const queue = client.queue.get(msg.guild.id);
|
||||
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));
|
||||
if (!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]);
|
||||
if (isNaN(pos)) {
|
||||
if (pos < 0)
|
||||
return msg.channel.send(client.messages.seekingPointPositive);
|
||||
let message;
|
||||
message = client.messages.seekMax.replace(
|
||||
"%LENGTH%",
|
||||
data.length_seconds
|
||||
);
|
||||
if (pos > data.length_seconds) return msg.channel.send(message);
|
||||
}
|
||||
client.funcs.end(client, msg, pos, command);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
@ -1,32 +1,68 @@
|
||||
module.exports = {
|
||||
name: 'settings',
|
||||
alias: 'pref',
|
||||
usage: '<setting> <value(opt)>',
|
||||
description: 'Change the server settings for Musix.',
|
||||
name: "settings",
|
||||
alias: "pref",
|
||||
usage: "<setting> <value(opt)>",
|
||||
description: "Change the server settings for Musix.",
|
||||
onlyDev: false,
|
||||
permission: 'MANAGE_GUILD',
|
||||
category: 'util',
|
||||
permission: "MANAGE_GUILD",
|
||||
category: "util",
|
||||
async execute(msg, args, client, Discord, command) {
|
||||
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()
|
||||
.setTitle(client.messages.settingsTitle)
|
||||
.addField(client.messages.settingsPrefix, client.messages.settingsPrefixDesc, true)
|
||||
.addField(client.messages.settingsVolume, client.messages.settingsVolumeDesc, 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)
|
||||
.addField(
|
||||
client.messages.settingsPrefix,
|
||||
client.messages.settingsPrefixDesc,
|
||||
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)
|
||||
.setAuthor(client.user.username, client.user.displayAvatarURL)
|
||||
.setColor(client.config.embedColor)
|
||||
.setColor(client.config.embedColor);
|
||||
const permissions = msg.channel.permissionsFor(msg.author);
|
||||
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]) {
|
||||
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);
|
||||
try {
|
||||
option.execute(msg, args, client);
|
||||
@ -34,9 +70,12 @@ module.exports = {
|
||||
msg.reply(client.messages.errorExeOpt);
|
||||
const embed = new Discord.MessageEmbed()
|
||||
.setTitle(`Musix ${error.toString()}`)
|
||||
.setDescription(error.stack.replace(/at /g, '**at **'))
|
||||
.setDescription(error.stack.replace(/at /g, "**at **"))
|
||||
.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);
|
||||
}
|
||||
} else {
|
||||
|
109
src/commands/settings/blacklist.ts
Normal file
109
src/commands/settings/blacklist.ts
Normal 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);
|
||||
}
|
||||
},
|
||||
};
|
28
src/commands/settings/premium.ts
Normal file
28
src/commands/settings/premium.ts
Normal 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);
|
||||
}
|
||||
},
|
||||
};
|
@ -1,50 +1,62 @@
|
||||
module.exports = {
|
||||
name: 'skip',
|
||||
alias: 's',
|
||||
usage: '',
|
||||
description: 'Skip the currently playing song.',
|
||||
onlyDev: false,
|
||||
permission: 'MANAGE_MESSAGES',
|
||||
category: 'music',
|
||||
execute(msg, args, client, Discord, command) {
|
||||
const queue = client.queue.get(msg.guild.id);
|
||||
const permissions = msg.channel.permissionsFor(msg.author);
|
||||
if (!queue || !queue.playing) return msg.channel.send(client.messages.noServerQueue);
|
||||
if (msg.author.id !== client.config.devId) {
|
||||
if (msg.member.voice.channel !== queue.voiceChannel) return msg.channel.send(client.messages.wrongVoiceChannel);
|
||||
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)) {
|
||||
return vote(queue, msg, client);
|
||||
} else {
|
||||
return skipSong(queue, msg, client);
|
||||
}
|
||||
} else {
|
||||
return skipSong(queue, msg, client);
|
||||
}
|
||||
} else {
|
||||
return skipSong(queue, msg, client);
|
||||
}
|
||||
}
|
||||
name: "skip",
|
||||
alias: "s",
|
||||
usage: "",
|
||||
description: "Skip the currently playing song.",
|
||||
onlyDev: false,
|
||||
permission: "MANAGE_MESSAGES",
|
||||
category: "music",
|
||||
execute(msg, args, client, Discord, command) {
|
||||
const queue = client.queue.get(msg.guild.id);
|
||||
const permissions = msg.channel.permissionsFor(msg.author);
|
||||
if (!queue || !queue.playing)
|
||||
return msg.channel.send(client.messages.noServerQueue);
|
||||
if (msg.author.id !== client.config.devId) {
|
||||
if (msg.member.voice.channel !== queue.voiceChannel)
|
||||
return msg.channel.send(client.messages.wrongVoiceChannel);
|
||||
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)
|
||||
) {
|
||||
return vote(queue, msg, client);
|
||||
} else {
|
||||
return skipSong(queue, msg, client);
|
||||
}
|
||||
} else {
|
||||
return skipSong(queue, msg, client);
|
||||
}
|
||||
} else {
|
||||
return skipSong(queue, msg, client);
|
||||
}
|
||||
},
|
||||
};
|
||||
function skipSong(queue, msg, client) {
|
||||
msg.channel.send(client.messages.skipped);
|
||||
queue.endReason = "skip";
|
||||
queue.connection.dispatcher.end();
|
||||
};
|
||||
msg.channel.send(client.messages.skipped);
|
||||
queue.endReason = "skip";
|
||||
queue.time = 0;
|
||||
queue.connection.dispatcher.end();
|
||||
}
|
||||
function vote(queue, msg, client) {
|
||||
queue.votesNeeded = Math.floor(queue.voiceChannel.members.size / 2);
|
||||
queue.votesNeeded.toFixed();
|
||||
if (queue.voiceChannel.members.size > 2) {
|
||||
if (queue.voters.includes(msg.member.id)) return msg.channel.send(client.messages.alreadyVoted);
|
||||
queue.votes++;
|
||||
queue.voters.push(msg.member.id);
|
||||
if (queue.votes >= queue.votesNeeded) {
|
||||
queue.voters = [];
|
||||
queue.votes = 0;
|
||||
queue.votesNeeded = null;
|
||||
return skipSong(queue, msg, client);
|
||||
} else return msg.channel.send(`${client.messages.notEnoughVotes} ${queue.votes} / ${queue.votesNeeded}!`);
|
||||
} else {
|
||||
return skipSong(queue, msg, client);
|
||||
}
|
||||
};
|
||||
queue.votesNeeded = Math.floor(queue.voiceChannel.members.size / 2);
|
||||
queue.votesNeeded.toFixed();
|
||||
if (queue.voiceChannel.members.size > 2) {
|
||||
if (queue.voters.includes(msg.member.id))
|
||||
return msg.channel.send(client.messages.alreadyVoted);
|
||||
queue.votes++;
|
||||
queue.voters.push(msg.member.id);
|
||||
if (queue.votes >= queue.votesNeeded) {
|
||||
queue.voters = [];
|
||||
queue.votes = 0;
|
||||
queue.votesNeeded = null;
|
||||
return skipSong(queue, msg, client);
|
||||
} else
|
||||
return msg.channel.send(
|
||||
`${client.messages.notEnoughVotes} ${queue.votes} / ${queue.votesNeeded}!`
|
||||
);
|
||||
} else {
|
||||
return skipSong(queue, msg, client);
|
||||
}
|
||||
}
|
||||
|
@ -1,25 +1,30 @@
|
||||
module.exports = {
|
||||
name: 'skipto',
|
||||
alias: 'st',
|
||||
usage: '<point in queue>',
|
||||
description: 'Skip to a point in the queue',
|
||||
onlyDev: false,
|
||||
permission: 'MANAGE_MESSAGES',
|
||||
category: 'music',
|
||||
async execute(msg, args, client, Discord, command) {
|
||||
const queue = client.queue.get(msg.guild.id);
|
||||
if (client.funcs.check(client, msg, command)) {
|
||||
if (!args[1]) return msg.channel.send(`${client.messages.correctUsage}\`${command.usage}\``);
|
||||
let point = parseInt(args[1]);
|
||||
point = point - 1;
|
||||
if (isNaN(point)) return msg.channel.send(client.messages.validNumber);
|
||||
if (point > queue.songs.size) return msg.channel.send(client.messages.noSongs);
|
||||
if (point < 0) return msg.channel.send(client.messages.cantSkipToCurrent);
|
||||
for (let i = 0; i < point; i++) {
|
||||
queue.songs.shift();
|
||||
}
|
||||
queue.endReason = "skipto";
|
||||
queue.connection.dispatcher.end();
|
||||
}
|
||||
name: "skipto",
|
||||
alias: "st",
|
||||
usage: "<point in queue>",
|
||||
description: "Skip to a point in the queue",
|
||||
onlyDev: false,
|
||||
permission: "MANAGE_MESSAGES",
|
||||
category: "music",
|
||||
async execute(msg, args, client, Discord, command) {
|
||||
const queue = client.queue.get(msg.guild.id);
|
||||
if (client.funcs.check(client, msg, command)) {
|
||||
if (!args[1])
|
||||
return msg.channel.send(
|
||||
`${client.messages.correctUsage}\`${command.usage}\``
|
||||
);
|
||||
let point = parseInt(args[1]);
|
||||
point = point - 1;
|
||||
if (isNaN(point)) return msg.channel.send(client.messages.validNumber);
|
||||
if (point > queue.songs.size)
|
||||
return msg.channel.send(client.messages.noSongs);
|
||||
if (point < 0) return msg.channel.send(client.messages.cantSkipToCurrent);
|
||||
for (let i = 0; i < point; i++) {
|
||||
queue.songs.shift();
|
||||
}
|
||||
queue.endReason = "skipto";
|
||||
queue.time = 0;
|
||||
queue.connection.dispatcher.end();
|
||||
}
|
||||
},
|
||||
};
|
||||
|
22
src/commands/soundcloud.ts
Normal file
22
src/commands/soundcloud.ts
Normal 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));
|
||||
},
|
||||
};
|
@ -1,23 +1,27 @@
|
||||
module.exports = {
|
||||
name: 'guildcreate',
|
||||
async execute(client, guild) {
|
||||
client.db.collection('guilds').doc(guild.id).set({
|
||||
prefix: client.config.prefix,
|
||||
defaultVolume: client.config.defaultVolume,
|
||||
permissions: client.config.permissions,
|
||||
dj: client.config.dj,
|
||||
djrole: client.config.djrole,
|
||||
startPlaying: client.config.startPlaying,
|
||||
bass: client.config.bass,
|
||||
});
|
||||
client.global.db.guilds[guild.id] = {
|
||||
prefix: client.config.prefix,
|
||||
defaultVolume: client.config.defaultVolume,
|
||||
permissions: client.config.permissions,
|
||||
dj: client.config.dj,
|
||||
djrole: client.config.djrole,
|
||||
startPlaying: client.config.startPlaying,
|
||||
bass: client.config.bass,
|
||||
};
|
||||
}
|
||||
}
|
||||
name: "guildcreate",
|
||||
async execute(client, guild) {
|
||||
client.db.collection("guilds").doc(guild.id).set({
|
||||
prefix: client.config.prefix,
|
||||
defaultVolume: client.config.defaultVolume,
|
||||
permissions: client.config.permissions,
|
||||
dj: client.config.dj,
|
||||
djrole: client.config.djrole,
|
||||
startPlaying: client.config.startPlaying,
|
||||
bass: client.config.bass,
|
||||
blacklist: [],
|
||||
premium: false,
|
||||
});
|
||||
client.global.db.guilds[guild.id] = {
|
||||
prefix: client.config.prefix,
|
||||
defaultVolume: client.config.defaultVolume,
|
||||
permissions: client.config.permissions,
|
||||
dj: client.config.dj,
|
||||
djrole: client.config.djrole,
|
||||
startPlaying: client.config.startPlaying,
|
||||
bass: client.config.bass,
|
||||
blacklist: [],
|
||||
premium: false,
|
||||
};
|
||||
},
|
||||
};
|
||||
|
@ -1,48 +1,56 @@
|
||||
const DBL = require("dblapi.js");
|
||||
|
||||
module.exports = {
|
||||
name: 'ready',
|
||||
async execute(client, Discord) {
|
||||
const remoteMusixGuildsData = await client.funcs.dbget('guilds', null, client);
|
||||
remoteMusixGuildsData.forEach(guildData => {
|
||||
client.global.db.guilds[guildData.id] = guildData.d;
|
||||
});
|
||||
if (client.config.devMode) {
|
||||
client.guilds.cache.forEach(guild => {
|
||||
client.global.db.guilds[guild.id] = {
|
||||
prefix: client.config.prefix,
|
||||
defaultVolume: client.config.defaultVolume,
|
||||
permissions: client.config.permissions,
|
||||
dj: client.config.dj,
|
||||
djrole: client.config.djrole,
|
||||
startPlaying: client.config.startPlaying,
|
||||
bass: client.config.bass,
|
||||
};
|
||||
});
|
||||
}
|
||||
console.log(`- DB Set - Shard: ${client.shard.ids} -`);
|
||||
client.user.setActivity(`@${client.user.username} help | 🎶`, { type: 'LISTENING' });
|
||||
client.user.setStatus('online');
|
||||
const dbl = new DBL(client.config.dblKey, client);
|
||||
if (client.config.dblApi && !client.config.devMode) {
|
||||
dbl.on('posted', () => {
|
||||
console.log('Server count posted!');
|
||||
});
|
||||
dbl.on('error', error => {
|
||||
console.log('Error with DBL: ' + error);
|
||||
});
|
||||
dbl.postStats(client.guilds.size);
|
||||
}
|
||||
console.log(`- Activated - Shard: ${client.shard.ids} -`);
|
||||
setInterval(() => {
|
||||
client.funcs.checkDB(client);
|
||||
}, 60000);
|
||||
setInterval(async () => {
|
||||
client.funcs.saveDB(client);
|
||||
if (client.config.dblApi && !client.config.devMode) dbl.postStats(client.guilds.cache.size);
|
||||
}, 1800000);
|
||||
setInterval(() => {
|
||||
client.funcs.ffmpeg(client, Discord);
|
||||
}, 7200000);
|
||||
name: "ready",
|
||||
async execute(client, Discord) {
|
||||
const remoteMusixGuildsData = await client.funcs.dbget(
|
||||
"guilds",
|
||||
null,
|
||||
client
|
||||
);
|
||||
remoteMusixGuildsData.forEach((guildData) => {
|
||||
client.global.db.guilds[guildData.id] = guildData.d;
|
||||
});
|
||||
if (client.config.devMode) {
|
||||
client.guilds.cache.forEach((guild) => {
|
||||
client.global.db.guilds[guild.id] = {
|
||||
prefix: client.config.devPrefix,
|
||||
defaultVolume: client.config.defaultVolume,
|
||||
permissions: client.config.permissions,
|
||||
dj: client.config.dj,
|
||||
djrole: client.config.djrole,
|
||||
startPlaying: client.config.startPlaying,
|
||||
bass: client.config.bass,
|
||||
blacklist: [],
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
console.log(`- DB Set - Shard: ${client.shard.ids} -`);
|
||||
client.user.setActivity(`@${client.user.username} help | 🎶`, {
|
||||
type: "LISTENING",
|
||||
});
|
||||
client.user.setStatus("online");
|
||||
const dbl = new DBL(client.config.dblKey, client);
|
||||
if (client.config.dblApi && !client.config.devMode) {
|
||||
dbl.on("posted", () => {
|
||||
console.log("Server count posted!");
|
||||
});
|
||||
dbl.on("error", (error) => {
|
||||
console.log("Error with DBL: " + error);
|
||||
});
|
||||
dbl.postStats(client.guilds.size);
|
||||
}
|
||||
console.log(`- Activated - Shard: ${client.shard.ids} -`);
|
||||
setInterval(() => {
|
||||
if (!client.config.devMode) client.funcs.checkDB(client);
|
||||
}, 60000);
|
||||
setInterval(async () => {
|
||||
client.funcs.saveDB(client);
|
||||
if (client.config.dblApi && !client.config.devMode)
|
||||
dbl.postStats(client.guilds.cache.size);
|
||||
}, 1800000);
|
||||
setInterval(() => {
|
||||
client.funcs.ffmpeg(client, Discord);
|
||||
}, 7200000);
|
||||
},
|
||||
};
|
||||
|
@ -1,18 +1,19 @@
|
||||
module.exports = async function (client, reason, guild) {
|
||||
const queue = client.queue.get(guild.id);
|
||||
queue.playing = false;
|
||||
if (reason === "seek") {
|
||||
return queue.playing = true;
|
||||
const queue = client.queue.get(guild.id);
|
||||
queue.playing = false;
|
||||
if (reason === "seek") {
|
||||
return (queue.playing = true);
|
||||
}
|
||||
|
||||
if (!queue.songLooping) {
|
||||
if (queue.looping) {
|
||||
queue.songs.push(queue.songs[0]);
|
||||
}
|
||||
|
||||
if (!queue.songLooping) {
|
||||
if (queue.looping) {
|
||||
queue.songs.push(queue.songs[0]);
|
||||
}
|
||||
|
||||
queue.votes = 0;
|
||||
queue.voters = [];
|
||||
queue.songs.shift();
|
||||
}
|
||||
client.funcs.play(guild, queue.songs[0], client, 0, true);
|
||||
};
|
||||
queue.time = 0;
|
||||
queue.votes = 0;
|
||||
queue.voters = [];
|
||||
queue.songs.shift();
|
||||
}
|
||||
client.funcs.play(guild, queue.songs[0], client, 0, true);
|
||||
};
|
||||
|
@ -1,60 +1,66 @@
|
||||
const { Client, Collection } = require('discord.js');
|
||||
const admin = require('firebase-admin');
|
||||
const serviceAccount = require('./config/serviceAccount.json');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const events = require('../events/events.ts');
|
||||
const { Client, Collection } = require("discord.js");
|
||||
const admin = require("firebase-admin");
|
||||
const serviceAccount = require("./config/serviceAccount.json");
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const events = require("../events/events.ts");
|
||||
|
||||
module.exports = class extends Client {
|
||||
constructor() {
|
||||
super({
|
||||
disableEveryone: true,
|
||||
disabledEvents: ['TYPING_START']
|
||||
});
|
||||
constructor() {
|
||||
super({
|
||||
disableEveryone: true,
|
||||
disabledEvents: ["TYPING_START"],
|
||||
});
|
||||
|
||||
admin.initializeApp({
|
||||
credential: admin.credential.cert(serviceAccount),
|
||||
});
|
||||
this.commands = new Collection();
|
||||
this.commandAliases = new Collection();
|
||||
this.settingCmd = new Collection();
|
||||
this.queue = new Map();
|
||||
this.funcs = {};
|
||||
this.dispatcher = {};
|
||||
this.config = require('./config/config.ts');
|
||||
this.messages = require('./config/messages.ts');
|
||||
this.db = admin.firestore();
|
||||
this.db.FieldValue = require('firebase-admin').firestore.FieldValue;
|
||||
this.dispatcher.finish = require('../events/dispatcherEvents/finish.ts');
|
||||
this.dispatcher.error = require('../events/dispatcherEvents/error.ts');
|
||||
this.global = {
|
||||
db: {
|
||||
guilds: {},
|
||||
},
|
||||
};
|
||||
admin.initializeApp({
|
||||
credential: admin.credential.cert(serviceAccount),
|
||||
});
|
||||
this.commands = new Collection();
|
||||
this.commandAliases = new Collection();
|
||||
this.settingCmd = new Collection();
|
||||
this.queue = new Map();
|
||||
this.funcs = {};
|
||||
this.dispatcher = {};
|
||||
this.config = require("../../config/config.ts");
|
||||
this.messages = require("./config/messages.ts");
|
||||
this.db = admin.firestore();
|
||||
this.db.FieldValue = require("firebase-admin").firestore.FieldValue;
|
||||
this.dispatcher.finish = require("../events/dispatcherEvents/finish.ts");
|
||||
this.dispatcher.error = require("../events/dispatcherEvents/error.ts");
|
||||
this.global = {
|
||||
db: {
|
||||
guilds: {},
|
||||
},
|
||||
};
|
||||
|
||||
fs.readdirSync(path.join(__dirname, 'funcs')).forEach(filename => {
|
||||
this.funcs[filename.slice(0, -3)] = require(`./funcs/${filename}`);
|
||||
});
|
||||
fs.readdirSync(path.join(__dirname, "funcs")).forEach((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'));
|
||||
for (const file of commandFiles) {
|
||||
const command = require(`../commands/${file}`);
|
||||
command.uses = 0;
|
||||
this.commands.set(command.name, command);
|
||||
this.commandAliases.set(command.alias, command);
|
||||
}
|
||||
const settingFiles = fs.readdirSync(path.join(path.dirname(__dirname), 'commands/settings')).filter(f => f.endsWith('.ts'));
|
||||
for (const file of settingFiles) {
|
||||
const option = require(`../commands/settings/${file}`);
|
||||
this.settingCmd.set(option.name, option);
|
||||
}
|
||||
if (this.config.devMode) {
|
||||
this.config.token = this.config.devToken;
|
||||
}
|
||||
|
||||
events(this);
|
||||
|
||||
this.login(this.config.token).catch(err => console.log('Failed to login: ' + err));
|
||||
const commandFiles = fs
|
||||
.readdirSync(path.join(path.dirname(__dirname), "commands"))
|
||||
.filter((f) => f.endsWith(".ts"));
|
||||
for (const file of commandFiles) {
|
||||
const command = require(`../commands/${file}`);
|
||||
command.uses = 0;
|
||||
this.commands.set(command.name, command);
|
||||
this.commandAliases.set(command.alias, command);
|
||||
}
|
||||
const settingFiles = fs
|
||||
.readdirSync(path.join(path.dirname(__dirname), "commands/settings"))
|
||||
.filter((f) => f.endsWith(".ts"));
|
||||
for (const file of settingFiles) {
|
||||
const option = require(`../commands/settings/${file}`);
|
||||
this.settingCmd.set(option.name, option);
|
||||
}
|
||||
if (this.config.devMode) {
|
||||
this.config.token = this.config.devToken;
|
||||
}
|
||||
|
||||
events(this);
|
||||
|
||||
this.login(this.config.token).catch((err) =>
|
||||
console.log("Failed to login: " + err)
|
||||
);
|
||||
}
|
||||
};
|
||||
|
@ -9,15 +9,27 @@ module.exports = {
|
||||
announceSongsTrue:
|
||||
emojis.green_check_mark + "announcesongs now set to `true`!",
|
||||
bassApplied:
|
||||
emojis.volumeHigh +
|
||||
"The bass level **%BASS%** will be applied when the next song starts playing!",
|
||||
emojis.volumeHigh + "The bass level **%BASS%** has been applied!",
|
||||
bassFalse: emojis.green_check_mark + "Bass is now false!",
|
||||
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)",
|
||||
cancellingVideoSelection: emojis.redx + "Cancelling video selection",
|
||||
cantSkipToCurrent:
|
||||
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!",
|
||||
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.",
|
||||
cmdUsesTitle: "Musix Command Usage During Current Uptime",
|
||||
correctUsage: emojis.redx + "correct usage: ",
|
||||
@ -38,6 +50,8 @@ module.exports = {
|
||||
devMode:
|
||||
emojis.redx +
|
||||
"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: ",
|
||||
djFalse: emojis.green_check_mark + "`DJ` now set to `false`",
|
||||
djRoleCreated:
|
||||
@ -56,24 +70,34 @@ module.exports = {
|
||||
errorExeOpt:
|
||||
emojis.redx + "there was an error trying to execute that option!",
|
||||
evalTitle: "Evaluation Command",
|
||||
failedToLoad: emojis.redx + "Songs failed to load: ",
|
||||
helpCmdFooter: "Command Alias:",
|
||||
helpFooter:
|
||||
'"%PREFIX%help <command>" to see more information about a command.',
|
||||
helpTitle: "help",
|
||||
idOrMentionChannel:
|
||||
emojis.redx + "Please provide a channel id or mention a channel!",
|
||||
inviteTitle: "Invite Musix to your Discord server!",
|
||||
joined: emojis.green_check_mark + "Joined",
|
||||
joinSupport: "Join the musix support server: ",
|
||||
loadingSongs: emojis.loading + "Loading song(s)",
|
||||
looping: emojis.repeat + "Looping the queue 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`!",
|
||||
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:
|
||||
emojis.green_check_mark +
|
||||
"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!",
|
||||
noLooping: emojis.repeat + "No longer looping the queue!",
|
||||
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!`,
|
||||
noPermsConnect:
|
||||
emojis.redx +
|
||||
@ -95,8 +119,10 @@ module.exports = {
|
||||
"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!",
|
||||
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!",
|
||||
noSongs: emojis.redx + "That song does not exist!",
|
||||
notPremium: emojis.redx + "This is not a premium guild!",
|
||||
nowPlayingDesc: emojis.notes + "**Now playing:**",
|
||||
notAllowed: emojis.redx + "You are not allowed to do that!",
|
||||
notEnoughVotes: emojis.redx + "Not enough votes!",
|
||||
@ -105,6 +131,8 @@ module.exports = {
|
||||
emojis.redx +
|
||||
"I'm sorry but you need to be in a voice channel to play music!",
|
||||
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!",
|
||||
permission: "🔒 Permission requirement:",
|
||||
permissionsFalse: emojis.redx + "That value is already `false`!",
|
||||
@ -122,6 +150,7 @@ module.exports = {
|
||||
prefixHere: "My prefix here is: ",
|
||||
prefixMaxLength: "The prefix must be shorter or equal to 5 letters!",
|
||||
prefixSet: emojis.green_check_mark + "New prefix set to:",
|
||||
premiumUsage: emojis.redx + "`settings premium <guild id>`",
|
||||
provideANumber:
|
||||
"Please provide a number ranging from 1-10 to select one of the search results.",
|
||||
provideASong:
|
||||
@ -151,6 +180,9 @@ module.exports = {
|
||||
"Whether to announce songs that start playing or not.",
|
||||
settingsBass: "bass",
|
||||
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>",
|
||||
settingsPermissions: "permissions",
|
||||
settingsPermissionsDesc:
|
||||
|
@ -1,7 +1,7 @@
|
||||
module.exports = {
|
||||
ytdlOptions: { filter: "audio", highWaterMark: 1 << 20, volume: false },
|
||||
ytdlOptions: { filter: "audio", highWaterMark: 1 << 25, volume: false },
|
||||
options: {
|
||||
seek: 0,
|
||||
seek: null,
|
||||
bitrate: 1024,
|
||||
volume: 1,
|
||||
type: "converted",
|
||||
|
@ -1,27 +1,34 @@
|
||||
module.exports = function (client, msg, command) {
|
||||
const queue = client.queue.get(msg.guild.id);
|
||||
const permissions = msg.channel.permissionsFor(msg.author);
|
||||
if (!queue || !queue.playing) {
|
||||
msg.channel.send(client.messages.noServerQueue);
|
||||
return false;
|
||||
const queue = client.queue.get(msg.guild.id);
|
||||
const permissions = msg.channel.permissionsFor(msg.author);
|
||||
if (!queue || !queue.playing) {
|
||||
msg.channel.send(client.messages.noServerQueue);
|
||||
return false;
|
||||
}
|
||||
if (msg.author.id !== client.config.devId) {
|
||||
if (msg.member.voice.channel !== queue.voiceChannel) {
|
||||
msg.channel.send(client.messages.wrongVoiceChannel);
|
||||
return false;
|
||||
}
|
||||
if (msg.author.id !== client.config.devId) {
|
||||
if (msg.member.voice.channel !== queue.voiceChannel) {
|
||||
msg.channel.send(client.messages.wrongVoiceChannel);
|
||||
return false;
|
||||
}
|
||||
if (client.global.db.guilds[msg.guild.id].permissions === true) {
|
||||
if (client.global.db.guilds[msg.guild.id].dj) {
|
||||
if (!msg.member.roles.cache.has(client.global.db.guilds[msg.guild.id].djrole)) {
|
||||
msg.channel.send(client.messages.noDj);
|
||||
return false;
|
||||
} else return true;
|
||||
} else if (!permissions.has(command.permission)) {
|
||||
let message
|
||||
message = client.messages.noPerms.replace("%PERMS%", command.permissions);
|
||||
msg.channel.send(message);
|
||||
return false;
|
||||
} else return true;
|
||||
if (client.global.db.guilds[msg.guild.id].permissions === true) {
|
||||
if (client.global.db.guilds[msg.guild.id].dj) {
|
||||
if (
|
||||
!msg.member.roles.cache.has(
|
||||
client.global.db.guilds[msg.guild.id].djrole
|
||||
)
|
||||
) {
|
||||
msg.channel.send(client.messages.noDj);
|
||||
return false;
|
||||
} else return true;
|
||||
} else if (!permissions.has(command.permission)) {
|
||||
let message;
|
||||
message = client.messages.noPerms.replace(
|
||||
"%PERMS%",
|
||||
command.permissions
|
||||
);
|
||||
msg.channel.send(message);
|
||||
return false;
|
||||
} else return true;
|
||||
} else return true;
|
||||
} else return true;
|
||||
};
|
||||
|
@ -1,11 +1,22 @@
|
||||
module.exports = async function (client) {
|
||||
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].defaultVolume === undefined) client.global.db.guilds[guild.id].defaultVolume = client.config.defaultVolume;
|
||||
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].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;
|
||||
});
|
||||
};
|
||||
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].defaultVolume === undefined)
|
||||
client.global.db.guilds[guild.id].defaultVolume =
|
||||
client.config.defaultVolume;
|
||||
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].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
12
src/struct/funcs/end.ts
Normal 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);
|
||||
};
|
@ -1,19 +1,28 @@
|
||||
module.exports = function (msg, args, client, Discord, command) {
|
||||
const permissions = msg.channel.permissionsFor(msg.client.user);
|
||||
if (!permissions.has('EMBED_LINKS')) return msg.channel.send(client.messages.noPermsEmbed);
|
||||
if (!permissions.has('USE_EXTERNAL_EMOJIS')) return msg.channel.send(client.noPermsUseExternalEmojis);
|
||||
try {
|
||||
command.uses++;
|
||||
command.execute(msg, args, client, Discord, command);
|
||||
} catch (error) {
|
||||
const date = new Date();
|
||||
msg.reply(client.messages.errorExe);
|
||||
const embed = new Discord.MessageEmbed()
|
||||
.setTitle(`Musix ${error.toString()}`)
|
||||
.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}`)
|
||||
.setColor('#b50002');
|
||||
client.users.cache.get(client.devId).send(embed);
|
||||
console.error(error);
|
||||
}
|
||||
const permissions = msg.channel.permissionsFor(msg.client.user);
|
||||
if (!permissions.has("EMBED_LINKS"))
|
||||
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 {
|
||||
command.uses++;
|
||||
command.execute(msg, args, client, Discord, command);
|
||||
} catch (error) {
|
||||
const date = new Date();
|
||||
msg.reply(client.messages.errorExe);
|
||||
const embed = new Discord.MessageEmbed()
|
||||
.setTitle(`Musix ${error.toString()}`)
|
||||
.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}`
|
||||
)
|
||||
.setColor("#b50002");
|
||||
client.users.cache.get(client.config.devId).send(embed);
|
||||
console.error(error);
|
||||
}
|
||||
};
|
||||
|
@ -1,15 +1,17 @@
|
||||
module.exports = async function (
|
||||
video,
|
||||
resource,
|
||||
msg,
|
||||
voiceChannel,
|
||||
client,
|
||||
playlist = false
|
||||
playlist,
|
||||
type
|
||||
) {
|
||||
const Discord = require("discord.js");
|
||||
const song = {
|
||||
title: Discord.Util.escapeMarkdown(video.title),
|
||||
url: video.url,
|
||||
title: Discord.Util.escapeMarkdown(resource.title),
|
||||
url: resource.url,
|
||||
author: msg.author,
|
||||
type: type,
|
||||
};
|
||||
|
||||
const queue = client.queue.get(msg.guild.id);
|
||||
@ -24,12 +26,12 @@ module.exports = async function (
|
||||
}
|
||||
|
||||
const construct = {
|
||||
textChannel: null,
|
||||
voiceChannel: null,
|
||||
textChannel: msg.channel,
|
||||
voiceChannel: voiceChannel,
|
||||
connection: null,
|
||||
songs: [],
|
||||
volume: null,
|
||||
bass: null,
|
||||
volume: client.global.db.guilds[msg.guild.id].defaultVolume,
|
||||
bass: client.global.db.guilds[msg.guild.id].bass,
|
||||
nigthCore: false,
|
||||
playing: false,
|
||||
paused: false,
|
||||
@ -42,11 +44,6 @@ module.exports = async function (
|
||||
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);
|
||||
|
||||
client.queue.set(msg.guild.id, construct);
|
||||
|
@ -1,10 +1,9 @@
|
||||
module.exports = async function (guild, song, client, seek, play) {
|
||||
const { Readable: ReadableStream } = require("stream");
|
||||
const Discord = require("discord.js");
|
||||
const ytdl = require("ytdl-core");
|
||||
const streamConfig = require("../config/streamConfig.ts");
|
||||
const getThumb = require("video-thumbnail-url");
|
||||
const prism = require("prism-media");
|
||||
|
||||
const queue = client.queue.get(guild.id);
|
||||
if (!song) {
|
||||
queue.voiceChannel.leave();
|
||||
@ -14,6 +13,9 @@ module.exports = async function (guild, song, client, seek, play) {
|
||||
|
||||
streamConfig.options.seek = seek;
|
||||
|
||||
let input = song.url;
|
||||
if (song.type === "ytdl") input = ytdl(song.url, streamConfig.ytdlOptions);
|
||||
|
||||
const ffmpegArgs = [
|
||||
"-analyzeduration",
|
||||
"0",
|
||||
@ -28,38 +30,43 @@ module.exports = async function (guild, song, client, seek, play) {
|
||||
"-af",
|
||||
`bass=g=${queue.bass}`,
|
||||
];
|
||||
client.funcs.sleep(500);
|
||||
if (queue.nigthCore) {
|
||||
ffmpegArgs.push("-af");
|
||||
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
|
||||
.play(
|
||||
ytdl(song.url, streamConfig.ytdlOptions).pipe(transcoder),
|
||||
streamConfig.options
|
||||
)
|
||||
.play(stream, streamConfig.options)
|
||||
.on("finish", () => {
|
||||
client.dispatcher.finish(client, queue.endReason, guild);
|
||||
})
|
||||
.on("start", () => {
|
||||
queue.endReason = null;
|
||||
dispatcher.player.streamingData.pausedTime = 0;
|
||||
})
|
||||
.on("error", (error) => {
|
||||
client.dispatcher.error(client, error, guild);
|
||||
});
|
||||
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 songtime = (data.length_seconds * 1000).toFixed(0);
|
||||
const thumbnail = getThumb(queue.songs[0].url);
|
||||
const embed = new Discord.MessageEmbed()
|
||||
.setTitle(`${client.messages.startPlaying}**${song.title}**`)
|
||||
.setDescription(
|
||||
`Song duration: \`${client.funcs.msToTime(songtime, "hh:mm:ss")}\``
|
||||
)
|
||||
.setThumbnail(thumbnail._rejectionHandler0)
|
||||
.setColor(client.config.embedColor);
|
||||
queue.textChannel.send(embed);
|
||||
}
|
||||
|
@ -1,16 +1,18 @@
|
||||
module.exports = async function (client) {
|
||||
if (client.config.saveDB && !client.config.devMode) {
|
||||
//console.log('DB saved');
|
||||
client.guilds.cache.forEach(guild => {
|
||||
client.db.collection('guilds').doc(guild.id).set({
|
||||
prefix: client.global.db.guilds[guild.id].prefix,
|
||||
defaultVolume: client.global.db.guilds[guild.id].defaultVolume,
|
||||
permissions: client.global.db.guilds[guild.id].permissions,
|
||||
dj: client.global.db.guilds[guild.id].dj,
|
||||
djrole: client.global.db.guilds[guild.id].djrole,
|
||||
startPlaying: client.global.db.guilds[guild.id].startPlaying,
|
||||
bass: client.global.db.guilds[guild.id].bass,
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
if (client.config.saveDB && !client.config.devMode) {
|
||||
//console.log('DB saved');
|
||||
client.guilds.cache.forEach((guild) => {
|
||||
client.db.collection("guilds").doc(guild.id).set({
|
||||
prefix: client.global.db.guilds[guild.id].prefix,
|
||||
defaultVolume: client.global.db.guilds[guild.id].defaultVolume,
|
||||
permissions: client.global.db.guilds[guild.id].permissions,
|
||||
dj: client.global.db.guilds[guild.id].dj,
|
||||
djrole: client.global.db.guilds[guild.id].djrole,
|
||||
startPlaying: client.global.db.guilds[guild.id].startPlaying,
|
||||
bass: client.global.db.guilds[guild.id].bass,
|
||||
blacklist: client.global.db.guilds[guild.id].blacklist,
|
||||
premium: client.global.db.guilds[guild.id].premium,
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
3
src/struct/funcs/sleep.ts
Normal file
3
src/struct/funcs/sleep.ts
Normal file
@ -0,0 +1,3 @@
|
||||
module.exports = function (milliseconds) {
|
||||
return new Promise((resolve) => setTimeout(resolve, milliseconds));
|
||||
};
|
153
web/app.js
Normal file
153
web/app.js
Normal 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
145
web/public/index.html
Normal 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>
|
Loading…
Reference in New Issue
Block a user