Advertisement
Guest User

Untitled

a guest
Aug 12th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.07 KB | None | 0 0
  1. const Discord = require('discord.js');
  2. const bot = new Discord.Client();
  3. const Command = require('command');
  4.  
  5. const items = [ //Dragons
  6. {name: 'Dragon skill ancient mighty fire', id: 99104, price: 'undefined'},
  7. {name: 'Dragon skill ancient mighty armored', id: 99120, price: 'undefined'},
  8. //Costumes
  9. {name: 'Smart box: Designer shirt', id: 246112, price: 'undefined'},
  10. {name: 'Elin designer shirt', id: 246112, price: 'undefined'},
  11. {name: 'Smart box: Dyeable Chambermaid', id: 246081, price: 100000},
  12. {name: 'Elleon moon', id: 246003, price: 50000}];
  13. {name: 'Dyeable black stocking', id: 177896, price: 'undefined'},
  14. {name: 'Dyeable white stocking', id: 177761, price: 'undefined'},
  15. //Expensive products
  16. {name: 'Liberation scroll', id: 94002, price: 100000},
  17. {name: 'Noble enigmatic', id: 179886, price: 100000},
  18. //Innerwears
  19. {name: 'Quality fresh', id: 99462, price: 120000},
  20. {name: 'Splendid sporty', id: 97938, price: 90000},
  21. {name: 'Splendid fresh', id: 97936, price: 40000},
  22. //Regular supplies
  23. {name: 'Semi-enigmatic scroll', id: 399, price: 1000},
  24. {name: 'Spellbind', id: 445, price: 120},
  25. {name: 'Combat acc', id: 150940, price: 120},
  26. {name: 'Master enigmatic scroll', id: 71, price: 110},
  27. {name: 'Lamb bulgogi', id: 71418, price: 350},
  28. {name: 'Strong cane', id: 150535, price: 300},
  29. {name: 'Noctenium infusion', id: 1300, price: 1.3}]
  30.  
  31. module.exports = function brokerAlerter(dispatch) {
  32.  
  33. let enabled = false;
  34. let timer = null;
  35. let i = 0;
  36. const command = Command(dispatch)
  37.  
  38. //Commands
  39. command.add('camper', () => {
  40. if(!enabled) {
  41. enabled = true;
  42. console.log('Starting.');
  43. command.message('Broker Checker: <font color="#00FF00">enabled</font><font color="#F86EFF">.</font>');
  44. searchPrices();
  45. }
  46. else {
  47. console.log('Stopping.');
  48. command.message('Broker Checker: <font color="#FF0000">disabled</font><font color="#F86EFF">.</font>');
  49. stop();
  50. }
  51. })
  52.  
  53. //Turning off when logging out
  54. dispatch.hook('C_RETURN_TO_LOBBY', 1, () => {
  55. if(enabled) {
  56. command.message('<font color="#fc0008">Stopping cuz you chose to log out.</font>');
  57. stop();
  58. }
  59. })
  60.  
  61. //Turning on when logging in
  62. dispatch.hook('S_LOGIN', 1, event => {
  63. enabled = true;
  64. searchPrices();
  65. });
  66.  
  67. //Hooking the results of the broker search
  68. dispatch.hook('S_TRADE_BROKER_WAITING_ITEM_LIST', 1, event => {
  69. if(enabled && event.listings.length > 0) {
  70. var itemID = event.listings[0].item;
  71. var itemPrice = event.listings[0].price.low/event.listings[0].quantity/10000;
  72. for(var j = 0; j < items.length; j++) {
  73. if(items[j].id == itemID && (items[j].price == 'undefined' || itemPrice <= items[j].price)) {
  74. console.log('found product');
  75. message(items[j].name + ' at broker for ' + itemPrice + 'g each!');
  76. }
  77. }
  78. }
  79. })
  80.  
  81. //Function to search broker for items
  82. function searchPrices() {
  83. if(enabled) {
  84. if(i >= items.length) {
  85. i = 0;
  86. }
  87. console.log("Searching for product: " + items[i].name);
  88. dispatch.toServer('C_TRADE_BROKER_WAITING_ITEM_LIST_NEW', 1, {
  89. lvlMin: 1,
  90. lvlMax: 65,
  91. rarity: 0,
  92. negotiable: 0,
  93. idStatus: 0,
  94. masterwork: 0,
  95. enchantable: 0,
  96. itemLvlMin: 0,
  97. itemLvlMax: 597,
  98. tierMin: 0,
  99. tierMax: 12,
  100. enchantMin: 0,
  101. enchantMax: 15,
  102. priceMin: { low: 1, high: 0, unsigned: false },
  103. priceMax: { low: 1115752192, high: 23, unsigned: false },
  104. unk1: 0,
  105. unk11: 1,
  106. exact: 0,
  107. unk2: 0,
  108. unk3: 0,
  109. unk4: 90000000,
  110. unk5: 0,
  111. unk6: 0,
  112. query: items[i].name,
  113. categories: '',
  114. items: '',
  115. query2: ''
  116. })
  117. i++;
  118. }
  119. timer = setTimeout(searchPrices, Math.floor(Math.random() * 5000) + 5000)
  120. }
  121.  
  122. //Function to stop
  123. function stop() {
  124. clearTimeout(timer)
  125. enabled = false
  126. }
  127.  
  128. bot.login('MzQ2MDAyMzA2ODYyNTQ2OTQ0.DHDlaQ.Ul7HvRdNZ-cHteNEfZGsfei0e0M');
  129. var channel;
  130.  
  131. bot.on('ready', () => {
  132. channel = bot.channels.get('346011481869123595');
  133. channel.send('Broker bot activated.');
  134. });
  135.  
  136. function message(msg) {
  137. channel.send(msg);
  138. }
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement