Skip to content

Instantly share code, notes, and snippets.

@sunkast
Created May 28, 2019 20:33
Show Gist options
  • Save sunkast/c65815715ab2e42109cefdfbb148e6af to your computer and use it in GitHub Desktop.
Save sunkast/c65815715ab2e42109cefdfbb148e6af to your computer and use it in GitHub Desktop.
// Only these channels are monitored
let scanChans = ["city-t5-raids", "city-t1-4-raids"];
// Only messages from the scanner bot are monitored
if (scanChans.includes(message.channel.name) && message.author.id === 'SCANNER_BOT_ID'){
// Add a reaction to each message
message.react('📣');
const filter = (reaction, user) => {
// Ignore the bot adding the reaction so it doesn't trigger the report command
return ['📣'].includes(reaction.emoji.name) && user.id !== 'REACTION_BOT_ID';
};
message.awaitReactions(filter, { max: 1 })
.then(collected => {
const reaction = collected.first();
// Set the name of the announce channel
const raidChan = message.guild.channels.find(channel => channel.name === "raid-reports");
if (reaction.emoji.name === '📣') {
let embed = message.embeds[0];
let raid = embed.author.name;
// Replace any gym title with EX so the gym name is correct
let gym = embed.title.replace(' EX','');
let time = embed.description.match(/((1[0-2]|0?[1-9]):([0-5][0-9]) ?([AaPp][Mm]))/g);
let curTime = new Date();
let v2date = curTime.getFullYear() + "/" + (curTime.getMonth() + 1) + "/" + curTime.getDate();
let raidDate = `${v2date} ${time[0]}`;
let endTime = new Date(raidDate);
let difference = endTime.getTime() - curTime.getTime();
let spawnTime = Math.round(difference / 60000);
console.log(`
curTime: ${curTime}
v2date: ${v2date}
raidDate: ${raidDate}
endTime: ${endTime}
Spawn time: ${spawnTime}`);
// Check if the raid is an egg or not.
if(raid.includes("Egg")){
if(spawnTime < 0) return console.log('Raid expired.');
let tier = raid.substr(1, 1);
console.log(`?r ${tier} "${gym}" ${spawnTime}`);
message.channel.send(`The ${raid} at ${gym} has been reported to PokeNav. Thank you!`);
raidChan.send(`?r ${tier} "${gym}" ${spawnTime}`);
}
if(!raid.includes("Egg")){
if(spawnTime < 10) return console.log('Raid is under 10 mins left or expired.');
console.log(`?r ${raid} "${gym}" ${spawnTime}`);
message.channel.send(`The ${raid} at ${gym} has been reported to PokeNav. Thank you!`);
raidChan.send(`?r ${raid} "${gym}" ${spawnTime}`);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment