1
0
mirror of https://github.com/musix-org/musix-oss synced 2024-12-22 21:13:18 +00:00

additional error logging and debugging.

This commit is contained in:
MatteZ02 2020-06-22 00:41:30 +03:00
parent 70316495f5
commit 2d7752d2cf
18 changed files with 126 additions and 87 deletions

View File

@ -7,7 +7,9 @@ if (config.devMode) {
config.shards = 1;
}
const { ShardingManager } = require("discord.js");
const {
ShardingManager
} = require("discord.js");
const manager = new ShardingManager("./src/bot.js", {
token: config.token,
respawn: config.respawn,
@ -28,3 +30,9 @@ console.log = function (arg) {
oldConsole.log(arg);
if (!config.devMode) webhookClient.send(arg);
};
oldConsole.error = console.error;
console.error = function (arg) {
oldConsole.error(arg);
if (!client.config.devMode) webhookClient.send(arg);
};

View File

@ -9,3 +9,9 @@ console.log = function (arg) {
oldConsole.log(arg);
if (!client.config.devMode) webhookClient.send(arg);
};
oldConsole.error = console.error;
console.error = function (arg) {
oldConsole.error(arg);
if (!client.config.devMode) webhookClient.send(arg);
};

View File

@ -17,7 +17,7 @@ module.exports = {
msg.channel.send(`${client.messages.joined} ${voiceChannel.name}!`);
} catch (error) {
client.queue.delete(msg.guild.id);
client.users.cache.get(client.config.devId).send(client.messages.errorConnecting + error);
console.log(error);
return msg.channel.send(client.messages.error);
}
}

View File

@ -68,15 +68,8 @@ module.exports = {
option.execute(msg, args, client);
} catch (error) {
msg.reply(client.messages.errorExeOpt);
const embed = new Discord.MessageEmbed()
.setTitle(`Musix ${error.toString()}`)
.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.users.cache.get(client.config.devId).send(embed);
console.log(error.toString());
console.log(error.stack.replace(/at /g, "**at **"));
}
} else {
return msg.channel.send(embed);

View File

@ -13,10 +13,12 @@ module.exports = {
const permissions = msg.channel.permissionsFor(msg.client.user);
if (!permissions.has('MANAGE_ROLES')) return msg.channel.send(client.messages.noPermsManageRoles);
msg.guild.createRole({
name: 'DJ',
})
name: 'DJ',
})
.then(role => client.global.db.guilds[msg.guild.id].djrole = role.id)
.catch(console.error)
.catch((error) => {
console.log(error);
})
client.global.db.guilds[msg.guild.id].dj = true;
msg.channel.send(client.messages.djRoleCreated);
}

View File

@ -0,0 +1,33 @@
module.exports = function (client) {
const Discord = require('discord.js');
client.on('ready', () => {
require(`./ready.js`).execute(client, Discord);
}).on('message', (msg) => {
require(`./msg.js`).execute(client, msg, Discord);
}).on('guildCreate', (guild) => {
require(`./guildCreate.js`).execute(client, guild);
}).on('voiceStateUpdate', (oldState, newState) => {
require(`./voiceStateUpdate.js`).execute(client, oldState, newState);
}).on('error', (error) => {
console.log(error);
}).on('debug', (info) => {
if (client.config.devMode) console.log(info);
}).on('invalidated', () => {
console.log("Client session invalidated! Exiting the process!")
process.exit(1);
}).on('rateLimit', (rateLimitInfo) => {
}).on('shardDisconnect', (event, id) => {
console.log(`Shard ${id} disconnected event ${event}`);
}).on('shardError', (error, shardId) => {
console.log(`Shard ${shardId} error ${error}`);
}).on('shardReady', (id, unavailableGuilds) => {
console.log(`Shard ${id} ready. Unavailable guilds: ${unavailableGuilds || 0}`);
}).on('shardReconnecting', (id) => {
console.log(`shard ${id} reconnecting.`);
}).on('shardResume', (id, replayedEvents) => {
console.log(`shard ${id} resume events ${replayedEvents}`);
}).on("warn", (info) => {
console.log(`Warn! info: ${info}`);
});
}

