]> git.lizzy.rs Git - furrybot.git/commitdiff
Add operator commands
authorElias Fleckenstein <eliasfleckenstein@web.de>
Mon, 13 Sep 2021 14:15:50 +0000 (16:15 +0200)
committerElias Fleckenstein <eliasfleckenstein@web.de>
Mon, 13 Sep 2021 14:15:50 +0000 (16:15 +0200)
bot.lua
http.lua
init.lua
nsfw.lua
operator.lua [new file with mode: 0644]

diff --git a/bot.lua b/bot.lua
index c92e8f97c56e8f88cadd0f3904090b226c1a4b4c..e75613999110647f6367ceaf82e3d2120aaacaa9 100644 (file)
--- a/bot.lua
+++ b/bot.lua
@@ -37,7 +37,7 @@ function furrybot.error_message(player, error, detail)
 end
 
 function furrybot.parse_message(player, message, discord)
-       if message:find("!") == 1 then
+       if message:find("!") == 1 and not furrybot.ignored[player] then
                local args = message:sub(2, #message):split(" ")
                local cmd = table.remove(args, 1)
                local func = furrybot.commands[cmd]
@@ -65,10 +65,10 @@ function furrybot.reload()
 
                if not status then
                        furrybot = old_fb
-                       return false, furrybot.colors.error .. "Error: " .. furrybot.colors.detail .. init
+                       furrybot.send("Error: " .. furrybot.colors.detail .. init, furrybot.colors.error)
                end
        else
-               return false, furrybot.colors.error .. "Syntax error: " .. furrybot.colors.detail .. err
+               furrybot.send("Syntax error: " .. furrybot.colors.detail .. err, furrybot.colors.error)
        end
 end
 
@@ -201,7 +201,7 @@ end
 return function(_http, _env, _storage)
        http, env, storage = _http, _env, _storage
 
-       for _, f in ipairs {"nsfw", "roleplay", "death", "economy", "random", "http"} do
+       for _, f in ipairs {"nsfw", "roleplay", "death", "economy", "random", "http", "operator"} do
                local func, err = env.loadfile("clientmods/furrybot/" .. f .. ".lua")
 
                if not func then
index c6dd8b9dbc9cde66706b3b19c4ce9bee0bc42d46..fc06d2cb322869d99dda8d135a713e210f0cd8a5 100644 (file)
--- a/http.lua
+++ b/http.lua
@@ -55,4 +55,3 @@ furrybot.commands["8ball"] = furrybot.commands.question
 return function(_http, _env, _storage)
        http, env, storage = _http, _env, _storage
 end
-
index dcaf9857a065eb95c9728b3670a49a25bcd13cb6..757938415540af8a97f767115b99d6232bfdfa7b 100644 (file)
--- a/init.lua
+++ b/init.lua
@@ -8,10 +8,4 @@ libclamity.register_on_chat_message(function(...)
        furrybot.parse_message(...)
 end)
 
-minetest.register_chatcommand("fbreload", {
-       func = function()
-               return furrybot.reload(http, env, storage)
-       end
-})
-
 loadfile(minetest.get_modpath("furrybot") .. "/bot.lua")()(http, env, storage)
index c9e1d35b2ba90191aeba77e054093fe01e673c72..cfb462ef550622c8534817833c71f348d156a47f 100644 (file)
--- a/nsfw.lua
+++ b/nsfw.lua
@@ -6,11 +6,11 @@ function furrybot.get_ascii_genitals(name, begin, middle, ending, seed)
 end
 
 function furrybot.get_ascii_dick(name)
-       return minetest.rainbow(furrybot.get_ascii_genitals(name, "8", "=", "D", 69))
+       return minetest.rainbow(furrybot.get_ascii_genitals(name, "8", "=", "D", 31242))
 end
 
 function furrybot.get_ascii_boobs(name)
-       return furrybot.get_ascii_genitals(name, "E", "Ξ", "3", 420)
+       return furrybot.get_ascii_genitals(name, "E", "Ξ", "3", 31243)
 end
 
 function furrybot.commands.dicksize(name, target)
diff --git a/operator.lua b/operator.lua
new file mode 100644 (file)
index 0000000..e668ac7
--- /dev/null
@@ -0,0 +1,68 @@
+local http, env, storage
+local C = minetest.get_color_escape_sequence
+
+function furrybot.is_operator(name)
+       return name == minetest.localplayer:get_name() or furrybot.operators[name]
+end
+
+function furrybot.operator_command(cmd, func)
+       furrybot.commands[cmd] = function (name, ...)
+               if furrybot.is_operator(name) then
+                       func(name, ...)
+               else
+                       furrybot.error_message(name, "Sorry, you need to be an operator run this command: ", cmd)
+               end
+       end
+       furrybot.unsafe_commands[cmd] = true
+end
+
+function furrybot.status_command(cmd, list_name, title, status)
+       furrybot.operator_command(cmd, function(name, target)
+               if target then
+                       if furrybot[list_name][target] == status then
+                               furrybot.error_message(name, "Player " .. (status and "already" or "not") .. " " .. title .. ": ", target)
+                       else
+                               furrybot[list_name][target] = status
+                               storage:set_string(list_name, minetest.serialize(furrybot[list_name]))
+                               furrybot.ping_message(name, "Successfully " .. cmd .. (cmd:sub(#cmd, #cmd) == "e" and "" or "e") .. "d " .. target, furrybot.colors.system)
+                       end
+               else
+                       furrybot.error_message(name, "You need to specify a player")
+               end
+       end)
+end
+
+function furrybot.list_command(list_name, title)
+       return function()
+               local names = {}
+
+               for name in pairs(furrybot[list_name]) do
+                       table.insert(names, name)
+               end
+
+               furrybot.send("List of " .. title .. ": " .. table.concat(names, ", "), furrybot.colors.system)
+       end
+end
+
+furrybot.operator_command("reload", function()
+       furrybot.reload(http, env, storage)
+end)
+
+furrybot.operator_command("disconnect", function()
+       minetest.disconnect()
+end)
+
+furrybot.status_command("op", "operators", "an operator", true)
+furrybot.status_command("deop", "operators", "an operator", nil)
+furrybot.commands.oplist = furrybot.list_command("operators", "operators")
+
+furrybot.status_command("ignore", "ignored", "ignored", true)
+furrybot.status_command("unignore", "ignored", "ignored", nil)
+furrybot.commands.ignorelist = furrybot.list_command("ignored", "ignored players")
+
+return function(_http, _env, _storage)
+       http, env, storage = _http, _env, _storage
+
+       furrybot.operators = minetest.deserialize(storage:get_string("operators")) or {}
+       furrybot.ignored = minetest.deserialize(storage:get_string("ignored")) or {}
+end