3 furrybot.unsafe_commands = {}
5 local http, env, storage
6 local C = minetest.get_color_escape_sequence
10 system = C("#FFFA00"),
12 detail = C("#FF6683"),
13 roleplay = C("#FFD94E"),
14 braces = C("#FFFAC0"),
17 random = C("#A300BE"),
23 function furrybot.send(msg, color)
24 minetest.send_chat_message("/me " .. furrybot.colors.braces .. "[" .. color .. msg .. furrybot.colors.braces .. "]")
27 function furrybot.ping(player, color)
28 return furrybot.colors.ping .. "@" .. player .. color
31 function furrybot.ping_message(player, message, color)
32 furrybot.send(furrybot.ping(player, color) .. ": " .. message, "")
35 function furrybot.error_message(player, error, detail)
36 furrybot.ping_message(player, error .. (detail and furrybot.colors.detail .. " '" .. detail .. "'" .. furrybot.colors.error or "") .. ".", furrybot.colors.error)
39 function furrybot.parse_message(player, message, discord)
40 if message:find("!") == 1 then
41 local args = message:sub(2, #message):split(" ")
42 local cmd = table.remove(args, 1)
43 local func = furrybot.commands[cmd]
45 if furrybot.unsafe_commands[cmd] and discord then
46 furrybot.error_message(player, "Sorry, you cannot run this command from discord: ", cmd)
48 func(player, unpack(args))
51 furrybot.error_message(player, "Invalid command", cmd)
56 function furrybot.reload()
57 local func, err = env.loadfile("clientmods/furrybot/bot.lua")
59 local old_fb = table.copy(furrybot)
60 local status, init = pcall(func)
62 init(http, env, storage)
65 return false, furrybot.colors.error .. "Error: " .. furrybot.colors.detail .. init
68 return false, furrybot.colors.error .. "Syntax error: " .. furrybot.colors.detail .. err
72 function furrybot.player_online(name)
73 for _, n in ipairs(minetest.get_player_names()) do
80 function furrybot.online_or_error(name, other, allow_self)
82 furrybot.error_message(name, "You need to specify a player")
83 elseif name == other and not allow_self then
84 furrybot.error_message(name, "You need to specify a different player than yourself")
85 elseif furrybot.player_online(other) then
88 furrybot.error_message(name, "Player not online", other)
92 function furrybot.choose(list, color)
93 return furrybot.colors.random .. list[math.random(#list)] .. color
96 function furrybot.random(min, max, color)
97 return furrybot.colors.random .. math.random(min, max) .. color
100 function furrybot.http_request(url, name, callback)
101 http.fetch({url = url}, function(res)
102 if res.succeeded then
105 furrybot.error_message(name, "Request failed with code", res.code)
110 function furrybot.json_http_request(url, name, callback)
111 furrybot.http_request(url, name, function(raw)
112 local data = minetest.parse_json(raw)
113 callback(data[1] or data)
117 function furrybot.strrandom(str, seed, ...)
119 local pr = PseudoRandom(seed)
121 v = v + str:byte(i) * pr:next()
123 return PseudoRandom(v):next(...)
126 function furrybot.repeat_string(str, times)
134 function furrybot.interactive_roleplay_command(action)
135 return function(name, target)
136 if furrybot.online_or_error(name, target) then
137 furrybot.send(name .. " " .. action .. " " .. target .. ".", furrybot.colors.roleplay)
142 function furrybot.solo_roleplay_command(action)
143 return function(name)
144 furrybot.send(name .. " " .. action .. ".", furrybot.colors.roleplay)
148 function furrybot.request_command(on_request, on_accept)
149 return function(name, target)
150 if furrybot.online_or_error(name, target) and on_request(name, target) ~= false then
151 furrybot.requests[target] = {
159 -- General purpose commands
161 function furrybot.commands.help()
163 for k in pairs(furrybot.commands) do
164 table.insert(keys, k)
166 furrybot.send("Available commands: " .. table.concat(keys, ", "), furrybot.colors.system)
169 function furrybot.commands.accept(name)
170 local tbl = furrybot.requests[name]
172 furrybot.requests[name] = nil
173 tbl.func(tbl.origin, name)
175 furrybot.error_message(name, "Nothing to accept")
178 furrybot.unsafe_commands.accept = true
180 function furrybot.commands.deny(name)
181 local tbl = furrybot.requests[name]
183 furrybot.requests[name] = nil
184 furrybot.ping_message(name, "Denied request", furrybot.colors.system)
186 furrybot.error_message(name, "Nothing to deny")
189 furrybot.unsafe_commands.deny = true
191 -- don't bug players that are running ClamityBot commands from discord
192 function furrybot.commands.status()
195 function furrybot.commands.cmd()
199 furrybot.send("FurryBot - " .. C("#170089") .. "https://github.com/EliasFleckenstein03/furrybot", furrybot.colors.system)
201 if furrybot.loaded then
202 furrybot.send("Reloaded", furrybot.colors.system)
204 furrybot.loaded = true
207 return function(_http, _env, _storage)
208 http, env, storage = _http, _env, _storage
210 for _, f in ipairs {"nsfw", "roleplay", "death", "economy", "random", "http"} do
212 env.loadfile("clientmods/furrybot/" .. f .. ".lua")()(http, env, storage)