Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bot_token = '0'; // redacted
- google_key = '0'; // redacted
- // converts timecodes into legible times (call with no parameter for time now)
- function time(timecode) {
- if (typeof timecode == 'undefined') {var date = new Date();} else {var date = new Date(timecode);};
- var hours = date.getHours();
- var minutes = "0" + date.getMinutes();
- var seconds = "0" + date.getSeconds();
- return hours + ':' + minutes.substr(-2) + ':' + seconds.substr(-2);
- }
- // converts Pokemon spawns into text notifications for Discord
- function tellD(pokemon) {
- iv_percent = Math.round(((pokemon.attack + pokemon.defence + pokemon.stamina)/45)*100);
- // tries to retrieve postcode and suburb from OpenStreetMap
- urlrg = 'https://nominatim.openstreetmap.org/reverse?format=json&lat='+pokemon.center.lat+'&lon='+pokemon.center.lng
- var xhs = new XMLHttpRequest(); xhs.open('GET', urlrg, false); xhs.send();
- address = JSON.parse(xhs.response).address;
- suburb = address.suburb; postcode = address.postcode;
- if (typeof postcode == 'undefined') {postcode = "?"; };
- if (typeof suburb == 'undefined') {suburb = ""; } else {suburb = ' ' + suburb};
- if (postcode.indexOf(' ') != -1) {postcode = postcode.substr(0,postcode.indexOf(' '));};
- // tries to retrieve more-accurate postcode from postcodes.io, and replaces OSM postcode if successful, adds ? if not
- urlps = 'https://api.postcodes.io/postcodes?lat='+pokemon.center.lat+'&lon='+pokemon.center.lng
- var xht = new XMLHttpRequest(); xht.open('GET', urlps, false); xht.send();
- try {postcode = JSON.parse(xht.response).result[0].outcode;}
- catch(error) {postcode = postcode + '?'; };
- url = 'http://www.google.com/maps/place/' + pokemon.center.lat + ',' + pokemon.center.lng;
- var expiry_time = time(pokemon.despawn*1000);
- var rem_time = timeToString(pokemon.remainingTime());
- return pokeDict[pokemon.id].name+' | '+iv_percent+'% | '+postcode+suburb+' | '+rem_time+' (until '+expiry_time+') | '+url;
- }
- // converts Pokemon spawns into map image url
- function StatIm(pokemon) {
- return 'https://maps.googleapis.com/maps/api/staticmap?markers='+pokemon.center.lat+','+pokemon.center.lng+'&zoom=15&size=400x400&sensor=false&key='+google_key;
- }
- // sends text to Discord
- function notifyD(content, channel) {
- var xhr = new XMLHttpRequest();
- xhr.open('POST', "https://discordapp.com/api/channels/"+channel+"/messages", true);
- xhr.setRequestHeader('Authorization', 'Bot '+bot_token);
- xhr.setRequestHeader('Content-Type', 'application/json');
- xhr.send('{"content":"'+content+'"}');
- console.log(content);
- }
- // sends text + embedded image to Discord
- function notifyImD(content, embed_url, channel) {
- var xhr = new XMLHttpRequest();
- xhr.open('POST', "https://discordapp.com/api/channels/"+channel+"/messages", true);
- xhr.setRequestHeader('Authorization', 'Bot '+bot_token);
- xhr.setRequestHeader('Content-Type', 'application/json');
- xhr.send('{"content":"'+content+'","embed": {"image": {"url":"'+embed_url+'"}}}');
- console.log('[I] '+content);
- }
- // opens connection with Discord
- var ws = new WebSocket('wss://gateway.discord.gg');
- gateway = JSON.stringify({
- "op": 2,
- "d": {
- "token": bot_token,
- "properties": {"$os": "linux", "$browser": "sometestingbrowser", "$device": "sometestingdevice", "$referrer": "", "$referring_domain": "",},
- "compress": true,
- "large_threshold": 250,
- }
- });
- setTimeout(function(){ws.send(gateway)}, 2 * 1000);
- // channel IDs
- const pysgeneral = '293028598024110080'
- const pyschannel1 = '293838131407486980'
- const pyschannel2 = '296066428694429697'
- const pyschannel3 = '296965358533869568'
- const pyschannel4 = '296986176567640064'
- const pglgeneral = '260119001018007552'
- const pgldev = '276041020402040833'
- const pgllarvitar = '283156333015072768'
- const pglbig = '268886255952068619'
- const pgldefenders = '268886358762717194'
- const pgldexfillers = '268886304509394944'
- const pglperfect = '260507173296013312'
- // IV filters
- iv = Array.apply(null, new Array(252)).map(Number.prototype.valueOf,0);
- iv[143] = -45; iv[149] = -45; iv[181] = -45; iv[201] = -45; iv[242] = -45; iv[248] = -45;
- iv[179] = -45; iv[180] = -45;
- iv[246] = -45; iv[247] = -45;
- iv[113] = -2;
- // radius filters
- r = Array.apply(null, new Array(252)).map(Number.prototype.valueOf,100);
- home_lat = 51.507406; home_lng = -0.127675;
- // channel assignments (for channels targetting particular species)
- target = Array.apply(null, new Array(252)).map(Number.prototype.valueOf,0);
- for (i = 0, len = target.length; i < len; i++) {
- if (new Set([143, 149, 181, 201, 242, 248]).has(i)) {target[i] = pglbig}
- else if (new Set([179, 180]).has(i)) {target[i] = pyschannel4}
- else if (new Set([246, 247]).has(i)) {target[i] = pgllarvitar}
- }
- var known_despawns = []; // keeps track of Pokemon already notified
- var first_run = 0; // the bot skips Pokemon already on the map when it's started
- setTimeout(function(){notifyD('Start', pysgeneral)}, 4 * 1000);
- // loop (from here to end of code)
- var timer = setInterval(function() {
- b = [];
- // polls map for desired Pokemon
- for (i = 0, len = this.pokemons.length; i < len; i++) {
- test = this.pokemons[i];
- test_iv = (test.attack + test.defence + test.stamina) - 45;
- if (test_iv >= iv[test.id]) {
- test_x = Math.abs(test.center.lat - home_lat)*110.574;
- test_y = Math.abs(test.center.lng - home_lng)*69.298;
- if (test_x*test_x + test_y*test_y < r[test.id]*r[test.id]) {
- test.iv = test_iv;
- b.push(test);
- }
- }
- }
- // sends out notifications for polled Pokemon
- for (i = 0, len = b.length; i < len; i++) {
- if (known_despawns.indexOf(b[i].despawn) != -1) { continue; };
- known_despawns.push(b[i].despawn);
- if (first_run == 0) { continue; };
- notif = tellD(b[i]);
- if (notif == null) {console.log('Skipped'); continue; };
- if (target[b[i].id] != 0) {notifyImD(notif, StatIm(b[i]), target[b[i].id])}
- if (b[i].iv == 0 || (b[i].iv >= -2 && b[i].id == 113)) {notifyImD(notif, StatIm(b[i]), pglperfect)}
- }
- first_run = 1;
- console.log('Ran at '+time())
- }, 30 * 1000);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement