# HG changeset patch # User Kim Alvefur # Date 1530738262 -7200 # Node ID cd23446eaff10de3932a8234afd403f5fa7be1e6 # Parent 8d2fe3b93c150ef555dec0185d9063283cbecb36 mod_muc_badge: Use room name instead of fixed string (beware the silly width calculations) diff -r 8d2fe3b93c15 -r cd23446eaff1 mod_muc_badge/mod_muc_badge.lua --- a/mod_muc_badge/mod_muc_badge.lua Wed Jul 04 23:04:04 2018 +0200 +++ b/mod_muc_badge/mod_muc_badge.lua Wed Jul 04 23:04:22 2018 +0200 @@ -36,31 +36,31 @@ -- https://github.com/badges/shields/blob/master/LICENSE.md local template = module:get_option_string("badge_template", [[ - + - + - - - + + + - {label} - {label} - {number} - {number} + {label} + {label} + {number} + {number} ]]); template = assert(require "util.template"(template)); -local label = module:get_option_string("badge_label", "Chatroom"); local number = module:get_option_string("badge_count", "%d online"); +local charwidth = 7; module:provides("http", { route = { @@ -76,13 +76,18 @@ for _ in pairs(room._occupants) do count = count + 1; end + local badge_label = room:get_name(); + local badge_count = string.format(number, count); local response = event.response; response.headers.content_type = "image/svg+xml"; local svg = [[]] .. tostring(template.apply({ - label = label; - number = string.format(number, count); + label = badge_label; + number = badge_count; + width = ("%d"):format( (#badge_label + #badge_count) * charwidth ); + labelwidth = ("%d"):format( #badge_label * charwidth ); + countwidth = ("%d"):format( #badge_count * charwidth ); })); return svg; end;