Mercurial > wow > breuesk
changeset 98:0cd1d46e7b66
Admin detection from a string of the format "BSKADMIN: admin1, admin2, ..." in the guild info box
author | John@Doomsday |
---|---|
date | Fri, 27 Apr 2012 09:41:26 -0400 |
parents | 19fd02bff870 |
children | 5914125bb4ea |
files | Admin.lua Core.lua Looting.lua breuesk.toc |
diffstat | 4 files changed, 63 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Admin.lua Fri Apr 27 09:41:26 2012 -0400 @@ -0,0 +1,60 @@ +local bsk=bsk +local _G=_G +local table=table +local pairs=pairs +local setmetatable=setmetatable +local ipairs=ipairs +local string=string +local sformat=string.format +local strsplit=strsplit +local tostring=tostring +local type=type +local unpack=unpack +local getn=getn +setfenv(1,bsk) + +adminList = {} + +local function GuildRosterUpdate() + local guildInfoText = _G.GetGuildInfoText() + local newAdminList = {} + for line in guildInfoText:gmatch("[^\r\n]+") do + local l,r = line:match("(.*):(.*)") -- could use wow strsplit had I known about it before writing this + l = string.trim(l or "") + r = string.trim(r or "") + if l == "BSKADMIN" then -- found a juicy line. may contain multiple, comma delimited + local admins = {strsplit(", ",r)} + for _,a in pairs(admins) do + a = string.trim(a or "") + if a ~= "" then + newAdminList[a] = true + end + end + end + end + + if _G.next(adminList) ~= nil then -- had old admins. don't want to spam on initial load + -- diff new vs old + for a in pairs(adminList) do + if not newAdminList[a] then + print("Admin removed:", a) + end + end + for a in pairs(newAdminList) do + if not adminList[a] then + print("Admin added:",a) + end + end + end + adminList = newAdminList +end + +function InitializeAdmin() + if not event then + _G.error("BSK: Improper order of initialization") + end + event:RegisterEvent("GUILD_ROSTER_UPDATE",GuildRosterUpdate) + _G.GuildRoster() -- will eventually force the event to fire +end + +
--- a/Core.lua Fri Apr 27 08:26:17 2012 -0400 +++ b/Core.lua Fri Apr 27 09:41:26 2012 -0400 @@ -68,6 +68,7 @@ bsk:OnInitializeSetStaticData() InitializeComm() InitializeLooting() + InitializeAdmin() end function OnEnable()