@@ -3,6 +3,74 @@ local E, F, L = ns[1], ns[2], ns[3]
33
44local M = E :Module (" Guild Helper" ) --- @class GuildHelper
55
6+ --- Get current guild name
7+ --- @return string ?
8+ local function getCurrentGuildName ()
9+ return (GetGuildInfo (" player" ))
10+ end
11+
12+ --- Build guild rank key in format {GUILD_NAME}_{RANK_NAME}
13+ --- @param guildName string
14+ --- @param rankName string
15+ --- @return string
16+ local function buildGuildRankKey (guildName , rankName )
17+ return guildName .. " _" .. rankName
18+ end
19+
20+ --- Set the input as a multiselect for guild ranks
21+ --- @param args table The args table to modify
22+ --- @param getConfigTable fun (): string[] Function that returns the config table storing " {GUILD_NAME}_{RANK_NAME}" strings
23+ local function setGuildRankMultiselect (args , getConfigTable )
24+ args .type = " multiselect"
25+ args .disabled = function ()
26+ return not getCurrentGuildName ()
27+ end
28+ args .values = function ()
29+ local t = {}
30+ if not getCurrentGuildName () then
31+ return t
32+ end
33+ local numRanks = GuildControlGetNumRanks ()
34+ if numRanks and numRanks > 0 then
35+ for i = 1 , numRanks do
36+ local rankName = GuildControlGetRankName (i )
37+ if rankName and rankName ~= " " then
38+ t [rankName ] = rankName
39+ end
40+ end
41+ end
42+ return t
43+ end
44+ args .get = function (_ , key )
45+ local guildName = getCurrentGuildName ()
46+ if not guildName then
47+ return false
48+ end
49+ local fullKey = buildGuildRankKey (guildName , key )
50+ return tContains (getConfigTable (), fullKey )
51+ end
52+ args .set = function (_ , key , value )
53+ local guildName = getCurrentGuildName ()
54+ if not guildName then
55+ return
56+ end
57+ local tbl = getConfigTable ()
58+ local fullKey = buildGuildRankKey (guildName , key )
59+ if value then
60+ if not tContains (tbl , fullKey ) then
61+ table.insert (tbl , fullKey )
62+ end
63+ else
64+ for i , v in ipairs (tbl ) do
65+ if v == fullKey then
66+ table.remove (tbl , i )
67+ break
68+ end
69+ end
70+ end
71+ end
72+ end
73+
674local settings = {
775 ui = {
876 order = 11 ,
@@ -212,9 +280,15 @@ local settings = {
212280 },
213281 guildRanks = {
214282 order = 4 ,
215- type = " input" ,
216- name = L [" Protected Guild Ranks" ],
217- desc = L [" Guild rank names to protect, separated by commas." ],
283+ name = function ()
284+ local guildName = getCurrentGuildName ()
285+ return string.format (
286+ " %s (%s)" ,
287+ L [" Protected Guild Ranks" ],
288+ guildName or F .Color .String (L [" You are not in a guild" ], " rose-600" )
289+ )
290+ end ,
291+ desc = L [" Select guild ranks to protect from being kicked." ],
218292 width = " full" ,
219293 hidden = function ()
220294 return not M .profile .kick .protection .enabled
@@ -425,9 +499,15 @@ local settings = {
425499 },
426500 ranks = {
427501 order = 2 ,
428- type = " input" ,
429- name = L [" Guild Ranks" ],
430- desc = L [" Guild rank names to target, separated by commas." ],
502+ name = function ()
503+ local guildName = getCurrentGuildName ()
504+ return string.format (
505+ " %s (%s)" ,
506+ L [" Guild Ranks" ],
507+ guildName or F .Color .String (L [" You are not in a guild" ], " rose-600" )
508+ )
509+ end ,
510+ desc = L [" Select guild ranks to apply kick rules." ],
431511 width = " full" ,
432512 hidden = function ()
433513 return not M .profile .kick .rules .guildRank .enabled
@@ -469,16 +549,16 @@ E:SetStringListSetting(settings.invite.args.channels, function()
469549 return M .profile .invite .channels
470550end )
471551
472- E : SetStringListSetting (settings .kick .args .protection .args .guildRanks , function ()
473- return M .profile .kick .protection .guildRanks
552+ setGuildRankMultiselect (settings .kick .args .protection .args .guildRanks , function ()
553+ return M .profile .kick .protection .selectedRanks
474554end )
475555
476556E :SetStringListSetting (settings .kick .args .rules .args .noteMark .args .patterns , function ()
477557 return M .profile .kick .rules .noteMark .patterns
478558end )
479559
480- E : SetStringListSetting (settings .kick .args .rules .args .guildRank .args .ranks , function ()
481- return M .profile .kick .rules .guildRank .ranks
560+ setGuildRankMultiselect (settings .kick .args .rules .args .guildRank .args .ranks , function ()
561+ return M .profile .kick .rules .guildRank .selectedRanks
482562end )
483563
484564M :SetSettings (settings )
0 commit comments