]> git.lizzy.rs Git - furrybot.git/blob - operator.lua
Add operator commands
[furrybot.git] / operator.lua
1 local http, env, storage
2 local C = minetest.get_color_escape_sequence
3
4 function furrybot.is_operator(name)
5         return name == minetest.localplayer:get_name() or furrybot.operators[name]
6 end
7
8 function furrybot.operator_command(cmd, func)
9         furrybot.commands[cmd] = function (name, ...)
10                 if furrybot.is_operator(name) then
11                         func(name, ...)
12                 else
13                         furrybot.error_message(name, "Sorry, you need to be an operator run this command: ", cmd)
14                 end
15         end
16         furrybot.unsafe_commands[cmd] = true
17 end
18
19 function furrybot.status_command(cmd, list_name, title, status)
20         furrybot.operator_command(cmd, function(name, target)
21                 if target then
22                         if furrybot[list_name][target] == status then
23                                 furrybot.error_message(name, "Player " .. (status and "already" or "not") .. " " .. title .. ": ", target)
24                         else
25                                 furrybot[list_name][target] = status
26                                 storage:set_string(list_name, minetest.serialize(furrybot[list_name]))
27                                 furrybot.ping_message(name, "Successfully " .. cmd .. (cmd:sub(#cmd, #cmd) == "e" and "" or "e") .. "d " .. target, furrybot.colors.system)
28                         end
29                 else
30                         furrybot.error_message(name, "You need to specify a player")
31                 end
32         end)
33 end
34
35 function furrybot.list_command(list_name, title)
36         return function()
37                 local names = {}
38
39                 for name in pairs(furrybot[list_name]) do
40                         table.insert(names, name)
41                 end
42
43                 furrybot.send("List of " .. title .. ": " .. table.concat(names, ", "), furrybot.colors.system)
44         end
45 end
46
47 furrybot.operator_command("reload", function()
48         furrybot.reload(http, env, storage)
49 end)
50
51 furrybot.operator_command("disconnect", function()
52         minetest.disconnect()
53 end)
54
55 furrybot.status_command("op", "operators", "an operator", true)
56 furrybot.status_command("deop", "operators", "an operator", nil)
57 furrybot.commands.oplist = furrybot.list_command("operators", "operators")
58
59 furrybot.status_command("ignore", "ignored", "ignored", true)
60 furrybot.status_command("unignore", "ignored", "ignored", nil)
61 furrybot.commands.ignorelist = furrybot.list_command("ignored", "ignored players")
62
63 return function(_http, _env, _storage)
64         http, env, storage = _http, _env, _storage
65
66         furrybot.operators = minetest.deserialize(storage:get_string("operators")) or {}
67         furrybot.ignored = minetest.deserialize(storage:get_string("ignored")) or {}
68 end