]> git.lizzy.rs Git - furrybot-discord.git/blob - http.js
Implement all HTTP commands
[furrybot-discord.git] / http.js
1 const fetch = require("node-fetch")
2 const google_images = require("free-google-images")
3 const common = require("./common.js")
4
5 module.exports = {
6         google: {
7                 params: "<keyword> [...]",
8                 help: "Google Image Search",
9                 func: (msg, keywords) => {
10                         google_images.searchRandom(keywords.join(" "))
11                                 .then(result => msg.reply(result.image.url))
12                 }
13         },
14         verse: {
15                 func: msg => fetch("https://labs.bible.org/api/?type=json&passage=random")
16                         .then(res => res.json())
17                         .then(data => msg.reply(`${data[0].text} [${data[0].bookname} ${data[0].chapter}, ${data[0].verse}]`))
18         },
19         define: {
20                 func: (msg, [word]) => word ? fetch("https://api.dictionaryapi.dev/api/v1/entries/en_US/" + word)
21                         .then(res => res.json())
22                         .then(data => {
23                                 let def = data[0]
24                                 msg.reply(`__**${def.word}**__`
25                                         + (def.phonetic ? ` _${def.phonetic}_` : "")
26                                         + "\n\n"
27                                         + Object.entries(def.meaning).reduce((str, meaning) => str
28                                                 + `_${meaning[0]}_\n`
29                                                 + meaning[1].reduce((str, definition, i) => str + `\t${i + 1}. ${definition.definition}\n`, "")
30                                         , "")
31                                         + `\n[Definitions from ${def.sourceUrls.join(", ")}]`
32                                 )
33                         })
34                         .catch(_ => msg.reply("Not found"))
35                         : msg.reply("You need to specify a word")
36         },
37         urban: {
38                 func: (msg, [word]) => word ? fetch("https://api.urbandictionary.com/v0/define?term=" + word)
39                         .then(res => res.json())
40                         .then(data => {
41                                 let def = common.choose(data.list)
42
43                                 msg.reply(`__**${def.word}**__\n`
44                                         + def.definition.replace(/\[/g,"").replace(/\]/g,"") + "\n\n"
45                                         + "**Example:**\n"
46                                         + def.example.replace(/\[/g,"").replace(/\]/g,"")
47                                 )
48                         })
49                         .catch(_ => msg.reply("Not found"))
50                         : msg.reply("You need to specify a word")
51         },
52         insult: {
53                 func: (msg, [targetPing]) => {
54                         const target = common.getPing(msg, targetPing, true)
55
56                         if (target)
57                                 fetch("https://insult.mattbas.org/api/insult")
58                                         .then(res => res.text())
59                                         .then(data => msg.channel.send(`<@!${target}> ${data}`))
60                 }
61         },
62         joke: {
63                 func: (msg, [first, last]) => {
64                         if (!first) {
65                                 first = "Chuck"
66                                 last = "Norris"
67                         } else if (!last) {
68                                 last = ""
69                         }
70
71                         fetch(`http://api.icndb.com/jokes/random?firstName=${first}&lastName=${last}`)
72                                 .then(res => res.json())
73                                 .then(data => msg.reply(data.value.joke.replace(/&quot;/g, "\"").replace(/  /g, " ")))
74                 }
75         },
76         "8ball": {
77                 func: msg => fetch("https://8ball.delegator.com/magic/JSON/whatever")
78                         .then(res => res.json())
79                         .then(data => msg.reply(data.magic.answer))
80         }
81 }