]> git.lizzy.rs Git - furrybot.git/commitdiff
Hot reloading working; tweaked command names
authorElias Fleckenstein <eliasfleckenstein@web.de>
Wed, 10 Mar 2021 08:12:08 +0000 (09:12 +0100)
committerElias Fleckenstein <eliasfleckenstein@web.de>
Wed, 10 Mar 2021 08:12:08 +0000 (09:12 +0100)
bot.lua [new file with mode: 0644]
init.lua

diff --git a/bot.lua b/bot.lua
new file mode 100644 (file)
index 0000000..aa2e6d5
--- /dev/null
+++ b/bot.lua
@@ -0,0 +1,139 @@
+furrybot.commands = {}
+
+local C = minetest.get_color_escape_sequence
+local http = minetest.get_http_api()
+
+function furrybot.send(msg, color)
+       minetest.send_chat_message("/me " .. C("#00FF3C") .. "[" .. C(color or "#FFFA00") .. msg .. C("#00FF3C") .. "]")
+end
+
+function furrybot.ping(player)
+       return C("#00DCFF") .. "@" .. player .. C("#FFFA00")
+end
+
+function furrybot.ping_player(player, message)
+       furrybot.send(furrybot.ping(player) .. ": " .. message)
+end
+
+function furrybot.ping_player_error(player, err, detail)
+       furrybot.ping_player(player, C("#D70029") .. " " .. err ..  " " .. (detail and C("#FF6683") .. "'" .. detail .. "'" .. C("#D70029") or "") .. ".")
+end
+
+function furrybot.player_online(name)
+       for _, n in ipairs(minetest.get_player_names()) do
+               if name == n then
+                       return true
+               end
+       end
+end
+
+function furrybot.check_online(name, target)
+       if name == target then
+               furrybot.ping_player_error(name, "You need to specify another player")
+       elseif furrybot.player_online(target) then
+               return true
+       else
+               furrybot.ping_player_error(name, "Player not online", target)
+       end
+end
+
+function furrybot.recieve(msg)
+       msg = minetest.strip_colors(msg)
+       if msg:find("<") == 1 then
+               local idx = msg:find(">")
+               local player = msg:sub(2, idx - 1)
+               local message = msg:sub(idx + 3, #msg)
+               if message:find("!") == 1 then
+                       local args = message:sub(2, #message):split(" ")
+                       local cmd = table.remove(args, 1)
+                       local func = furrybot.commands[cmd]
+                       if func then
+                               func(player, unpack(args))
+                       else
+                               furrybot.ping_player_error(player, "Invalid command", cmd)
+                       end
+               end
+       end
+end
+
+function furrybot.commands.hug(name, target)
+       if furrybot.check_online(name, target) then
+               furrybot.send(name .. " hugs " .. target .. ".")
+       end
+end
+
+furrybot.commands.cuddle = furrybot.commands.hug
+
+function furrybot.commands.kiss(name, target)
+       if furrybot.check_online(name, target) then
+               furrybot.send(name .. " kisses " .. target .. ".")
+       end
+end
+
+furrybot.target_list = {}
+
+function furrybot.commands.bang(name, target)
+       if furrybot.check_online(name, target) then
+               furrybot.target_list[target] = function()
+                       furrybot.send(ping(name) .. " and " .. ping(target) .. " are having sex! OwO")
+               end,
+               furrybot.ping_player(target, name .. " wants to have sex with you. Type !accept to accept or !deny to deny.")
+       end
+end
+
+furrybot.commands.sex = furrybot.commands.bang
+furrybot.commands.fuck = furrybot.commands.bang
+
+function furrybot.commands.accept(name)
+       local func = furrybot.target_list[name]
+       if func then
+               func()
+       else
+               furrybot.ping_player_error(name, "Nothing to accept")
+       end
+end
+
+function furrybot.commands.deny(name)
+       if furrybot.target_list[name] then
+               furrybot.target_list[name] = nil
+               furrybot.ping_player(name, "Denied request")
+       else
+               furrybot.ping_player_error(name, "Nothing to deny")
+       end
+end
+
+function furrybot.commands.hit(name, target)
+       if furrybot.check_online(name, target) then
+               furrybot.send(name .. " hits " .. target)
+       end
+end
+
+furrybot.commands.slap = furrybot.commands.hit
+furrybot.commands.beat = furrybot.commands.hit
+
+function furrybot.commands.help()
+       local keys = {}
+       for k in pairs(furrybot.commands) do
+               table.insert(keys, k)
+       end
+       furrybot.send("Available commands: " .. table.concat(keys, ", "))
+end
+
+function furrybot.commands.verse(name)
+       local req = {
+               url = "https://labs.bible.org/api/?type=json&passage=random",
+       }
+       local res = http.fetch_sync(req)
+       if res.succeeded then
+               local data = minetest.parse_json(res.data)[1]
+               furrybot.send(data.text .. C("#00FFC3") .. "[" .. data.bookname .. " " .. data.chapter .. "," .. data.verse .. "]")
+       else
+               furrybot.ping_player_error(name, "Request failed with code", res.code)
+       end
+end
+
+if furrybot.loaded then
+       furrybot.send("Reloaded")
+else
+       furrybot.loaded = true
+end
index 3bb3b4be05af8f8f3765d42e7e4f3b9696c3233a..2b9c2a0e9b71c869a13b35036bddee938f143f8a 100644 (file)
--- a/init.lua
+++ b/init.lua
-furrybot = rawget(_G, "furrybot") or {}
-furrybot.commands = {}
+furrybot = {}
 
-local C = minetest.get_color_escape_sequence
-local http = minetest.get_http_api()
+dofile(minetest.get_modpath("furrybot") .. "/bot.lua")
 
-function furrybot.send(msg, color)
-       minetest.send_chat_message("/me " .. C("#00FF3C") .. "[" .. C(color or "#FFFA00") .. msg .. C("#00FF3C") .. "]")
-end
-
-function furrybot.ping(player)
-       return C("#00DCFF") .. "@" .. player .. C("#FFFA00")
-end
-
-function furrybot.ping_player(player, message)
-       furrybot.send(furrybot.ping(player) .. ": " .. message)
-end
-
-function furrybot.ping_player_error(player, err, detail)
-       furrybot.ping_player(player, C("#D70029") .. " " .. err ..  " " .. (detail and C("#FF6683") .. "'" .. detail .. "'" .. C("#D70029") or "") .. ".")
-end
+local env = assert(minetest.request_insecure_environment())
 
-function furrybot.player_online(name)
-       for _, n in ipairs(minetest.get_player_names()) do
-               if name == n then
-                       return true
-               end
-       end
-end
+minetest.register_on_receiving_chat_message(function(msg)
+       furrybot.recieve(msg)
+end)
 
-function furrybot.check_online(name, target)
-       if name == target then
-               ping_player_error(name, "You need to specify another player")
-       elseif player_online(target) then
-               return true
-       else
-               ping_player_error(name, "Player not online", target)
+minetest.register_chatcommand("furrybot-reload", {
+       func = function()
+               furrybot.reload()
        end
-end
-
-function furrybot.recieve(msg)
-       msg = minetest.strip_colors(msg)
-       if msg:find("<") == 1 then
-               local idx = msg:find(">")
-               local player = msg:sub(2, idx - 1)
-               local message = msg:sub(idx + 3, #msg)
-               if message:find("!") == 1 then
-                       local args = message:sub(2, #message):split(" ")
-                       local cmd = table.remove(args, 1)
-                       local func = furrybot.commands[cmd]
-                       if func then
-                               func(player, unpack(args))
-                       else
-                               furrybot.ping_player_error(player, "Invalid command", cmd)
-                       end
-               end
-       end
-end
-
-function furrybot.commands.furhug(name, target)
-       if furrybot.check_online(name, target) then
-               furrybot.send(name .. " hugs " .. target .. ".")
-       end
-end
-
-furrybot.commands.furcuddle = furrybot.commands.furhug
-
-function furrybot.commands.furkiss(name, target)
-       if furrybot.check_online(name, target) then
-               furrybot.send(name .. " kisses " .. target .. ".")
-       end
-end
-
-furrybot.target_list = {}
-
-function furrybot.commands.furbang(name, target)
-       if furrybot.check_online(name, target) then
-               furrybot.target_list[target] = function()
-                       furrybot.send(ping(name) .. " and " .. ping(target) .. " are having sex! OwO")
-               end,
-               furrybot.ping_player(target, name .. " wants to have sex with you. Type !accept to accept or !deny to deny.")
-       end
-end
-
-furrybot.commands.fursex = furrybot.commands.furbang
-furrybot.commands.furfuck = furrybot.commands.furbang
-
-function furrybot.commands.accept(name)
-       local func = furrybot.target_list[name]
-       if func then
-               func()
-       else
-               furrybot.ping_player_error(name, "Nothing to accept")
-       end
-end
-
-function furrybot.commands.deny(name)
-       if furrybot.target_list[name] then
-               furrybot.target_list[name] = nil
-               furrybot.ping_player(name, "Denied request")
-       else
-               furrybot.ping_player_error(name, "Nothing to deny")
-       end
-end
-
-function furrybot.commands.furhit(name, target)
-       if furrybot.check_online(name, target) then
-               furrybot.send(name .. " hits " .. target)
-       end
-end
-
-furrybot.commands.furslap = furrybot.commands.furhit
-
-function furrybot.commands.help()
-       local keys = {}
-       for k in pairs(furrybot.commands) do
-               table.insert(keys, k)
-       end
-       furrybot.send("Available commands: " .. table.concat(keys, ", "))
-end
-
-function furrybot.commands.verse(name)
-       local req = {
-               url = "https://labs.bible.org/api/?type=json&passage=random",
-       }
-       local res = http.fetch_sync(req)
-       if res.succeeded then
-               local data = minetest.parse_json(res.data)[1]
-               furrybot.send(data.text .. C("#00FFC3") .. "[" .. data.bookname .. " " .. data.chapter .. "," .. data.verse .. "]")
-       else
-               furrybot.ping_player_error(name, "Request failed with code", res.code)
-       end
-end
+})
 
 function furrybot.reload()
-       local f = loadfile(minetest.get_modpath("furrybot") .. "/init.lua")
-       setfenv(f, _G)
-       f()
+       local func = env.loadfile("clientmods/furrybot/bot.lua")
+       func()
 end
-
-if not furrybot.loaded then
-       minetest.register_on_receiving_chat_message(function(msg)
-               furrybot.recieve(msg)
-       end)
-
-       minetest.register_chatcommand("furrybot-reload", {
-               func = function()
-                       furrybot.reload()
-               end
-       })
-else
-       furrybot.send("Reloaded")
-end
-
-furrybot.loaded = true