From 1e7c549e7d00069369554d42ffc2b176e29e7520 Mon Sep 17 00:00:00 2001 From: Gavin Isgar Date: Sun, 22 Jul 2018 22:30:42 -0400 Subject: [PATCH 1/2] Add improved error reporting system Added a better error reporting system. --- main.js | 361 ++++++++++++++++++++------------------- main.ts | 511 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 699 insertions(+), 173 deletions(-) create mode 100644 main.ts diff --git a/main.js b/main.js index 4e6aa4a..faa8965 100644 --- a/main.js +++ b/main.js @@ -1,12 +1,11 @@ // COPYRIGHT (C) GAVIN ISGAR 2017-2018 - -const Discord = require("discord.js"); -const DiscordRPC = require("discord-rpc"); -const opus = require("opusscript"); -const ffmpeg = require("ffmpeg-binaries"); -const ytdl = require("ytdl-core"); -const bot = new Discord.Client(); -const msg = new Discord.Message(); +var Discord = require("discord.js"); +var DiscordRPC = require("discord-rpc"); +var opus = require("opusscript"); +var ffmpeg = require("ffmpeg-binaries"); +var ytdl = require("ytdl-core"); +var bot = new Discord.Client(); +var msg = new Discord.Message(); var net = require('net'); var http = require("http"); var url = require("url"); @@ -15,26 +14,23 @@ var request = require("request"); var commands = require("./commands.json"); var tokens = require("./exclude/tokens.json"); var fs = require("fs"); -const readline = require("readline"); -const package = require("./package.json"); -const { app, BrowserWindow } = require('electron'); +var readline = require("readline"); +var package = require("./package.json"); +var _a = require('electron'), app = _a.app, BrowserWindow = _a.BrowserWindow; var date = new Date(); - //-----SERVER EVENTS----- var activeevent = ""; // --------- - // -----CHANNELS----- var logChannel = "423939166401855518"; var newcomerChannel = "423937750937501697"; var mainChannel = "443227379712917505"; // ---------- - -bot.on('message', (message) => { +bot.on('message', function (message) { try { if (fs.readFileSync("./exclude/bannedusers.ratz").includes(message.author.id.toString()) == true) { - message.channel.send(`${message.author}, you are banned from communicating in the server.`); - message.delete(); + message.channel.send(message.author + ", you are banned from communicating in the server."); + message["delete"](); } else { if (fs.readFileSync("./exclude/users.ratz").includes(message.author.id.toString()) == false) { @@ -43,14 +39,14 @@ bot.on('message', (message) => { } else { if (message.content.toString() == "/ratz slimedog") { - fs.appendFileSync("./exclude/users.ratz", `\r\n${message.author.id.toString()}`); - message.delete(); - message.channel.send(`${message.author}, you now have access to type in the server!`); + fs.appendFileSync("./exclude/users.ratz", "\r\n" + message.author.id.toString()); + message["delete"](); + message.channel.send(message.author + ", you now have access to type in the server!"); } else { - fs.appendFileSync("./exclude/removedauthmessages.ratz", `\r\n(${message.author.username} [${message.author.id}], ${message.createdTimestamp}) ${message.content.toString()}`); - message.delete(); - message.channel.send(`${message.author}, you have not completely read the rules in order to have access to chat. To get access, re-read the rules and type the secret response message specified.`) + fs.appendFileSync("./exclude/removedauthmessages.ratz", "\r\n(" + message.author.username + " [" + message.author.id + "], " + message.createdTimestamp + ") " + message.content.toString()); + message["delete"](); + message.channel.send(message.author + ", you have not completely read the rules in order to have access to chat. To get access, re-read the rules and type the secret response message specified."); } } } @@ -61,35 +57,35 @@ bot.on('message', (message) => { try { var user = bot.users.find("id", result); var embed = new Discord.RichEmbed() - .setTitle(`Discord User Information for ${user.username}`) + .setTitle("Discord User Information for " + user.username) .setColor(0xcb00ff) .setThumbnail(user.avatarURL) - .addField(`Username`, user.username) - .addField(`ID`, user.id) - .addField(`Tag`, user.tag) - .addField(`Account Created`, user.createdTimestamp) - .addField(`Last Message ID`, user.lastMessageID) + .addField("Username", user.username) + .addField("ID", user.id) + .addField("Tag", user.tag) + .addField("Account Created", user.createdTimestamp) + .addField("Last Message ID", user.lastMessageID); message.channel.send(embed); } catch (err) { - message.channel.send(`${message.author}, there was a problem that occurred while processing the command.`); + message.channel.send(sendError(TYPE.BACKEND, ERROR.RATZx0000008)); } } if (message.content.toString() == "/ratz slimedog") { - message.channel.send(`${message.author}, you are already authorized to type in the server!`); + message.channel.send(message.author + ", you are already authorized to type in the server!"); } if (message.content.toString() == "/ratz showcommands") { var i; - const embed = new Discord.RichEmbed() - .setTitle(`Commands for ratzBot`) + var embed_1 = new Discord.RichEmbed() + .setTitle("Commands for ratzBot") .setColor(0xcb00ff) - .setThumbnail(bot.user.avatarURL.toString()) + .setThumbnail(bot.user.avatarURL.toString()); for (i = 0; commands.names[i]; i++) { for (i = 0; commands.definitions[i]; i++) { - embed.addField(commands.names[i], commands.definitions[i]); + embed_1.addField(commands.names[i], commands.definitions[i]); } } - message.channel.send({ embed }); + message.channel.send({ embed: embed_1 }); } if (message.content.toString() == "/ratz botinfo") { var embed = new Discord.RichEmbed() @@ -99,21 +95,21 @@ bot.on('message', (message) => { .addField("Developer", "Gavin Isgar (https://www.github.com/gisgar3/)") .addField("Version Number", package.version) .addField("Source Languages", "JavaScript\nTypeScript") - .addField("GitHub Repository", "https://www.github.com/gisgar3/ratzbot/") + .addField("GitHub Repository", "https://www.github.com/gisgar3/ratzbot/"); message.channel.send(embed); } if (message.content.startsWith("/ratz steamuserinfo ")) { var result = message.content.slice(20); var getSteamProfile = { method: "GET", - url: `https://api.steampowered.com/ISteamUser/GetPlayerSummaries/v2/?key=${tokens.steamtoken}&steamids=${result}`, - } - request(getSteamProfile, (error, response, body) => { + url: "https://api.steampowered.com/ISteamUser/GetPlayerSummaries/v2/?key=" + tokens.steamtoken + "&steamids=" + result + }; + request(getSteamProfile, function (error, response, body) { try { - if (!error & response.statusCode == 200) { + if (!error && response.statusCode == 200) { var stats = JSON.parse(body); - const embed = new Discord.RichEmbed() - .setTitle(`Steam User Information for ${stats.response.players[0].steamid}`) + var embed_2 = new Discord.RichEmbed() + .setTitle("Steam User Information for " + stats.response.players[0].steamid) .setURL(stats.response.players[0].profileurl) .setColor(0xcb00ff) .setThumbnail(stats.response.players[0].avatarfull) @@ -122,75 +118,78 @@ bot.on('message', (message) => { .addField("Primary Clan", stats.response.players[0].primaryclanid) .addField("Last Logoff", stats.response.players[0].lastlogoff) .addField("Account Created", stats.response.players[0].timecreated); - message.channel.send({ embed }); + message.channel.send({ embed: embed_2 }); + } + else { + message.channel.send(sendError(TYPE.BACKEND, ERROR.RATZx0000007)); } } catch (err) { - console.log(`ERROR: ${err}`); + message.channel.send(sendError(TYPE.BACKEND, ERROR.RATZx0000007)); } - }) + }); } if (message.content.toString() == "/ratz releaseinfo") { var getReleaseInfo = { method: "GET", - url: `https://api.github.com/repos/Gisgar3/ratzBot/releases`, + url: "https://api.github.com/repos/Gisgar3/ratzBot/releases", headers: { "User-Agent": "Gisgar3" } - } - request(getReleaseInfo, (error, response, body) => { + }; + request(getReleaseInfo, function (error, response, body) { try { - if (!error & response.statusCode == 200) { + if (!error && response.statusCode == 200) { var stats = JSON.parse(body); var embed = new Discord.RichEmbed() .setTitle("ratzBot GitHub Release Information") .setThumbnail(bot.user.avatarURL) .setColor(0xcb00ff) .setURL(stats[0].html_url) - .addField(`Latest Release`, "" + stats[0].name) - .addField(`Release Branch`, "" + stats[0].target_commitish) - .addField(`Tag`, stats[0].tag_name) - .addField(`Changelog`, stats[0].body) - .addField(`Pre-Release Status`, "" + stats[0].prerelease) - .addField(`Author`, stats[0].author.login) - if (`${stats[0].prerelease}` == "true" && `${stats[0].tag_name}`.endsWith("-RC")) { + .addField("Latest Release", "" + stats[0].name) + .addField("Release Branch", "" + stats[0].target_commitish) + .addField("Tag", stats[0].tag_name) + .addField("Changelog", stats[0].body) + .addField("Pre-Release Status", "" + stats[0].prerelease) + .addField("Author", stats[0].author.login); + if ("" + stats[0].prerelease == "true" && ("" + stats[0].tag_name).endsWith("-RC")) { embed.setFooter("BUILD STAGE: Release Candidate"); } - else if (`${stats[0].prerelease}` == "true" && `${stats[0].tag_name}`.endsWith("-Beta")) { + else if ("" + stats[0].prerelease == "true" && ("" + stats[0].tag_name).endsWith("-Beta")) { embed.setFooter("BUILD STAGE: Beta"); } - else if (`${stats[0].prerelease}` == "true" && `${stats[0].tag_name}`.endsWith("-Alpha")) { + else if ("" + stats[0].prerelease == "true" && ("" + stats[0].tag_name).endsWith("-Alpha")) { embed.setFooter("BUILD STAGE: Alpha"); } - else if (`${stats[0].prerelease}` == "false") { + else if ("" + stats[0].prerelease == "false") { embed.setFooter("BUILD STAGE: General Availability"); } message.channel.send(embed); } else { - message.channel.send(`${error} + ${response.statusCode}`); + message.channel.send(sendError(TYPE.BACKEND, ERROR.RATZx0000006)); } } catch (err) { - message.channel.send(`${message.author}, an error occured during the process. Try again later.`); + message.channel.send(sendError(TYPE.BACKEND, ERROR.RATZx0000006)); } - }) + }); } if (message.content.startsWith("/ratz gituserinfo ")) { var result = message.content.slice(18); var getGitUserInfo = { method: "GET", - url: `https://api.github.com/users/${result}`, + url: "https://api.github.com/users/" + result, headers: { "User-Agent": "Gisgar3" } - } - request(getGitUserInfo, (error, response, body) => { + }; + request(getGitUserInfo, function (error, response, body) { try { - if (!error & response.statusCode == 200) { + if (!error && response.statusCode == 200) { var stats = JSON.parse(body); - const embed = new Discord.RichEmbed() - .setTitle(`GitHub User Information for ${result}`) + var embed_3 = new Discord.RichEmbed() + .setTitle("GitHub User Information for " + result) .setURL(stats.html_url) .setColor(0xcb00ff) .setThumbnail(stats.avatar_url) @@ -200,33 +199,33 @@ bot.on('message', (message) => { .addField("Location", "" + stats.location) .addField("Email", "" + stats.email) .addField("Hireable", "" + stats.hireable) - .addField("Public Repositories", stats.public_repos) - message.channel.send(embed); + .addField("Public Repositories", stats.public_repos); + message.channel.send(embed_3); } else { - message.channel.send(`${message.author}, an error occured during the process. Try again later.`); + message.channel.send(sendError(TYPE.BACKEND, ERROR.RATZx0000006)); } } catch (err) { - message.channel.send(`${message.author}, an error occured during the process. Try again later.`); + message.channel.send(sendError(TYPE.BACKEND, ERROR.RATZx0000006)); } - }) + }); } if (message.content.startsWith("/ratz gitrepoinfo ")) { var result = message.content.slice(18); var getGitRepoInfo = { method: "GET", - url: `https://api.github.com/repos/${result}`, + url: "https://api.github.com/repos/" + result, headers: { 'User-Agent': 'Gisgar3' } - } - request(getGitRepoInfo, (error, response, body) => { + }; + request(getGitRepoInfo, function (error, response, body) { try { - if (!error & response.statusCode == 200) { + if (!error && response.statusCode == 200) { var stats = JSON.parse(body); - const embed = new Discord.RichEmbed() - .setTitle(`GitHub Repository for ${result}`) + var embed_4 = new Discord.RichEmbed() + .setTitle("GitHub Repository for " + result) .setURL(stats.html_url) .setColor(0xcb00ff) .setThumbnail(stats.owner.avatar_url) @@ -234,68 +233,68 @@ bot.on('message', (message) => { .addField("Description", stats.description) .addField("Owner", stats.owner.login) .addField("Language", stats.language) - .addField("Archive Status", stats.archived) - message.channel.send(embed); + .addField("Archive Status", stats.archived); + message.channel.send(embed_4); } else { - message.channel.send(`${message.author}, an error occured during the process. Try again later.`); + message.channel.send(sendError(TYPE.BACKEND, ERROR.RATZx0000006)); } } catch (err) { - message.channel.send(`${message.author}, an error occured during the process. Try again later.`); + message.channel.send(sendError(TYPE.BACKEND, ERROR.RATZx0000006)); } - }) + }); } if (message.content.toString() == "/ratz btcinfo") { var getBTCInfo = { method: "GET", url: "https://api.blockchain.info/stats" - } - request(getBTCInfo, (error, response, body) => { + }; + request(getBTCInfo, function (error, response, body) { try { - if (!error & response.statusCode == 200) { + if (!error && response.statusCode == 200) { var stats = JSON.parse(body); - const embed = new Discord.RichEmbed() + var embed_5 = new Discord.RichEmbed() .setTitle("BTC Information") .setColor(0xcb00ff) .setThumbnail(bot.user.avatarURL) - .addField("Market Price (USD)", `$${stats.market_price_usd}`) + .addField("Market Price (USD)", "$" + stats.market_price_usd) .addField("BTC Mined", stats.n_btc_mined) .addField("Blocks Mined", stats.n_blocks_mined) .addField("Total Blocks", stats.n_blocks_total) - .addField("Total BTC Sent", stats.total_btc_sent) - message.channel.send(embed); + .addField("Total BTC Sent", stats.total_btc_sent); + message.channel.send(embed_5); } else { - message.channel.send(`${message.author}, an error occured during the process. Try again later.`); + message.channel.send(sendError(TYPE.BACKEND, ERROR.RATZx0000005)); } } catch (err) { - message.channel.send(`${message.author}, an error occured during the process. Try again later.`); + message.channel.send(sendError(TYPE.BACKEND, ERROR.RATZx0000005)); } - }) + }); } // -----SERVER EVENTS----- if (message.content.toString() == "/ratz joinactiveevent") { if (activeevent == "") { - message.channel.send(`${message.author}, there is no active event on the server.`); + message.channel.send(message.author + ", there is no active event on the server."); } else { try { - fs.appendFileSync("./exclude/eventuserlist.ratz", `\r\n${message.author.id}`); - message.channel.send(`${message.author}, you are now joined into the ${activeevent}!`); + fs.appendFileSync("./exclude/eventuserlist.ratz", "\r\n" + message.author.id); + message.channel.send(message.author + ", you are now joined into the " + activeevent + "!"); } catch (err) { - message.channel.send(`${message.author}, an error occured during the process. Try again later.`); + message.channel.send(sendError(TYPE.BACKEND, ERROR.RATZx0000004)); } } } if (message.content.toString() == "/ratz showactiveevent") { if (activeevent == "") { - message.channel.send(`${message.author}, there is no active event on the server.`); + message.channel.send(message.author + ", there is no active event on the server."); } else { - message.channel.send(`${message.author}, the active event on the server is the ${activeevent}.`); + message.channel.send(message.author + ", the active event on the server is the " + activeevent + "."); } } // -----STREAMLABS INTEGRATION----- @@ -303,37 +302,37 @@ bot.on('message', (message) => { var result = message.content.slice(18); var getRTCInfo = { method: "GET", - url: `https://streamlabs.com/api/v1.0/points?access_token=${tokens.streamlabstoken}&username=${result}&channel=ratzdoll` - } - request(getRTCInfo, (error, response, body) => { + url: "https://streamlabs.com/api/v1.0/points?access_token=" + tokens.streamlabstoken + "&username=" + result + "&channel=ratzdoll" + }; + request(getRTCInfo, function (error, response, body) { try { - if (!error & response.statusCode == 200) { + if (!error && response.statusCode == 200) { var stats = JSON.parse(body); - message.channel.send(`${message.author}, ${result} has ${stats.points} RTC!`); + message.channel.send(message.author + ", " + result + " has " + stats.points + " RTC!"); } else { - message.channel.send(`${message.author}, an error occured during the process. Try again later.`); + message.channel.send(sendError(TYPE.BACKEND, ERROR.RATZx0000003)); } } catch (err) { - message.channel.send(`${message.author}, an error occured during the process. Try again later.`); + message.channel.send(sendError(TYPE.BACKEND, ERROR.RATZx0000003)); } - }) + }); } // -----TWITCH NEW API----- if (message.content.toString() == "/ratz laststream") { var getStreamVOD = { method: 'GET', - url: `https://api.twitch.tv/helix/videos?user_id=157901049&first=1`, + url: "https://api.twitch.tv/helix/videos?user_id=157901049&first=1", headers: { - "Client-ID": `${tokens.twitchapiclientid}` + "Client-ID": "" + tokens.twitchapiclientid } - } - request(getStreamVOD, (error, response, body) => { + }; + request(getStreamVOD, function (error, response, body) { try { - if (!error & response.statusCode == 200) { + if (!error && response.statusCode == 200) { var stats = JSON.parse(body); - const embed = new Discord.RichEmbed() + var embed_6 = new Discord.RichEmbed() .setTitle("Last Stream VOD from ratzDoll") .setThumbnail(bot.user.avatarURL) .setColor(0xcb00ff) @@ -341,53 +340,53 @@ bot.on('message', (message) => { .addField("Title", "" + stats.data[0].title) .addField("Published At", "" + stats.data[0].published_at) .addField("Duration", "" + stats.data[0].duration) - .addField("View Count", stats.data[0].view_count) - message.channel.send(embed); + .addField("View Count", stats.data[0].view_count); + message.channel.send(embed_6); } else { - message.channel.send(`${message.author}, an error occured during the process. Try again later.`); + message.channel.send(sendError(TYPE.BACKEND, ERROR.RATZx0000002)); } } catch (err) { - message.channel.send(`${message.author}, an error occured during the process. Try again later.`); + message.channel.send(sendError(TYPE.BACKEND, ERROR.RATZx0000002)); } - }) + }); } // -----VOICE CHANNELS----- if (message.content.startsWith("/ratz play ")) { var result = message.content.slice(11); if (message.member.voiceChannel) { - message.member.voiceChannel.join().then(connection => { + message.member.voiceChannel.join().then(function (connection) { try { - const stream = ytdl(result, { filter: `audioonly` }); - const dispatcher = connection.playStream(stream); - message.channel.send(`${message.author}, your music is now playing.`); - dispatcher.on("end", end => { - message.channel.send(`${message.author}, your music has ended.`); + var stream = ytdl(result, { filter: "audioonly" }); + var dispatcher = connection.playStream(stream); + message.channel.send(message.author + ", your music is now playing."); + dispatcher.on("end", function (end) { + message.channel.send(message.author + ", your music has ended."); message.member.voiceChannel.leave(); - }) + }); } catch (err) { - message.channel.send(`${message.author}, an error occured during the process. Try again later.`); + message.channel.send(sendError(TYPE.BACKEND, ERROR.RATZx0000001)); } - }) + }); } else { - message.channel.send(`${message.author}, you are not in a voice channel. Join a voice channel to play music!`); + message.channel.send(message.author + ", you are not in a voice channel. Join a voice channel to play music!"); } } if (message.content.toString() == "/ratz stop") { if (message.member.voiceChannel) { try { - message.member.voiceChannel.connection.disconnect() + message.member.voiceChannel.connection.disconnect(); message.member.voiceChannel.leave(); } catch (err) { - message.channel.send(`${message.author}, an error occured during the process. Try again later.`); + message.channel.send(sendError(TYPE.BACKEND, ERROR.RATZx0000001)); } } else { - message.channel.send(`${message.author}, you are not in a voice channel.`); + message.channel.send(message.author + ", you are not in a voice channel."); } } // -----TOPIC DETECTION AND REVIEW----- @@ -396,93 +395,109 @@ bot.on('message', (message) => { // Do nothing } else { - fs.appendFileSync("./exclude/bannedmessages.ratz", `\r\n(${message.author.username} [${message.author.id}], ${message.createdTimestamp}) ${message.content.toString()}`); - message.delete(); - message.channel.send(`${message.author}, your message was deleted because it possibly relates to a blocked topic. To appeal the deletion of your message, contact an administrator.`); + fs.appendFileSync("./exclude/bannedmessages.ratz", "\r\n(" + message.author.username + " [" + message.author.id + "], " + message.createdTimestamp + ") " + message.content.toString()); + message["delete"](); + message.channel.send(message.author + ", your message was deleted because it possibly relates to a blocked topic. To appeal the deletion of your message, contact an administrator."); } } if (message.content.includes("NIGGER") || message.content.includes("nigger") || message.content.includes("NIGGA") || message.content.includes("nigga")) { - fs.appendFileSync("./exclude/bannedmessages.ratz", `\r\n(${message.author.username} [${message.author.id}], ${message.createdTimestamp}) ${message.content.toString()}`); - message.delete(); - message.channel.send(`${message.author}, your message was deleted because it possibly relates to a blocked topic. To appeal the deletion of your message, contact an administrator.`); + fs.appendFileSync("./exclude/bannedmessages.ratz", "\r\n(" + message.author.username + " [" + message.author.id + "], " + message.createdTimestamp + ") " + message.content.toString()); + message["delete"](); + message.channel.send(message.author + ", your message was deleted because it possibly relates to a blocked topic. To appeal the deletion of your message, contact an administrator."); } } } } 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}`); + fs.appendFileSync("./exclude/errors.ratz", "\r\nERROR at " + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds() + " " + date.getMonth() + "/" + date.getDate() + "/" + date.getFullYear() + ": " + err); } -}) - -bot.on("guildMemberAdd", (member) => { - bot.channels.get(newcomerChannel).send(`**| WELCOME |** ${member} has joined the server!`); -}) - -bot.on("guildMemberRemove", (member) => { - bot.channels.get(newcomerChannel).send(`**| GOODBYE |** ${member} has left the server!`); -}) - -bot.on("error", (error) => { - fs.appendFileSync("./exclude/errors.ratz", `\r\nERROR at ${date.getHours()}:${date.getMinutes()}:${date.getSeconds()} ${date.getMonth()}/${date.getDate()}/${date.getFullYear()}: ${error.name} | ${error.message}\n`); -}) - -bot.on("disconnect", (userconnection) => { +}); +bot.on("guildMemberAdd", function (member) { + bot.channels.get(newcomerChannel).send("**| WELCOME |** " + member + " has joined the server!"); +}); +bot.on("guildMemberRemove", function (member) { + bot.channels.get(newcomerChannel).send("**| GOODBYE |** " + member + " has left the server!"); +}); +bot.on("error", function (error) { + fs.appendFileSync("./exclude/errors.ratz", "\r\nERROR at " + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds() + " " + date.getMonth() + "/" + date.getDate() + "/" + date.getFullYear() + ": " + error.name + " | " + error.message + "\n"); +}); +bot.on("disconnect", function (userconnection) { try { bot.login(tokens.bottoken); } catch (err) { - console.log(`**RECON. ERROR**: ${err}`); + console.log("**RECON. ERROR**: " + err); } -}) - +}); // -----READLINE----- -const rl = readline.createInterface({ +var rl = readline.createInterface({ input: process.stdin, output: process.stdout }); - -rl.on("line", (input) => { +rl.on("line", function (input) { if (input.toString().startsWith("/ratz userban ")) { var result = input.slice(14); try { bot.guilds.forEach(function (getGuilds) { if (getGuilds.name == "ratzcord") { getGuilds.members.forEach(function (getMembers) { - if (getMembers.id == `${result}`) { + if (getMembers.id == "" + result) { getMembers.ban("Banned by ratzBot system."); - console.log(`**BAN**: User ${result} was successfully banned.`); + console.log("**BAN**: User " + result + " was successfully banned."); } else { // Do nothing } - }) + }); } else { // Do nothing } - }) + }); } catch (err) { - console.log(`**ERROR**: ${err}`); + console.log("**ERROR**: " + err); } } if (input.toString().startsWith("/ratz writemain ")) { var result = input.slice(16); try { - bot.channels.get(mainChannel).send(`${result}`); + bot.channels.get(mainChannel).send("" + result); } catch (err) { - console.log(`**ERROR**: ${err}`); + console.log("**ERROR**: " + err); } } // -----SERVER EVENTS----- if (input.toString().startsWith("/ratz setevent ")) { var result = input.slice(15); activeevent = result; - console.log(`**EVENT**: Event has been set.`); + console.log("**EVENT**: Event has been set."); } -}) - - -bot.login(tokens.bottoken); \ No newline at end of file +}); +bot.login(tokens.bottoken); +// -----ERROR REPORTING----- +var ERROR; +(function (ERROR) { + ERROR["RATZx0000001"] = "RATZx0000001"; + ERROR["RATZx0000002"] = "RATZx0000002"; + ERROR["RATZx0000003"] = "RATZx0000003"; + ERROR["RATZx0000004"] = "RATZx0000004"; + ERROR["RATZx0000005"] = "RATZx0000005"; + ERROR["RATZx0000006"] = "RATZx0000006"; + ERROR["RATZx0000007"] = "RATZx0000007"; + ERROR["RATZx0000008"] = "RATZx0000008"; +})(ERROR || (ERROR = {})); +; +var TYPE; +(function (TYPE) { + TYPE["FRONTEND"] = "FRONTEND"; + TYPE["BACKEND"] = "BACKEND"; +})(TYPE || (TYPE = {})); +; +function sendError(TYPE, ERROR) { + this.type = TYPE; + this.error = ERROR; + return "An error occured during the process: **| " + TYPE + " | " + ERROR + " |**"; +} diff --git a/main.ts b/main.ts new file mode 100644 index 0000000..f77c6ea --- /dev/null +++ b/main.ts @@ -0,0 +1,511 @@ +// COPYRIGHT (C) GAVIN ISGAR 2017-2018 + +const Discord = require("discord.js"); +const DiscordRPC = require("discord-rpc"); +const opus = require("opusscript"); +const ffmpeg = require("ffmpeg-binaries"); +const ytdl = require("ytdl-core"); +const bot = new Discord.Client(); +const msg = new Discord.Message(); +var net = require('net'); +var http = require("http"); +var url = require("url"); +var path = require("path"); +var request = require("request"); +var commands = require("./commands.json"); +var tokens = require("./exclude/tokens.json"); +var fs = require("fs"); +const readline = require("readline"); +const package = require("./package.json"); +const { app, BrowserWindow } = require('electron'); +var date = new Date(); + +//-----SERVER EVENTS----- +var activeevent = ""; +// --------- + +// -----CHANNELS----- +var logChannel = "423939166401855518"; +var newcomerChannel = "423937750937501697"; +var mainChannel = "443227379712917505"; +// ---------- + +bot.on('message', (message) => { + try { + if (fs.readFileSync("./exclude/bannedusers.ratz").includes(message.author.id.toString()) == true) { + message.channel.send(`${message.author}, you are banned from communicating in the server.`); + message.delete(); + } + else { + if (fs.readFileSync("./exclude/users.ratz").includes(message.author.id.toString()) == false) { + if (message.author.username == "GitHub" && message.author.bot == 1) { + // Do nothing + } + else { + if (message.content.toString() == "/ratz slimedog") { + fs.appendFileSync("./exclude/users.ratz", `\r\n${message.author.id.toString()}`); + message.delete(); + message.channel.send(`${message.author}, you now have access to type in the server!`); + } + else { + fs.appendFileSync("./exclude/removedauthmessages.ratz", `\r\n(${message.author.username} [${message.author.id}], ${message.createdTimestamp}) ${message.content.toString()}`); + message.delete(); + message.channel.send(`${message.author}, you have not completely read the rules in order to have access to chat. To get access, re-read the rules and type the secret response message specified.`) + } + } + } + else { + // ---COMMANDS--- + if (message.content.toString().startsWith("/ratz discorduserinfo ")) { + var result = message.content.slice(22); + try { + var user = bot.users.find("id", result); + var embed = new Discord.RichEmbed() + .setTitle(`Discord User Information for ${user.username}`) + .setColor(0xcb00ff) + .setThumbnail(user.avatarURL) + .addField(`Username`, user.username) + .addField(`ID`, user.id) + .addField(`Tag`, user.tag) + .addField(`Account Created`, user.createdTimestamp) + .addField(`Last Message ID`, user.lastMessageID) + message.channel.send(embed); + } + catch (err) { + message.channel.send(sendError(TYPE.BACKEND, ERROR.RATZx0000008)); + } + } + if (message.content.toString() == "/ratz slimedog") { + message.channel.send(`${message.author}, you are already authorized to type in the server!`); + } + if (message.content.toString() == "/ratz showcommands") { + var i; + const embed = new Discord.RichEmbed() + .setTitle(`Commands for ratzBot`) + .setColor(0xcb00ff) + .setThumbnail(bot.user.avatarURL.toString()) + for (i = 0; commands.names[i]; i++) { + for (i = 0; commands.definitions[i]; i++) { + embed.addField(commands.names[i], commands.definitions[i]); + } + } + message.channel.send({ embed }); + } + if (message.content.toString() == "/ratz botinfo") { + var embed = new Discord.RichEmbed() + .setTitle("ratzBot Information") + .setThumbnail(bot.user.avatarURL.toString()) + .setColor(0xcb00ff) + .addField("Developer", "Gavin Isgar (https://www.github.com/gisgar3/)") + .addField("Version Number", package.version) + .addField("Source Languages", "JavaScript\nTypeScript") + .addField("GitHub Repository", "https://www.github.com/gisgar3/ratzbot/") + message.channel.send(embed); + } + if (message.content.startsWith("/ratz steamuserinfo ")) { + var result = message.content.slice(20); + var getSteamProfile = { + method: "GET", + url: `https://api.steampowered.com/ISteamUser/GetPlayerSummaries/v2/?key=${tokens.steamtoken}&steamids=${result}`, + } + request(getSteamProfile, (error, response, body) => { + try { + if (!error && response.statusCode == 200) { + var stats = JSON.parse(body); + const embed = new Discord.RichEmbed() + .setTitle(`Steam User Information for ${stats.response.players[0].steamid}`) + .setURL(stats.response.players[0].profileurl) + .setColor(0xcb00ff) + .setThumbnail(stats.response.players[0].avatarfull) + .addField("Username", stats.response.players[0].personaname) + .addField("Profile State", stats.response.players[0].profilestate) + .addField("Primary Clan", stats.response.players[0].primaryclanid) + .addField("Last Logoff", stats.response.players[0].lastlogoff) + .addField("Account Created", stats.response.players[0].timecreated); + message.channel.send({ embed }); + } + else { + message.channel.send(sendError(TYPE.BACKEND, ERROR.RATZx0000007)); + } + } + catch (err) { + message.channel.send(sendError(TYPE.BACKEND, ERROR.RATZx0000007)); + } + }) + } + if (message.content.toString() == "/ratz releaseinfo") { + var getReleaseInfo = { + method: "GET", + url: `https://api.github.com/repos/Gisgar3/ratzBot/releases`, + headers: { + "User-Agent": "Gisgar3" + } + } + request(getReleaseInfo, (error, response, body) => { + try { + if (!error && response.statusCode == 200) { + var stats = JSON.parse(body); + var embed = new Discord.RichEmbed() + .setTitle("ratzBot GitHub Release Information") + .setThumbnail(bot.user.avatarURL) + .setColor(0xcb00ff) + .setURL(stats[0].html_url) + .addField(`Latest Release`, "" + stats[0].name) + .addField(`Release Branch`, "" + stats[0].target_commitish) + .addField(`Tag`, stats[0].tag_name) + .addField(`Changelog`, stats[0].body) + .addField(`Pre-Release Status`, "" + stats[0].prerelease) + .addField(`Author`, stats[0].author.login) + if (`${stats[0].prerelease}` == "true" && `${stats[0].tag_name}`.endsWith("-RC")) { + embed.setFooter("BUILD STAGE: Release Candidate"); + } + else if (`${stats[0].prerelease}` == "true" && `${stats[0].tag_name}`.endsWith("-Beta")) { + embed.setFooter("BUILD STAGE: Beta"); + } + else if (`${stats[0].prerelease}` == "true" && `${stats[0].tag_name}`.endsWith("-Alpha")) { + embed.setFooter("BUILD STAGE: Alpha"); + } + else if (`${stats[0].prerelease}` == "false") { + embed.setFooter("BUILD STAGE: General Availability"); + } + message.channel.send(embed); + } + else { + message.channel.send(sendError(TYPE.BACKEND, ERROR.RATZx0000006)); + } + } + catch (err) { + message.channel.send(sendError(TYPE.BACKEND, ERROR.RATZx0000006)); + } + }) + } + if (message.content.startsWith("/ratz gituserinfo ")) { + var result = message.content.slice(18); + var getGitUserInfo = { + method: "GET", + url: `https://api.github.com/users/${result}`, + headers: { + "User-Agent": "Gisgar3" + } + } + request(getGitUserInfo, (error, response, body) => { + try { + if (!error && response.statusCode == 200) { + var stats = JSON.parse(body); + const embed = new Discord.RichEmbed() + .setTitle(`GitHub User Information for ${result}`) + .setURL(stats.html_url) + .setColor(0xcb00ff) + .setThumbnail(stats.avatar_url) + .addField("Name", stats.name) + .addField("Company", "" + stats.company) + .addField("Bio", "" + stats.bio) + .addField("Location", "" + stats.location) + .addField("Email", "" + stats.email) + .addField("Hireable", "" + stats.hireable) + .addField("Public Repositories", stats.public_repos) + message.channel.send(embed); + } + else { + message.channel.send(sendError(TYPE.BACKEND, ERROR.RATZx0000006)); + } + } + catch (err) { + message.channel.send(sendError(TYPE.BACKEND, ERROR.RATZx0000006)); + } + }) + } + if (message.content.startsWith("/ratz gitrepoinfo ")) { + var result = message.content.slice(18); + var getGitRepoInfo = { + method: "GET", + url: `https://api.github.com/repos/${result}`, + headers: { + 'User-Agent': 'Gisgar3' + } + } + request(getGitRepoInfo, (error, response, body) => { + try { + if (!error && response.statusCode == 200) { + var stats = JSON.parse(body); + const embed = new Discord.RichEmbed() + .setTitle(`GitHub Repository for ${result}`) + .setURL(stats.html_url) + .setColor(0xcb00ff) + .setThumbnail(stats.owner.avatar_url) + .addField("Name", stats.name) + .addField("Description", stats.description) + .addField("Owner", stats.owner.login) + .addField("Language", stats.language) + .addField("Archive Status", stats.archived) + message.channel.send(embed); + } + else { + message.channel.send(sendError(TYPE.BACKEND, ERROR.RATZx0000006)); + } + } + catch (err) { + message.channel.send(sendError(TYPE.BACKEND, ERROR.RATZx0000006)); + } + }) + } + if (message.content.toString() == "/ratz btcinfo") { + var getBTCInfo = { + method: "GET", + url: "https://api.blockchain.info/stats" + } + request(getBTCInfo, (error, response, body) => { + try { + if (!error && response.statusCode == 200) { + var stats = JSON.parse(body); + const embed = new Discord.RichEmbed() + .setTitle("BTC Information") + .setColor(0xcb00ff) + .setThumbnail(bot.user.avatarURL) + .addField("Market Price (USD)", `$${stats.market_price_usd}`) + .addField("BTC Mined", stats.n_btc_mined) + .addField("Blocks Mined", stats.n_blocks_mined) + .addField("Total Blocks", stats.n_blocks_total) + .addField("Total BTC Sent", stats.total_btc_sent) + message.channel.send(embed); + } + else { + message.channel.send(sendError(TYPE.BACKEND, ERROR.RATZx0000005)); + } + } + catch (err) { + message.channel.send(sendError(TYPE.BACKEND, ERROR.RATZx0000005)); + } + }) + } + // -----SERVER EVENTS----- + if (message.content.toString() == "/ratz joinactiveevent") { + if (activeevent == "") { + message.channel.send(`${message.author}, there is no active event on the server.`); + } + else { + try { + fs.appendFileSync("./exclude/eventuserlist.ratz", `\r\n${message.author.id}`); + message.channel.send(`${message.author}, you are now joined into the ${activeevent}!`); + } + catch (err) { + message.channel.send(sendError(TYPE.BACKEND, ERROR.RATZx0000004)); + } + } + } + if (message.content.toString() == "/ratz showactiveevent") { + if (activeevent == "") { + message.channel.send(`${message.author}, there is no active event on the server.`); + } + else { + message.channel.send(`${message.author}, the active event on the server is the ${activeevent}.`); + } + } + // -----STREAMLABS INTEGRATION----- + if (message.content.startsWith("/ratz ratcoininfo ")) { + var result = message.content.slice(18); + var getRTCInfo = { + method: "GET", + url: `https://streamlabs.com/api/v1.0/points?access_token=${tokens.streamlabstoken}&username=${result}&channel=ratzdoll` + } + request(getRTCInfo, (error, response, body) => { + try { + if (!error && response.statusCode == 200) { + var stats = JSON.parse(body); + message.channel.send(`${message.author}, ${result} has ${stats.points} RTC!`); + } + else { + message.channel.send(sendError(TYPE.BACKEND, ERROR.RATZx0000003)); + } + } + catch (err) { + message.channel.send(sendError(TYPE.BACKEND, ERROR.RATZx0000003)); + } + }) + } + // -----TWITCH NEW API----- + if (message.content.toString() == "/ratz laststream") { + var getStreamVOD = { + method: 'GET', + url: `https://api.twitch.tv/helix/videos?user_id=157901049&first=1`, + headers: { + "Client-ID": `${tokens.twitchapiclientid}` + } + } + request(getStreamVOD, (error, response, body) => { + try { + if (!error && response.statusCode == 200) { + var stats = JSON.parse(body); + const embed = new Discord.RichEmbed() + .setTitle("Last Stream VOD from ratzDoll") + .setThumbnail(bot.user.avatarURL) + .setColor(0xcb00ff) + .setURL(stats.data[0].url) + .addField("Title", "" + stats.data[0].title) + .addField("Published At", "" + stats.data[0].published_at) + .addField("Duration", "" + stats.data[0].duration) + .addField("View Count", stats.data[0].view_count) + message.channel.send(embed); + } + else { + message.channel.send(sendError(TYPE.BACKEND, ERROR.RATZx0000002)); + } + } + catch (err) { + message.channel.send(sendError(TYPE.BACKEND, ERROR.RATZx0000002)); + } + }) + } + // -----VOICE CHANNELS----- + if (message.content.startsWith("/ratz play ")) { + var result = message.content.slice(11); + if (message.member.voiceChannel) { + message.member.voiceChannel.join().then(connection => { + try { + const stream = ytdl(result, { filter: `audioonly` }); + const dispatcher = connection.playStream(stream); + message.channel.send(`${message.author}, your music is now playing.`); + dispatcher.on("end", end => { + message.channel.send(`${message.author}, your music has ended.`); + message.member.voiceChannel.leave(); + }) + } + catch (err) { + message.channel.send(sendError(TYPE.BACKEND, ERROR.RATZx0000001)); + } + }) + } + else { + message.channel.send(`${message.author}, you are not in a voice channel. Join a voice channel to play music!`); + } + } + if (message.content.toString() == "/ratz stop") { + if (message.member.voiceChannel) { + try { + message.member.voiceChannel.connection.disconnect() + message.member.voiceChannel.leave(); + } + catch (err) { + message.channel.send(sendError(TYPE.BACKEND, ERROR.RATZx0000001)); + } + } + else { + message.channel.send(`${message.author}, you are not in a voice channel.`); + } + } + // -----TOPIC DETECTION AND REVIEW----- + if ((message.content.includes("XXXTentacion") || message.content.includes("xxxtentacion")) && (message.content.includes("death") || message.content.includes("died"))) { + if (fs.readFileSync("./exclude/approvedmessages.ratz").includes(message.content.toString())) { + // Do nothing + } + else { + fs.appendFileSync("./exclude/bannedmessages.ratz", `\r\n(${message.author.username} [${message.author.id}], ${message.createdTimestamp}) ${message.content.toString()}`); + message.delete(); + message.channel.send(`${message.author}, your message was deleted because it possibly relates to a blocked topic. To appeal the deletion of your message, contact an administrator.`); + } + } + if (message.content.includes("NIGGER") || message.content.includes("nigger") || message.content.includes("NIGGA") || message.content.includes("nigga")) { + fs.appendFileSync("./exclude/bannedmessages.ratz", `\r\n(${message.author.username} [${message.author.id}], ${message.createdTimestamp}) ${message.content.toString()}`); + message.delete(); + message.channel.send(`${message.author}, your message was deleted because it possibly relates to a blocked topic. To appeal the deletion of your message, contact an administrator.`); + } + } + } + } + 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}`); + } +}) + +bot.on("guildMemberAdd", (member) => { + bot.channels.get(newcomerChannel).send(`**| WELCOME |** ${member} has joined the server!`); +}) + +bot.on("guildMemberRemove", (member) => { + bot.channels.get(newcomerChannel).send(`**| GOODBYE |** ${member} has left the server!`); +}) + +bot.on("error", (error) => { + fs.appendFileSync("./exclude/errors.ratz", `\r\nERROR at ${date.getHours()}:${date.getMinutes()}:${date.getSeconds()} ${date.getMonth()}/${date.getDate()}/${date.getFullYear()}: ${error.name} | ${error.message}\n`); +}) + +bot.on("disconnect", (userconnection) => { + try { + bot.login(tokens.bottoken); + } + catch (err) { + console.log(`**RECON. ERROR**: ${err}`); + } +}) + +// -----READLINE----- +const rl = readline.createInterface({ + input: process.stdin, + output: process.stdout +}); + +rl.on("line", (input) => { + if (input.toString().startsWith("/ratz userban ")) { + var result = input.slice(14); + try { + bot.guilds.forEach(function (getGuilds) { + if (getGuilds.name == "ratzcord") { + getGuilds.members.forEach(function (getMembers) { + if (getMembers.id == `${result}`) { + getMembers.ban("Banned by ratzBot system."); + console.log(`**BAN**: User ${result} was successfully banned.`); + } + else { + // Do nothing + } + }) + } + else { + // Do nothing + } + }) + } + catch (err) { + console.log(`**ERROR**: ${err}`); + } + } + if (input.toString().startsWith("/ratz writemain ")) { + var result = input.slice(16); + try { + bot.channels.get(mainChannel).send(`${result}`); + } + catch (err) { + console.log(`**ERROR**: ${err}`); + } + } + // -----SERVER EVENTS----- + if (input.toString().startsWith("/ratz setevent ")) { + var result = input.slice(15); + activeevent = result; + console.log(`**EVENT**: Event has been set.`); + } +}) + + +bot.login(tokens.bottoken); +// -----ERROR REPORTING----- +enum ERROR { + RATZx0000001 = "RATZx0000001", + RATZx0000002 = "RATZx0000002", + RATZx0000003 = "RATZx0000003", + RATZx0000004 = "RATZx0000004", + RATZx0000005 = "RATZx0000005", + RATZx0000006 = "RATZx0000006", + RATZx0000007 = "RATZx0000007", + RATZx0000008 = "RATZx0000008" +}; +enum TYPE { + FRONTEND = "FRONTEND", + BACKEND = "BACKEND" +}; +function sendError(TYPE: TYPE, ERROR: ERROR) { + this.type = TYPE; + this.error = ERROR; + return `An error occured during the process: **| ${TYPE} | ${ERROR} |**` +} \ No newline at end of file From 7905cfdf5cfc0cbb80af35d37eb4f6d65c4723c0 Mon Sep 17 00:00:00 2001 From: Gavin Isgar Date: Tue, 24 Jul 2018 21:56:04 -0400 Subject: [PATCH 2/2] 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": {