minetest-telegram-bridge/chat_mod/init.lua

30 lines
750 B
Lua
Raw Normal View History

2019-01-28 21:09:16 +01:00
local http_api = minetest.request_http_api()
2019-01-22 14:29:16 +01:00
function send_messages(res)
for message in string.gmatch(res["data"], "[^\n]+") do
minetest.chat_send_all(message)
end
end
2019-01-28 21:09:16 +01:00
function main()
2019-01-22 14:29:16 +01:00
port = minetest.settings:get("chat_server_port")
if port == nil then
port = "9876"
end
http_api.fetch({url = "http://localhost:" .. port .. "/get"}, send_messages)
2019-01-28 21:09:16 +01:00
minetest.after(0.5, main)
end
function dead(player)
http_api.fetch_async({url = "http://localhost:" .. port .. "/sendCode",
post_data = {message = player.get_player_name(player) ..
" died."}})
2019-01-22 14:29:16 +01:00
end
if http_api == nil then
minetest.log("error", "Chat Mod is not in secure.http_mods or secure.trusted_mods. Exiting.")
else
2019-01-28 21:09:16 +01:00
main()
end
2019-01-28 21:09:16 +01:00
minetest.register_on_dieplayer(dead)