Facebook
From Voluminous Rhinoceros, 4 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 391
  1. #WYSYŁANIE POWIADOMIENIA NA DISCORD
  2. (function(_n, data, ut) {
  3.     //pobranie localStorage
  4.     let dane = {};
  5.     if (localStorage.getItem("adiherosybrutus")) {
  6.         dane = JSON.parse(localStorage.getItem("adiherosybrutus"));
  7.     }
  8.     if (dane) {
  9.         for (let i in dane) {
  10.             if (ut() > dane[i].time) {
  11.                 delete dane[i];
  12.             }
  13.         }
  14.     }
  15.     //getTime
  16.     function getTime() {
  17.         let czas = new Date(),
  18.             godzina = czas.getHours(),
  19.             sekunda = czas.getSeconds(),
  20.             minuta = czas.getMinutes();
  21.         if (godzina < 10) godzina = `0${godzina}`;
  22.         if (minuta < 10) minuta = `0${minuta}`;
  23.         if (sekunda < 10) sekunda = `0${sekunda}`;
  24.         return `${godzina}:${minuta}:${sekunda}`;
  25.     }
  26.     //funkcja wysłania na diskordzika
  27.     function sendToDiscord(lvl, nick, icon, x, y) {
  28.         $.ajax({
  29.             url: data[0],
  30.             type: 'POST',
  31.             data: JSON.stringify({
  32.                 'embeds': [{
  33.                     'title': `${hero.nick} ¡ ${hero.lvl}${hero.prof} znalazł herosa/tytana!`,
  34.                     'color': ((Math.floor(lvl / 300 * 221) + 32) * 256 + (Math.floor(lvl / 300 * (-112)) + 120)) * 256 + Math.floor(lvl / 300 * (-204)) + 217,
  35.                     'description': `${nick} (${lvl}lvl)\n${map.name} (${x}, ${y})\n${getTime()}\n${g.worldname[0].toUpperCase() + g.worldname.substring(1)}`,
  36.                     'thumbnail': {
  37.                         'url': `http://classic.margonem.pl${icon}`
  38.                     }
  39.                 }],
  40.                 content: `@here ZnaleĹşli mnie na mapie ${map.name}`,
  41.                 username: nick,
  42.                 avatar_url: `http://classic.margonem.pl${icon}`
  43.             }),
  44.             contentType: 'application/json; charset=utf-8',
  45.             dataType: 'json',
  46.             async: false
  47.         });
  48.     }
  49.     //funkcja sprawdzajaca czy dane id z ts istnieje
  50.     function checkHerosData(id) {
  51.         if (dane[id]) {
  52.             if (ut() > dane[id].time) {
  53.                 delete dane[id];
  54.                 return true;
  55.             } else {
  56.                 return false;
  57.             }
  58.         }
  59.         return true;
  60.     }
  61.     newNpc = function(e) {
  62.         _n.apply(this, arguments);
  63.         for (let i in e) {
  64.             let heros = e[i];
  65.             if (map.mode != 5 && heros.wt > 79 && g.worldname != "experimental" && checkHerosData(heros.id)) {
  66.                 dane[heros.id] = {
  67.                     time: ut() + (10 * 60)
  68.                 }
  69.                 localStorage.setItem("adiherosybrutus", JSON.stringify(dane));
  70.                 sendToDiscord(heros.lvl, heros.nick, heros.icon, heros.x, heros.y);
  71.                 break;
  72.             }
  73.         }
  74.     }
  75. })(newNpc, ["https://discordapp.com/api/webhooks/636640361997008907/P8bUPy6AXyHysA9MG-NBKbFLWfv5lj3iMNYIFvP2dwfWQk2jfpFj29lsVr4svlhjdk-X"], unix_time)