summaryrefslogtreecommitdiff
path: root/http.lua
blob: fc06d2cb322869d99dda8d135a713e210f0cd8a5 (plain)
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
local http, env, storage
local C = minetest.get_color_escape_sequence

function furrybot.commands.verse(name)
	furrybot.json_http_request("https://labs.bible.org/api/?type=json&passage=random", name, function(data)
		furrybot.send(data.text .. furrybot.colors.info .. "[" .. data.bookname .. " " .. data.chapter .. "," .. data.verse .. "]", furrybot.colors.fun)
	end)
end

function furrybot.commands.define(name, word)
	if word then
		furrybot.json_http_request("https://api.dictionaryapi.dev/api/v1/entries/en_US/" .. word:gsub("computer", "person"), name, function(data)
			local meaning = data.meaning
			local selected = meaning.abbreviation or meaning["cardinal number"] or meaning.exclamation or meaning.noun or meaning.verb or meaning.adjective or meaning["transitive verb"] or meaning.adverb or meaning["relative adverb"] or meaning.preposition
			if not selected then
				print(dump(meaning))
				furrybot.error_message(name, "Error in parsing response")
			else
				furrybot.send(word:sub(1, 1):upper() .. word:sub(2, #word):lower() .. ": " .. furrybot.colors.fun .. selected[1].definition, furrybot.colors.info)
			end
		end)
	else
		furrybot.error_message(name, "You need to specify a word")
	end
end

function furrybot.commands.insult(name, target)
	if furrybot.online_or_error(name, target, true) then
		furrybot.http_request("https://insult.mattbas.org/api/insult", name, function(data)
			furrybot.ping_message(target, data, furrybot.colors.fun)
		end)
	end
end

function furrybot.commands.joke(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(""", "\""):gsub("  ", " ")
		furrybot.send(joke, furrybot.colors.fun)
	end)
end

function furrybot.commands.question(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
furrybot.commands["8ball"] = furrybot.commands.question

return function(_http, _env, _storage)
	http, env, storage = _http, _env, _storage
end