Formatting

This commit is contained in:
AliasAlreadyTaken 2023-05-08 09:51:28 +02:00
parent 8b5bc33b59
commit a514764db7

View File

@ -1,16 +1,13 @@
-- 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")
@ -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,45 +65,40 @@ local function send(user_name, message_text)
gateway = settings.gateway
}
http.fetch(
{
http.fetch({
url = url_send,
extra_headers = post_headers,
timeout = timeout,
post_data = core.write_json(data_in)
},
function(result)
}, 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)
)
core.log("action",
"[MOD] yl_matterbridge : send result = " .. dump(result) .. ", data = " .. dump(data_out))
end
return true
end
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(
{
http.fetch({
url = url_receive,
extra_headers = post_headers,
timeout = timeout
},
function(result)
}, 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
@ -115,10 +107,8 @@ local function receive()
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)
)
core.log("error",
"[MOD] yl_matterbridge: receive/http.fetch failed. Result (data) = " .. dump(result))
end
end
return false
@ -130,16 +120,13 @@ local function receive()
end
yl_matterbridge.receive_all_from_bridge(dataset)
else
core.log(
"error",
core.log("error",
"[MOD] yl_matterbridge: receive/http.fetch failed. No dataset in returned data = " ..
dump(data_out)
)
dump(data_out))
end
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