View File

@ -0,0 +1,21 @@
module.exports = function (client, connection) {
connection.on("authenticated", () => {
if (client.config.devMode) console.log("Voice connection initiated.");
}).on("debug", (message) => {
if (client.config.devMode) console.log(message);
}).on("disconnect", () => {
if (client.config.devMode) console.log("Voice connection disconnected.");
}).on("error", (error) => {
console.log(error);
}).on("failed", (error) => {
if (client.config.devMode) console.log(error);
}).on("newSession", () => {
if (client.config.devMode) console.log("New voice session id received!");
}).on("ready", () => {
if (client.config.devMode) console.log("Voice connection ready.");
}).on("reconnecting", () => {
if (client.config.devMode) console.log("Voice connection reconnecting.");
}).on("warn", (warning) => {
console.log(`Voice connection warning: ${warning}`);
})
}

View File

@ -1,12 +1,11 @@
module.exports = async function (client, error, guild) {
const queue = client.queue.get(guild.id);
console.error(error);
console.log(error);
/*if (error = "Error: input stream: This video contains content from WMG, who has blocked it on copyright grounds.") {
queue.endReason = "skip";
queue.connection.dispatcher.end();
return queue.textChannel.send(client.messages.songBlockedWMG);
}*/
client.users.cache.get(client.config.devId).send(client.messages.dispatcherError + error);
queue.voiceChannel.leave();
client.queue.delete(guild.id);
return queue.textChannel.send(client.messages.errorDispatcher + `\`${error}\``);

View File

@ -1,22 +1,24 @@
module.exports = async function (client, reason, guild) {
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]);
module.exports = {
async execute(client, guild) {
const queue = client.queue.get(guild.id);
queue.playing = false;
if (queue.endReason === "seek") {
return (queue.playing = true);
}
queue.time = 0;
queue.votes = 0;
queue.voters = [];
if (reason !== "replay") {
if (reason === "previous") queue.songs.unshift(queue.prevSongs.pop())
if (reason !== "previous") queue.prevSongs.push(queue.songs.shift());
if (!queue.songLooping) {
if (queue.looping) {
queue.songs.push(queue.songs[0]);
}
queue.time = 0;
queue.votes = 0;
queue.voters = [];
if (queue.endReason !== "replay") {
if (queue.endReason === "previous") queue.songs.unshift(queue.prevSongs.pop())
if (queue.endReason !== "previous") queue.prevSongs.push(queue.songs.shift());
}
}
}
client.funcs.play(guild, queue.songs[0], client, 0, true);
client.funcs.play(guild, queue.songs[0], client, 0, true);
},
};

View File

@ -0,0 +1,16 @@
module.exports = function (client, dispatcher, queue, guild) {
dispatcher.on("finish", () => {
if (client.config.devMode) console.log("Dispatcher finish.");
require("./finish").execute(client, guild);
})
.on("start", () => {
if (client.config.devMode) console.log("Dispatcher start.");
queue.endReason = null;
dispatcher.player.streamingData.pausedTime = 0;
})
.on("error", (error) => {
require("./error").execute(client, error, guild);
}).on("debug", (info) => {
if (client.config.devMode) console.log(info);
})
}

View File

@ -1,19 +0,0 @@
module.exports = function (client) {
const Discord = require('discord.js');
const events = './clientEvents/';
client.on('ready', () => {
require(`${events}ready.js`).execute(client, Discord);
});
client.on('message', (msg) => {
require(`${events}msg.js`).execute(client, msg, Discord);
});
client.on('guildCreate', (guild) => {
require(`${events}guildCreate.js`).execute(client, guild);
});
client.on('voiceStateUpdate', (oldState, newState) => {
require(`${events}voiceStateUpdate.js`).execute(client, oldState, newState);
});
client.on('error', (error) => {
client.channels.fetch(client.config.debug_channel).send(`Error: ${error} on shard: ${client.shard}`);
});
}

