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"] = {
-- Specify which frontents should be used
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"] = {
frontends = { "proxigram" }

View file

@ -39,7 +39,7 @@ client:hook("ready", function()
local body = event.stanza:get_child_text("body")
if body then
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
send_reply_link(room, match, site, instance, event)
end

View file

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