Advertisement
satiel7314

Untitled

Feb 8th, 2021
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.32 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Webhook Notifications - PEC
  3. // @namespace PEC
  4. // @version 2.8.4
  5. // @author Hypercube
  6. // @description Sends a message to the Discord clan server when you find a hero+ mob.
  7. // @updateURL https://margonem.xeyven.pl/addons/pec/webhook-notifications.user.js
  8. // @downloadURL https://margonem.xeyven.pl/addons/pec/webhook-notifications.user.js
  9. // @match http://tempest.margonem.pl
  10. // @run-at document-end
  11. // @grant none
  12. // ==/UserScript==
  13. (() => {
  14. const NI = getCookie('interface') === 'ni';
  15. const URI =
  16. 'https://discordapp.com/api/webhooks/750406396633153689/_TM41ZfZCESMYNeHX8GYrfLk2qqs1Y4MTnGQemSSdWn8gvvItES0XZdPsmRs5przNS1Z';
  17. let loaded = false;
  18. let started = false;
  19.  
  20. function getCookie(name) {
  21. const value = '; ' + document.cookie;
  22. const parts = value.split(`; ${name}=`);
  23.  
  24. if (parts.length == 2) {
  25. return parts.pop().split(';')[0];
  26. }
  27. }
  28.  
  29. function myNick() {
  30. return NI ? Engine.hero.d.nick : hero.nick;
  31. }
  32.  
  33. function getMapProp(prop) {
  34. return NI ? Engine.map.d[prop] : map[prop];
  35. }
  36.  
  37. function checkNpc(npc) {
  38. if (npc.wt > 79 && npc.lvl > 89) {
  39. const type =
  40. npc.wt < 100 ? 'heros' : getMapProp('mode') !== 5 ? 'tytan' : 'kolos';
  41. const color =
  42. type === 'heros' ? 3448267 : type === 'tytan' ? 12718623 : 12345678;
  43.  
  44. sendMessage({
  45. ...npc,
  46. color,
  47. imageURI: window.location.origin + (NI ? CFG.npath : '') + npc.icon,
  48. stringifiedType: type
  49. });
  50. }
  51. }
  52.  
  53. function sendMessage(mob) {
  54. let rolePing = ''
  55. switch(mob.nick){
  56. case 'Perski książę':
  57. rolePing= '<@&750411110276136980>'
  58. break;
  59. case 'Baca bez łowiec':
  60. rolePing= '<@&750410920370503801>'
  61. break;
  62. case 'Lichwiarz Grauhaz':
  63. rolePing= '<@&750394834745032955>'
  64. break;
  65. case 'Obłąkany łowca orków':
  66. rolePing= '<@&750395676583526491>'
  67. break;
  68. case 'Czarująca Atalia':
  69. rolePing= '<@&750425691815805038>'
  70. break;
  71. case 'Święty braciszek':
  72. rolePing= '<@&750396443273068575>'
  73. break;
  74. case 'Viviana Nandin':
  75. rolePing= '<@&750396900632559617>'
  76. break;
  77. case 'Mulher Ma':
  78. rolePing= '<@&750397524451393656>'
  79. break;
  80. case 'Demonis Pan Nicości':
  81. rolePing= '<@&750398428042756126>'
  82. break;
  83. case 'Vapor Veneno':
  84. rolePing= '<@&750399001697976481>'
  85. break;
  86. case 'Dęborożec':
  87. rolePing= '<@&750399225564758076>'
  88. break;
  89. case 'Tepeyollotl':
  90. rolePing= '<@&750400178120294421>'
  91. break;
  92. case 'Negthotep Czarny Kapłan':
  93. rolePing= '<@&750400178120294421>'
  94. break;
  95. case 'Młody smok':
  96. rolePing= '<@&750400178120294421>'
  97. break;
  98. case 'Renegat Baulus':
  99. rolePing= '<@&750415601830330461>'
  100. break;
  101. case 'Piekielny Arcymag':
  102. rolePing= '<@&750415611732951180>'
  103. break;
  104. case 'Versus Zoons':
  105. rolePing= '<@&750415616653131877>'
  106. break;
  107. case 'Łowczyni wspomnień':
  108. rolePing= '<@&750415632268525721>'
  109. break;
  110. case 'Przyzywacz demonów':
  111. rolePing= '<@&750415636387070042>'
  112. break;
  113. case 'Maddok Magua':
  114. rolePing= '<@&750416020706951229>'
  115. break;
  116. case 'Tezcatlipoca':
  117. rolePing= '<@&750416028193915041>'
  118. break;
  119. case 'Tanroth':
  120. rolePing= '<@&750416037366988810>'
  121. break;
  122.  
  123. }
  124. const message = {
  125. username: mob.nick,
  126. avatar_url: mob.imageURI,
  127. content: rolePing,
  128. embeds: [
  129. {
  130. color: mob.color,
  131. title: `${myNick()} znalazł ${mob.stringifiedType}a`,
  132. thumbnail: {
  133. url: mob.imageURI
  134. },
  135. fields: [
  136. {
  137. inline: true,
  138. name: new Date().toLocaleString(),
  139. value: `\`${mob.nick} ${mob.lvl} lvl\n${getMapProp('name')} (${
  140. mob.x
  141. }, ${mob.y})\``
  142. }
  143. ]
  144. }
  145. ]
  146. };
  147.  
  148. fetch(URI, {
  149. method: 'POST',
  150. cache: 'no-cache',
  151. headers: { 'Content-Type': 'application/json' },
  152. body: JSON.stringify(message)
  153. }).catch(error => {
  154. console.error(error);
  155.  
  156. log('Błąd przy wysyłaniu danych do webhooka PEC', 2);
  157. log(error, 2);
  158. });
  159. }
  160.  
  161. function start() {
  162. if (NI) {
  163. API.addCallbackToEvent('newNpc', data => {
  164. if (data && data.d) {
  165. checkNpc(data.d);
  166. }
  167. });
  168. } else {
  169. const oldNewNpc = newNpc;
  170.  
  171. newNpc = npcs => {
  172. oldNewNpc(npcs);
  173.  
  174. if (npcs) {
  175. for (const npc of Object.values(npcs)) {
  176. checkNpc(npc);
  177. }
  178. }
  179. };
  180. }
  181.  
  182. const npcs = NI ? Engine.npcs.check() : g.npc;
  183.  
  184. for (const npc of Object.values(npcs)) {
  185. checkNpc(npc);
  186. }
  187. }
  188.  
  189. const oldSend = XMLHttpRequest.prototype.send;
  190.  
  191. XMLHttpRequest.prototype.send = function() {
  192. const callback = this.onreadystatechange;
  193.  
  194. this.onreadystatechange = function() {
  195. if (4 === this.readyState) {
  196. if (this.responseURL.includes('margonem.pl/engine?t=init&initlvl=4')) {
  197. loaded = true;
  198. }
  199. }
  200.  
  201. if (callback !== null) {
  202. callback.apply(this, arguments);
  203. }
  204. };
  205.  
  206. oldSend.apply(this, arguments);
  207.  
  208. if (loaded && !started) {
  209. started = true;
  210.  
  211. start();
  212. }
  213. };
  214. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement