aboutsummaryrefslogtreecommitdiff
path: root/bot.lua
diff options
context:
space:
mode:
authorElias Fleckenstein <eliasfleckenstein@web.de>2021-09-12 19:10:06 +0200
committerElias Fleckenstein <eliasfleckenstein@web.de>2021-09-12 19:10:06 +0200
commitedf1ee1b8c06c85cedabd998836ecc4b96809fd1 (patch)
tree957a7406b9a1153103f1f77f411b0906bd0be7b2 /bot.lua
downloadamogus-edf1ee1b8c06c85cedabd998836ecc4b96809fd1.tar.xz
Initial commit
Diffstat (limited to 'bot.lua')
-rw-r--r--bot.lua40
1 files changed, 40 insertions, 0 deletions
diff --git a/bot.lua b/bot.lua
new file mode 100644
index 0000000..cbffb2e
--- /dev/null
+++ b/bot.lua
@@ -0,0 +1,40 @@
+local http, env, storage
+
+function amogus.urlencode(url)
+ url = url:gsub("\n", "\r\n")
+ url = url:gsub("([^%w ])", function(c)
+ return string.format("%%%02X", string.byte(c))
+ end)
+ url = url:gsub(" ", "+")
+ return url
+end
+
+function amogus.parse_message(player, message, discord)
+ if player ~= minetest.localplayer:get_name() then
+ http.fetch({url = "http://localhost:6969?message=" .. amogus.urlencode(message), timeout = 100}, function(res)
+ if res.succeeded then
+ minetest.send_chat_message(res.data)
+ end
+ end)
+ end
+end
+
+function amogus.reload()
+ local func, err = env.loadfile("clientmods/amogus/bot.lua")
+ if func then
+ local old_amogus = table.copy(amogus)
+ local status, init = pcall(func)
+ if status then
+ init(http, env, storage)
+ else
+ amogus = old_amogus
+ return false, "Error: " .. init
+ end
+ else
+ return false, "Syntax error: " .. err
+ end
+end
+
+return function(_http, _env, _storage)
+ http, env, storage = _http, _env, _storage
+end