]> git.lizzy.rs Git - furrybot.git/blob - bot.lua
Add joke command
[furrybot.git] / bot.lua
1 furrybot.commands = {}
2
3 local C = minetest.get_color_escape_sequence
4
5 function furrybot.send(msg, color)
6         minetest.send_chat_message("/me " .. C("#00FF3C") .. "[" .. C(color or "#FFFA00") .. msg .. C("#00FF3C") .. "]")
7 end
8
9 function furrybot.ping(player)
10         return C("#00DCFF") .. "@" .. player .. C("#FFFA00")
11 end
12
13 function furrybot.ping_player(player, message)
14         furrybot.send(furrybot.ping(player) .. ": " .. message)
15 end
16
17 function furrybot.ping_player_error(player, err, detail)
18         furrybot.ping_player(player, C("#D70029") .. " " .. err .. (detail and C("#FF6683") .. " '" .. detail .. "'" .. C("#D70029") or "") .. ".")
19 end
20
21 function furrybot.recieve(msg)
22         msg = minetest.strip_colors(msg)
23         if msg:find("<") == 1 then
24                 local idx = msg:find(">")
25                 local player = msg:sub(2, idx - 1)
26                 local message = msg:sub(idx + 3, #msg)
27                 if message:find("!") == 1 then
28                         local args = message:sub(2, #message):split(" ")
29                         local cmd = table.remove(args, 1)
30                         local func = furrybot.commands[cmd]
31                         if func then
32                                 func(player, unpack(args))
33                         else
34                                 furrybot.ping_player_error(player, "Invalid command", cmd)
35                         end
36                 end
37         end
38 end
39
40 function furrybot.player_online(name)
41         for _, n in ipairs(minetest.get_player_names()) do
42                 if name == n then
43                         return true
44                 end
45         end
46 end
47
48 function furrybot.check_online(name, target)
49         if not target then
50                 furrybot.ping_player_error(name, "You need to specify a player")
51         elseif name == target then
52                 furrybot.ping_player_error(name, "You need to specify a different player than yourself")
53         elseif furrybot.player_online(target) then
54                 return true
55         else
56                 furrybot.ping_player_error(name, "Player not online", target)
57         end
58 end
59
60 function furrybot.choose(list)
61         return list[math.random(#list)]
62 end
63
64 function furrybot.http_request(url, name, callback)
65         furrybot.http.fetch({url = url}, function(res)
66                 if res.succeeded then
67                         callback(res.data)
68                 else
69                         furrybot.ping_player_error(name, "Request failed with code", res.code)
70                 end
71         end)
72 end
73
74 function furrybot.json_http_request(url, name, callback)
75         furrybot.http_request(url, name, function(raw)
76                 local data = minetest.parse_json(raw)
77                 callback(data[1] or data)
78         end)
79 end
80
81 function furrybot.rand(str, seed, ...)
82         local v = 0
83         local pr = PseudoRandom(seed)
84         for i = 1, #str do
85                 v = v + str:byte(i) * pr:next()
86         end
87         return PseudoRandom(v):next(...)
88 end
89
90 -- commands
91
92 function furrybot.commands.hug(name, target)
93         if furrybot.check_online(name, target) then
94                 furrybot.send(name .. " hugs " .. target .. ".")
95         end
96 end
97
98 furrybot.commands.cuddle = furrybot.commands.hug
99
100 function furrybot.commands.kiss(name, target)
101         if furrybot.check_online(name, target) then
102                 furrybot.send(name .. " kisses " .. target .. ".")
103         end
104 end
105
106 furrybot.target_list = {}
107
108 function furrybot.commands.bang(name, target)
109         if furrybot.check_online(name, target) then
110                 furrybot.target_list[target] = function()
111                         furrybot.send(ping(name) .. " and " .. ping(target) .. " are having sex! OwO")
112                 end,
113                 furrybot.ping_player(target, name .. " wants to have sex with you. Type !accept to accept or !deny to deny.")
114         end
115 end
116
117 furrybot.commands.sex = furrybot.commands.bang
118 furrybot.commands.fuck = furrybot.commands.bang
119
120 function furrybot.commands.accept(name)
121         local func = furrybot.target_list[name]
122         if func then
123                 func()
124         else
125                 furrybot.ping_player_error(name, "Nothing to accept")
126         end
127 end
128
129 function furrybot.commands.deny(name)
130         if furrybot.target_list[name] then
131                 furrybot.target_list[name] = nil
132                 furrybot.ping_player(name, "Denied request")
133         else
134                 furrybot.ping_player_error(name, "Nothing to deny")
135         end
136 end
137
138 function furrybot.commands.hit(name, target)
139         if furrybot.check_online(name, target) then
140                 furrybot.send(name .. " hits " .. target)
141         end
142 end
143
144 furrybot.commands.slap = furrybot.commands.hit
145 furrybot.commands.beat = furrybot.commands.hit
146
147 function furrybot.commands.help()
148         local keys = {}
149         for k in pairs(furrybot.commands) do
150                 table.insert(keys, k)
151         end
152         furrybot.send("Available commands: " .. table.concat(keys, ", "))
153 end
154
155 function furrybot.commands.verse(name)
156         furrybot.json_http_request("https://labs.bible.org/api/?type=json&passage=random", name, function(data)
157                 furrybot.send(data.text .. C("#00FFC3") .. "[" .. data.bookname .. " " .. data.chapter .. "," .. data.verse .. "]")
158         end)
159 end
160
161 function furrybot.commands.define(name, word)
162         if word then
163                 furrybot.json_http_request("https://api.dictionaryapi.dev/api/v1/entries/en_US/" .. word, name, function(data)
164                         local meaning = data.meaning
165                         local selected = meaning.exclamation or meaning.noun or meaning.verb or meaning.adjective or meaning["transitive verb"] or meaning.adverb or meaning["relative adverb"]
166                         if not selected then
167                                 print(dump(meaning))
168                                 furrybot.ping_player_error(name, "Error in parsing response")
169                         else
170                                 furrybot.send(C("#00FFC3") .. word:sub(1, 1):upper() .. word:sub(2, #word):lower() .. ": " .. C("#FFFA00") .. selected[1].definition)
171                         end
172                 end)
173         else
174                 furrybot.ping_player_error(name, "You need to specify a word")
175         end
176 end
177
178 function furrybot.commands.insult(name, target)
179         if furrybot.check_online(name, target) then
180                 furrybot.http_request("https://insult.mattbas.org/api/insult", name, function(data)
181                         furrybot.ping_player(target, data)
182                 end)
183         end
184 end
185
186 function furrybot.commands.rolldice(name)
187         furrybot.ping_player(name, "rolled a dice and got a " .. C("#AAFF43") .. math.random(6))
188 end
189
190 function furrybot.commands.coinflip(name)
191         furrybot.ping_player(name, "flipped a coin and got " .. C("#AAFF43") .. furrybot.choose({"Heads", "Tails"}))
192 end
193
194 function furrybot.commands.status()
195 end
196
197 function furrybot.commands.cmd()
198 end
199
200 function furrybot.commands.cocksize(name, target)
201         target = target or name
202         local msg = C("#FF4DE1")
203         local size = furrybot.rand(target, 31242, 2, 10)
204         for i = 1, size do
205                 msg = msg .. "="
206         end
207         msg = msg .. "D"
208         furrybot.send(msg .. C("#FFFA00") .. "  <= " .. furrybot.ping(target) .. "'s Cock")
209 end
210
211 furrybot.commands.dicksize = furrybot.commands.cocksize
212
213 function furrybot.commands.joke(name, first, last)
214         if not first then
215                 first = "Chuck"
216                 last = "Norris"
217         end
218         furrybot.json_http_request("http://api.icndb.com/jokes/random?firstName=" .. first .. "&lastName=" .. (last or ""), name, function(data)
219                 local joke = data.value.joke:gsub("&quot;", "\""):gsub("  ", " ")
220                 furrybot.send(joke)
221         end)
222 end
223
224 if furrybot.loaded then
225         furrybot.send("Reloaded")
226 else
227         furrybot.loaded = true
228 end