· 5 years ago · Dec 15, 2020, 09:14 PM
1const Discord = require('discord.js');
2const request = require('request');
3const $ = require ('jquery');
4const client = new Discord.Client();
5const APIKey = 'CgWsfUhtfSeEqizO';//mavri
6const APIKey2 = 'tpZoyS5zrFHeXGFW';//spek
7const APIKey3 = '1fSKxqrglksLbHcU';//doro
8const APIKey4 = '0ypDSNwooPCj2jO9';//d4
9const APIKey5 = 'enFaMboaewvgKeFf';//ross
10
11// While yes this might seem retarded at first, my initial intention
12// was to modify these and switch them around, which was a retarded
13// decision, so I just have 2 sets of consts that are identical. cool.
14const API1 = 'CgWsfUhtfSeEqizO';//mavri
15const API2 = 'enFaMboaewvgKeFf';//ross
16const API3 = '0ypDSNwooPCj2jO9';//d4
17const API4 = 'tpZoyS5zrFHeXGFW'//doro
18const API5 = 'tpZoyS5zrFHeXGFW'//spek
19
20let currentKey = 'CgWsfUhtfSeEqizO';// starts from doro goes trough all of them, and eventually returns
21
22const prefix = '!';
23const token = 'NTgwMTE5NzAwMzQ4ODYyNDkx.XOMEkg.Fv0gYF0kPq527d9oZVJ6zFDYzPU';//extremely competent discord bot
24client.login(token);
25client.on('ready', () => {
26
27 console.log('Ready!')
28 const ChannelID = client.channels.cache.get('785572623253504010');
29 const target = client.channels.cache.get('765652992812646431');
30 let id = client.channels.cache.get('764847389135601685');
31 Start(id);
32/*
33 ReviveMessage(ChannelID);
34
35 LowPriceNotifications('Donator Pack', 283, 23900000, 'https://i.imgur.com/t4Zsw6j.png', APIKey2, target);
36 //LowPriceNotifications('Dumbbells', 331, 440000000, 'https://i.imgur.com/Z7YF1oM.png', APIKey2, target);
37 //LowPriceNotifications('Cesium-137', 336, 360000000, 'https://i.imgur.com/45LFEyj.png', APIKey2, target);
38 LowPriceNotifications('Erotic DVD', 366, 3200000, 'https://i.imgur.com/oO3v17M.png', APIKey2, target);
39
40 LowPriceNotifications('Feathery Hotel Coupon', 367, 13000000, 'https://i.imgur.com/Z6OAoct.png', APIKey4, target);
41 //LowPriceNotifications('Lottery Voucher', 369, 855000, 'https://i.imgur.com/F3JsXpI.png', APIKey4, target);
42 LowPriceNotifications('Drug Pack', 370, 4000000, 'https://i.imgur.com/zho6jc4.png', APIKey4, target);
43 LowPriceNotifications('Business Class Ticket', 396, 6800000, 'https://i.imgur.com/LHIy6nE.png', APIKey4, target);
44 LowPriceNotifications('Xanax', 206, 825000, 'https://i.imgur.com/UT89sqY.png', APIKey4, target);
45
46 LowPriceNotifications('Six Pack of Energy Drink', 818, 17300000, 'https://i.imgur.com/5EKXuZK.png', APIKey2, target);
47 LowPriceNotifications('Can of Crocozade (15E)', 987, 1250000, 'https://i.imgur.com/GiJOytR.png', APIKey3, target);
48 LowPriceNotifications('Can of Santa Shooters (20E)', 553, 1700000, 'https://i.imgur.com/o6EmqVu.png', APIKey2, target);
49 LowPriceNotifications('Can of Munster (20E)', 530, 1950000, 'https://i.imgur.com/4paFeWx.png', APIKey3, target);
50
51 LowPriceNotifications('Can of Rockstar Rudolph (25E)', 554, 2400000, 'https://i.imgur.com/tJsHUC8.png', APIKey5, target);
52 LowPriceNotifications('Can of Red Cow (25E)', 532, 2400000, 'https://i.imgur.com/3fy8PxW.png', APIKey5, target);
53 LowPriceNotifications('Can of Taurine Elite (30E)', 533, 4100000, 'https://i.imgur.com/JPMdijd.png', APIKey4, target);
54 LowPriceNotifications('Can of X-MASS (30E)', 555, 4200000, 'https://i.imgur.com/0haxhPQ.png', APIKey5, target);
55
56 */
57});
58
59client.on('error', console.error);
60
61let bruh = 0;
62
63client.on('message', message => {
64 //console.log('Received!');
65 if (message.content.includes('torn.com/profiles.php?XID=') || message.content.includes('tornabc.com/loader.php?sid=attack&user2ID=')) {
66 ++bruh;
67 console.log(message.content);
68 let id_start = message.content.indexOf('torn.com/profiles.php?XID=') + 26;
69 let id_end = message.content.indexOf('#/');
70 let player_id = Number(message.content.substring(id_start, id_end));
71 let temp_player_id = '0';
72 let player_name = '0';
73 let player_level = '0';
74 let player_age = '0';
75 let player_last_action = '0';
76 let player_xanax = '0';
77 let player_faction_name = '0';
78 let player_faction_id = '0';
79 let player_status = '0';
80 //console.log(id_start);
81 if (id_start !== 25) {
82 id_start = message.content.indexOf('torn.com/loader.php?sid=attack&user2ID=') + 39;
83 for (let i = id_start; i < message.content.length + 1; ++i) {
84 temp_player_id = Number(message.content.substring(id_start, i));
85 //console.log(temp_player_id);
86 player_id = temp_player_id;
87 }
88 }
89 console.log(player_id);
90 if (player_id !== 0 && player_id !== 4 && player_id !== 15) {
91 request({ url: 'https://api.torn.com/user/' + temp_player_id + '?selections=&key=' + currentKey, json: true }, function (error, response, body) {
92 if (typeof (body) != 'undefined') {
93 if (typeof (body.error) != 'undefined') {
94 if (body.error.error === 'Incorrect key') {
95 console.log('Incorrect key');
96 process.exit();
97 }
98 }
99 if (typeof (body.status) !== 'undefined') {
100 player_name = body.name;
101 player_level = body.level;
102 player_age = body.age;
103 player_age = formatNumber(player_age);
104 console.log(player_age);
105 console.log(player_name);
106 player_status = body.status.description;
107 player_last_action = body.last_action.relative;
108 player_faction_name = body.faction.faction_name;
109 player_faction_id = body.faction.faction_id;
110 }
111 }
112 });
113 request({ url: 'https://api.torn.com/user/' + player_id + '?selections=personalstats&key=' + currentKey, json: true }, function (error, response, body) {
114 if (typeof (body) != 'undefined') {
115 if (typeof (body.error) != 'undefined') {
116 if (body.error.error === 'Incorrect key') {
117 console.log('Incorrect key');
118 process.exit();
119 }
120 }
121 if (typeof (body.personalstats) !== 'undefined') {
122 player_xanax = body.personalstats.xantaken;
123 }
124 else console.log("Xanax is undefined, help");
125 }
126 });
127
128 if (player_xanax === '0')
129 player_xanax = "Might Be Wrong (0)";
130 //if (player_id === 2402357)
131 //player_id = '69besteweeb69';
132
133 setTimeout(function () {
134
135 let UserInfo = {
136 title: player_name + ' [' + player_id + ']',
137 url: 'https://www.torn.com/profiles.php?XID=' + player_id,
138 description: '[Attack](https://www.torn.com/loader.php?sid=attack&user2ID=' + player_id + ')\n' +
139 'Faction: [' + player_faction_name + '](https://www.torn.com/factions.php?step=profile&ID=' + player_faction_id + ')',
140 fields: [
141 {
142 name: 'Level',
143 value: player_level,
144 inline: true,
145 },
146 {
147 name: 'Age',
148 value: player_age,
149 inline: true,
150 },
151 {
152 name: 'Xanax',
153 value: player_xanax,
154 inline: true,
155 },
156 {
157 name: 'Status',
158 value: player_status,
159 inline: false,
160 },
161 {
162 name: 'Last Action',
163 value: player_last_action,
164 inline: false,
165 }
166 ]
167 };
168 if (player_name !== '0' && player_level !== '0')
169 message.channel.send({ embed: UserInfo });
170 else message.channel.send("API System Messed Up");
171 }, 200);
172
173 if (bruh > 2) {
174 bruh = 0;
175 if (currentKey === API1){
176 currentKey = API2;
177 message.channel.send("`Switched to Ross's API Key!`")
178 }
179 else if (currentKey === API2){
180 currentKey = API3;
181 message.channel.send("`Switched to Arnout's API Key!`")
182 }
183 else if (currentKey === API3){
184 currentKey = API4;
185 message.channel.send("`Switched to Doro's API Key!`")
186 }
187 else if (currentKey === API4){
188 currentKey = API5;
189 message.channel.send("`Switched to Spek's API Key!`")
190 }
191 else if (currentKey === API5){
192 currentKey = API1;
193 message.channel.send("`Switched to Mavri's API Key!`")
194 }
195
196 }
197 }
198 } else if (message.content === `${prefix}server`) {
199 message.channel.send(`Server name: ${message.guild.name}\nTotal members: ${message.guild.memberCount}`);
200 } else if (message.content === `${prefix}user-info`) {
201 message.channel.send(`Your username: ${message.author.username}\nYour ID: ${message.author.id}`);
202 } else if (message.content === 'boi, make Ross cry') {
203 message.channel.send('https://cdn.discordapp.com/attachments/724731046372966420/764634464109592597/Dear_HentaiHaven_TM-3.mp4');
204 } else if (message.content === '!revives INQ') {
205 faction = INQ;
206 message.channel.send('Watching INQ!');
207 } else if (message.content === '!revives HHU') {
208 faction = HHU;
209 message.channel.send('Watching HHU!');
210 } else if (message.content === '.,botstop') {
211 process.exit();
212 } else if (message.content === '!version')
213 {
214 let BotInfo = {
215 title: 'Inquisitor Dev Bot',
216 url: 'https://www.mavriware.me/discord',
217 description: 'It is the best bot you will ever see',
218 fields: [
219 {
220 name: 'Version:',
221 value: '1.1.1',
222 inline: true,
223 },
224 {
225 name: 'Time since last update:',
226 value: 'Quite a long time.',
227 inline: true,
228 },
229 {
230 name: 'Status:',
231 value: 'Looks Fairly Online To Me.',
232 inline: false,
233 },
234 ]
235 };
236 message.channel.send({embed: BotInfo});
237 }
238 else if (message.content === '!ping') {
239 message.reply(`Latency is ${message.createdTimestamp - Date.now()}ms. API Latency is ${Math.round(client.ws.ping)}ms`);
240 } else if (message.content === '!start chain') {
241 message.channel.send('yo that is kinda pog starting chain');
242 Start();
243 }
244});
245
246
247function formatNumber(num) {
248 return num.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,');
249}
250
251var oldprice = [];
252const HHU = 40664;
253const INQ = 15929;
254var faction = INQ;
255for (i = 1; i <= 987; i++)
256 oldprice[i] = 999999999999;
257// this is absolutely retarded, but it works
258let hospitalArr = new Array(3000000).fill(0);
259function ReviveMessage(ChannelID){
260 setInterval(function(){
261 request({url: 'https://api.torn.com/faction/' + faction + '?selections=&key='+APIKey3, json: true}, function (error, response, body) {
262 if(typeof(body) != 'undefined'){
263 if(typeof(body.error) != 'undefined'){
264 if(body.error.error === 'Incorrect key') {
265 console.log('Incorrect key');
266 process.exit();
267 }
268 }
269 console.log();
270 let members = body.members;
271 for (var prop in members) {
272 if (Object.prototype.hasOwnProperty.call(members, prop)) {
273 let ajutor = members[prop].status.description;
274 if (ajutor.includes('hospital') && hospitalArr [prop] === 0){
275 console.log(ajutor);
276 console.log(prop);
277 let embed1 = {
278 title: members[prop].name + ' [' + prop + ']',
279 url: 'https://www.torn.com/profiles.php?XID=' + prop,
280 description: ajutor,
281 fields: [
282 {
283 name: 'Last Action',
284 value: members[prop].last_action.relative,
285 inline: true,
286 },
287 {
288 name: 'Status',
289 value: members[prop].last_action.status,
290 inline: true,
291 }
292 ]
293 //image: {
294 //url: 'https://i.imgur.com/becvi0j.jpeg',
295 //},
296 };
297 ChannelID.send({embed: embed1})
298 hospitalArr[prop] = 1;
299 } else if (hospitalArr [prop] === 1 && !ajutor.includes('hospital')){
300 let embed0 = {
301 title: members[prop].name + ' [' + prop + ']',
302 url: 'https://www.torn.com/profiles.php?XID=' + prop,
303 description: 'Is no longer hospitalized!',
304 //image: {
305 //url: 'https://i.imgur.com/becvi0j.jpeg',
306 //},
307 };
308
309 ChannelID.send({embed: embed0});
310 hospitalArr[prop] = 0;
311
312 }
313 }
314 }
315 }
316 });
317},6000);
318}
319
320
321function LowPriceNotifications(ItemName, ItemID, MaxPrice, ImageLink, Key, target) {
322 setInterval(function(){
323 request({url: 'https://api.torn.com/market/'+ItemID+'?selections=&key='+Key, json: true}, function (error, response, body) {
324 if(typeof(body) != 'undefined'){
325 if(typeof(body.error) != 'undefined'){
326 if(body.error.error === 'Incorrect key') {
327 console.log('Incorrect key');
328 process.exit();
329 }
330 }
331 var baz = body.bazaar;
332 var RA = [];
333 var price = [];
334 for (i in baz)
335 {
336 RA.push([i,baz[i].cost,baz[i].quantity]);
337 }
338 RA.sort(function(a,b){return a[1] - b[1];});
339 if(typeof(RA[0]) != 'undefined'){
340 price[ItemID] = RA[0][1];
341 var count = 0;
342 for(i in RA){
343 if(i !== 0 && RA[i][1] !== RA[i-1, 1]){
344 break;
345 }
346 count = count + RA[1][2];
347 }
348 //if (!error && response.statusCode === 200) {
349 if(price[ItemID] < MaxPrice && price[ItemID] !== oldprice[ItemID]){
350 console.log(ItemName + ': ' + price[ItemID] + ' old: ' + oldprice[ItemID]);
351 let item_embed = {
352 title: ItemName,
353 url: 'https://www.torn.com/imarket.php#/p=shop&type=' + ItemID,
354 thumbnail: {
355 url: ImageLink,
356 },
357 fields: [
358 {
359 name: 'Alerting When Below',
360 value: '$' + formatNumber(MaxPrice),
361 inline: true,
362 },
363 {
364 name: 'Current Price',
365 value: '$' + formatNumber(price[ItemID]),
366 inline: true,
367 }
368 ]
369 };
370 target.send({ embed: item_embed });
371 oldprice[ItemID] = price[ItemID];
372 }
373 //}
374
375 }
376 }
377 });
378 },30000);
379}
380
381let oldUsers = [];
382let oldContributions = [];
383
384let newUsers = [];
385let newContributions = [];
386
387let updateOld;
388
389
390
391function ConvertObjectToArray(speedData, id){
392 updateOld = false; //we dont need to update the old at this point. We want this to only get set if we find differences in peoples contributions.
393
394 if(oldUsers.length < 1){ //check if old users has been assigned, if so we only need to get the new users.
395
396 for(i = 0; i < Object.keys(speedData).length; i++){
397 if(Object.entries(speedData)[i][1].in_faction == 0){
398 //removes them from the database by not including in new one
399 } else {
400
401 //adds them to our 2 old arrays
402 oldUsers.push(Object.entries(speedData)[i][0]);
403 oldContributions.push(Object.entries(speedData)[i][1].contributed);
404
405 }
406 }
407 console.log("Assigned "+ oldUsers.length +" old users");
408
409
410 } else {
411
412 newUsers = [];
413 newContributions = [];
414
415 for(i = 0; i < Object.keys(speedData).length; i++){
416 if(Object.entries(speedData)[i][1].in_faction === 0){
417 //removes them from the database by not including in new one
418 } else {
419 //adds them to our 2 new arrays
420 newUsers.push(Object.entries(speedData)[i][0]);
421 newContributions.push(Object.entries(speedData)[i][1].contributed);
422 }
423 }
424
425 console.log("Assigned "+ newUsers.length +" new users");
426 }
427
428 if(newUsers.length >= 1){ //only do this if we have a newUsers array with at least 1 entry
429 CheckForDifferences(id);
430 }
431
432}
433
434function CheckForDifferences(id){
435 for (i = 0; i < newUsers.length; i++){ //cycle through our current users
436 for(x = 0; x < oldUsers.length; x++){ //check our 'old users'
437 if(newUsers[i] === oldUsers[x]){ //find our 'current users' in our 'older users' array
438 if(newContributions[i] > oldContributions[x]){ //check if they have spent energy
439
440 Alert(newUsers[i], oldContributions[x], newContributions[i], id); //sends who, oldValue and newValue to the alert method. Best to get this away from here so you can fuck around with discord or do what you like.
441
442 }
443 }
444 }
445 }
446
447 if(updateOld){
448 oldUsers = [];
449 oldContributions = [];
450 oldUsers = newUsers;
451 oldContributions = newContributions;
452 console.log("Reassigned old users to new users");
453 }
454}
455
456function Alert(who, oldV, newV, id){
457 //sets up the alert by printing to console, do whatever you want with this.
458 let diff = newV - oldV;
459 console.log(newUsers[i] + " has spent " + diff + " Energy at the Gym." + "\n" + "Old contribution: "+ oldV + "\n" + "New Contribution: "+ newV);
460 updateOld = true; //we need to update oldNames ready for the next check.
461 id.send(newUsers[i] + " has spent " + diff + " Energy at the Gym." + "\n" + "Old contribution: "+ oldV + "\n" + "New Contribution: "+ newV);
462}
463
464
465function Start(id){
466 setInterval(function GetData(){
467 request({ url: "https://api.torn.com/faction/?selections=contributors&stat=gymspeed&key=CgWsfUhtfSeEqizO", json: true }, function (error, response, body) { //gets the data from that link
468 speedData = body.contributors.gymspeed; //gets to the actual content
469 ConvertObjectToArray(speedData, id); //asks the function to convert this nonsense to useable data.
470 });
471 console.log("Re/Started the loop.");
472
473 }, 20000);
474}
475