From 7905cfdf5cfc0cbb80af35d37eb4f6d65c4723c0 Mon Sep 17 00:00:00 2001 From: Gavin Isgar Date: Tue, 24 Jul 2018 21:56:04 -0400 Subject: [PATCH] Improve Error Reporting and Change File Version Changed version number and improved the error system to report errors to the 'errors.ratz' file. --- main.js | 25 +++++++++++++++++++++++-- main.ts | 28 ++++++++++++++++++++++++---- package-lock.json | 2 +- package.json | 2 +- 4 files changed, 49 insertions(+), 8 deletions(-) diff --git a/main.js b/main.js index faa8965..3f2e606 100644 --- a/main.js +++ b/main.js @@ -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") { @@ -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); } }); } @@ -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); } }); } @@ -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); } }); } @@ -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); } }); } @@ -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); } }); } @@ -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); } } } @@ -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); } }); } @@ -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); } }); } @@ -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); } }); } @@ -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 { @@ -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) { @@ -488,6 +505,7 @@ var ERROR; ERROR["RATZx0000006"] = "RATZx0000006"; ERROR["RATZx0000007"] = "RATZx0000007"; ERROR["RATZx0000008"] = "RATZx0000008"; + ERROR["RATZx0000009"] = "RATZx0000009"; })(ERROR || (ERROR = {})); ; var TYPE; @@ -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"); +} diff --git a/main.ts b/main.ts index f77c6ea..69f53da 100644 --- a/main.ts +++ b/main.ts @@ -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") { @@ -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); } }) } @@ -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); } }) } @@ -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); } }) } @@ -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); } }) } @@ -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); } }) } @@ -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); } } } @@ -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); } }) } @@ -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); } }) } @@ -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); } }) } @@ -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 { @@ -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"); } }) @@ -487,7 +504,6 @@ rl.on("line", (input) => { } }) - bot.login(tokens.bottoken); // -----ERROR REPORTING----- enum ERROR { @@ -498,7 +514,8 @@ enum ERROR { RATZx0000005 = "RATZx0000005", RATZx0000006 = "RATZx0000006", RATZx0000007 = "RATZx0000007", - RATZx0000008 = "RATZx0000008" + RATZx0000008 = "RATZx0000008", + RATZx0000009 = "RATZx0000009" }; enum TYPE { FRONTEND = "FRONTEND", @@ -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`) } \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index e26acd8..9b5d4cd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "ratzbot", - "version": "2.7.0", + "version": "3.0.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index d2f1cd6..b228de2 100644 --- a/package.json +++ b/package.json @@ -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": {