Skip to content

Commit

Permalink
Improve Error Reporting and Change File Version
Browse files Browse the repository at this point in the history
Changed version number and improved the error system to report errors to the 'errors.ratz' file.
  • Loading branch information
Gisgar3 committed Jul 25, 2018
1 parent 1e7c549 commit 7905cfd
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 8 deletions.
25 changes: 23 additions & 2 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ bot.on('message', function (message) {
}
catch (err) {
message.channel.send(sendError(TYPE.BACKEND, ERROR.RATZx0000008));
appendError(TYPE.BACKEND, ERROR.RATZx0000008, message.author.id);
}
}
if (message.content.toString() == "/ratz slimedog") {
Expand Down Expand Up @@ -122,10 +123,12 @@ bot.on('message', function (message) {
}
else {
message.channel.send(sendError(TYPE.BACKEND, ERROR.RATZx0000007));
appendError(TYPE.BACKEND, ERROR.RATZx0000007, message.author.id);
}
}
catch (err) {
message.channel.send(sendError(TYPE.BACKEND, ERROR.RATZx0000007));
appendError(TYPE.BACKEND, ERROR.RATZx0000007, message.author.id);
}
});
}
Expand Down Expand Up @@ -168,10 +171,12 @@ bot.on('message', function (message) {
}
else {
message.channel.send(sendError(TYPE.BACKEND, ERROR.RATZx0000006));
appendError(TYPE.BACKEND, ERROR.RATZx0000006, message.author.id);
}
}
catch (err) {
message.channel.send(sendError(TYPE.BACKEND, ERROR.RATZx0000006));
appendError(TYPE.BACKEND, ERROR.RATZx0000006, message.author.id);
}
});
}
Expand Down Expand Up @@ -204,10 +209,12 @@ bot.on('message', function (message) {
}
else {
message.channel.send(sendError(TYPE.BACKEND, ERROR.RATZx0000006));
appendError(TYPE.BACKEND, ERROR.RATZx0000006, message.author.id);
}
}
catch (err) {
message.channel.send(sendError(TYPE.BACKEND, ERROR.RATZx0000006));
appendError(TYPE.BACKEND, ERROR.RATZx0000006, message.author.id);
}
});
}
Expand Down Expand Up @@ -238,10 +245,12 @@ bot.on('message', function (message) {
}
else {
message.channel.send(sendError(TYPE.BACKEND, ERROR.RATZx0000006));
appendError(TYPE.BACKEND, ERROR.RATZx0000006, message.author.id);
}
}
catch (err) {
message.channel.send(sendError(TYPE.BACKEND, ERROR.RATZx0000006));
appendError(TYPE.BACKEND, ERROR.RATZx0000006, message.author.id);
}
});
}
Expand All @@ -267,10 +276,12 @@ bot.on('message', function (message) {
}
else {
message.channel.send(sendError(TYPE.BACKEND, ERROR.RATZx0000005));
appendError(TYPE.BACKEND, ERROR.RATZx0000005, message.author.id);
}
}
catch (err) {
message.channel.send(sendError(TYPE.BACKEND, ERROR.RATZx0000005));
appendError(TYPE.BACKEND, ERROR.RATZx0000005, message.author.id);
}
});
}
Expand All @@ -286,6 +297,7 @@ bot.on('message', function (message) {
}
catch (err) {
message.channel.send(sendError(TYPE.BACKEND, ERROR.RATZx0000004));
appendError(TYPE.BACKEND, ERROR.RATZx0000004, message.author.id);
}
}
}
Expand All @@ -312,10 +324,12 @@ bot.on('message', function (message) {
}
else {
message.channel.send(sendError(TYPE.BACKEND, ERROR.RATZx0000003));
appendError(TYPE.BACKEND, ERROR.RATZx0000003, message.author.id);
}
}
catch (err) {
message.channel.send(sendError(TYPE.BACKEND, ERROR.RATZx0000003));
appendError(TYPE.BACKEND, ERROR.RATZx0000003, message.author.id);
}
});
}
Expand Down Expand Up @@ -345,10 +359,12 @@ bot.on('message', function (message) {
}
else {
message.channel.send(sendError(TYPE.BACKEND, ERROR.RATZx0000002));
appendError(TYPE.BACKEND, ERROR.RATZx0000002, message.author.id);
}
}
catch (err) {
message.channel.send(sendError(TYPE.BACKEND, ERROR.RATZx0000002));
appendError(TYPE.BACKEND, ERROR.RATZx0000002, message.author.id);
}
});
}
Expand All @@ -368,6 +384,7 @@ bot.on('message', function (message) {
}
catch (err) {
message.channel.send(sendError(TYPE.BACKEND, ERROR.RATZx0000001));
appendError(TYPE.BACKEND, ERROR.RATZx0000001, message.author.id);
}
});
}
Expand All @@ -383,6 +400,7 @@ bot.on('message', function (message) {
}
catch (err) {
message.channel.send(sendError(TYPE.BACKEND, ERROR.RATZx0000001));
appendError(TYPE.BACKEND, ERROR.RATZx0000001, message.author.id);
}
}
else {
Expand All @@ -409,8 +427,7 @@ bot.on('message', function (message) {
}
}
catch (err) {
var date = new Date();
fs.appendFileSync("./exclude/errors.ratz", "\r\nERROR at " + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds() + " " + date.getMonth() + "/" + date.getDate() + "/" + date.getFullYear() + ": " + err);
appendError(TYPE.BACKEND, ERROR.RATZx0000009, "SYSTEM");
}
});
bot.on("guildMemberAdd", function (member) {
Expand Down Expand Up @@ -488,6 +505,7 @@ var ERROR;
ERROR["RATZx0000006"] = "RATZx0000006";
ERROR["RATZx0000007"] = "RATZx0000007";
ERROR["RATZx0000008"] = "RATZx0000008";
ERROR["RATZx0000009"] = "RATZx0000009";
})(ERROR || (ERROR = {}));
;
var TYPE;
Expand All @@ -501,3 +519,6 @@ function sendError(TYPE, ERROR) {
this.error = ERROR;
return "An error occured during the process: **| " + TYPE + " | " + ERROR + " |**";
}
function appendError(TYPE, ERROR, USER) {
fs.appendFileSync("./exclude/errors.ratz", "ERROR CODE: " + ERROR + "\r\nERROR TYPE: " + TYPE + "\r\nUSER: " + USER + "\r\nRECEIVED: " + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds() + " " + (date.getMonth() + 1) + "/" + date.getDate() + "/" + date.getFullYear() + "\r\n\r\n");
}
28 changes: 24 additions & 4 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ bot.on('message', (message) => {
}
catch (err) {
message.channel.send(sendError(TYPE.BACKEND, ERROR.RATZx0000008));
appendError(TYPE.BACKEND, ERROR.RATZx0000008, message.author.id);
}
}
if (message.content.toString() == "/ratz slimedog") {
Expand Down Expand Up @@ -126,10 +127,12 @@ bot.on('message', (message) => {
}
else {
message.channel.send(sendError(TYPE.BACKEND, ERROR.RATZx0000007));
appendError(TYPE.BACKEND, ERROR.RATZx0000007, message.author.id);
}
}
catch (err) {
message.channel.send(sendError(TYPE.BACKEND, ERROR.RATZx0000007));
appendError(TYPE.BACKEND, ERROR.RATZx0000007, message.author.id);
}
})
}
Expand Down Expand Up @@ -172,10 +175,12 @@ bot.on('message', (message) => {
}
else {
message.channel.send(sendError(TYPE.BACKEND, ERROR.RATZx0000006));
appendError(TYPE.BACKEND, ERROR.RATZx0000006, message.author.id);
}
}
catch (err) {
message.channel.send(sendError(TYPE.BACKEND, ERROR.RATZx0000006));
appendError(TYPE.BACKEND, ERROR.RATZx0000006, message.author.id);
}
})
}
Expand Down Expand Up @@ -208,10 +213,12 @@ bot.on('message', (message) => {
}
else {
message.channel.send(sendError(TYPE.BACKEND, ERROR.RATZx0000006));
appendError(TYPE.BACKEND, ERROR.RATZx0000006, message.author.id);
}
}
catch (err) {
message.channel.send(sendError(TYPE.BACKEND, ERROR.RATZx0000006));
appendError(TYPE.BACKEND, ERROR.RATZx0000006, message.author.id);
}
})
}
Expand Down Expand Up @@ -242,10 +249,12 @@ bot.on('message', (message) => {
}
else {
message.channel.send(sendError(TYPE.BACKEND, ERROR.RATZx0000006));
appendError(TYPE.BACKEND, ERROR.RATZx0000006, message.author.id);
}
}
catch (err) {
message.channel.send(sendError(TYPE.BACKEND, ERROR.RATZx0000006));
appendError(TYPE.BACKEND, ERROR.RATZx0000006, message.author.id);
}
})
}
Expand All @@ -271,10 +280,12 @@ bot.on('message', (message) => {
}
else {
message.channel.send(sendError(TYPE.BACKEND, ERROR.RATZx0000005));
appendError(TYPE.BACKEND, ERROR.RATZx0000005, message.author.id);
}
}
catch (err) {
message.channel.send(sendError(TYPE.BACKEND, ERROR.RATZx0000005));
appendError(TYPE.BACKEND, ERROR.RATZx0000005, message.author.id);
}
})
}
Expand All @@ -290,6 +301,7 @@ bot.on('message', (message) => {
}
catch (err) {
message.channel.send(sendError(TYPE.BACKEND, ERROR.RATZx0000004));
appendError(TYPE.BACKEND, ERROR.RATZx0000004, message.author.id);
}
}
}
Expand All @@ -316,10 +328,12 @@ bot.on('message', (message) => {
}
else {
message.channel.send(sendError(TYPE.BACKEND, ERROR.RATZx0000003));
appendError(TYPE.BACKEND, ERROR.RATZx0000003, message.author.id);
}
}
catch (err) {
message.channel.send(sendError(TYPE.BACKEND, ERROR.RATZx0000003));
appendError(TYPE.BACKEND, ERROR.RATZx0000003, message.author.id);
}
})
}
Expand Down Expand Up @@ -349,10 +363,12 @@ bot.on('message', (message) => {
}
else {
message.channel.send(sendError(TYPE.BACKEND, ERROR.RATZx0000002));
appendError(TYPE.BACKEND, ERROR.RATZx0000002, message.author.id);
}
}
catch (err) {
message.channel.send(sendError(TYPE.BACKEND, ERROR.RATZx0000002));
appendError(TYPE.BACKEND, ERROR.RATZx0000002, message.author.id);
}
})
}
Expand All @@ -372,6 +388,7 @@ bot.on('message', (message) => {
}
catch (err) {
message.channel.send(sendError(TYPE.BACKEND, ERROR.RATZx0000001));
appendError(TYPE.BACKEND, ERROR.RATZx0000001, message.author.id);
}
})
}
Expand All @@ -387,6 +404,7 @@ bot.on('message', (message) => {
}
catch (err) {
message.channel.send(sendError(TYPE.BACKEND, ERROR.RATZx0000001));
appendError(TYPE.BACKEND, ERROR.RATZx0000001, message.author.id);
}
}
else {
Expand All @@ -413,8 +431,7 @@ bot.on('message', (message) => {
}
}
catch (err) {
var date = new Date();
fs.appendFileSync("./exclude/errors.ratz", `\r\nERROR at ${date.getHours()}:${date.getMinutes()}:${date.getSeconds()} ${date.getMonth()}/${date.getDate()}/${date.getFullYear()}: ${err}`);
appendError(TYPE.BACKEND, ERROR.RATZx0000009, "SYSTEM");
}
})

Expand Down Expand Up @@ -487,7 +504,6 @@ rl.on("line", (input) => {
}
})


bot.login(tokens.bottoken);
// -----ERROR REPORTING-----
enum ERROR {
Expand All @@ -498,7 +514,8 @@ enum ERROR {
RATZx0000005 = "RATZx0000005",
RATZx0000006 = "RATZx0000006",
RATZx0000007 = "RATZx0000007",
RATZx0000008 = "RATZx0000008"
RATZx0000008 = "RATZx0000008",
RATZx0000009 = "RATZx0000009"
};
enum TYPE {
FRONTEND = "FRONTEND",
Expand All @@ -508,4 +525,7 @@ function sendError(TYPE: TYPE, ERROR: ERROR) {
this.type = TYPE;
this.error = ERROR;
return `An error occured during the process: **| ${TYPE} | ${ERROR} |**`
}
function appendError(TYPE: TYPE, ERROR: ERROR, USER: String) {
fs.appendFileSync("./exclude/errors.ratz", `ERROR CODE: ${ERROR}\r\nERROR TYPE: ${TYPE}\r\nUSER: ${USER}\r\nRECEIVED: ${date.getHours()}:${date.getMinutes()}:${date.getSeconds()} ${date.getMonth() + 1}/${date.getDate()}/${date.getFullYear()}\r\n\r\n`)
}
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ratzbot",
"version": "2.7.0",
"version": "3.0.0",
"description": "Discord bot for Twitch streamer ratzDoll",
"main": "main.js",
"scripts": {
Expand Down

0 comments on commit 7905cfd

Please sign in to comment.