summaryrefslogtreecommitdiff
path: root/bot.lua
blob: 87581561338282d3413c8b6dfa197337c16bdf09 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
furrybot.commands = {}

local C = minetest.get_color_escape_sequence

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 not target then
		furrybot.ping_player_error(name, "You need to specify a player")
	elseif name == target then
		furrybot.ping_player_error(name, "You need to specify a different player than yourself")
	elseif furrybot.player_online(target) then
		return true
	else
		furrybot.ping_player_error(name, "Player not online", target)
	end
end

function furrybot.choose(list)
	return list[math.random(#list)]
end

function furrybot.http_request(url, name, callback)
	furrybot.http.fetch({url = url}, function(res)
		if res.succeeded then
			callback(res.data)
		else
			furrybot.ping_player_error(name, "Request failed with code", res.code)
		end
	end)
end

function furrybot.json_http_request(url, name, callback)
	furrybot.http_request(url, name, function(data)
		callback(minetest.parse_json(data)[1])
	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)
	furrybot.json_http_request("https://labs.bible.org/api/?type=json&passage=random", name, function(data)
		furrybot.send(data.text .. C("#00FFC3") .. "[" .. data.bookname .. " " .. data.chapter .. "," .. data.verse .. "]")
	end)
end

function furrybot.commands.define(name, word)
	if word then
		furrybot.json_http_request("https://api.dictionaryapi.dev/api/v1/entries/en_US/" .. word, name, function(data)
			local meaning = data.meaning
			local selected = meaning.exclamation or meaning.noun or meaning.verb or meaning.adjective or meaning["transitive verb"] or meaning.adverb or meaning["relative adverb"]
			if not selected then
				print(dump(meaning))
				furrybot.ping_player_error(name, "Error in parsing response")
			else
				furrybot.send(C("#00FFC3") .. word:sub(1, 1):upper() .. word:sub(2, #word):lower() .. ": " .. C("#FFFA00") .. selected[1].definition)
			end
		end)
	else
		furrybot.ping_player_error(name, "You need to specify a word")
	end
end

function furrybot.commands.insult(name, target)
	if furrybot.check_online(name, target) then
		furrybot.http_request("https://insult.mattbas.org/api/insult", name, function(data)
			furrybot.ping_player(target, data)
		end)
	end
end

function furrybot.commands.rolldice(name)
	furrybot.ping_player(name, "rolled a dice and got a " .. C("#AAFF43") .. math.random(6))
end

function furrybot.commands.coinflip(name)
	furrybot.ping_player(name, "flipped a coin and got " .. C("#AAFF43") .. furrybot.choose({"Heads", "Tails"}))
end

function furrybot.commands.status()
end

function furrybot.commands.cmd()
end

if furrybot.loaded then
	furrybot.send("Reloaded")
else
	furrybot.loaded = true
end