Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Webhook Notifications - PEC
- // @namespace PEC
- // @version 2.8.3
- // @author Hypercube
- // @description Sends a message to the Discord clan server when you find a hero+ mob.
- // @icon https://assets.xeyven.pl/logos/pec.png
- // @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/615243675802533888/sEFK6sC5G-C-n--TanKma6uP23DBHJJ5Lk9NK9A5nPGxk4mOJ62X8P39VJ6BW9-VW63X';
- 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 > 90) {
- const type =
- npc.wt < 100 ? 'heros' : getMapProp('mode') !== 5 ? 'tytan' : 'kolos';
- const color =
- type === 'heros' ? 3448267 : type === 'tytan' ? 12718623 : 8037675;
- sendMessage({
- ...npc,
- color,
- imageURI: window.location.origin + (NI ? CFG.npath : '') + npc.icon,
- stringifiedType: type
- });
- }
- }
- function sendMessage(mob) {
- const message = {
- username: mob.nick,
- avatar_url: mob.imageURI,
- content: '@everyone',
- 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();
- }
- };
- })();
Add Comment
Please, Sign In to add comment