annotate 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
rev   line source
John@98 1 local bsk=bsk
John@98 2 local _G=_G
John@98 3 local table=table
John@98 4 local pairs=pairs
John@98 5 local setmetatable=setmetatable
John@98 6 local ipairs=ipairs
John@98 7 local string=string
John@98 8 local sformat=string.format
John@98 9 local strsplit=strsplit
John@98 10 local tostring=tostring
John@98 11 local type=type
John@98 12 local unpack=unpack
John@98 13 local getn=getn
John@98 14 setfenv(1,bsk)
John@98 15
John@98 16 adminList = {}
John@98 17
John@98 18 local function GuildRosterUpdate()
John@98 19 local guildInfoText = _G.GetGuildInfoText()
John@98 20 local newAdminList = {}
John@98 21 for line in guildInfoText:gmatch("[^\r\n]+") do
John@98 22 local l,r = line:match("(.*):(.*)") -- could use wow strsplit had I known about it before writing this
John@98 23 l = string.trim(l or "")
John@98 24 r = string.trim(r or "")
John@98 25 if l == "BSKADMIN" then -- found a juicy line. may contain multiple, comma delimited
John@98 26 local admins = {strsplit(", ",r)}
John@98 27 for _,a in pairs(admins) do
John@98 28 a = string.trim(a or "")
John@98 29 if a ~= "" then
John@98 30 newAdminList[a] = true
John@98 31 end
John@98 32 end
John@98 33 end
John@98 34 end
John@98 35
John@98 36 if _G.next(adminList) ~= nil then -- had old admins. don't want to spam on initial load
John@98 37 -- diff new vs old
John@98 38 for a in pairs(adminList) do
John@98 39 if not newAdminList[a] then
John@98 40 print("Admin removed:", a)
John@98 41 end
John@98 42 end
John@98 43 for a in pairs(newAdminList) do
John@98 44 if not adminList[a] then
John@98 45 print("Admin added:",a)
John@98 46 end
John@98 47 end
John@98 48 end
John@98 49 adminList = newAdminList
John@98 50 end
John@98 51
John@98 52 function InitializeAdmin()
John@98 53 if not event then
John@98 54 _G.error("BSK: Improper order of initialization")
John@98 55 end
John@98 56 event:RegisterEvent("GUILD_ROSTER_UPDATE",GuildRosterUpdate)
John@98 57 _G.GuildRoster() -- will eventually force the event to fire
John@98 58 end
John@98 59
John@98 60