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