View File

@ -7,7 +7,6 @@ const admin = require("firebase-admin");
const serviceAccount = require("./config/serviceAccount.json");
const fs = require("fs");
const path = require("path");
const events = require("../events/events.js");
const myIntents = new Intents();
myIntents.add(
@ -39,8 +38,6 @@ module.exports = class extends Client {
this.messages = require("./config/messages.js");
this.db = admin.firestore();
this.db.FieldValue = require("firebase-admin").firestore.FieldValue;
this.dispatcher.finish = require("../events/dispatcherEvents/finish.js");
this.dispatcher.error = require("../events/dispatcherEvents/error.js");
this.global = {
db: {
guilds: {},
@ -71,7 +68,7 @@ module.exports = class extends Client {
this.config.token = this.config.devToken;
}
events(this);
require("../events/clientEvents/handler.js")(this);
this.login(this.config.token).catch((err) =>
console.log("Failed to login: " + err)

View File

@ -24,7 +24,7 @@ module.exports = {
embedColor: "#b50002",
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,
@ -98,4 +98,4 @@ module.exports.emojis = {
stop: "<:stop:674685626108477519> ",
stopWatch: ":stopwatch: ",
volumeHigh: "<:volumehigh:674685637626167307> ",
}
}

View File

@ -13,16 +13,8 @@ module.exports = function (msg, args, client, Discord, command) {
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);
console.log(error.toString());
console.log(error.stack.replace(/at /g, "**at **"));
}
};

View File

@ -4,6 +4,6 @@ module.exports = async function (client) {
await client.channels.fetch(client.config.secondary_test_channel)
.then(x => x.join());
} catch (error) {
client.users.cache.get(client.config.devId).send(client.messages.errorDetected + error);
console.log(error);
}
};

View File

@ -57,12 +57,11 @@ module.exports = async function (
try {
const connection = await voiceChannel.join();
construct.connection = connection;
require("../../events/connectionEvents/handler")(client, connection);
client.funcs.play(msg.guild, construct.songs[0], client, 0, true);
} catch (error) {
client.queue.delete(msg.guild.id);
client.users.cache
.get(client.config.devId)
.send(client.messages.errorConnecting + error);
console.log(error);
return msg.channel.send(client.messages.error + error);
}
return;

View File

@ -30,7 +30,7 @@ module.exports = async function (guild, song, client, seek, play) {
if (song.type === "ytdl")
input = ytdl(song.url, streamConfig.ytdlOptions)
//.on('info', (info, format) => console.log(format))
.on("error", (err) => console.log(err));
.on("error", (error) => console.log(error));
const ffmpegArgs = [
"-analyzeduration",
@ -65,19 +65,9 @@ module.exports = async function (guild, song, client, seek, play) {
console.log(error);
});
const dispatcher = queue.connection
.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);
});
const dispatcher = queue.connection.play(stream, streamConfig.options)
dispatcher.setVolume(queue.volume / 100);
require("../../events/dispatcherEvents/handler")(client, dispatcher, queue, guild);
if ((client.global.db.guilds[guild.id].startPlaying && play) || play) {
if (song.type !== "ytdl") return;
const embed = new Discord.MessageEmbed()

View File

@ -2,7 +2,7 @@ module.exports = function (a) {
for (let i = a.length - 1; i > 1; i--) {
const j = Math.floor(Math.random() * (i + 1));
if (i === 0 || j === 0) {
console.log(`J or I is 0. I: ${i} J: ${j}`);
// J or I is 0. It works like this so hands off!
} else {
[a[i], a[j]] = [a[j], a[i]];
}