vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | -- AutoGrats by Krod |
2 | -- |
||
3 | -- version 1.3.1 |
||
4 | -- Date 11.10.2005 |
||
5 | -- |
||
6 | -- Comments to: ram@catsec.com |
||
7 | -- |
||
8 | -- Sends automatic congrats messages when a guild member dings... |
||
9 | |||
10 | function ag_OnLoad() -- register events |
||
11 | this:RegisterEvent("GUILD_ROSTER_UPDATE"); |
||
12 | this:RegisterEvent("CHAT_MSG_GUILD"); |
||
13 | this:RegisterEvent("VARIABLES_LOADED"); |
||
14 | waiting_for_update=false; |
||
15 | end |
||
16 | |||
17 | function ag_OnEvent(event)-- check for initialization |
||
18 | if (event == "VARIABLES_LOADED")then -- invoke init once all vars are loaded |
||
19 | ag_Init(); |
||
20 | end |
||
21 | if (event == "GUILD_ROSTER_UPDATE")then -- got a guild roster update event |
||
22 | ag_GotRoster(); |
||
23 | end |
||
24 | if (ag_enabled and event == "CHAT_MSG_GUILD" ) then -- got a guild text event |
||
25 | ag_GuildText(arg1, arg2, arg3); |
||
26 | end |
||
27 | end |
||
28 | |||
29 | function ag_Init() -- Initialize slash commands |
||
30 | SlashCmdList["autograts"] = ag_Cmd; |
||
31 | SLASH_autograts1 = "/grats"; |
||
32 | if (ag_enabled==nil) then |
||
33 | ag_enabled=true; |
||
34 | end |
||
35 | ag_Print("Autograts by Krod, type: /grats help for more information"); |
||
36 | if (ag_enabled) then |
||
37 | ag_Print("Autograts by Krod: Enabled"); |
||
38 | else |
||
39 | ag_Print("Autograts by Krod: Disabled"); |
||
40 | end |
||
41 | if (grats==nil) then -- a grats table does not exists - load default |
||
42 | ag_Reset(); |
||
43 | end |
||
44 | if (nicks==nil) then -- no nickname table, needs to create it |
||
45 | nicks={}; |
||
46 | end |
||
47 | ag_Version(); |
||
48 | end |
||
49 | |||
50 | function ag_Version() -- version update code |
||
51 | if (version==nil) then -- no version information, means version is less then 1.1 |
||
52 | version=1.0; |
||
53 | end |
||
54 | if (version<1.2) then -- version if less then 1.2, need to clear players table |
||
55 | players={}; |
||
56 | version=1.2; |
||
57 | end |
||
58 | end |
||
59 | |||
60 | function ag_GuildText(msg, who, lang) -- analyse guild message to find the word "ding" in it |
||
61 | if (string.find(" "..string.lower(string.gsub(msg,"%p+","")).." "," ".."ding".." ") and who~=UnitName("player")) then |
||
62 | ag_person=who; |
||
63 | ag_lang=lang; |
||
64 | waiting_for_update=true; |
||
65 | waiting_for_who=false; |
||
66 | GuildRoster(); -- ask for guildroster update |
||
67 | end |
||
68 | end |
||
69 | |||
70 | function ag_Cmd(msg) -- process command line |
||
71 | if (not msg or msg=="") then |
||
72 | msg="help"; |
||
73 | end |
||
74 | local args=ag_Spliter(msg); -- split command line arguments into words |
||
75 | local i; |
||
76 | if (strlower(msg)=="off") then -- turn autograts off |
||
77 | ag_enabled=false; |
||
78 | ag_Print("Autograts Disabled"); |
||
79 | elseif (strlower(msg)=="on") then -- turn autograts on |
||
80 | ag_enabled=true; |
||
81 | ag_Print("Autograts Enabled") |
||
82 | elseif (strlower(msg)=="players") then -- show players list |
||
83 | ag_Print("Registered players:"); |
||
84 | table.foreach(players,function(i,l) ag_Print(i.." ("..l..")") end); |
||
85 | elseif (strlower(msg)=="who") then -- show who leveled and update the list |
||
86 | waiting_for_who=true; |
||
87 | waiting_for_update=false; |
||
88 | GuildRoster(); |
||
89 | elseif (strlower(msg)=="list") then -- show grats list |
||
90 | ag_Print("Showing grats list"); |
||
91 | if (grats) then |
||
92 | for i=1,table.getn(grats),1 do |
||
93 | ag_Print(i..". Level range: "..grats[i][1].." - "..grats[i][2].." : "..grats[i][3]); |
||
94 | end |
||
95 | else |
||
96 | ag_Print("***Empty***"); |
||
97 | end |
||
98 | elseif (strlower(msg)=="reset") then -- Reset all grats to Defaults |
||
99 | ag_Print("Reseting all grats to defaults"); |
||
100 | grats=nil; |
||
101 | ag_Reset(); |
||
102 | elseif (strlower(args[1])=="nick") then -- process nickname commands |
||
103 | if (args[2]) then |
||
104 | if (strlower(args[2])=="clear") then -- removing all nicknames |
||
105 | nicks={}; |
||
106 | ag_Print("All nicknames cleared"); |
||
107 | elseif (strlower(args[2])=="list") then -- List all nicknames |
||
108 | ag_Print("Nicknames:"); |
||
109 | table.foreach(nicks,function(p,n) ag_Print("Player: "..p.." is nicknamed: '"..n.."'.") end); |
||
110 | elseif (args[3]) then -- Set A players nickname |
||
111 | local p=args[2]; |
||
112 | local n=args[3]; |
||
113 | nicks[p]=n; |
||
114 | ag_Print("Player: "..p.." is now nicknamed: '"..n.."'."); |
||
115 | else -- No third argument was specified: try to remove the nickname speficied in the second argument |
||
116 | local p=args[2]; |
||
117 | if (nicks[p]) then -- the Nickname specified in the second argument exists - erase it |
||
118 | nicks[p]=nil; |
||
119 | ag_Print("Removed nickname for: "..p.."."); |
||
120 | else -- the Nickname specified in the second argument do not exist - show error |
||
121 | ag_Print("Couldn't remove nickname for: "..p..", Player not found."); |
||
122 | end |
||
123 | end |
||
124 | else |
||
125 | ag_Print("Syntax Error, use /grats nick {clear/list/{player name}}"); |
||
126 | end |
||
127 | elseif (strlower(args[1])=="remove") then -- remove a grats line |
||
128 | if (args[2]) then -- a second argument was specified |
||
129 | if (strlower(args[2])=="all") then -- removing all grats |
||
130 | grats=nil; |
||
131 | ag_Print("All grats removed"); |
||
132 | else -- remove specific grats line |
||
133 | local ln=tonumber(args[2]); |
||
134 | if (grats[ln]) then -- found the line number |
||
135 | table.remove(grats,ln); |
||
136 | ag_Print("Removed Line: "..ln); |
||
137 | else -- line number was not found |
||
138 | ag_Print("No such line"); |
||
139 | end |
||
140 | end |
||
141 | else |
||
142 | ag_Print("syntax error: use /grats remove {all/line number}"); |
||
143 | end |
||
144 | |||
145 | elseif (strlower(args[1])=="add") then -- add a grats line |
||
146 | if (args[2] and args[3] and args[4]) then -- if all command line arguments exists |
||
147 | valid=true; |
||
148 | errstr=""; -- low level argument (second argument) |
||
149 | low=tonumber(args[2]); |
||
150 | if (low<1 or low>60) then -- low level bellow or above the range |
||
151 | valid=false; |
||
152 | errstr="lower level out of range."; |
||
153 | end |
||
154 | if (grats) then -- a grats table exists |
||
155 | for i=1,table.getn(grats) do -- check for valid range for the 'low' argument |
||
156 | if (low>=grats[i][1] and low<=grats[i][2]) then -- conflicts found... |
||
157 | valid=false; |
||
158 | errstr="lower level conflicts with another message (line"..i..")"; |
||
159 | end |
||
160 | end |
||
161 | end |
||
162 | high=tonumber(args[3]); -- high level argument (third argument) |
||
163 | if (high<1 or high>60 or high<low) then -- low level bellow or above the range |
||
164 | valid=false; |
||
165 | errstr="high level out of range."; |
||
166 | end |
||
167 | if (grats) then -- a grats table exists |
||
168 | for i=1,table.getn(grats) do -- check for valid range for the 'high' argument |
||
169 | if (high>=grats[i][1] and high<=grats[i][2]) then -- conflicts found... |
||
170 | valid=false; |
||
171 | errstr="high level collides with another message (line"..i..")"; |
||
172 | end |
||
173 | end |
||
174 | end |
||
175 | if (valid) then -- if the command line is valid insert the new message at the correct spot |
||
176 | local place=1; |
||
177 | if (grats) then |
||
178 | for i=1,table.getn(grats) do |
||
179 | if (low>grats[i][1]) then |
||
180 | place=i; |
||
181 | end |
||
182 | end |
||
183 | if (place==table.getn(grats)) then |
||
184 | table.insert(grats,{low,high,table.concat(args," ",4)}); |
||
185 | else |
||
186 | table.insert(grats,place,{low,high,table.concat(args," ",4)}); |
||
187 | end |
||
188 | else |
||
189 | grats={[1]={low,high,table.concat(args," ",4)}} |
||
190 | end |
||
191 | ag_Print("Autograts message added"); |
||
192 | else |
||
193 | ag_Print("syntax error: "..errstr); |
||
194 | end |
||
195 | else -- Error in "Add" parameters |
||
196 | ag_Print("syntax error: use /grats add {low} {high} {message}"); |
||
197 | end |
||
198 | else -- show help |
||
199 | ag_Print("/grats on - turns autograts on"); |
||
200 | ag_Print("/grats off - turns autograts off"); |
||
201 | ag_Print("/grats players - list all known players"); |
||
202 | ag_Print("/grats list - list all messages"); |
||
203 | ag_Print("/grats reset - reset messages to the default ones"); |
||
204 | ag_Print("/grats remove all - removes all messages"); |
||
205 | ag_Print("/grats remove {line} - removes the specified message line (N=line number"); |
||
206 | ag_Print("/grats who - shows you all guild members who leveled since you were last online"); |
||
207 | ag_Print("/grats nick {player} {nickname} - sets the {nickname} for {player}"); |
||
208 | ag_Print("/grats nick list - lists all nicknames"); |
||
209 | ag_Print("/grats nick clear - clears all nicknames"); |
||
210 | ag_Print("/grats nick {player} - clears the nickname for {player}"); |
||
211 | ag_Print("/grats add {low} {high} {message} - adds a message for the specified level range:"); |
||
212 | ag_Print(" in {message} the following will be replaced by autograts:"); |
||
213 | ag_Print(" @c will be replaced by the player who dinged Class"); |
||
214 | ag_Print(" @p will be replaced by the player who dinged Name or nickname"); |
||
215 | ag_Print(" @l will be replaced by the player who dinged Level"); |
||
216 | ag_Print(" @t will be replaced by number of levels left till 60"); |
||
217 | ag_Print("example: /grats add 1 60 Woohoo @p you are a great @c. will yield: 'Woohoo Krod you are a great Hunter'"); |
||
218 | end |
||
219 | end |
||
220 | |||
221 | function ag_Print(printout) -- print messages |
||
222 | DEFAULT_CHAT_FRAME:AddMessage(printout,0.5,1,1); |
||
223 | end |
||
224 | |||
225 | function ag_GetInfo(guild_member) |
||
226 | local g = GetNumGuildMembers(); |
||
227 | local i; |
||
228 | for i=1,g do |
||
229 | local name, rank, rankIndex, level, class, zone, group, note, officernote, online = GetGuildRosterInfo(i); |
||
230 | if (name == guild_member) then |
||
231 | return level,class; |
||
232 | end |
||
233 | end |
||
234 | return 0, "none"; |
||
235 | end |
||
236 | |||
237 | function ag_GotRoster() -- invoked when Guild Roster is updated |
||
238 | if (waiting_for_who) then -- waiting for the /grats who |
||
239 | waiting_for_who=false; |
||
240 | local g = GetNumGuildMembers(); |
||
241 | local i; |
||
242 | local f=false; |
||
243 | for i=1,g do |
||
244 | local name, rank, rankIndex, level, class, zone, group, note, officernote, online = GetGuildRosterInfo(i); |
||
245 | if (players[name]~=level) then |
||
246 | players[name]=level; |
||
247 | f=true; |
||
248 | ag_Print(name.." had leveled since you were last online."); |
||
249 | end |
||
250 | end |
||
251 | if (not f) then |
||
252 | ag_Print("No online guild member had leveled since you were last online."); |
||
253 | end |
||
254 | end |
||
255 | |||
256 | if (waiting_for_update) then -- get information on the player (level,class) |
||
257 | local l,c=ag_GetInfo(ag_person); |
||
258 | local t=60-l; |
||
259 | local s; |
||
260 | local m=ag_GetMsg(l); -- get the right message to the player's level |
||
261 | if (players[ag_person]~=l) then -- if the player does not appear in the table or the players level is NOT the same as registered then send congrats |
||
262 | if (m) then -- if a personalized message exists: |
||
263 | local s=grats[m][3]; |
||
264 | if (nicks[ag_person]) then |
||
265 | s=string.gsub(s,"@p",nicks[ag_person]); |
||
266 | else |
||
267 | s=string.gsub(s,"@p",ag_person); |
||
268 | end |
||
269 | s=string.gsub(s,"@l",l); |
||
270 | s=string.gsub(s,"@t",t); |
||
271 | s=string.gsub(s,"@c",c); |
||
272 | SendChatMessage(s, "GUILD", ag_lang); -- send the message |
||
273 | else -- message does not exist, send default grats |
||
274 | SendChatMessage("Grats!", "GUILD", ag_lang); |
||
275 | end |
||
276 | players[ag_person]=l; |
||
277 | end |
||
278 | waiting_for_update=false; |
||
279 | end |
||
280 | end |
||
281 | |||
282 | function ag_GetMsg(level) -- get the corresponding message to the players level |
||
283 | if (grats==nil) then -- No grats table: return nil |
||
284 | return nil; |
||
285 | end |
||
286 | local i; |
||
287 | for i=1,table.getn(grats),1 do -- search grats table a line matching the dingers level |
||
288 | local low=grats[i][1]; |
||
289 | local high=grats[i][2]; |
||
290 | if (level>=low and level<=high) then -- line found, return it |
||
291 | return i; |
||
292 | end |
||
293 | end |
||
294 | return nil; -- no level range found, return nil |
||
295 | end |
||
296 | |||
297 | function ag_Spliter(str) -- split a string into a table |
||
298 | local t = {}; |
||
299 | for word in string.gfind(str, "%S+") do |
||
300 | table.insert(t, word) |
||
301 | end |
||
302 | return t; |
||
303 | end |
||
304 | |||
305 | function ag_Reset() -- define default grats table |
||
306 | grats={ |
||
307 | [1]={1,9,"*cough* Well.. Hmm.. grats I guess. Surely you're the mightiest @c in the world."}, |
||
308 | [2]={10,49,"Grats @p, only @t to go :-)"}, |
||
309 | [3]={50,59,"WOW! Grats @p, only @t to go ... almost there!"}, |
||
310 | [4]={60,60,"WOW! @p, you're 60!!! that calls for a party!"}, |
||
311 | } |
||
312 | end |