Some variables do not change during runtime

This commit is contained in:
AliasAlreadyTaken 2022-02-26 22:50:36 +01:00
parent cb6dde19e5
commit a6707a0816
1 changed files with 12 additions and 12 deletions

View File

@ -34,11 +34,14 @@ local http = core.request_http_api()
assert(http, "[MOD] yl_matterbridge: Please add yl_matterbridge to secure.http_mods")
local post_headers = {"Content-Type: application/json"}
if token and token ~= "" then
table.insert(post_headers, "Authorization: Bearer " .. token)
end
local url_send = "http://" .. address .. ":" .. port .. "/api/message"
local url_receive = "http://" .. address .. ":" .. port .. "/api/messages"
function send(user_name, message_text)
local url = "http://" .. address .. ":" .. port .. "/api/message"
local post_headers = {"Content-Type: application/json"}
if token and token ~= "" then table.insert(post_headers,"Authorization: Bearer "..token) end
core.log("action", "[MOD] yl_matterbridge : Posted " .. dump(post_headers))
local timeout = 10
local data = {
text = message_text,
@ -48,7 +51,7 @@ function send(user_name, message_text)
http.fetch(
{
url = url,
url = url_send,
extra_headers = post_headers,
timeout = timeout,
post_data = core.write_json(data)
@ -56,7 +59,7 @@ function send(user_name, message_text)
function(result)
if result.succeeded then
local data = core.parse_json(result.data)
core.log("action", "[MOD] yl_matterbridge : Posted " .. dump(data))
core.log("action", "[MOD] yl_matterbridge : Posted " .. dump(data))
else
core.log("error", "[MOD] yl_matterbridge: send/http.fetch failed. Result = " .. dump(result))
return false
@ -67,14 +70,11 @@ function send(user_name, message_text)
end
local function receive()
local url = "http://" .. address .. ":" .. port .. "/api/messages"
local post_headers = {"Content-Type: application/json"}
if token and token ~= "" then table.insert(post_headers,"Authorization: Bearer "..token) end
local timeout = 0
http.fetch(
{
url = url,
url = url_receive,
extra_headers = post_headers,
timeout = timeout
},
@ -83,7 +83,7 @@ local function receive()
local data = core.parse_json(result.data)
for _, v in ipairs(data) do
if v.username and v.text and v.account then
core.log("action", "[MOD] yl_matterbridge : Received " .. dump(data))
core.log("action", "[MOD] yl_matterbridge : Received " .. dump(data))
yl_matterbridge.receive_from_bridge(v.username, v.text, v.account)
end
end
@ -100,7 +100,7 @@ end
-- Don't forget to add an optional dependency to yl_matterbridge
function yl_matterbridge.receive_from_bridge(user_name, message_text, account_name)
core.chat_send_all("<"..account_name.."|" .. user_name .. "> " .. message_text)
core.chat_send_all("<" .. account_name .. "|" .. user_name .. "> " .. message_text)
end
function yl_matterbridge.send_to_bridge(user_name, message_text)