-
Notifications
You must be signed in to change notification settings - Fork 1
/
ZLM_ChatReports.lua
216 lines (210 loc) · 7.99 KB
/
ZLM_ChatReports.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
ZLM.ChatReplyWords = { "^![Ll][Oo][Tt][Tt][Oo]", "^![Ll][Oo][Tt][Tt][Ee][Rr][Yy]","^![Zz][Ll][Mm]" };
ZLM.ChatReplyTestWord = "^!lottotest";
ZLM_OptionDefaults.profile.Reporting = {
maxReportsResults = 5,
guildReply = true,
guildReplyCooldown = 4
}
ZLM_OptionsTable.args.Reporting = {
name = "Reporting",
type = "group",
order = 1,
args = {
maxReportResults = {
name = "Number to show.",
desc = "The number of top spots on the scoreboard to reply with. Number one, to number ?",
type = "range",
min = 1,
max = 10,
step = 1,
bigStep = 1,
set = "SetMaxReportResults",
get = "GetMaxReportResults",
order = 1,
descStyle="inline"
},
guildReply = {
name = "Reply in Guild",
desc = "Reply to !lotto scoreboard queries in guild chat",
type = "toggle",
set = "SetGuildReply",
get = "GetGuildReply",
order = 2,
descStyle="inline"
},
guildReplyCooldown = {
name = "Guild Reply Cooldown (in minutes)",
desc = "Cooldown for Guild scoreboard spam.",
type = "range",
min = 0,
max = 10,
step = 0.5,
bigStep = 0.5,
set = "SetGuildReplyCooldown",
get = "GetGuildReplyCooldown",
order = 3,
descStyle="inline"
},
}
};
function ZLM:SetMaxReportResults(_,value)
self.db.profile.Reporting.maxReportResults = value;
end
function ZLM:GetMaxReportResults(_)
return self.db.profile.Reporting.maxReportResults;
end
function ZLM:SetGuildReply(_,value)
self.db.profile.Reporting.guildReply = value;
end
function ZLM:GetGuildReply(_)
return self.db.profile.Reporting.guildReply;
end
function ZLM:SetGuildReplyCooldown(_,value)
self.db.profile.Reporting.guildReplyCooldown = value;
end
function ZLM:GetGuildReplyCooldown(_)
return self.db.profile.Reporting.guildReplyCooldown;
end
ZLM.GuildChatCooldown = false;
-- Primarily used like caps()/upper() etc. to take names and make them a uniform no-space name-realm combo regardless of source.
function ZLM:PlayerName(player)
if not string.match(player,"-") then
local realm = GetRealmName();
player = player.."-"..realm;
end
--Remove Spaces
player = string.gsub(player,"%s", "")
return player;
end
function ZLM:GetPlayerRank(player)
local rank = 0;
for i,v in ipairs(ZLM_ScoreboardData) do
--print(ZLM:PlayerName(v.Name).." "..player);
if ZLM:PlayerName(v.Name) == ZLM:PlayerName(tostring(player)) then
-- Insert personalized report.
rank = i;
end
end
return rank;
end
function ZLM:GetScoreByRank(rank)
if not not ZLM_ScoreboardData[rank] then
return ZLM_ScoreboardData[rank];
end
return 0;
end
function ZLM:Announce(message,channel,player)
if channel == "BATTLE.NET" then
BNSendWhisper(player,message);
else
SendChatMessage(message, channel, nil, player);
end
end
function ZLM:ChatReport(player,test,channel)
channel = channel or "WHISPER"
local requestorRank,_ = ZLM:GetPlayerRank(player); -- returns number
local reportLimit = ZLM:GetMaxReportResults();
local numRecords = #ZLM_ScoreboardData;
local printAtEnd = false;
local prefix;
local prefixpattern;
if test then
--prefixpattern = "don'tmatchme";
prefix = "[test]"
else
--prefixpattern = "%[ZLM\]";
prefix = "[ZLM]";
end
if requestorRank > reportLimit then reportLimit = reportLimit - 1; printAtEnd = true; end
if reportLimit > 0 then
local firstTrailLength = 12
local firstPadding = "............";
ZLM:Announce(prefix.." Place....Score.......Name", channel, player);
for i = 1,reportLimit do
if i > numRecords then break; end
local rankLength = math.floor(math.log10(i)+1)
local score = ZLM:GetScoreByRank(i);
local scoreLength =math.floor(math.log10(score.Points)+1)
local padding1 = string.sub(firstPadding,1,firstTrailLength - rankLength);
local padding2 = string.sub(firstPadding,1,firstTrailLength - scoreLength);
if ZLM:PlayerName(player)== ZLM:PlayerName(score.Name) then
ZLM:Announce(prefix.."*"..i .. padding1 .. score.Points .. padding2 .. score.Name.." <--", channel, player);
else
ZLM:Announce(prefix.." "..i .. padding1 .. score.Points .. padding2 .. score.Name, channel, player);
end
end
if printAtEnd then
local rankLength = math.floor(math.log10(requestorRank)+1)
local score = ZLM:GetScoreByRank(requestorRank);
local scoreLength =math.floor(math.log10(score.Points)+1)
local padding1 = string.sub(firstPadding,1,firstTrailLength - rankLength);
local padding2 = string.sub(firstPadding,1,firstTrailLength - scoreLength);
ZLM:Announce(prefix.."*"..requestorRank .. padding1 .. score.Points .. padding2 .. score.Name.. " <--", channel, player);
end
end
if channel == "WHISPER" then
print("Lottery scoreboard info requested by, and sent to: "..player)
end
end
function ZLM.ChatEvent(event, message, author, _, _, arg5, flag, _,_,_,arg10,_,_,id)
local words = ZLM.ChatReplyWords;
local gchat = nil;
local channel = "WHISPER";
if event == "CHAT_MSG_GUILD" then
gchat = true;
channel = "GUILD";
end
if gchat and ZLM.GuildChatCooldown or not ZLM:GetGuildReply()then return; end
if event == "CHAT_MSG_BN_WHISPER" then
channel = "BATTLE.NET";
author = id;
end
if not not string.match(message,"^%(") and not not string.match(message,"%)") then
message = string.gsub(message,"^(.*): ","") -- Removes incognito type main names from message.
end
for k, v in pairs(words) do
if not not string.match(message,v) then
local test = not not string.match(message,ZLM.ChatReplyTestWord);
ZLM:ChatReport(author,test, channel);
if gchat then
ZLM.GuildChatCooldown = true;
ZLM:Wait(ZLM:GetGuildReplyCooldown() * 30,
function()
if ZLM:GetGuildReplyCooldown() > 0 then
--print("Guild Cooldown Reset.");
end
ZLM.GuildChatCooldown = false;
end);
end
end
end
end
function ZLM_ChatFilter(self,event,myChatMessage, author,...)
local words = ZLM.ChatReplyWords;
local prefixpattern = "%[ZLM\]";
if type(myChatMessage) == "string" then
--Hide whisper if it's our prefix
if not not string.match(myChatMessage,prefixpattern) then
--print("It's a prefix!"..myChatMessage.." == "..ZLMPrefix);
return true, myChatMessage, author, ...;
end
--Hide whisper if it's one of our words.
for k, v in pairs(words) do
if not not string.match(myChatMessage,v) then
-- SendChatMessage("True now!", "WHISPER", nil, author);
return true, myChatMessage, author, ...;
end
end
end
return false, myChatMesssage, author,...
end
ChatFrame_AddMessageEventFilter("CHAT_MSG_WHISPER",ZLM_ChatFilter);
ChatFrame_AddMessageEventFilter("CHAT_MSG_WHISPER_INFORM",ZLM_ChatFilter);
ChatFrame_AddMessageEventFilter("CHAT_MSG_BN_WHISPER",ZLM_ChatFilter);
ZLM:RegisterEvent("CHAT_MSG_WHISPER",ZLM.ChatEvent);
ZLM:RegisterEvent("CHAT_MSG_GUILD",ZLM.ChatEvent);
ZLM:RegisterEvent("CHAT_MSG_BN_WHISPER",ZLM.ChatEvent);
--[[ZLM:RegisterEvent("CHAT_MSG_WHISPER",function(...) ZLM.ChatEvent("CHAT_MSG_WHISPER",...) end);
ZLM:RegisterEvent("CHAT_MSG_GUILD",function(...) ZLM.ChatEvent("CHAT_MSG_GUILD",...) end);
ZLM:RegisterEvent("CHAT_MSG_BN_WHISPER",function(...) ZLM:ChatEvent("CHAT_MSG_BN_WHISPER",...); end);
]]