Formatting
This commit is contained in:
parent
8b5bc33b59
commit
a514764db7
129
init.lua
129
init.lua
|
@ -1,24 +1,21 @@
|
|||
-- Version 1.0.3
|
||||
-- Author AliasAlreadyTaken
|
||||
-- License MIT
|
||||
|
||||
-- Changelog
|
||||
|
||||
-- 0.0.1 First puny attempts
|
||||
-- 0.0.2 Feature complete including settings
|
||||
-- 1.0.0 Ready for release
|
||||
-- 1.0.1 Bugfix https://gitea.your-land.de/your-land/bugtracker/issues/1646
|
||||
-- 1.0.2 Bugfix settingtypes: bool instead of boolean
|
||||
-- 1.0.3 Release to cdb
|
||||
|
||||
local mod_start_time = core.get_us_time()
|
||||
core.log("action", "[MOD] yl_matterbridge loading")
|
||||
|
||||
yl_matterbridge = {}
|
||||
--yl_matterbridge.error = {}
|
||||
--yl_matterbridge.modstorage = core.get_mod_storage()
|
||||
--yl_matterbridge.modpath = core.get_modpath("yl_matterbridge") .. DIR_DELIM
|
||||
--yl_matterbridge.worldpath = core.get_worldpath() .. DIR_DELIM
|
||||
-- yl_matterbridge.error = {}
|
||||
-- yl_matterbridge.modstorage = core.get_mod_storage()
|
||||
-- yl_matterbridge.modpath = core.get_modpath("yl_matterbridge") .. DIR_DELIM
|
||||
-- yl_matterbridge.worldpath = core.get_worldpath() .. DIR_DELIM
|
||||
|
||||
yl_matterbridge.information = {}
|
||||
yl_matterbridge.information.version = "1.0.3"
|
||||
|
@ -54,12 +51,12 @@ local url_send = "http://" .. settings.address .. ":" .. settings.port .. "/api/
|
|||
local url_receive = "http://" .. settings.address .. ":" .. settings.port .. "/api/messages"
|
||||
|
||||
local function send(user_name, message_text)
|
||||
if yl_matterbridge.enabled == false then return false end
|
||||
if yl_matterbridge.enabled == false then
|
||||
return false
|
||||
end
|
||||
if settings.debug then
|
||||
core.log(
|
||||
"action",
|
||||
"[MOD] yl_matterbridge : send user_name = " .. dump(user_name) .. ", message_text = " .. dump(message_text)
|
||||
)
|
||||
core.log("action", "[MOD] yl_matterbridge : send user_name = " .. dump(user_name) .. ", message_text = " ..
|
||||
dump(message_text))
|
||||
end
|
||||
local timeout = 10
|
||||
local data_in = {
|
||||
|
@ -68,78 +65,68 @@ local function send(user_name, message_text)
|
|||
gateway = settings.gateway
|
||||
}
|
||||
|
||||
http.fetch(
|
||||
{
|
||||
url = url_send,
|
||||
extra_headers = post_headers,
|
||||
timeout = timeout,
|
||||
post_data = core.write_json(data_in)
|
||||
},
|
||||
function(result)
|
||||
if (not result.completed) or (not result.succeeded) or (result.code ~= 200) then
|
||||
core.log("error", "[MOD] yl_matterbridge: send/http.fetch failed. Result = " .. dump(result))
|
||||
return false
|
||||
else
|
||||
if settings.debug then
|
||||
local data_out = core.parse_json(result.data)
|
||||
core.log(
|
||||
"action",
|
||||
"[MOD] yl_matterbridge : send result = " .. dump(result) .. ", data = " .. dump(data_out)
|
||||
)
|
||||
end
|
||||
return true
|
||||
http.fetch({
|
||||
url = url_send,
|
||||
extra_headers = post_headers,
|
||||
timeout = timeout,
|
||||
post_data = core.write_json(data_in)
|
||||
}, function(result)
|
||||
if (not result.completed) or (not result.succeeded) or (result.code ~= 200) then
|
||||
core.log("error", "[MOD] yl_matterbridge: send/http.fetch failed. Result = " .. dump(result))
|
||||
return false
|
||||
else
|
||||
if settings.debug then
|
||||
local data_out = core.parse_json(result.data)
|
||||
core.log("action",
|
||||
"[MOD] yl_matterbridge : send result = " .. dump(result) .. ", data = " .. dump(data_out))
|
||||
end
|
||||
return true
|
||||
end
|
||||
)
|
||||
end)
|
||||
end
|
||||
|
||||
local function receive()
|
||||
if yl_matterbridge.enabled == false then return false end
|
||||
if yl_matterbridge.enabled == false then
|
||||
return false
|
||||
end
|
||||
if settings.debug then
|
||||
core.log("action", "[MOD] yl_matterbridge : receive")
|
||||
end
|
||||
local timeout = 0
|
||||
|
||||
http.fetch(
|
||||
{
|
||||
url = url_receive,
|
||||
extra_headers = post_headers,
|
||||
timeout = timeout
|
||||
},
|
||||
function(result)
|
||||
if (not result.completed) or (not result.succeeded) or (result.code ~= 200) then
|
||||
core.log("error", "[MOD] yl_matterbridge: receive/http.fetch failed. Result (req) = " .. dump(result))
|
||||
return false
|
||||
else
|
||||
local data_out = core.parse_json(result.data)
|
||||
if not data_out then
|
||||
if not next(data_out) then
|
||||
if settings.debug then
|
||||
core.log(
|
||||
"error",
|
||||
"[MOD] yl_matterbridge: receive/http.fetch failed. Result (data) = " .. dump(result)
|
||||
)
|
||||
end
|
||||
http.fetch({
|
||||
url = url_receive,
|
||||
extra_headers = post_headers,
|
||||
timeout = timeout
|
||||
}, function(result)
|
||||
if (not result.completed) or (not result.succeeded) or (result.code ~= 200) then
|
||||
core.log("error", "[MOD] yl_matterbridge: receive/http.fetch failed. Result (req) = " .. dump(result))
|
||||
return false
|
||||
else
|
||||
local data_out = core.parse_json(result.data)
|
||||
if not data_out then
|
||||
if not next(data_out) then
|
||||
if settings.debug then
|
||||
core.log("error",
|
||||
"[MOD] yl_matterbridge: receive/http.fetch failed. Result (data) = " .. dump(result))
|
||||
end
|
||||
return false
|
||||
end
|
||||
for _, dataset in ipairs(data_out) do
|
||||
if dataset then
|
||||
if settings.debug then
|
||||
core.log("action", "[MOD] yl_matterbridge : dataset = " .. dump(dataset))
|
||||
end
|
||||
yl_matterbridge.receive_all_from_bridge(dataset)
|
||||
else
|
||||
core.log(
|
||||
"error",
|
||||
"[MOD] yl_matterbridge: receive/http.fetch failed. No dataset in returned data = " ..
|
||||
dump(data_out)
|
||||
)
|
||||
return false
|
||||
end
|
||||
for _, dataset in ipairs(data_out) do
|
||||
if dataset then
|
||||
if settings.debug then
|
||||
core.log("action", "[MOD] yl_matterbridge : dataset = " .. dump(dataset))
|
||||
end
|
||||
yl_matterbridge.receive_all_from_bridge(dataset)
|
||||
else
|
||||
core.log("error",
|
||||
"[MOD] yl_matterbridge: receive/http.fetch failed. No dataset in returned data = " ..
|
||||
dump(data_out))
|
||||
end
|
||||
end
|
||||
end
|
||||
)
|
||||
end)
|
||||
end
|
||||
|
||||
-- API
|
||||
|
@ -159,10 +146,8 @@ function yl_matterbridge.receive_all_from_bridge(dataset)
|
|||
local account_name = dataset.account
|
||||
yl_matterbridge.receive_from_bridge(user_name, message_text, account_name)
|
||||
else
|
||||
core.log(
|
||||
"error",
|
||||
"[MOD] yl_matterbridge: receive/http.fetch failed. No dataset in returned data = " .. dump(dataset)
|
||||
)
|
||||
core.log("error",
|
||||
"[MOD] yl_matterbridge: receive/http.fetch failed. No dataset in returned data = " .. dump(dataset))
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue