Mercurial > wow > breuesk
view Admin.lua @ 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 | |
children | 5914125bb4ea |
line wrap: on
line source
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