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 and not furrybot.ignored[player] 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)
63 status, init = init(http, env, storage)
68 furrybot.send("Error: " .. furrybot.colors.detail .. init, furrybot.colors.error)
71 furrybot.send("Syntax error: " .. furrybot.colors.detail .. err, furrybot.colors.error)
75 function furrybot.player_online(name)
76 for _, n in ipairs(minetest.get_player_names()) do
83 function furrybot.online_or_error(name, other, allow_self)
85 furrybot.error_message(name, "You need to specify a player")
86 elseif name == other and not allow_self then
87 furrybot.error_message(name, "You need to specify a different player than yourself")
88 elseif furrybot.player_online(other) then
91 furrybot.error_message(name, "Player not online", other)
95 function furrybot.choose(list, color)
96 return furrybot.colors.random .. list[math.random(#list)] .. color
99 function furrybot.random(min, max, color)
100 return furrybot.colors.random .. math.random(min, max) .. color
103 function furrybot.http_request(url, name, callback)
104 http.fetch({url = url}, function(res)
105 if res.succeeded then
108 furrybot.error_message(name, "Request failed with code", res.code)
113 function furrybot.json_http_request(url, name, callback)
114 furrybot.http_request(url, name, function(raw)
115 local data = minetest.parse_json(raw)
116 callback(data[1] or data)
120 function furrybot.strrandom(str, seed, ...)
122 local pr = PseudoRandom(seed)
124 v = v + str:byte(i) * pr:next()
126 return PseudoRandom(v):next(...)
129 function furrybot.repeat_string(str, times)
137 function furrybot.interactive_roleplay_command(action)
138 return function(name, target)
139 if furrybot.online_or_error(name, target) then
140 furrybot.send(name .. " " .. action .. " " .. target .. ".", furrybot.colors.roleplay)
145 function furrybot.solo_roleplay_command(action)
146 return function(name)
147 furrybot.send(name .. " " .. action .. ".", furrybot.colors.roleplay)
151 function furrybot.request_command(on_request, on_accept)
152 return function(name, target)
153 if furrybot.online_or_error(name, target) and on_request(name, target) ~= false then
154 furrybot.requests[target] = {
162 -- General purpose commands
164 function furrybot.commands.help()
167 for cmd in pairs(furrybot.commands) do
168 table.insert(commands, cmd)
173 furrybot.send("Available commands: " .. table.concat(commands, ", "), furrybot.colors.system)
176 function furrybot.commands.accept(name)
177 local tbl = furrybot.requests[name]
179 furrybot.requests[name] = nil
180 tbl.func(tbl.origin, name)
182 furrybot.error_message(name, "Nothing to accept")
185 furrybot.unsafe_commands.accept = true
187 function furrybot.commands.deny(name)
188 local tbl = furrybot.requests[name]
190 furrybot.requests[name] = nil
191 furrybot.ping_message(name, "Denied request", furrybot.colors.system)
193 furrybot.error_message(name, "Nothing to deny")
196 furrybot.unsafe_commands.deny = true
198 -- don't bug players that are running ClamityBot commands from discord
199 function furrybot.commands.status()
202 function furrybot.commands.cmd()
205 return function(_http, _env, _storage)
206 http, env, storage = _http, _env, _storage
208 for _, f in ipairs {"nsfw", "roleplay", "death", "economy", "random", "http", "operator", "bullshit"} do
209 local func, err = env.loadfile("clientmods/furrybot/" .. f .. ".lua")
215 func()(http, env, storage)
218 furrybot.send("FurryBot - " .. C("#170089") .. "https://github.com/EliasFleckenstein03/furrybot", furrybot.colors.system)
220 if furrybot.loaded then
221 furrybot.send("Reloaded", furrybot.colors.system)
223 furrybot.loaded = true