37 lines
1.2 KiB
Lua
37 lines
1.2 KiB
Lua
local http = minetest.request_http_api()
|
|
|
|
function yl_matterbridge.send(user_name, message_text)
|
|
local url = "http://" .. yl_matterbridge.address .. ":" .. yl_matterbridge.port .. "/api/message"
|
|
local post_headers = {"Content-Type: application/json"}
|
|
local timeout = 10
|
|
local data = {
|
|
text = message_text,
|
|
username = user_name,
|
|
gateway = yl_matterbridge.gateway
|
|
}
|
|
|
|
http.fetch(
|
|
{
|
|
url = url,
|
|
extra_headers = post_headers,
|
|
timeout = timeout,
|
|
post_data = minetest.write_json(data)
|
|
},
|
|
function(result)
|
|
if result.succeeded then
|
|
local data = minetest.parse_json(result.data)
|
|
core.log("action", "[MOD] yl_matterbridge : Posted " .. dump(data))
|
|
else
|
|
minetest.log("error", "[yl_matterbridge] " .. dump(result))
|
|
minetest.chat_send_player(user_name, "We were not able to send your text.")
|
|
return false
|
|
end
|
|
end
|
|
)
|
|
return true
|
|
end
|
|
|
|
minetest.register_on_chat_message(function(name, message)
|
|
yl_matterbridge.send(user_name, message_text)
|
|
end
|
|
) |