-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
653 lines (650 loc) · 18 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
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
const fetch = require('node-fetch')
const baseurl = "https://apiv1.spapi.online"
const misc = baseurl + "/misc"
const fun = baseurl + "/fun"
const anime = baseurl + "/anime"
const image = baseurl + "/image"
class SPAPIerror extends Error {
constructor(endpoint, message) {
super(`${endpoint}]: ${message}`);
this.name = '[SPAPI-Wrapper: '
}
}
// Misc Endpoints
async function genPassword() {
try {
const fetched = await fetch(misc + "/genpass")
const pass = await fetched.json()
return (pass.password)
} catch(error) {
throw new SPAPIerror("genPassword()", error)
}
}
/**
*
* @param {String} url
*/
async function getRealurl(url) {
if (!url) {
throw new SPAPIerror("getRealurl()", "No url provided.")
} else {
try {
const fetched = await fetch(misc + `/realurl?url=${encodeURIComponent(url)}`)
const realurl = await fetched.json()
return (realurl.realurl)
} catch(err) {
throw new SPAPIerror("getRealurl()", err)
}
}
}
/**
*
* @param {String} url
*/
async function lengthenURL(url) {
if (!url) {
throw new SPAPIerror("lengthenURL()", "No url provided.")
} else {
try {const fetched = await fetch(misc + `/lengthen?url=${encodeURIComponent(url)}`)
const lgnt = await fetched.json()
return (await lgnt.lengthened)} catch(err) {
throw new SPAPIerror("lengthenURL()", err)
}
}
}
/**
*
* @param {String} text
*/
async function getMock(text) {
if (!text) {
throw new SPAPIerror("getMock()", "No text provided.")
} else {
try {const fetched = await fetch(misc + `/mock?text=${encodeURIComponent(text)}`)
const mock = await fetched.json()
return (mock.mocked)} catch(err) {
throw new SPAPIerror("getMock()", err)
}
}
}
/**
*
* @param {String} countryname
*/
async function getCovid(countryname) {
if (!countryname) {
throw new SPAPIerror("getCovid()", "No country name provided.")
} else {
try{const fetched = await fetch(misc + `/covidcountry?country=${encodeURIComponent(countryname)}`)
return (await fetched.json())} catch(err) {
throw new SPAPIerror("getCovid()", err)
}
}
}
async function getIp(ip) {
if (!ip) {
throw new SPAPIerror("getIp()", "No ip provided.")
} else {
try {const fetched = await fetch(misc + `/ipinfo?ip=${encodeURIComponent(ip)}`)
return (await fetched.json())} catch(err) {
throw new SPAPIerror("getIp()", err)
}
}
}
/**
*
* @param {String} method
* @param {String} message
* @returns "Morse encoded/decoded message"
*/
async function convertMorse(method, message) {
try {
if (!method) {
throw new SPAPIerror("convertMorse()", "No method provided.")
} else {
if (method === "encode") {
try {const fetched = await fetch(misc + `/morse/encode?message=${encodeURIComponent(message)}`)
const en = await fetched.json()
return (en.encoded)} catch(err) {
throw new SPAPIerror("convertMorse()", err)
}
} else if (method === "decode") {
try {const fetched = await fetch(misc + `/morse/decode?message=${encodeURIComponent(message)}`)
const de = await fetched.json()
return (de.decoded)} catch(err) {
throw new SPAPIerror("convertMorse()", err)
}
} else {
throw new SPAPIerror("convertMorse()", "Invalid method.")
}
}
} catch(error) {
throw new SPAPIerror("convertMorse()", error)
}
}
/**
*
* @param {String} message
*/
async function getBinary(message) {
if (!message) {
throw new SPAPIerror("getBinary()", "No message provided.")
} else {
try {const fetched = await fetch(misc + `/binary?query=${encodeURIComponent(message)}`)
const converted = await fetched.json()
return (converted.converted)} catch(err) {
throw new SPAPIerror("getBinary()", err)
}
}
}
/**
*
* @param {String} country
*/
async function covidInfo(country) {
if (!country) {
throw new SPAPIerror("covidInfo()", "No country provided.")
} else {
try {const fetched = await fetch(misc + `/covidcountry?country=${encodeURIComponent(country)}`)
return (await fetched.json())} catch(err) {
throw new SPAPIerror("covidInfo()", err)
}
}
}
//end of misc endpoints
//Fun endpoints
async function getTod() {
try {const fetched = await fetch(fun + '/truthordare')
return (await fetched.json())} catch(err) {
throw new SPAPIerror("getTod()", err)
}
}
async function getAnifact() {
try {const fetched = await fetch(fun + '/anifact')
return (await fetched.json())} catch(err) {
throw new SPAPIerror("getAnifact()", err)
}
}
async function get8ball() {
try {const fetched = await fetch(fun + '/8ball')
const res = await fetched.json()
return (res.response)} catch(err) {
throw new SPAPIerror("get8ball()", err)
}
}
async function getJoke() {
try {
const fetched = await fetch(fun + '/joke')
const joke = await fetched.json()
return (joke.joke)
} catch(error) {
throw new SPAPIerror("getJoke()", error)
}
}
async function getQuestionoftheday() {
try {const fetched = await fetch(fun + '/qotd')
const qotd = await fetched.json()
return (qotd.qotd)} catch(err) {
throw new SPAPIerror("getQuestionoftheday()", err)
}
}
async function getRandomFact() {
try {const fetched = await fetch(fun + '/fact')
const fact = await fetched.json()
return (fact.fact)} catch(err) {
throw new SPAPIerror("getRandomFact()", err)
}
}
async function getRandomQuote() {
try {const fetched = await fetch(fun + '/quote')
return (await fetched.json())} catch(err) {
throw new SPAPIerror("getRandomQuote()", err)
}
}
/**
* @param {String} subreddit (Optional)
*/
async function getMeme(subreddit="") {
try {const fetched = await fetch(fun + '/meme?sub=' + encodeURIComponent(subreddit))
return (await fetched.json())} catch(err) {
throw new SPAPIerror("getMeme()", err)
}
}
/**
*
* @param {String} text
*/
async function owofy(text) {
if (!text) {
throw new SPAPIerror("owofy()", "No text provided.")
} else {
try {const fetched = await fetch(fun + `/owofy?text=${encodeURIComponent(text)}`)
const owo = await fetched.json()
return (owo.response)} catch(err) {
throw new SPAPIerror("owofy()", err)
}
}
}
/**
*
* @param {String} text
*/
async function getAscii(text) {
if (!text) {
throw new SPAPIerror("getAscii()", "No text provided.")
} else {
try {const fetched = await fetch(fun + `/ascii?text=${encodeURIComponent(text)}`)
const asc = await fetched.json()
return (asc.ascii)} catch(err) {
throw new SPAPIerror("getAscii()", err)
}
}
}
/**
*
* @param {String} hex
*/
async function getColor(hex) {
if (!hex) {
throw new SPAPIerror("getColor()", "No hex provided.")
} else {
try {const fetched = await fetch(fun + `/color?hex=${encodeURIComponent(hex)}`)
return (await fetched.json())} catch(err) {
throw new SPAPIerror("getColor()", err)
}
}
}
/**
*
* @param {String} word
*/
async function define(word) {
if (!word) {
throw new SPAPIerror("define()", "No word provided.")
} else {
try {const fetched = await fetch(fun + `/define?word=${encodeURIComponent(word)}`)
return (await fetched.json())} catch(err) {
throw new SPAPIerror("define()", err)
}
}
}
/**
*
* @param {String} movie
*/
async function getMovie(movie) {
if (!movie) {
throw new SPAPIerror("getMovie()", "No movie provided.")
} else {
try {const fetched = await fetch(fun + `/movie?movname=${encodeURIComponent(movie)}`)
return (await fetched.json())} catch(err) {
throw new SPAPIerror("getMovie()", err)
}
}
}
/**
*
* @param {String} movie
*/
async function getMoviePoster(movie) {
if (!movie) {
throw new SPAPIerror("getMoviePoster()", "No movie provided.")
} else {
try {const fetched = await fetch(fun + `/movposter/${encodeURIComponent(movie)}`)
return (await fetched.json())} catch(err) {
throw new SPAPIerror("getMoviePoster()", err)
}
}
}
/**
*
* @param {String} song
*/
async function getSongLyrics(song) {
if (!song) {
throw new SPAPIerror("getSongLyrics()", "No song provided.")
} else {
try {const fetched = await fetch(fun + `/lyrics?songname=${encodeURIComponent(song)}`)
const ly = await fetched.json()
return ly} catch(err) {
throw new SPAPIerror("getSongLyrics()", err)
}
}
}
/**
*
* @param {String} app
*/
async function googlePlay(app) {
if (!app) {
throw new SPAPIerror("googlePlay()", "No app provided.")
} else {
try {const fetched = await fetch(fun + `/playstore?app=${encodeURIComponent(app)}`)
return (await fetched.json())} catch(err) {
throw new SPAPIerror("googlePlay()", err)
}
}
}
/**
*
* @param {String} app
*/
async function appstore(app) {
if (!app) {
throw new SPAPIerror("appstore()", "No app provided.")
} else {
try {const fetched = await fetch(fun + `/appstore?app=${encodeURIComponent(app)}`)
return (await fetched.json())} catch(err) {
throw new SPAPIerror("appstore()", err)
}
}
}
/**
*
* @param {String} pkg
*/
async function getNPM(pkg) {
if (!pkg) {
throw new SPAPIerror("getNPM()", "No package provided.")
} else {
try {const fetched = await fetch(fun + `/npm?pkg=${encodeURIComponent(pkg)}`)
return (await fetched.json())}catch(err) {
throw new SPAPIerror("getNPM()", err)
}
}
}
/**
*
* @param {String} url URL to shorten
* @param {String} token Token from bit.ly
*/
async function bitlyShorten(url, token) {
if (!url && !token) {
throw new SPAPIerror("bitlyShorten()", "No url or token provided. Make sure to provide both.")
} else {
try {const fetched = await fetch(fun + `/shorten?url=${encodeURIComponent(url)}&token=${encodeURIComponent(token)}`)
return (await fetched.json())} catch(err) {
throw new SPAPIerror("bitlyShorten()", err)
}
}
}
/**
*
* @param {String} url URL to shorten
* @param {String} token Token from bit.ly
*/
async function bitlyExpand(url, token) {
if (!url && !token) {
throw new SPAPIerror("bitlyExpand()", "No url or token provided. Make sure to provide both.")
} else {
try {const fetched = await fetch(fun + `/expand?url=${encodeURIComponent(url)}&token=${encodeURIComponent(token)}`)
return (await fetched.json())} catch(err) {
throw new SPAPIerror("bitlyExpand()", err)
}
}
}
/**
*
* @param {String} text
* @param {String} to
*/
async function translate(text, to) {
if (!text && !to) {
throw new SPAPIerror("translate()", "No text or to language provided. Make sure to provide both.")
} else {
try {const fetched = await fetch(fun + `/translate?text=${encodeURIComponent(text)}&to=${encodeURIComponent(to)}`)
return (await fetched.json())} catch(err) {
throw new SPAPIerror("translate()", err)
}
}
}
/**
*
* @param {String} place
*/
async function getWeather(place) {
if (!place) {
throw new SPAPIerror("getWeather()", "No place provided.")
} else {
try {const fetched = await fetch(fun + `/weather?place=${encodeURIComponent(place)}`)
return (await fetched.json())} catch(err) {
throw new SPAPIerror("getWeather()", err)
}
}
}
/**
*
* @param {Number} userid
*/
async function getUserBanner(userid) {
if (!userid) {
throw new SPAPIerror("getUserBanner()", "No user id provided.")
} else {
try {const fetched = await fetch(fun + `/discord?userid=${encodeURIComponent(userid)}`)
return (await fetched.json())} catch(err) {
throw new SPAPIerror("getUserBanner()", err)
}
}
}
async function getPickupLine() {
try {
const fetched = await fetch(fun + '/pickup')
const p = await fetched.json()
return (p.pickup)
} catch(error) {
throw new SPAPIerror("getPickupLine()", error)
}
}
/**
*
* @param {String} channelName
*/
async function youtubeChannel(channelName) {
if (!channelName) {
throw new SPAPIerror("youtubeChannel()", "No channel name provided.")
} else {
try {const fetched = await fetch(fun + `/ytchannel?channel=${encodeURIComponent(channelName)}`)
return (await fetched.json())} catch(err) {
throw new SPAPIerror("youtubeChannel()", err)
}
}
}
/**
*
* @param {String} username
*/
async function getGithubProfile(username) {
if (!username) {
throw new SPAPIerror("getGithubProfile()", "No username provided.")
} else {
try {const fetched = await fetch(fun + `/githubuser?user=${encodeURIComponent(username)}`)
return (await fetched.json())} catch(err) {
throw new SPAPIerror("getGithubProfile()", err)
}
}
}
/**
*
* @param {String} country
*/
async function getCountry(country) {
if (!country) {
throw new SPAPIerror("getCountry()", "No country provided.")
} else {
try {const fetched = await fetch(fun + `/countryinfo?name=${encodeURIComponent(country)}`)
return (await fetched.json())} catch(err) {
throw new SPAPIerror("getCountry()", err)
}
}
}
/**
*
* @param {String} app
*/
async function steamSearch(app) {
if (!app) {
throw new SPAPIerror("steamSearch()", "No app provided.")
} else {
try {const fetched = await fetch(fun + `/steam?game=${encodeURIComponent(app)}`)
return (await fetched.json())} catch(err) {
throw new SPAPIerror("steamSearch()", err)
}
}
}
/**
*
* @param {String} code
*/
async function discordInvite(code) {
if (!code) {
throw new SPAPIerror("discordInvite()", "No code provided.")
} else {
const no = ["https://", "discord.gg", "discord.com"]
const link = no.some(boo => `${code}`.includes(boo))
if (link === true) {
throw new SPAPIerror("discordInvite()", "Param must contain only the code and not the link.")
} else {
try {const fetched = await fetch(fun + `/inviteinfo?code=${encodeURIComponent(code)}`)
return (await fetched.json())} catch(err) {
throw new SPAPIerror("discordInvite()", err)
}
}
}
}
/**
*
* @param {String} bookname
*/
async function bookInfo(bookname) {
if (!bookname) {
throw new SPAPIerror("bookInfo()", "No book name provided.")
} else {
try {const fetched = await fetch(fun + `/bookinfo?book=${encodeURIComponent(bookname)}`)
return (await fetched.json())} catch(err) {
throw new SPAPIerror("bookInfo()", err)
}
}
}
// end of fun endpoints
//anime endpoints
async function getAllAnime() {
try {
const fetched = await fetch(anime + '/all')
return (await fetched.json())
} catch(error) {
throw new SPAPIerror("getAllAnime()", error)
}
}
async function getAnimeCharacter(characterName) {
if (!characterName) {
throw new SPAPIerror("getAnimeCharacter()", "No character name provided.")
} else {
try {const fetched = await fetch(anime + `/animechar?char=${encodeURIComponent(characterName)}`)
return (await fetched.json())} catch(err) {
throw new SPAPIerror("getAnimeCharacter()", err)
}
}
}
async function getAnimeInfo(animename) {
if (!animename) {
throw new SPAPIerror("getAnimeInfo()", "No anime name provided.")
} else {
try {const fetched = await fetch(anime + `/info?anime=${encodeURIComponent(animename)}`)
return (await fetched.json())} catch(err) {
throw new SPAPIerror("getAnimeInfo()", err)
}
}
}
//end of anime endpoints
// Image endpoints
function renderColor(hex) {
if (!hex) {
throw new SPAPIerror("renderColor()", "No hex provided.")
} else {
return (image + `/render?hex=${encodeURIComponent(hex)}`)
}
}
function getQR(text) {
if (!text) {
throw new SPAPIerror("getQR()", "No text provided.")
} else {
return (image + `/qrcode?text=${encodeURIComponent(text)}`)
}
}
function renderFlag(country) {
if (!country) {
throw new SPAPIerror("renderFlag()", "No country provided.")
} else {
return (image + `/flag?country=${encodeURIComponent(country)}`)
}
}
function minecraftBlock(block) {
if (!block) {
throw new SPAPIerror("minecraftBlock()", "No block provided.")
} else {
return (image + `/minecraftblock?block=${encodeURIComponent(block)}`)
}
}
function screenshot(site) {
if (!site) {
throw new SPAPIerror("screenshot()", "No site provided.")
} else {
const yes = ["https://", "http://"]
const must = yes.some(sh => `${site}`.includes(sh))
if (must === false) {
throw new SPAPIerror("screenshot()", "Site must be a link")
} else {
return (image + `/screenshot?site=${encodeURIComponent(site)}`)
}
}
}
// end of image endpoints
module.exports = {
genPassword,
getRealurl,
lengthenURL,
getMock,
getCovid,
getIp,
convertMorse,
getBinary,
covidInfo,
getTod,
getAnifact,
get8ball,
getJoke,
getQuestionoftheday,
getRandomFact,
getRandomQuote,
getMeme,
owofy,
getAscii,
getColor,
define,
getMovie,
getMoviePoster,
getSongLyrics,
googlePlay,
appstore,
getNPM,
bitlyShorten,
bitlyExpand,
translate,
getWeather,
getUserBanner,
getPickupLine,
youtubeChannel,
getGithubProfile,
getCountry,
steamSearch,
discordInvite,
bookInfo,
getAllAnime,
getAnimeCharacter,
getAnimeInfo,
renderColor,
getQR,
renderFlag,
minecraftBlock,
screenshot
}