Skip to content

Instantly share code, notes, and snippets.

@Kampfkarren
Created May 25, 2016 22:03
Show Gist options
  • Save Kampfkarren/415d13eb9fa6fc3325004645e9c2c029 to your computer and use it in GitHub Desktop.
Save Kampfkarren/415d13eb9fa6fc3325004645e9c2c029 to your computer and use it in GitHub Desktop.
"use strict";
/*
npm install discord.js
make a file with config.json that looks like this
{
"email": "botemail",
"password": "password"
}
*/
const Discord = require("discord.js");
const config = require("./config.json");
const bot = new Discord.Client();
const request = require("request");
const channel = "184471916684378112";
let invasions = {};
function checkInvasions(){
request("https://www.toontownrewritten.com/api/invasions", (e, r, b) => {
let json = JSON.parse(b);
let str = "";
for(let dist in json.invasions){
if(invasions[dist] === undefined){
invasions[dist] = json.invasions[dist];
str += `A ${invasions[dist].type} invasion has started in ${dist}!\n`;
}else{
invasions[dist].progress = json.invasions[dist].progress; //this is the only thing that needs to be updated
}
}
if(str !== ""){
bot.sendMessage(channel, str);
}
});
}
bot.on("message", function(message){
});
bot.on("ready", () => {
console.log("Bot ready.");
checkInvasions();
/*jshint -W117*/
setInterval(checkInvasions, 10000);
/*jshint +W117*/ //theres probably some way to add this for just one line but whatev
});
bot.login(config.email, config.password);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment