aboutsummaryrefslogtreecommitdiff
path: root/http.js
diff options
context:
space:
mode:
Diffstat (limited to 'http.js')
-rw-r--r--http.js91
1 files changed, 91 insertions, 0 deletions
diff --git a/http.js b/http.js
new file mode 100644
index 0000000..604d032
--- /dev/null
+++ b/http.js
@@ -0,0 +1,91 @@
+const fetch = require("node-fetch")
+const google_images = require("free-google-images")
+const common = require("./common.js")
+
+module.exports = {
+ google: {
+ params: "<keyword> [...]",
+ help: "Google Image Search",
+ func: (msg, keywords) => {
+ google_images.searchRandom(keywords.join(" "))
+ .then(result => msg.reply(result.image.url))
+ }
+ },
+ verse: {
+ func: msg => fetch("https://labs.bible.org/api/?type=json&passage=random")
+ .then(res => res.json())
+ .then(data => msg.reply(`${data[0].text} [${data[0].bookname} ${data[0].chapter}, ${data[0].verse}]`))
+ },
+ define: {
+ func: (msg, [word]) => word ? fetch("https://api.dictionaryapi.dev/api/v1/entries/en_US/" + word)
+ .then(res => res.json())
+ .then(data => {
+ let def = data[0]
+ msg.reply(`__**${def.word}**__`
+ + (def.phonetic ? ` (_${def.phonetic}_)` : "")
+ + "\n\n"
+ + Object.entries(def.meaning).reduce((str, meaning) => str
+ + `_${meaning[0]}_\n`
+ + meaning[1].reduce((str, definition, i) => str + `\t${i + 1}. ${definition.definition}\n`, "")
+ , "")
+ + `\n[Definitions from ${def.sourceUrls.join(", ")}]`
+ )
+ })
+ .catch(_ => msg.reply("Not found"))
+ : msg.reply("You need to specify a word")
+ },
+ urban: {
+ func: (msg, [word]) => word ? fetch("https://api.urbandictionary.com/v0/define?term=" + word)
+ .then(res => res.json())
+ .then(data => {
+ let def = common.choose(data.list)
+
+ msg.reply(`__**${def.word}**__\n`
+ + def.definition.replace(/\[/g,"").replace(/\]/g,"") + "\n\n"
+ + "**Example:**\n"
+ + def.example.replace(/\[/g,"").replace(/\]/g,"")
+ )
+ })
+ .catch(_ => msg.reply("Not found"))
+ : msg.reply("You need to specify a word")
+ },
+ insult: {
+ func: (msg, [targetPing]) => {
+ const target = common.getPing(msg, targetPing, true)
+
+ if (target)
+ fetch("https://insult.mattbas.org/api/insult")
+ .then(res => res.text())
+ .then(data => msg.channel.send(`<@!${target}> ${data}`))
+ }
+ }
+}
+/*
+
+furrybot.commands.joke = {
+ func = function(name, first, last)
+ if not first then
+ first = "Chuck"
+ last = "Norris"
+ elseif not last then
+ last = ""
+ end
+ furrybot.json_http_request("http://api.icndb.com/jokes/random?firstName=" .. first .. "&lastName=" .. last, name, function(data)
+ local joke = data.value.joke:gsub("&quot;", "\""):gsub(" ", " ")
+ furrybot.send(joke, furrybot.colors.fun)
+ end)
+ end,
+}
+
+furrybot.commands["8ball"] = {
+ func = function(name)
+ furrybot.json_http_request("https://8ball.delegator.com/magic/JSON/anything", name, function(data)
+ furrybot.ping_message(name, data.magic.answer, furrybot.colors.fun)
+ end)
+ end,
+}
+
+return function(_http, _env, _storage)
+ http, env, storage = _http, _env, _storage
+end
+*/