diff --git a/config.lua b/config.lua index 1cac8b6..24e8816 100644 --- a/config.lua +++ b/config.lua @@ -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" } diff --git a/main.lua b/main.lua index 38de5fe..bf67618 100755 --- a/main.lua +++ b/main.lua @@ -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 diff --git a/utils.lua b/utils.lua index fd83a38..fefdadf 100644 --- a/utils.lua +++ b/utils.lua @@ -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