allow instance overriding in config

This commit is contained in:
mcneb10 2024-06-01 18:43:32 -05:00
parent b85b1aa080
commit 65d6da15b3
3 changed files with 13 additions and 7 deletions

View file

@ -23,6 +23,8 @@ config = {
["reddit[.]com"] = { ["reddit[.]com"] = {
-- Specify which frontents should be used -- Specify which frontents should be used
frontends = { "libreddit", "redlib" } frontends = { "libreddit", "redlib" }
-- This can be used to force and instance on a per site basis, overrides everything else
-- force_instance = { "example.com" }
}, },
["instagram[.]com"] = { ["instagram[.]com"] = {
frontends = { "proxigram" } frontends = { "proxigram" }

View file

@ -39,7 +39,7 @@ client:hook("ready", function()
local body = event.stanza:get_child_text("body") local body = event.stanza:get_child_text("body")
if body then if body then
for site, services in pairs(config.sites) do for site, services in pairs(config.sites) do
local instance = choose_instance(services.frontends) local instance = choose_instance(services)
for match in string.gmatch(body, string.format("%%s(%s/%%S+)", site)) do for match in string.gmatch(body, string.format("%%s(%s/%%S+)", site)) do
send_reply_link(room, match, site, instance, event) send_reply_link(room, match, site, instance, event)
end end

View file

@ -60,12 +60,16 @@ end
-- Choose instance from available services -- Choose instance from available services
function choose_instance(services) function choose_instance(services)
-- TODO: make it try all available services before falling back -- TODO: make it try all available frontends before falling back
-- Choose a random service -- Return instance if overrided in config
local service = services[math.random(#services)] if services.force_instance then
-- Get list of instances for service return services.force_instance
end
-- Choose a random frontend
local frontend = services.frontends[math.random(#services.frontends)]
-- Get list of instances for frontend
for _, service_instance_list in pairs(config.instances) do for _, service_instance_list in pairs(config.instances) do
if service_instance_list.type == service then if service_instance_list.type == frontend then
-- Based on config choose instance -- Based on config choose instance
if config.random_frontend then if config.random_frontend then
-- TODO: cache this? -- TODO: cache this?
@ -99,7 +103,7 @@ function choose_instance(services)
end end
end end
end end
return string.format("%s-no-instances-available", service) return string.format("%s-no-instances-available", frontend)
end end
-- Config file -- Config file