]> git.lizzy.rs Git - furrybot.git/blob - init.lua
Hot reloading and working .verse command
[furrybot.git] / init.lua
1 furrybot = rawget(_G, "furrybot") or {}
2 furrybot.commands = {}
3
4 local C = minetest.get_color_escape_sequence
5 local http = minetest.get_http_api()
6
7 function furrybot.send(msg, color)
8         minetest.send_chat_message("/me " .. C("#00FF3C") .. "[" .. C(color or "#FFFA00") .. msg .. C("#00FF3C") .. "]")
9 end
10
11 function furrybot.ping(player)
12         return C("#00DCFF") .. "@" .. player .. C("#FFFA00")
13 end
14
15 function furrybot.ping_player(player, message)
16         furrybot.send(furrybot.ping(player) .. ": " .. message)
17 end
18
19 function furrybot.ping_player_error(player, err, detail)
20         furrybot.ping_player(player, C("#D70029") .. " " .. err ..  " " .. (detail and C("#FF6683") .. "'" .. detail .. "'" .. C("#D70029") or "") .. ".")
21 end
22
23 function furrybot.player_online(name)
24         for _, n in ipairs(minetest.get_player_names()) do
25                 if name == n then
26                         return true
27                 end
28         end
29 end
30
31 function furrybot.check_online(name, target)
32         if name == target then
33                 ping_player_error(name, "You need to specify another player")
34         elseif player_online(target) then
35                 return true
36         else
37                 ping_player_error(name, "Player not online", target)
38         end
39 end
40
41 function furrybot.recieve(msg)
42         msg = minetest.strip_colors(msg)
43         if msg:find("<") == 1 then
44                 local idx = msg:find(">")
45                 local player = msg:sub(2, idx - 1)
46                 local message = msg:sub(idx + 3, #msg)
47                 if message:find("!") == 1 then
48                         local args = message:sub(2, #message):split(" ")
49                         local cmd = table.remove(args, 1)
50                         local func = furrybot.commands[cmd]
51                         if func then
52                                 func(player, unpack(args))
53                         else
54                                 furrybot.ping_player_error(player, "Invalid command", cmd)
55                         end
56                 end
57         end
58 end
59
60 function furrybot.commands.furhug(name, target)
61         if furrybot.check_online(name, target) then
62                 furrybot.send(name .. " hugs " .. target .. ".")
63         end
64 end
65
66 furrybot.commands.furcuddle = furrybot.commands.furhug
67
68 function furrybot.commands.furkiss(name, target)
69         if furrybot.check_online(name, target) then
70                 furrybot.send(name .. " kisses " .. target .. ".")
71         end
72 end
73
74 furrybot.target_list = {}
75
76 function furrybot.commands.furbang(name, target)
77         if furrybot.check_online(name, target) then
78                 furrybot.target_list[target] = function()
79                         furrybot.send(ping(name) .. " and " .. ping(target) .. " are having sex! OwO")
80                 end,
81                 furrybot.ping_player(target, name .. " wants to have sex with you. Type !accept to accept or !deny to deny.")
82         end
83 end
84
85 furrybot.commands.fursex = furrybot.commands.furbang
86 furrybot.commands.furfuck = furrybot.commands.furbang
87
88 function furrybot.commands.accept(name)
89         local func = furrybot.target_list[name]
90         if func then
91                 func()
92         else
93                 furrybot.ping_player_error(name, "Nothing to accept")
94         end
95 end
96
97 function furrybot.commands.deny(name)
98         if furrybot.target_list[name] then
99                 furrybot.target_list[name] = nil
100                 furrybot.ping_player(name, "Denied request")
101         else
102                 furrybot.ping_player_error(name, "Nothing to deny")
103         end
104 end
105
106 function furrybot.commands.furhit(name, target)
107         if furrybot.check_online(name, target) then
108                 furrybot.send(name .. " hits " .. target)
109         end
110 end
111
112 furrybot.commands.furslap = furrybot.commands.furhit
113
114 function furrybot.commands.help()
115         local keys = {}
116         for k in pairs(furrybot.commands) do
117                 table.insert(keys, k)
118         end
119         furrybot.send("Available commands: " .. table.concat(keys, ", "))
120 end
121
122 function furrybot.commands.verse(name)
123         local req = {
124                 --url = "https://labs.bible.org/api/?type=json&passage=random",
125                 url = "localhost",
126         }
127         local res = http.fetch_sync(req)
128         if res.succeeded then
129                 --local data = minetest.parse_json(res.data)[1]
130                 --furrybot.send(data.text .. C("#00FFC3") .. "[" .. data.bookname .. " " .. data.chapter .. "," .. data.verse .. "]")
131                 furrybot.send(res.data)
132         else
133                 furrybot.ping_player_error(name, "Request failed with code", res.code)
134         end
135 end
136
137 function furrybot.reload()
138         local f = loadfile(minetest.get_modpath("furrybot") .. "/init.lua")
139         setfenv(f, _G)
140         f()
141 end
142
143 if not furrybot.loaded then
144         minetest.register_on_receiving_chat_message(function(msg)
145                 furrybot.recieve(msg)
146         end)
147
148         minetest.register_chatcommand("furrybot-reload", {
149                 func = function()
150                         furrybot.reload()
151                 end
152         })
153 else
154         furrybot.send("Reloaded")
155 end
156
157 furrybot.loaded = true