]> git.lizzy.rs Git - furrybot-discord.git/blob - http.js
Add bad apple
[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(" "), true)
11                                 .then(result => msg.reply(result.image.url))
12         },
13         verse: {
14                 func: msg => fetch("https://labs.bible.org/api/?type=json&passage=random")
15                         .then(res => res.json())
16                         .then(data => msg.reply(`${data[0].text}\n\t${data[0].bookname} ${data[0].chapter}, ${data[0].verse}`))
17         },
18         define: {
19                 func: (msg, term) => term.length > 0 ? fetch("https://api.dictionaryapi.dev/api/v1/entries/en_US/" + term.join(" "))
20                         .then(res => res.json())
21                         .then(data => {
22                                 let def = data[0]
23                                 msg.reply(`__**${def.word}**__`
24                                         + (def.phonetic ? ` _${def.phonetic}_` : "")
25                                         + "\n\n"
26                                         + Object.entries(def.meaning).reduce((str, meaning) => str
27                                                 + `_${meaning[0]}_\n`
28                                                 + meaning[1].reduce((str, definition, i) => str + `\t${i + 1}. ${definition.definition}\n`, "")
29                                         , "")
30                                         + `\n[Definitions from ${def.sourceUrls.join(", ")}]`
31                                 )
32                         })
33                         .catch(_ => msg.reply("Not found"))
34                         : msg.reply("You need to specify a word")
35         },
36         urban: {
37                 func: (msg, term) => term.length > 0 ? fetch("https://api.urbandictionary.com/v0/define?term=" + term.join(" "))
38                         .then(res => res.json())
39                         .then(data => {
40                                 let def = common.choose(data.list)
41
42                                 msg.reply(`__**${def.word}**__\n`
43                                         + def.definition.replace(/\[/g,"").replace(/\]/g,"") + "\n\n"
44                                         + "**Example:**\n"
45                                         + def.example.replace(/\[/g,"").replace(/\]/g,"")
46                                 )
47                         })
48                         .catch(_ => msg.reply("Not found"))
49                         : msg.reply("You need to specify a word")
50         },
51         insult: {
52                 func: (msg, [targetPing]) => {
53                         const target = common.getPing(msg, targetPing, true)
54
55                         if (target)
56                                 fetch("https://insult.mattbas.org/api/insult")
57                                         .then(res => res.text())
58                                         .then(data => msg.channel.send(`<@!${target}> ${data}`))
59                 }
60         },
61         chucknorris: {
62                 func: (msg, [first, last]) => {
63                         if (!first) {
64                                 first = "Chuck"
65                                 last = "Norris"
66                         } else if (!last) {
67                                 last = ""
68                         }
69
70                         fetch(`http://api.icndb.com/jokes/random?firstName=${first}&lastName=${last}`)
71                                 .then(res => res.json())
72                                 .then(data => msg.reply(data.value.joke.replace(/&quot;/g, "\"").replace(/  /g, " ")))
73                 }
74         },
75         joke: {
76                 func: msg => fetch("https://v2.jokeapi.dev/joke/Any")
77                         .then(res => res.json())
78                         .then(data => msg.reply(data.type == "single" ? data.joke : data.setup + "\n" + "||" + data.delivery + "||"))
79         },
80         "8ball": {
81                 func: msg => fetch("https://8ball.delegator.com/magic/JSON/whatever")
82                         .then(res => res.json())
83                         .then(data => msg.reply(data.magic.answer))
84         },
85         emojify: {
86                 func: (msg, text) => fetch("https://api.emojify.net/convert", {
87                                 method: "POST",
88                                 headers: {
89                                         "Accept": "application/json",
90                                         "Content-Type": "application/json",
91                                 },
92                                 body: JSON.stringify({
93                                         density: 100,
94                                         input: text.join(" "),
95                                         shouldFilterEmojis: false,
96                                 }),
97                         })
98                                 .then(res => res.json())
99                                 .then(data => msg.reply(data.result))
100         }
101 }