]> git.lizzy.rs Git - furrybot.git/commitdiff
Add joke command
authorElias Fleckenstein <eliasfleckenstein@web.de>
Wed, 10 Mar 2021 10:33:03 +0000 (11:33 +0100)
committerElias Fleckenstein <eliasfleckenstein@web.de>
Wed, 10 Mar 2021 10:33:03 +0000 (11:33 +0100)
bot.lua

diff --git a/bot.lua b/bot.lua
index 8604dad850552e1293dc1776c5221e6c2a228f7b..de71d4ae36495c1d958f550d61108ddba5b8b0fb 100644 (file)
--- a/bot.lua
+++ b/bot.lua
@@ -72,8 +72,9 @@ function furrybot.http_request(url, name, callback)
 end
 
 function furrybot.json_http_request(url, name, callback)
-       furrybot.http_request(url, name, function(data)
-               callback(minetest.parse_json(data)[1])
+       furrybot.http_request(url, name, function(raw)
+               local data = minetest.parse_json(raw)
+               callback(data[1] or data)
        end)
 end
 
@@ -209,6 +210,17 @@ end
 
 furrybot.commands.dicksize = furrybot.commands.cocksize
 
+function furrybot.commands.joke(name, first, last)
+       if not first then
+               first = "Chuck"
+               last = "Norris"
+       end
+       furrybot.json_http_request("http://api.icndb.com/jokes/random?firstName=" .. first .. "&lastName=" .. (last or ""), name, function(data)
+               local joke = data.value.joke:gsub("&quot;", "\""):gsub("  ", " ")
+               furrybot.send(joke)
+       end)
+end
+
 if furrybot.loaded then
        furrybot.send("Reloaded")
 else