-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
433 lines (394 loc) · 14.6 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
const puppeteer = require('puppeteer')
const Discord = require('discord.js')
const client = new Discord.Client()
const fs = require('fs');
const grabPage3 = async () => {
const browser = await puppeteer.launch()
const page = await browser.newPage()
await page.goto(website)
const el = await page.$('.ThumbnailLayouts__ThumbnailGrid-sc-18xwycr-0')
const buffer = await el.screenshot({ path: "./screenshot.png" })
await browser.close()
return buffer
}
const grabPage1 = async () => {
const browser = await puppeteer.launch()
const page = await browser.newPage()
await page.goto(website1)
const buffer = await page.screenshot({ path: "./screenshot.png" })
await browser.close()
return buffer
}
const grabPage2 = async () => {
const browser = await puppeteer.launch()
const page = await browser.newPage()
await page.goto(website)
const buffer = await page.screenshot({ path: "./screenshot.png" })
await browser.close()
return buffer
}
client.on('ready', () => {
console.log('I am ready!')
const activities_list = [
"For Drops",
"NBA TOP SHOT",
"For !help",
"People Win"
]; // creates an arraylist containing phrases you want your bot to switch through.
setInterval(() => {
const index = Math.floor(Math.random() * (activities_list.length - 1) + 1); // generates a random number between 1 and the length of the activities array list (in this case 5).
client.user.setActivity(activities_list[index], { type: 'WATCHING' }); // sets bot's activities to one of the phrases in the arraylist.
}, 5000); // Runs this every 10 seconds.
})
//Help Command
client.on('message', async message => {
if (message.content.includes('!help')) {
var help = '**Command: !p** \n Get The moments of a player. Player name all lower case. \n!p EXAMPLE: !p lebron james'+
'\n\n **Command: !s** \n Store a Specific Moment. Easiest is to just copy straight from the website. The moment name has to be seperated by a comma. \n !s EXAMPLE: !s KYLE ANDERSON Dunk Base Set (Series 2), https://www.nbatopshot.com/listings/p2p/208ae30a-a4fe-42d4-9e51-e6fd1ad2a7a9+a3cd9d63-7ca6-41c6-b8ee-a10733d02a96'+
' \n\n **Command: !m** \n Recall the moment stored using !s command. \n !m EXAMPLE: KYLE ANDERSON Dunk Base Set (Series 2)'+
'\n\n **Command: !add** \n Add an abbreviation for a moment, for personal use, and ease of access. comma comes after abbreviation. \n !add EXAMPLE: !add KA, https://www.nbatopshot.com/listings/p2p/208ae30a-a4fe-42d4-9e51-e6fd1ad2a7a9+a3cd9d63-7ca6-41c6-b8ee-a10733d02a96'+
'\n\n **Command: !u** \n Use The Added Abbreviation. \n !u EXAMPLE: !u KA'+
'\n\n **Command: !list** \n Get The List Of Stored Abbreviations. \n !list EXAMPLE: !list'+
'\n\n **Command: !rm** \n Remove a Previously Stored Abbreviation. \n !rm EXAMPLE: !rm KA'
const embed = new Discord.RichEmbed()
// Set the title of the field
.setTitle('Help And Commands')
// Set the color of the embed
.setColor(0xff0000)
// Set the main content of the embed
.setDescription(help.toString())
//console.log('message sent')
// Send the embed to the same channel as the message
message.channel.send(embed)
}
})
client.on('message', async message => {
if (message.content.includes('!rm')) {
var messagec = message.content
var sender = message.author.username + '#'+ message.author.discriminator;
var message1 = messagec.replace("!rm ","");
const fs = require('fs')
fs.readFile('./shortcuts.json', 'utf8', function (err,data1) {
if (err) {
return console.log(err);
}
var data1 = data1 + "}"
const data2 = JSON.parse(data1)
delete data2[sender][message1]
var data3 = JSON.stringify(data2)
var data3 = data3.replace(/\}([^}]*)$/,'')
fs.writeFile("./shortcuts.json", data3, (err) => {
if (err)
console.log(err);})
// We can create embeds using the MessageEmbed constructor
// Read more about all that you can do with the constructor
// over at https://discord.js.org/#/docs/main/stable/class/RichEmbed
const embed = new Discord.RichEmbed()
// Set the title of the field
.setTitle("Abbreviation Has Been Removed!")
// Set the color of the embed
.setColor(0xff0000)
// Set the main content of the embed
.setDescription('Brought To You By The NBA Top Shot Pros')
// Send the embed to the same channel as the message
message.channel.send(embed);
})
}
})
//Get List
client.on('message', async message => {
if (message.content.includes('!list')) {
var sender = message.author.username + '#'+ message.author.discriminator;
const fs = require('fs')
fs.readFile('./shortcuts.json', 'utf8', function (err,data1) {
if (err) {
return console.log(err);
}
var data1 = data1 + "}"
const data2 = JSON.parse(data1)
var listitems = data2[sender]
const textFormat = Object.entries(listitems)
.map(([key, value]) => key + ': ' + value)
.join('\n');
const embed = new Discord.RichEmbed()
// Set the title of the field
.setTitle('Here Is The Moments You Have Stored!')
// Set the color of the embed
.setColor(0xff0000)
// Set the main content of the embed
.setDescription(textFormat)
//console.log('message sent')
// Send the embed to the same channel as the message
message.channel.send(embed)
})
}
})
//Call Abbreviation
client.on('message', async message => {
if (message.content.includes('!u')) {
var messagec = message.content;
var message1 = messagec.replace("!u ","");
var sender = message.author.username + '#'+ message.author.discriminator;
const fs = require('fs')
fs.readFile('./shortcuts.json', 'utf8', function (err,data1) {
if (err) {
return console.log(err);
}
try {
var data1 = data1 + "}"
const data2 = JSON.parse(data1)
//console.log(message2)
var sendercheck = data2[sender];
website = data2[sender][message1]
//console.log(website)
async function myfunction() {
const grabPage2 = async () => {
const browser = await puppeteer.launch()
const page = await browser.newPage()
await page.goto(website)
const buffer = await page.screenshot({ path: "./screenshot.png", })
await browser.close()
return buffer
}
};
(async() => {
const buffer = await grabPage2(website);
// We can create embeds using the MessageEmbed constructor
// Read more about all that you can do with the constructor
// over at https://discord.js.org/#/docs/main/stable/class/RichEmbed
const embed = new Discord.RichEmbed()
// Set the title of the field
.setTitle('Here Is Your NBA Top Shot Stats For ' + message1 + '!')
// Set the color of the embed
.setColor(0xff0000)
// Set the main content of the embed
.setDescription('Brought To You By The NBA Top Shot Pros')
.attachFile(buffer)
//console.log('message sent')
// Send the embed to the same channel as the message
message.channel.send(embed)
fs.unlink("./screenshot.png",(err => {
if (err) console.log(err)}));
})();
}
catch (err) {
console.log(err)
}
})
}
})
//ADD Abbreviation
client.on('message', async message => {
if (message.content.includes('!add')&& message.content.includes(',')) {
var messagec = message.content;
//!add BB, JAMES HARDEN Layup Base Set (Series 2)
// 1. write abbreviation to file under sender name
//2. fetch the link from file
//3. save abbreviation and link to new file
var message1 = messagec.replace("!add ","");
var messagev = message1.split(",")
var sender = message.author.username + '#'+ message.author.discriminator;
var abbrev = messagev[0]
var alink = messagev[1]
var slink1= alink.replace(/\s+/g, '');
//console.log(mname,slink)
const fs = require('fs')
fs.readFile('./shortcuts.json', 'utf8', function (err,data1) {
if (err) {
return console.log(err);
}
try {
var data1 = data1 + "}"
const data2 = JSON.parse(data1)
//console.log(message2)
var sendercheck = data2[sender];
//console.log(data2)
data2[sender][abbrev] = alink
var data3 = JSON.stringify(data2)
var data3 = data3.replace(/\}([^}]*)$/,'')
fs.writeFile("./shortcuts.json", data3, (err) => {
if (err)
console.log(err);})
// We can create embeds using the MessageEmbed constructor
// Read more about all that you can do with the constructor
// over at https://discord.js.org/#/docs/main/stable/class/RichEmbed
const embed = new Discord.RichEmbed()
// Set the title of the field
.setTitle("Abbreviation Has Been Stored, You Can Now Use It")
// Set the color of the embed
.setColor(0xff0000)
// Set the main content of the embed
.setDescription('Brought To You By The NBA Top Shot Pros')
// Send the embed to the same channel as the message
message.channel.send(embed);
fs.unlink("./screenshot.png",(err => {
if (err) console.log(err)}));
}
catch(err) {
console.log(err)
const fs = require('fs');
let moment =`
"${sender}": {
"${abbrev}": "${alink}"
}`;
const data5 = ","+"\n" +(moment);
//console.log(data1)
fs.appendFile('./shortcuts.json', data5, (err) => {
if (err) {
console.log(err);
}
// We can create embeds using the MessageEmbed constructor
// Read more about all that you can do with the constructor
// over at https://discord.js.org/#/docs/main/stable/class/RichEmbed
const embed = new Discord.RichEmbed()
// Set the title of the field
.setTitle("Abbreviation Has Been Stored, It Can Now Be Used!")
// Set the color of the embed
.setColor(0xff0000)
// Set the main content of the embed
.setDescription('Brought To You By The NBA Top Shot Pros')
// Send the embed to the same channel as the message
message.channel.send(embed);
fs.unlink("./screenshot.png",(err => {
if (err) console.log(err)}));
});
//console.log('hello1')
}
})
}
})
//Store Moments for !m
client.on('message', async message => {
if (message.content.includes('!s')&& message.content.includes(',')) {
var messagec = message.content;
var message1 = messagec.replace("!s ","");
var messagev = message1.split(",")
var mname = messagev[0]
var slink = messagev[1]
var slink1= slink.replace(/\s+/g, '');
//console.log(mname,slink)
const fs = require('fs');
let moment =`
"${mname}": {
"website": "${slink}"
}`;
const data1 = ","+"\n" +(moment);
//console.log(data1)
fs.appendFile('./moments.json', data1, (err) => {
if (err) {
console.log(err);
}
// We can create embeds using the MessageEmbed constructor
// Read more about all that you can do with the constructor
// over at https://discord.js.org/#/docs/main/stable/class/RichEmbed
console.log('hello')
const embed = new Discord.RichEmbed()
// Set the title of the field
.setTitle("Moment Has Been Stored, It Can Now Be Recalled Using The !m Function!")
// Set the color of the embed
.setColor(0xff0000)
// Set the main content of the embed
.setDescription('Brought To You By The NBA Top Shot Pros')
// Send the embed to the same channel as the message
message.channel.send(embed);
fs.unlink("./screenshot.png",(err => {
if (err) console.log(err)}));
});
//console.log('hello1')
}
})
//GET Player Cards
client.on('message', async message => {
if (message.content.includes('!p')) {
var messagec = message.content;
var message1 = messagec.replace("!p ","");
var message3 = message1.replace(/\s+/g, '-');
var message2 = message3.toLowerCase();
var data = require("./playerlist.json")
var website1 = data[`${message2}`].link;
website = website1.replace(/\s+/g, '-');
async function myfunction() {
const grabPage3 = async () => {
const browser = await puppeteer.launch()
const page = await browser.newPage()
await page.goto(website)
const buffer = await page.screenshot({ path: "./screenshot.png", })
await browser.close()
return buffer
}
};
(async() => {
const buffer = await grabPage3(website);
// We can create embeds using the MessageEmbed constructor
// Read more about all that you can do with the constructor
// over at https://discord.js.org/#/docs/main/stable/class/RichEmbed
const embed = new Discord.RichEmbed()
// Set the title of the field
.setTitle('Here Is Your NBA Top Shot Stats For ' + message1 + '!')
// Set the color of the embed
.setColor(0xff0000)
// Set the main content of the embed
.setDescription('Brought To You By The NBA Top Shot Pros')
.attachFile(buffer)
//console.log('message sent')
// Send the embed to the same channel as the message
message.channel.send(embed)
fs.unlink("./screenshot.png",(err => {
if (err) console.log()}));
})();
}
})
//GET SPECIFIC MOMENT
client.on('message', async message => {
if (message.content.includes('!m')) {
var messagec = message.content;
var message1 = messagec.replace("!m ","");
const fs = require('fs')
fs.readFile('./moments.json', 'utf8', function (err,data1) {
if (err) {
return console.log(err);
}
//console.log(data1);
var data = data1 +"}"
const message2 = JSON.parse(data)
//console.log(message2)
website1 = message2[message1].website;
console.log(website1)
async function myfunction() {
const grabPage1 = async () => {
const browser = await puppeteer.launch()
const page = await browser.newPage()
await page.goto(website1)
const buffer = await page.screenshot({ path: "./screenshot.png" })
await browser.close()
return buffer
}
};
// Here we wait for the myfunction to finish
// and then returns a promise that'll be waited for aswell
// It's useless to wait the myfunction to finish before to return
// we can simply returns a promise that will be resolved later
// Call start
(async() => {
const buffer = await grabPage1(website1);
// We can create embeds using the MessageEmbed constructor
// Read more about all that you can do with the constructor
// over at https://discord.js.org/#/docs/main/stable/class/RichEmbed
const embed = new Discord.RichEmbed()
// Set the title of the field
.setTitle('Here Is Your NBA Top Shot Stats For ' + message1 + '!')
// Set the color of the embed
.setColor(0xff0000)
// Set the main content of the embed
.setDescription('Brought To You By The NBA Top Shot Pros')
.attachFile(buffer)
//console.log('message sent')
// Send the embed to the same channel as the message
message.channel.send(embed)
fs.unlink("./screenshot.png",(err => {
if (err) console.log(err)}));
})();
})
}
});
client.login('ODE3NTI5NzkxNzcwMDAxNDU4.YEK18w._oWxDlYeZHFN582JVl8x_ru5RyI')