Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Webhook Notifications - PEC
- // @namespace PEC
- // @version 2.8.4
- // @author Hypercube
- // @description Sends a message to the Discord clan server when you find a hero+ mob.
- // @updateURL https://margonem.xeyven.pl/addons/pec/webhook-notifications.user.js
- // @downloadURL https://margonem.xeyven.pl/addons/pec/webhook-notifications.user.js
- // @match http://tempest.margonem.pl
- // @run-at document-end
- // @grant none
- // ==/UserScript==
- (() => {
- const NI = getCookie('interface') === 'ni';
- const URI =
- 'https://discordapp.com/api/webhooks/750406396633153689/_TM41ZfZCESMYNeHX8GYrfLk2qqs1Y4MTnGQemSSdWn8gvvItES0XZdPsmRs5przNS1Z';
- let loaded = false;
- let started = false;
- function getCookie(name) {
- const value = '; ' + document.cookie;
- const parts = value.split(`; ${name}=`);
- if (parts.length == 2) {
- return parts.pop().split(';')[0];
- }
- }
- function myNick() {
- return NI ? Engine.hero.d.nick : hero.nick;
- }
- function getMapProp(prop) {
- return NI ? Engine.map.d[prop] : map[prop];
- }
- function checkNpc(npc) {
- if (npc.wt > 79 && npc.lvl > 89) {
- const type =
- npc.wt < 100 ? 'heros' : getMapProp('mode') !== 5 ? 'tytan' : 'kolos';
- const color =
- type === 'heros' ? 3448267 : type === 'tytan' ? 12718623 : 12345678;
- sendMessage({
- ...npc,
- color,
- imageURI: window.location.origin + (NI ? CFG.npath : '') + npc.icon,
- stringifiedType: type
- });
- }
- }
- function sendMessage(mob) {
- let rolePing = ''
- switch(mob.nick){
- case 'Perski książę':
- rolePing= '<@&750411110276136980>'
- break;
- case 'Baca bez łowiec':
- rolePing= '<@&750410920370503801>'
- break;
- case 'Lichwiarz Grauhaz':
- rolePing= '<@&750394834745032955>'
- break;
- case 'Obłąkany łowca orków':
- rolePing= '<@&750395676583526491>'
- break;
- case 'Czarująca Atalia':
- rolePing= '<@&750425691815805038>'
- break;
- case 'Święty braciszek':
- rolePing= '<@&750396443273068575>'
- break;
- case 'Viviana Nandin':
- rolePing= '<@&750396900632559617>'
- break;
- case 'Mulher Ma':
- rolePing= '<@&750397524451393656>'
- break;
- case 'Demonis Pan Nicości':
- rolePing= '<@&750398428042756126>'
- break;
- case 'Vapor Veneno':
- rolePing= '<@&750399001697976481>'
- break;
- case 'Dęborożec':
- rolePing= '<@&750399225564758076>'
- break;
- case 'Tepeyollotl':
- rolePing= '<@&750400178120294421>'
- break;
- case 'Negthotep Czarny Kapłan':
- rolePing= '<@&750400178120294421>'
- break;
- case 'Młody smok':
- rolePing= '<@&750400178120294421>'
- break;
- case 'Renegat Baulus':
- rolePing= '<@&750415601830330461>'
- break;
- case 'Piekielny Arcymag':
- rolePing= '<@&750415611732951180>'
- break;
- case 'Versus Zoons':
- rolePing= '<@&750415616653131877>'
- break;
- case 'Łowczyni wspomnień':
- rolePing= '<@&750415632268525721>'
- break;
- case 'Przyzywacz demonów':
- rolePing= '<@&750415636387070042>'
- break;
- case 'Maddok Magua':
- rolePing= '<@&750416020706951229>'
- break;
- case 'Tezcatlipoca':
- rolePing= '<@&750416028193915041>'
- break;
- case 'Tanroth':
- rolePing= '<@&750416037366988810>'
- break;
- }
- const message = {
- username: mob.nick,
- avatar_url: mob.imageURI,
- content: rolePing,
- embeds: [
- {
- color: mob.color,
- title: `${myNick()} znalazł ${mob.stringifiedType}a`,
- thumbnail: {
- url: mob.imageURI
- },
- fields: [
- {
- inline: true,
- name: new Date().toLocaleString(),
- value: `\`${mob.nick} ${mob.lvl} lvl\n${getMapProp('name')} (${
- mob.x
- }, ${mob.y})\``
- }
- ]
- }
- ]
- };
- fetch(URI, {
- method: 'POST',
- cache: 'no-cache',
- headers: { 'Content-Type': 'application/json' },
- body: JSON.stringify(message)
- }).catch(error => {
- console.error(error);
- log('Błąd przy wysyłaniu danych do webhooka PEC', 2);
- log(error, 2);
- });
- }
- function start() {
- if (NI) {
- API.addCallbackToEvent('newNpc', data => {
- if (data && data.d) {
- checkNpc(data.d);
- }
- });
- } else {
- const oldNewNpc = newNpc;
- newNpc = npcs => {
- oldNewNpc(npcs);
- if (npcs) {
- for (const npc of Object.values(npcs)) {
- checkNpc(npc);
- }
- }
- };
- }
- const npcs = NI ? Engine.npcs.check() : g.npc;
- for (const npc of Object.values(npcs)) {
- checkNpc(npc);
- }
- }
- const oldSend = XMLHttpRequest.prototype.send;
- XMLHttpRequest.prototype.send = function() {
- const callback = this.onreadystatechange;
- this.onreadystatechange = function() {
- if (4 === this.readyState) {
- if (this.responseURL.includes('margonem.pl/engine?t=init&initlvl=4')) {
- loaded = true;
- }
- }
- if (callback !== null) {
- callback.apply(this, arguments);
- }
- };
- oldSend.apply(this, arguments);
- if (loaded && !started) {
- started = true;
- start();
- }
- };
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement