-
Notifications
You must be signed in to change notification settings - Fork 0
/
behemothbot.js
428 lines (405 loc) · 14.9 KB
/
behemothbot.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
const Discord = require('discord.js');
const { prefix, token } = require('./config.json');
const axios = require('axios');
const cheerio = require('cheerio');
const request = require('request');
const { title } = require('process');
const client = new Discord.Client();
client.once('ready', () => {
console.log('Ready! BehemothBot is online.');
});
client.on('message', message => {
console.log(message.content);
if (!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).trim().split(/ +/);
const command = args.shift().toLowerCase();
if (command === 'ping') {
message.channel.send('pong')
}
else if (command === 'calljs') {
message.channel.send('BehemothBot.js is active')
}
else if (command === 'weather') {
const country = args[0]
const state = args[1]
const city = args[2]
const getWeather = async () => {
try {
const { data } = await axios.get(
'https://www.wunderground.com/weather/' + country + '/' + state + '/' + city + '/'
);
const $ = cheerio.load(data)
const weather = $('span.test-true.wu-unit.wu-unit-temperature.is-degree-visible.ng-star-inserted > span.wu-value.wu-value-to').text()
const weatherResults = weather.charAt(2) + weather.charAt(1)
const Embed = new Discord.MessageEmbed()
.setColor('#0099ff')
.setTitle(`Weather for ${city} `)
.setDescription(`${weatherResults}`)
.setTimestamp()
.setFooter('BehemothBot');
message.channel.send(Embed);
} catch (error) {
console.log(error)
message.channel.send(error)
}
}
getWeather()
}
else if (command === 'covid') {
const getCovid = async () => {
try {
const { data } = await axios.get(
'https://covidusa.net/'
);
const $ = cheerio.load(data);
const covidStats = $('div.stat.py-4 > div.stat-value.display-4.text-warning').text()
const Embed = new Discord.MessageEmbed()
.setColor('#0099ff')
.setTitle('Covid-19 Statistics - US')
.setDescription(`(1st is current, 2nd is 7 day projection, 3rd is 14 day projection, and 4th is 30 day projection) \n${covidStats}`)
.setTimestamp()
.setFooter('BehemothBot');
message.channel.send(Embed);
} catch (error) {
console.log(error)
message.channel.send(error)
}
}
getCovid()
}
else if (command === 'wikipedia') {
const getCovid = async () => {
try {
const { data } = await axios.get(
'https://en.wikipedia.org/wiki/Special:Random'
);
const $ = cheerio.load(data);
const wikipediatitle = $('h1.firstHeading').text()
const wikipediacontents = $('p').text()
const Embed = new Discord.MessageEmbed()
.setColor('#0099ff')
.setTitle(wikipediatitle)
.setDescription(wikipediacontents.substring(0, 500))
.setTimestamp()
.setFooter('BehemothBot');
message.channel.send(Embed);
} catch (error) {
console.log(error)
message.channel.send(error)
}
}
getCovid()
}
else if (command === 'number') {
const number = args[0]
const getNumber = async () => {
try {
const { data } = await axios.get(
'https://www.calculatorsoup.com/calculators/conversions/numberstowords.php?number=' + number + '&format=words&letter_case=lowercase&action=solve'
);
const $ = cheerio.load(data);
const getAnswer = $('div.still').text()
const Embed = new Discord.MessageEmbed()
.setColor('#0099ff')
.setTitle(number)
.setDescription(getAnswer)
.setTimestamp()
.setFooter('BehemothBot');
message.channel.send(Embed);
} catch (error) {
console.log(error)
message.channel.send(error)
}
}
getNumber()
}
else if (command === 'check') {
message.channel.send('If you are only seeing this message then BehemothBot is partially down (C# Portion). If you are only seeing this then most commands will not work because BehemothBot is mostly built upon a D# client.')
}
else if (command === 'reddit') {
subreddit = args[0]
age = args[1]
const getPost = async () => {
try {
const { data } = await axios.get(
'https://old.reddit.com/r/' + subreddit + '/' + age + '/'
);
const $ = cheerio.load(data);
const a = $("img").attr("href")
const img = $('img').attr("src")
const score = $('div.midcol.unvoted > div.score.unvoted').text()
href = $('div > p.title > a').attr("href");
var imglink = 'http://old.reddit.com' + href;
try {
const { data } = await axios.get(
imglink
);
const $ = cheerio.load(data)
const imgLarge = $('img.preview').attr("src")
const Embed = new Discord.MessageEmbed()
.setColor('#0099ff')
.setTitle(`Reddit /r/${subreddit}`)
.setDescription(imglink)
.setImage(imgLarge)
.setTimestamp()
.setFooter(`${score} upvotes - BehemothBot`);
message.channel.send(Embed);
} catch (error) {
console.log(error)
message.channel.send('This post could not be found, this means the post could be a link from another site' + error)
}
} catch (error) {
console.log(error)
message.channel.send('This subreddit could not be found, make sure it was typed correctly and that the subreddit exists' + error)
}
}
getPost()
}
else if (command === 'meme') {
const getPost = async () => {
try {
const { data } = await axios.get(
'https://old.reddit.com/r/dankmemes/new/'
);
const $ = cheerio.load(data);
const a = $("img").attr("href")
const img = $('img').attr("src")
href = $('div > p.title > a').attr("href");
var imglink = 'http://old.reddit.com' + href;
try {
const { data } = await axios.get(
imglink
);
const $ = cheerio.load(data)
const imgLarge = $('img.preview').attr("src")
const Embed = new Discord.MessageEmbed()
.setColor('#0099ff')
.setTitle('Meme')
.setDescription(imglink)
.setImage(imgLarge)
.setTimestamp()
.setFooter('BehemothBot');
message.channel.send(Embed);
} catch (error) {
console.log(error)
}
} catch (error) {
console.log(error);
message.channel.send(error)
}
};
getPost()
}
else if (command === 'ann') {
const announcement = new Discord.MessageEmbed()
.setColor('#0099ff')
.setTitle('ANNOUNCEMENT')
.setAuthor('DrBehemoth')
.setDescription('Put whatever you got for christmas in flexing channel')
.setTimestamp()
.setFooter('BehemothBot');
message.channel.send(announcement)
}
else if (command === 'fm') {
const spotifyAccount = args[0]
switch (args[1]) {
case "recent":
const getrecentSong = async () => {
try {
const { data } = await axios.get(
'https://www.last.fm/user/' + spotifyAccount + '/'
);
const $ = cheerio.load(data)
const recentsongName = $('section > table.chartlist tr:nth-child(1) > td.chartlist-name > a').text()
const recentsongArtist = $('section > table.chartlist tr:nth-child(1) > td.chartlist-artist > a').text()
const recentsongArtistLink = $('section > table.chartlist tr:nth-child(1) > td.chartlist-artist > a').attr("href")
const recentsongimgRef = $('section > table.chartlist tr:nth-child(1) > td.chartlist-name > a').attr("href")
const recentsongartistHref = 'https://www.last.fm/music' + recentsongArtistLink
const recentsongHref = 'https://www.last.fm' + recentsongimgRef + '/'
const Embed = new Discord.MessageEmbed()
.setColor('#0099ff')
.setTitle(`${spotifyAccount}s Recent Song`)
.setDescription(`[${recentsongName}](${recentsongHref}) by [${recentsongArtist}](${recentsongartistHref})`)
.setTimestamp()
.setFooter('BehemothBot');
message.channel.send(Embed);
} catch (error) {
console.log(error)
message.channel.send(error)
}
}
getrecentSong()
break;
case "recentall":
const getrecentsongAll = async () => {
try {
const { data } = await axios.get(
'https://www.last.fm/user/' + spotifyAccount + '/'
);
const $ = cheerio.load(data)
const recentsongName = $('section > table.chartlist tr:nth-child(1) > td.chartlist-name > a').text()
const recentsongArtist = $('section > table.chartlist tr:nth-child(1) > td.chartlist-artist > a').text()
const recentsongArtistLink = $('section > table.chartlist tr:nth-child(1) > td.chartlist-artist > a').attr("href")
const recentsongimgRef = $('section > table.chartlist tr:nth-child(1) > td.chartlist-name > a').attr("href")
const recentsongartistHref = 'https://www.last.fm/music' + recentsongArtistLink
const recentsongHref = 'https://www.last.fm' + recentsongimgRef + '/'
const recentsongName2 = $('section > table.chartlist tr:nth-child(2) > td.chartlist-name > a').text()
const recentsongArtist2 = $('section > table.chartlist tr:nth-child(2) > td.chartlist-artist > a').text()
const recentsongArtistLink2 = $('section > table.chartlist tr:nth-child(2) > td.chartlist-artist > a').attr("href")
const recentsongimgRef2 = $('section > table.chartlist tr:nth-child(2) > td.chartlist-name > a').attr("href")
const recentsongartistHref2 = 'https://www.last.fm/music' + recentsongArtistLink2
const recentsongHref2 = 'https://www.last.fm' + recentsongimgRef2 + '/'
const recentsongName3 = $('section > table.chartlist tr:nth-child(3) > td.chartlist-name > a').text()
const recentsongArtist3 = $('section > table.chartlist tr:nth-child(3) > td.chartlist-artist > a').text()
const recentsongArtistLink3 = $('section > table.chartlist tr:nth-child(3) > td.chartlist-artist > a').attr("href")
const recentsongimgRef3 = $('section > table.chartlist tr:nth-child(3) > td.chartlist-name > a').attr("href")
const recentsongartistHref3 = 'https://www.last.fm/music' + recentsongArtistLink3
const recentsongHref3 = 'https://www.last.fm' + recentsongimgRef3 + '/'
const Embed = new Discord.MessageEmbed()
.setColor('#0099ff')
.setTitle(`${spotifyAccount}s Recent Songs`)
.setDescription(`[${recentsongName}](${recentsongHref}) by [${recentsongArtist}](${recentsongartistHref}) \n [${recentsongName2}](${recentsongHref2}) by [${recentsongArtist2}](${recentsongartistHref2}) \n [${recentsongName3}](${recentsongHref3}) by [${recentsongArtist3}](${recentsongartistHref3})`)
.setTimestamp()
.setFooter('BehemothBot');
message.channel.send(Embed);
} catch (error) {
console.log(error)
message.channel.send(error)
}
}
getrecentsongAll()
break;
case "plays":
switch (args[2]) {
case "all":
const getPlays = async () => {
try {
const { data } = await axios.get(
'https://www.last.fm/user/' + spotifyAccount + '/'
);
const $ = cheerio.load(data)
const scrobbleCount = $('li.header-metadata-item.header-metadata-item--scrobbles > p.header-metadata-display > a').text()
const Embed = new Discord.MessageEmbed()
.setColor('#0099ff')
.setTitle(`Spotify Plays`)
.setDescription(`${scrobbleCount}`)
.setTimestamp()
.setFooter('BehemothBot');
message.channel.send(Embed);
} catch (error) {
console.log(error)
message.channel.send(error)
}
}
getPlays()
break;
case "artist":
const getArtistPlays = async () => {
const artist = args[3]
if (args[artist, 4] != null) var url = 'https://www.last.fm/user/' + spotifyAccount + '/library/music/' + artist + '+' + args[4];
if (args[artist] != null) var url = 'https://www.last.fm/user/' + spotifyAccount + '/library/music/' + artist;
try {
const { data } = await axios.get(
url
);
const $ = cheerio.load(data)
const scrobbleartistCountSongs = $('ul.metadata-list li:nth-child(1) > p.metadata-display').text()
const scrobbleartistCountAlbums = $('ul.metadata-list li:nth-child(2) > p.metadata-display').text()
const scrobbleartistCountTracks = $('ul.metadata-list li:nth-child(3) > p.metadata-display').text()
const artistImg = $('span.avatar.library-header-image > img').attr("src")
const artistName = $('h2.library-header-title').text()
const Embed = new Discord.MessageEmbed()
.setColor('#0099ff')
.setTitle(`${spotifyAccount}s ${artistName} Plays`)
.setImage(artistImg)
.setDescription(`${scrobbleartistCountSongs} plays \n ${scrobbleartistCountAlbums} albums \n ${scrobbleartistCountTracks} tracks`)
.setTimestamp()
.setFooter('BehemothBot');
message.channel.send(Embed);
} catch (error) {
console.log(error)
message.channel.send(error)
}
}
getArtistPlays()
break;
}
break;
case "artistcount":
const getArtistcount = async () => {
try {
const { data } = await axios.get(
'https://www.last.fm/user/' + spotifyAccount + '/'
);
const $ = cheerio.load(data)
const artistCount = $('li.header-metadata-item.header-metadata-item--artists > p.header-metadata-display > a').text()
const Embed = new Discord.MessageEmbed()
.setColor('#099ff')
.setTitle(`${spotifyAccount}s Artist Count`)
.setDescription(`${spotifyAccount} has played ${artistCount} artists in total`)
.setTimestamp()
.setFooter('BehemothBot')
message.channel.send(Embed)
} catch (error) {
console.log(error)
message.channel.send(error)
}
}
getArtistcount()
break;
case "since":
const getsinceWhen = async () => {
try {
const { data } = await axios.get(
'https://www.last.fm/user/' + spotifyAccount + '/'
);
const $ = cheerio.load(data)
const sinceWhen = $('span.header-scrobble-since').text()
const Embed = new Discord.MessageEmbed()
.setColor('#099ff')
.setTitle(`${spotifyAccount}`)
.setDescription(`${spotifyAccount} ${sinceWhen}`)
.setTimestamp()
.setFooter('BehemothBot')
message.channel.send(Embed)
} catch (error) {
console.log(error)
message.channel.send(error)
}
}
getsinceWhen()
break;
case "artist":
switch (args[2]) {
case "top":
switch (args[3]) {
case "songs":
const gettopsongsBy = async () => {
try {
const { data } = await axios.get(
'https://www.last.fm/user/' + spotifyAccount + '/library/music/' + args[3]
);
const $ = cheerio.load(data)
const track1 = $('table.chartlist tr:nth-child(1) > td.chartlist-name > a').text()
const Embed = new Discord.MessageEmbed()
.setColor('#099ff')
.setTitle(`${spotifyAccount}`)
.setDescription(`${spotifyAccount} ${track1}`)
.setTimestamp()
.setFooter('BehemothBot')
message.channel.send(Embed)
} catch (error) {
console.log(error)
message.channel.send(error)
}
}
gettopsongsBy()
break;
}
break;
}
break;
}
}
})
client.login(token)