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

New config system and error logging

This commit is contained in:
MatteZ02 2020-06-16 21:51:11 +03:00
parent 3a1ad33dd6
commit 4b3b798ddc
9 changed files with 101 additions and 71 deletions

View File

@ -1,4 +1,5 @@
const config = require("./src/struct/config/config.js"); const config = require("./src/struct/config/config.js");
const DiscordWebhook = require("discord-webhook-node");
if (config.devMode) { if (config.devMode) {
console.log("- dev mode- "); console.log("- dev mode- ");
@ -6,9 +7,7 @@ if (config.devMode) {
config.shards = 1; config.shards = 1;
} }
const { const { ShardingManager } = require("discord.js");
ShardingManager
} = require("discord.js");
const manager = new ShardingManager("./src/bot.js", { const manager = new ShardingManager("./src/bot.js", {
token: config.token, token: config.token,
respawn: config.respawn, respawn: config.respawn,
@ -20,3 +19,12 @@ manager.spawn(config.shards, config.shardDelay, config.shardTimeout);
manager.on("shardCreate", (shard) => manager.on("shardCreate", (shard) =>
console.log(`- Launched shard ${shard.id} -`) console.log(`- Launched shard ${shard.id} -`)
); );
const webhookClient = new DiscordWebhook.Webhook(config.webhookUrl);
const oldConsole = {};
oldConsole.log = console.log;
console.log = function (arg) {
oldConsole.log(arg);
webhookClient.send(arg);
};

View File

@ -23,6 +23,7 @@
"cookie-parser": "^1.4.5", "cookie-parser": "^1.4.5",
"cors": "^2.8.5", "cors": "^2.8.5",
"dblapi.js": "^2.4.0", "dblapi.js": "^2.4.0",
"discord-webhook-node": "^1.0.7",
"discord.js": "^12.2.0", "discord.js": "^12.2.0",
"dotenv": "^8.2.0", "dotenv": "^8.2.0",
"erlpack": "github:discordapp/erlpack", "erlpack": "github:discordapp/erlpack",

View File

@ -1,2 +1,11 @@
const MusicClient = require('./struct/client.js'); const MusicClient = require("./struct/client.js");
const DiscordWebhook = require("discord-webhook-node");
const client = new MusicClient({}); const client = new MusicClient({});
const webhookClient = new DiscordWebhook.Webhook(client.config.webhookUrl);
const oldConsole = {};
oldConsole.log = console.log;
console.log = function (arg) {
oldConsole.log(arg);
webhookClient.send(arg);
};

View File

@ -14,6 +14,7 @@ module.exports = {
spotify_refresh_token: process.env.SPOTIFY_REFRESH_TOKEN, spotify_refresh_token: process.env.SPOTIFY_REFRESH_TOKEN,
lastfm_api_key: process.env.LASTFM_API_KEY, lastfm_api_key: process.env.LASTFM_API_KEY,
lastfm_secret: process.env.LASTFM_SECRET, lastfm_secret: process.env.LASTFM_SECRET,
webhookUrl: process.env.WEBHOOK_URL,
port: 8888, port: 8888,
redirectUri: "http://localhost:8888/callback/", redirectUri: "http://localhost:8888/callback/",
testServer: "489111553321336832", testServer: "489111553321336832",
@ -23,7 +24,7 @@ module.exports = {
embedColor: "#b50002", embedColor: "#b50002",
invite: "https://discordapp.com/oauth2/authorize?client_id=607266889537945605&permissions=3427328&scope=bot", invite: "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,
@ -40,3 +41,61 @@ module.exports = {
startPlaying: true, startPlaying: true,
bass: 1, bass: 1,
}; };
module.exports.streamConfig = {
ytdlOptions: {
filter: "audio",
highWaterMark: 1 << 25,
volume: false,
requestOptions: {
maxRedirects: 4
}
},
options: {
seek: null,
bitrate: 1024,
volume: 1,
type: "converted",
},
}
module.exports.queueConfig = {
textChannel: null,
voiceChannel: null,
connection: null,
songs: [],
volume: null,
bass: null,
nigthCore: false,
playing: false,
paused: false,
looping: false,
songLooping: false,
votes: 0,
voters: [],
votesNeeded: null,
time: 0,
endReason: null,
}
module.exports.emojis = {
garbage: "🗑️ ",
green_check_mark: "<:green_check_mark:674265384777416705> ",
loading: "<a:loading:674284196700618783> ",
loudSound: ":loud_sound: ",
megaPhone: "📣 ",
notes: "<a:aNotes:674602408105476106>",
pause: "<:pause:674685548610322462> ",
previous: "<:reverse:705012312142119012> ",
redx: "<:redx:674263474704220182> ",
repeat: "<:repeat1:674685561377914892> ",
repeatSong: "<:repeatsong:674685573419761716> ",
resume: "<:resume:674685585478254603> ",
shuffle: "<:shuffle:674685595980791871> ",
signal: ":signal_strength: ",
skip: "<:skip:674685614221688832> ",
speaker: ":speaker: ",
stop: "<:stop:674685626108477519> ",
stopWatch: ":stopwatch: ",
volumeHigh: "<:volumehigh:674685637626167307> ",
}

View File

@ -1,21 +0,0 @@
module.exports = {
garbage: "🗑️ ",
green_check_mark: "<:green_check_mark:674265384777416705> ",
loading: "<a:loading:674284196700618783> ",
loudSound: ":loud_sound: ",
megaPhone: "📣 ",
notes: "<a:aNotes:674602408105476106>",
pause: "<:pause:674685548610322462> ",
previous: "<:reverse:705012312142119012> ",
redx: "<:redx:674263474704220182> ",
repeat: "<:repeat1:674685561377914892> ",
repeatSong: "<:repeatsong:674685573419761716> ",
resume: "<:resume:674685585478254603> ",
shuffle: "<:shuffle:674685595980791871> ",
signal: ":signal_strength: ",
skip: "<:skip:674685614221688832> ",
speaker: ":speaker: ",
stop: "<:stop:674685626108477519> ",
stopWatch: ":stopwatch: ",
volumeHigh: "<:volumehigh:674685637626167307> ",
};

View File

@ -1,4 +1,6 @@
const emojis = require("./emojis.js"); const {
emojis
} = require("./config.js");
module.exports = { module.exports = {
emojis: emojis, emojis: emojis,

View File

@ -1,18 +0,0 @@
module.exports = {
textChannel: null,
voiceChannel: null,
connection: null,
songs: [],
volume: null,
bass: null,
nigthCore: false,
playing: false,
paused: false,
looping: false,
songLooping: false,
votes: 0,
voters: [],
votesNeeded: null,
time: 0,
endReason: null,
};

View File

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

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 { console.log("test");
Readable: ReadableStream const { Readable: ReadableStream } = require("stream");
} = 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.js"); const { streamConfig } = require("../config/config.js");
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) {
@ -25,9 +24,10 @@ module.exports = async function (guild, song, client, seek, play) {
streamConfig.options.seek = seek; streamConfig.options.seek = seek;
let input = song.url; let input = song.url;
if (song.type === "ytdl") input = ytdl(song.url, streamConfig.ytdlOptions) if (song.type === "ytdl")
//.on('info', (info, format) => console.log(format)) input = ytdl(song.url, streamConfig.ytdlOptions)
.on('error', err => console.log(err)); //.on('info', (info, format) => console.log(format))
.on("error", (err) => console.log(err));
const ffmpegArgs = [ const ffmpegArgs = [
"-analyzeduration", "-analyzeduration",
@ -80,7 +80,10 @@ module.exports = async function (guild, song, client, seek, play) {
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(queue.songs[0].info.lengthSeconds * 1000, "hh:mm:ss")}\`` `Song duration: \`${client.funcs.msToTime(
queue.songs[0].info.lengthSeconds * 1000,
"hh:mm:ss"
)}\``
) )
.setColor(client.config.embedColor); .setColor(client.config.embedColor);
queue.textChannel.send(embed); queue.textChannel.send(embed);