read and write
This commit is contained in:
parent
df3c54c21f
commit
62b3444c10
40
init.lua
40
init.lua
@ -26,7 +26,7 @@ dofile(yl_matterbridge.modpath .. "config.lua")
|
|||||||
|
|
||||||
local http = minetest.request_http_api()
|
local http = minetest.request_http_api()
|
||||||
|
|
||||||
function yl_matterbridge.send(user_name, message_text)
|
function send(user_name, message_text)
|
||||||
local url = "http://" .. yl_matterbridge.address .. ":" .. yl_matterbridge.port .. "/api/message"
|
local url = "http://" .. yl_matterbridge.address .. ":" .. yl_matterbridge.port .. "/api/message"
|
||||||
local post_headers = {"Content-Type: application/json"}
|
local post_headers = {"Content-Type: application/json"}
|
||||||
local timeout = 10
|
local timeout = 10
|
||||||
@ -35,7 +35,7 @@ function yl_matterbridge.send(user_name, message_text)
|
|||||||
username = user_name,
|
username = user_name,
|
||||||
gateway = yl_matterbridge.gateway
|
gateway = yl_matterbridge.gateway
|
||||||
}
|
}
|
||||||
core.log("action", "[MOD] yl_matterbridge : Posted " .. dump(data))
|
|
||||||
http.fetch(
|
http.fetch(
|
||||||
{
|
{
|
||||||
url = url,
|
url = url,
|
||||||
@ -49,7 +49,6 @@ function yl_matterbridge.send(user_name, message_text)
|
|||||||
core.log("action", "[MOD] yl_matterbridge : Posted " .. dump(data))
|
core.log("action", "[MOD] yl_matterbridge : Posted " .. dump(data))
|
||||||
else
|
else
|
||||||
minetest.log("error", "[yl_matterbridge] " .. dump(result))
|
minetest.log("error", "[yl_matterbridge] " .. dump(result))
|
||||||
--minetest.chat_send_player(user_name, "We were not able to send your text.")
|
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -57,10 +56,39 @@ function yl_matterbridge.send(user_name, message_text)
|
|||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_on_chat_message(function(user_name, message_text)
|
minetest.register_on_chat_message(
|
||||||
yl_matterbridge.send(user_name, message_text)
|
function(user_name, message_text)
|
||||||
end
|
send(user_name, message_text)
|
||||||
|
end
|
||||||
)
|
)
|
||||||
|
|
||||||
|
local gs = function(dtime)
|
||||||
|
local url = "http://" .. yl_matterbridge.address .. ":" .. yl_matterbridge.port .. "/api/messages"
|
||||||
|
local timeout = 0
|
||||||
|
|
||||||
|
http.fetch(
|
||||||
|
{
|
||||||
|
url = url,
|
||||||
|
timeout = timeout
|
||||||
|
},
|
||||||
|
function(result)
|
||||||
|
if result.succeeded then
|
||||||
|
local data = minetest.parse_json(result.data)
|
||||||
|
core.log("action", "[MOD] yl_matterbridge : Posted " .. dump(data))
|
||||||
|
for _,v in ipairs(data) do
|
||||||
|
if v.username and v.text then
|
||||||
|
core.chat_send_all("<"..v.username.."@irc> "..v.text)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
minetest.log("error", "[yl_matterbridge] " .. dump(result))
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
minetest.register_globalstep(gs)
|
||||||
|
|
||||||
local mod_end_time = (core.get_us_time() - mod_start_time) / 1000000
|
local mod_end_time = (core.get_us_time() - mod_start_time) / 1000000
|
||||||
core.log("action", "[MOD] yl_matterbridge loaded in [" .. mod_end_time .. "s]")
|
core.log("action", "[MOD] yl_matterbridge loaded in [" .. mod_end_time .. "s]")
|
||||||
|
Loading…
Reference in New Issue
Block a user