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