From 120ec6ed5df3c3acd5c40d85da1c6289218ebebf Mon Sep 17 00:00:00 2001 From: AliasAlreadyTaken Date: Thu, 26 Dec 2024 09:21:33 +0100 Subject: [PATCH] AliasAlreadyTaken/yl_matterbridge#9 Adds fetch frequency setting --- README.md | 44 ++++++++++++++++++++++++++++++++++++++++++++ init.lua | 12 +++++++++++- settingtypes.txt | 9 +++++++-- 3 files changed, 62 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b93a75a..a124635 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,8 @@ Download and install [matterbridge](https://github.com/42wim/matterbridge) ## Configuration +### Matterbridge + Create a config for [matterbridge](https://github.com/42wim/matterbridge) and the chat protocols you want to use. * https://github.com/42wim/matterbridge/wiki/How-to-create-your-config @@ -55,6 +57,48 @@ account="api.mt" channel="api" ``` +### Minetest + +See also [settingtypes.txt](settingtypes.txt) + +On top of adding `yl_matterbridge` to http_mods, there are settings to add to minetest.conf: + +``` +yl_matterbridge.address = 127.0.0.1 +``` + +The address or IP to the matterbridge server + +``` +yl_matterbridge.port = 4242 +``` + +The port the matterbridge server listens on + +``` +yl_matterbridge.gateway = default +``` + +The name of the gateway of the matterbridge server + +``` +yl_matterbridge.token +``` + +A secret token string to identify yourself towards the matterbridge server + +``` +yl_matterbridge.debug = false +``` + +Set this to true to enable debugging + +``` +yl_matterbridge.fetch_interval = 0.0 +``` + +Specifies the interval (in seconds) at which a new query is sent to the bridge. + ## Modmakers API: Overwrite these function in your chat mod, if you want to handle messages yourself diff --git a/init.lua b/init.lua index a1c31dd..5b2fe89 100644 --- a/init.lua +++ b/init.lua @@ -34,6 +34,7 @@ settings.port = core.settings:get("yl_matterbridge.port") or "4242" settings.gateway = core.settings:get("yl_matterbridge.gateway") or "default" settings.token = core.settings:get("yl_matterbridge.token") or "" settings.debug = core.settings:get_bool("yl_matterbridge.debug", false) or false +settings.fetch_interval = core.settings:get("yl_matterbridge.fetch_interval") or "0.0" local http = core.request_http_api() @@ -85,13 +86,22 @@ local function send(user_name, message_text, gateway) end) end -local function receive() +local timer = 0 + +local function receive(dtime) if yl_matterbridge.enabled == false then return false end if settings.debug then core.log("action", "[MOD] yl_matterbridge : receive") end + + timer = timer + dtime + if timer <= settings.fetch_interval then + return false + end + timer = 0 + local timeout = 0 http.fetch({ diff --git a/settingtypes.txt b/settingtypes.txt index 182faa3..cf47650 100644 --- a/settingtypes.txt +++ b/settingtypes.txt @@ -8,7 +8,7 @@ # Defaults to 127.0.0.1 yl_matterbridge.address (Bridge IP address or URL) string 127.0.0.1 -# The port the matterbridge server listens to +# The port the matterbridge server listens on # You need to set this to the port of the API connection, which you configured in the toml # Defaults to 4242 yl_matterbridge.port (Bridge port) string 4242 @@ -26,4 +26,9 @@ yl_matterbridge.token (Bridge token) string # Whether or not debugging messages are enabled # If set to true, the mod will write every send and receive to the log, among other debug messages. # Optional, default false -yl_matterbridge.debug (Debug mode) bool false \ No newline at end of file +yl_matterbridge.debug (Debug mode) bool false + +# Fetch/Receive interval +# Specifies the interval (in seconds) at which a new query is sent to the bridge. A value of 0.0 means queries are sent on every server step. +# Optional, defaults to 0.0 +yl_matterbridge.fetch_interval (Fetch/Receive interval) float 0.0 0.0 30.0