diff options
author | Elias Fleckenstein <eliasfleckenstein@web.de> | 2021-03-10 10:22:04 +0100 |
---|---|---|
committer | Elias Fleckenstein <eliasfleckenstein@web.de> | 2021-03-10 10:22:04 +0100 |
commit | bb6b251e2cc526072d83068638ee3eca72b53fdd (patch) | |
tree | 59594724edde39cf034da708b71375e590a6f173 /bot.lua | |
parent | dd5084619d8ba5d87b7c00f0c5d27a6da9bce587 (diff) | |
download | furrybot-bb6b251e2cc526072d83068638ee3eca72b53fdd.tar.xz |
Add define command
Diffstat (limited to 'bot.lua')
-rw-r--r-- | bot.lua | 46 |
1 files changed, 36 insertions, 10 deletions
@@ -40,6 +40,17 @@ function furrybot.choose(list) return list[math.random(#list)] end +function furrybot.http_request(url, name, callback) + furrybot.http.fetch({url = url}, function(res) + if res.succeeded then + local data = minetest.parse_json(res.data)[1] + callback(data) + else + furrybot.ping_player_error(name, "Request failed with code", res.code) + end + end) +end + function furrybot.recieve(msg) msg = minetest.strip_colors(msg) if msg:find("<") == 1 then @@ -123,19 +134,28 @@ function furrybot.commands.help() end function furrybot.commands.verse(name) - local req = { - url = "https://labs.bible.org/api/?type=json&passage=random", - } - local res = furrybot.http.fetch(req, function(res) - if res.succeeded then - local data = minetest.parse_json(res.data)[1] - furrybot.send(data.text .. C("#00FFC3") .. "[" .. data.bookname .. " " .. data.chapter .. "," .. data.verse .. "]") - else - furrybot.ping_player_error(name, "Request failed with code", res.code) - end + furrybot.http_request("https://labs.bible.org/api/?type=json&passage=random", name, function(data) + furrybot.send(data.text .. C("#00FFC3") .. "[" .. data.bookname .. " " .. data.chapter .. "," .. data.verse .. "]") end) end +function furrybot.commands.define(name, word) + if word then + furrybot.http_request("https://api.dictionaryapi.dev/api/v1/entries/en_US/" .. word, name, function(data) + local meaning = data.meaning + local selected = meaning.exclamation or meaning.noun or meaning.verb or meaning["transitive verb"] or meaning.adverb or meaning["relative adverb"] + if not selected then + print(dump(meaning)) + furrybot.ping_player_error(name, "Error in parsing response") + else + furrybot.send(C("#00FFC3") .. word:sub(1, 1):upper() .. word:sub(2, #word):lower() .. ": " .. C("#FFFA00") .. selected[1].definition) + end + end) + else + furrybot.ping_player_error(name, "You need to specify a word") + end +end + function furrybot.commands.rolldice(name) furrybot.ping_player(name, "rolled a dice and got a " .. C("#AAFF43") .. math.random(6)) end @@ -144,6 +164,12 @@ function furrybot.commands.coinflip(name) furrybot.ping_player(name, "flipped a coin and got " .. C("#AAFF43") .. furrybot.choose({"Heads", "Tails"})) end +function furrybot.commands.status() +end + +function furrybot.commands.cmd() +end + if furrybot.loaded then furrybot.send("Reloaded") else |