From a6707a0816ab79962f8409a9e9f25d6acc068172 Mon Sep 17 00:00:00 2001 From: AliasAlreadyTaken Date: Sat, 26 Feb 2022 22:50:36 +0100 Subject: [PATCH] Some variables do not change during runtime --- init.lua | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/init.lua b/init.lua index 4a548c4..25d93f5 100644 --- a/init.lua +++ b/init.lua @@ -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)