Production Diff
During ipv2 development, I have made changes to production not in this repo. It would be better to use docker or something for deployment and have branches set up properly so this wouldn't be possible. These changes should be applied in the next bot version:
diff --git a/bot.js b/bot.js
index dd2ba7e..2d48cb1 100644
--- a/bot.js
+++ b/bot.js
@@ -9,4 +9,7 @@ else token = config.token;
bot.login(token);
+console.log("Logging in...");
+bot.on("ready", () => {console.log("Login succesful")});
+
module.exports = bot;
diff --git a/index.js b/index.js
index 9f98bb5..661d237 100644
--- a/index.js
+++ b/index.js
@@ -10,6 +10,9 @@ const handleQuote = require("./src/commands/quote");
const MB = require("./src/MessageBuilder");
const request = require("request");
+console.log("RESTARTED");
+//console.log = () => {}; // when too many errors are thrown everything breaks down. temporary fix
+
global.__basedir = __dirname;
@@ -28,6 +31,7 @@ let mostRecentCommands = [];
function devlog(...msg) {
if(!production) console.log(...msg);
+ //else console.log("DEVLOG ",...msg);
}
usage.add("help", new Usage({
@@ -71,7 +75,7 @@ usage.add("spoiler", new Usage({
else (async() => (await data.msg.reply("This command works better when I have the permission `MANAGE_MESSAGES`")).delete(10*1000))();
message = message.join` `;
let mb = MB();
- mb.title.tag`Spoiler`;
+ mb.title.tag`||Spoiler||`;
mb.description.tag`[Hover to View](https://dummyimage.com/600x400/000/fff&text=${encodeURIComponent(message).replace(/[_]/g, "")} "${message}")`;
return await data.msg.reply(...mb.build(data.embed || true)); // spoilers must use embeds
@@ -172,18 +176,19 @@ async function retrieveGuildInfo(g, msg) {
function updateActivity() {
let count = bot.guilds.size;
- bot.user.setActivity(`ip!help on ${count} servers`);
- if(process.env.NODE_ENV === "development") return; // only production should post
- let options = {
- url: `https://bots.discord.pw/api/bots/${config.bdpid}/stats`,
- headers: {
- Authorization: config["bots.discord.pw"]
- },
- json: {
- server_count: count // eslint-disable-line camelcase
- }
- };
- request.post(options, (er, res) => {if(er) console.log("er... my res isn't existant", er); else console.log(res.body);});
+
+bot && bot.user && bot.user.setActivity(`ip!help on ${count} servers`);
+// if(process.env.NODE_ENV === "development") return; // only production should post
+// let options = {
+// url: `https://bots.discord.pw/api/bots/${config.bdpid}/stats`,
+// headers: {
+// Authorization: config["bots.discord.pw"]
+// },
+// json: {
+// server_count: count // eslint-disable-line camelcase
+// }
+// };
+// request.post(options, (er, res) => {if(er) console.log("er... my res isn't existant", er); else console.log(res.body);});
}
bot.on("ready", async() => {
@@ -230,6 +235,7 @@ bot.on("channelCreate", async(newC) => {
});
bot.on("channelUpdate", async(old, newC) => {
+ if(newC.name.indexOf("-") === -1) {return;}
let info = await retrieveGuildInfo(newC.guild);
if(info.channelSpacing) {
newC.setName(newC.name.split("-").join(" "));
@@ -423,9 +429,14 @@ bot.on("guildDelete", (guild) => { // forget about the guild at some point in ti
console.log(`_ Left guild ${guild.name} (${guild.nameAcronym})`);
});
-process.on("unhandledRejection", (reason, p) => {
- let finalMsg = `
-Hey <@${config.owner}>, there was an error
+bot.on("error", e => {
+console.log("!!!!!!!!There was a bot.on error!!!!!!!!!!!!", e);
+});
+
+
+let erfn = ( async (reason, p) => {
+let finalMsg = `
+Hey <@${"everyone" || config.owner}>, there was an error
**Recent Commands:**
${mostRecentCommands.map(c => `\`${c.content}\` / ${moment(c.date).fromNow()}`).join`\n`}
@@ -440,9 +451,16 @@ ${reason.stack}
console.log(finalMsg);
try{
let rept = config.errorReporting.split`/`;
- bot.guilds.get(rept[0]).channels.get(rept[1]).send(finalMsg); // TODO disable logging in production and instead show the 10 messages before here with this
+ await bot.guilds.get(rept[0]).channels.get(rept[1]).send(finalMsg); // TODO disable logging in production and instead show the 10 messages before here with this
}catch(e) {
- console.log("Failed to report");
+ console.log("Failed to report",e);
+console.log("bot will now restart");process.exit(0);throw e;
}
// application specific logging, throwing an error, or other logic here
});
+
+
+
+process.on("unhandledRejection", erfn);
+process.on("uncaughtException", erfn);
+
diff --git a/src/commands/about.js b/src/commands/about.js
index cc42b15..8a7d807 100644
--- a/src/commands/about.js
+++ b/src/commands/about.js
@@ -10,11 +10,10 @@ let about = new Usage({
mb.title.tag`Inter·punct Bot`;
mb.description.tag`A bot that does stuff.`;
mb.addField((title, description) => {title.tag`<:list:476514785106591744> discordbots.org (vote pls)`, description.tag`<https://discordbots.org/bot/433078185555656705>`;});
- mb.addField((title, description) => {title.tag`<:list:476514785106591744> bots.discord.pw`, description.tag`<https://bots.discord.pw/bots/433078185555656705>`;});
+ mb.addField((title, description) => {title.tag`<:list:476514785106591744> discord.bots.gg`, description.tag`<https://discord.bots.gg/bots/433078185555656705>`;});
mb.addField((title, description) => {title.tag`<:javascript:476513336490721290> source code`, description.tag`<https://gitlab.com/pfgitlab/interpunctbot>`;});
mb.addField((title, description) => {title.tag`<:documentation:476514294075490306> documentation`, description.tag`<https://gitlab.com/pfgitlab/interpunctbot/blob/master/README.md>`;});
mb.addField((title, description) => {title.tag`<:discord:478701038447230996> support server`, description.tag`<https://discord.gg/j7qpZdE>`;});
- mb.addField((title, description) => {title.tag`<:discord:478701038447230996> support server`, description.tag`<https://discord.gg/j7qpZdE>`;});
mb.addField((title, description) => {title.tag`<a:cursor:404001393360502805> prefix`, description.tag`\`${data.prefix}\``;});
mb.setAuthor("pfg#4865", "https://cdn.discordapp.com/avatars/341076015663153153/d4d033b5a2df0c42328659202e09438e.png?size=128");
diff --git a/src/commands/settings.js b/src/commands/settings.js
index 02cf221..e16b815 100644
--- a/src/commands/settings.js
+++ b/src/commands/settings.js
@@ -199,10 +199,10 @@ settings.add("speedrun", new Usage({
let games = gameData.items;
if(games.length <= 0) return await data.msg.reply("Please supply a valid game abbreviation");
let id = games[0].id;
-
+console.log("GAMELIST", JSON.stringify(games));
let categories = games[0].categories.data;
- let categoryFilter = categories.items.filter(cat => cat.name.toLowerCase() === category.join` `.toLowerCase());
+ let categoryFilter = categories.filter(cat => cat.name.toLowerCase() === category.join` `.toLowerCase());
if(categoryFilter.length <= 0) return await data.msg.reply(`Please supply a valid category name. Categories: ${categories.items.map(cat => cat.name).join`, `}`);
await data.db("guilds").where({id: data.msg.guild.id}).update({speedrun: `${id}, ${categoryFilter[0].id}`});