4 local http, env, storage
5 local C = minetest.get_color_escape_sequence
11 detail = C("#FF6683"),
12 roleplay = C("#FFD94E"),
13 braces = C("#FFFAC0"),
16 random = C("#A300BE"),
21 function furrybot.send(msg, color)
22 minetest.send_chat_message("/me " .. furrybot.colors.braces .. "[" .. color .. msg .. furrybot.colors.braces .. "]")
25 function furrybot.ping(player, color)
26 return furrybot.colors.ping .. "@" .. player .. color
29 function furrybot.ping_message(player, message, color)
30 furrybot.send(furrybot.ping(player, color) .. ": " .. message, "")
33 function furrybot.error_message(player, error, detail)
34 furrybot.ping_message(player, error .. (detail and furrybot.colors.detail .. " '" .. detail .. "'" .. furrybot.colors.error or "") .. ".", furrybot.colors.error)
37 function furrybot.parse_message(player, message, discord)
38 if message:find("!") == 1 and not furrybot.ignored[player] then
39 local args = message:sub(2, #message):split(" ")
40 local cmd = table.remove(args, 1)
41 local def = furrybot.commands[cmd]
44 if (def.unsafe or def.operator) and discord then
45 furrybot.error_message(player, "Sorry, you cannot run this command from discord: ", cmd)
46 elseif def.operator and not furrybot.is_operator(player) then
47 furrybot.error_message(player, "Sorry, you need to be an operator run this command: ", cmd)
48 elseif not def.ignore then
49 def.func(player, unpack(args))
52 furrybot.error_message(player, "Invalid command", cmd)
57 function furrybot.reload()
58 local func, err = env.loadfile("clientmods/furrybot/bot.lua")
60 local old_fb = table.copy(furrybot)
61 local status, init = pcall(func)
64 status, init = init(http, env, storage)
69 furrybot.send("Error: " .. furrybot.colors.detail .. init, furrybot.colors.error)
72 furrybot.send("Syntax error: " .. furrybot.colors.detail .. err, furrybot.colors.error)
76 function furrybot.player_online(name)
77 for _, n in ipairs(minetest.get_player_names()) do
84 function furrybot.online_or_error(name, other, allow_self)
86 furrybot.error_message(name, "You need to specify a player")
87 elseif name == other and not allow_self then
88 furrybot.error_message(name, "You need to specify a different player than yourself")
89 elseif furrybot.player_online(other) then
92 furrybot.error_message(name, "Player not online", other)
96 function furrybot.choose(list, color)
97 return furrybot.colors.random .. list[math.random(#list)] .. color
100 function furrybot.random(min, max, color)
101 return furrybot.colors.random .. math.random(min, max) .. color
104 function furrybot.http_request(url, name, callback)
105 http.fetch({url = url}, function(res)
106 if res.succeeded then
109 furrybot.error_message(name, "Request failed with code", res.code)
114 function furrybot.json_http_request(url, name, callback)
115 furrybot.http_request(url, name, function(raw)
116 local data = minetest.parse_json(raw)
117 callback(data[1] or data)
121 function furrybot.strrandom(str, seed, ...)
123 local pr = PseudoRandom(seed)
125 v = v + str:byte(i) * pr:next()
127 return PseudoRandom(v):next(...)
130 function furrybot.repeat_string(str, times)
138 function furrybot.uppercase(str)
139 return str:sub(1, 1):upper() .. str:sub(2, #str)
142 function furrybot.interactive_roleplay_command(cmd, action)
143 furrybot.commands[cmd] = {
145 help = furrybot.uppercase(cmd) .. " another player",
146 func = function(name, target)
147 if furrybot.online_or_error(name, target) then
148 furrybot.send(name .. " " .. action .. " " .. target .. ".", furrybot.colors.roleplay)
154 function furrybot.solo_roleplay_command(cmd, action, help)
155 furrybot.commands[cmd] = {
156 help = furrybot.uppercase(cmd),
157 func = function(name)
158 furrybot.send(name .. " " .. action .. ".", furrybot.colors.roleplay)
163 function furrybot.request_command(cmd, help, on_request, on_accept, unsafe)
164 furrybot.commands[cmd] = {
167 help = "Request to " .. help,
168 func = function(name, target)
169 if furrybot.online_or_error(name, target) and on_request(name, target) ~= false then
170 furrybot.requests[target] = {
179 function furrybot.is_operator(name)
180 return name == minetest.localplayer:get_name() or furrybot.operators[name]
183 function furrybot.list_change_command(cmd, list_name, title, status)
184 furrybot.commands[cmd] = {
186 func = function(name, target)
188 if furrybot[list_name][target] == status then
189 furrybot.error_message(name, "Player " .. (status and "already" or "not") .. " " .. title .. ": ", target)
191 furrybot[list_name][target] = status
192 storage:set_string(list_name, minetest.serialize(furrybot[list_name]))
193 furrybot.ping_message(name, "Successfully " .. cmd .. (cmd:sub(#cmd, #cmd) == "e" and "" or "e") .. "d " .. target, furrybot.colors.system)
196 furrybot.error_message(name, "You need to specify a player")
202 function furrybot.list_command(cmd, list_name, title)
203 furrybot.commands[cmd] = {
207 for name in pairs(furrybot[list_name]) do
208 table.insert(names, name)
211 furrybot.send("List of " .. title .. ": " .. table.concat(names, ", "), furrybot.colors.system)
216 furrybot.commands.cmd = {
220 furrybot.commands.status = {
224 furrybot.commands.help = {
225 params = "[<command>]",
226 help = "Display help for a commands or show list of available commands",
227 func = function(name, command)
229 local def = furrybot.commands[command]
232 furrybot.send("!" .. command .. (def.params and " " .. def.params or "") .. ": " .. (def.help or "No description given"), furrybot.colors.system)
234 furrybot.error_message(name, "Invalid command", command)
239 for cmd in pairs(furrybot.commands) do
240 table.insert(commands, cmd)
245 furrybot.send("Available commands: " .. table.concat(commands, ", "), furrybot.colors.system)
250 furrybot.commands.accept = {
252 help = "Accept a request",
253 func = function(name)
254 local tbl = furrybot.requests[name]
256 furrybot.requests[name] = nil
257 tbl.func(tbl.origin, name)
259 furrybot.error_message(name, "Nothing to accept")
264 furrybot.commands.deny = {
266 help = "Deny a request",
267 func = function(name)
268 local tbl = furrybot.requests[name]
270 furrybot.requests[name] = nil
271 furrybot.ping_message(name, "Denied request", furrybot.colors.system)
273 furrybot.error_message(name, "Nothing to deny")
278 return function(_http, _env, _storage)
279 http, env, storage = _http, _env, _storage
281 furrybot.operators = minetest.deserialize(storage:get_string("operators")) or {}
282 furrybot.ignored = minetest.deserialize(storage:get_string("ignored")) or {}
284 for _, f in ipairs {"nsfw", "roleplay", "death", "economy", "random", "http", "operator", "bullshit", "marriage", "waifu"} do
285 local func, err = env.loadfile("clientmods/furrybot/" .. f .. ".lua")
291 func()(http, env, storage)
294 furrybot.send("FurryBot - " .. C("#170089") .. "https://github.com/EliasFleckenstein03/furrybot", furrybot.colors.system)
296 if furrybot.loaded then
297 furrybot.send("Reloaded", furrybot.colors.system)
299 furrybot.loaded = true