From cbcc1428e32e5327a1db1b1c14f9f73d3007794c Mon Sep 17 00:00:00 2001 From: Rikard Blixt Date: Mon, 16 Oct 2023 10:24:43 +0200 Subject: [PATCH] feat: non-exact role names in role of (#3376) * feat: non-exact role names in role of * Make it work --- .../infobox/extensions/commons/role_of.lua | 48 +++++++++++-------- 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/components/infobox/extensions/commons/role_of.lua b/components/infobox/extensions/commons/role_of.lua index c1847be2f4c..fa50dd4f48a 100644 --- a/components/infobox/extensions/commons/role_of.lua +++ b/components/infobox/extensions/commons/role_of.lua @@ -6,9 +6,11 @@ -- Please see https://github.com/Liquipedia/Lua-Modules to contribute -- +local Array = require('Module:Array') local Class = require('Module:Class') -local Opponent = require('Module:Opponent') -local OpponentDisplay = require('Module:OpponentDisplay') +local OpponentLibraries = require('Module:OpponentLibraries') +local Opponent = OpponentLibraries.Opponent +local OpponentDisplay = OpponentLibraries.OpponentDisplay local Variables = require('Module:Variables') local RoleOf = {} @@ -24,26 +26,34 @@ function RoleOf.get(args) local team = args.team or mw.title.getCurrentTitle().text local teamPage = mw.ext.TeamLiquidIntegration.resolve_redirect(team):gsub(' ', '_') - local teamData = mw.ext.LiquipediaDB.lpdb('squadplayer', { - conditions = '[[pagename::' .. teamPage .. ']] AND [[status::active]] AND ' .. - '([[position::' .. args.role .. ']] OR [[role::' .. args.role .. ']])', - query = 'id, link, nationality', - limit = 1 - })[1] - - if not teamData then + local staffData = mw.ext.LiquipediaDB.lpdb('squadplayer', { + conditions = '[[pagename::' .. teamPage .. ']] AND [[status::active]]', + query = 'id, link, nationality, position, role', + limit = 100, + }) + + if #staffData == 0 then return end - Variables.varDefine(args.role .. 'id', teamData.link) - local opponent = Opponent.readOpponentArgs{ - type = Opponent.solo, - name = teamData.id, - link = teamData.link, - flag = teamData.nationality, - } - ---@cast opponent -nil - return tostring(OpponentDisplay.InlineOpponent{opponent = opponent}) + local output = {} + Array.forEach(staffData, function (staff) + if not (staff.role or ''):lower():find(string.lower(args.role)) + and not (staff.position or ''):lower():find(string.lower(args.role)) then + return + end + + Variables.varDefine(args.role .. 'id', staff.link) + local opponent = Opponent.readOpponentArgs{ + type = Opponent.solo, + name = staff.id, + link = staff.link, + flag = staff.nationality, + } + table.insert(output, tostring(OpponentDisplay.InlineOpponent{opponent = opponent})) + end) + + return table.concat(output, ' ') end return Class.export(RoleOf)