forked from guoyongshi/BFFilter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.lua
364 lines (300 loc) · 9.29 KB
/
main.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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
--https://github.com/tomrus88/BlizzardInterfaceCode
local BFFilter=LibStub("AceAddon-3.0"):NewAddon(BFF_ADDON_NAME, "AceConsole-3.0","AceTimer-3.0")
local cfgreg = LibStub("AceConfigRegistry-3.0")
local function update_player_info()
local _, class, _ = UnitClass('player')
bfwf_player.class=class
bfwf_player.classes=1 --单一职业
if class=='SHAMAN' or class=='PRIEST' or class=='WARRIOR' then
bfwf_player.classes = 2 --双职业
elseif class == 'DRUID' or class=='PALADIN' then
bfwf_player.classes = 3 --三职业
end
end
--插件加载完成
function BFFilter:OnInitialize()
self:RegisterChatCommand("bff", "OnCommand")
bfwf_configs_init()
bfwf_minimap_button_init()
bfwf_chat_filter_init()
end
--用户登录完成
function BFFilter:OnEnable()
if not self.timer then
self.timer = self:ScheduleRepeatingTimer("OnCheck", 1)
end
if BFWC_Filter_SavedConfigs.use_class_color then
SetCVar("chatClassColorOverride", "0")
end
if not bfwf_g_data.myid then
bfwf_g_data.myid,_ = UnitGUID('player')
end
bfwf_player.level = UnitLevel('player')
if not BFWC_Filter_SavedConfigs.player then
BFWC_Filter_SavedConfigs.player = {}
end
if bfwf_g_data.myid and not BFWC_Filter_SavedConfigs.player[bfwf_g_data.myid] then
BFWC_Filter_SavedConfigs.player[bfwf_g_data.myid] = {}
end
update_player_info()
self:OnLevelUp()
if BFWC_Filter_SavedConfigs.show_drag_handle then
bfwf_show_drag_handle()
end
end
function BFFilter:OnDisable()
if self.timer then
self:CancelTimer(self.timer)
self.timer = nil
end
end
function BFFilter:OnCommand(input)
bfwf_toggle_config_dialog()
end
local last_level = 0
function BFFilter:OnCheck()
if not bfwf_player.class then
update_player_info()
end
if not bfwf_g_data.myid then
bfwf_g_data.myid,_ = UnitGUID('player')
end
bfwf_player.level = UnitLevel('player') or bfwf_player.level
if bfwf_player.level>last_level then
self:OnLevelUp()
end
self:CheckBigFootChannel()
if not bfwf_g_data.myid then
bfwf_g_data.myid = UnitGUID('player')
end
bfwf_update_config_dialog()
bfwf_send_team_create_msg()
bfwf_send_wanted_job_msg()
if bfwf_update_ui and cfgreg then
bfwf_update_ui = false
cfgreg:NotifyChange(BFF_ADDON_NAME)
end
end
function BFFGetJoinedChannels()
local chns={}
for i=1,10 do
local frm=_G['ChatFrame'..i]
if frm and frm.GetID then
local id = frm:GetID()
if id then
local arr={GetChatWindowChannels(id)}
for j,v in ipairs(arr) do
if type(v)=='string' then
table.insert(chns,v)
end
end
end
end
end
return chns
end
local function BFFGetChannelID(chname)
if not chname then
return nil
end
local arr={GetChannelList()}
for i,k in ipairs(arr) do
if k == chname then
return arr[i-1]
end
end
return nil
end
local try_auto_join = 0
function BFFilter:CheckBigFootChannel()
local channels = BFFGetJoinedChannels()
for i,k in ipairs(channels) do
if k == '大脚世界频道' then
bfwf_big_foot_world_channel_joined = true
return
end
end
bfwf_big_foot_world_channel_joined = false
if BFWC_Filter_SavedConfigs.autojoin_bigfoot then
if try_auto_join>5 then
--大脚世界频道的有可能被捣乱加上密码
BFWC_Filter_SavedConfigs.autojoin_bigfoot = false
try_auto_join = 0
return
end
try_auto_join = try_auto_join + 1
--JoinPermanentChannel只是开启指定频道,过滤器能捕捉到频道信息,但不在聊天窗显示,
--要在聊天窗显示需要在聊天窗设置里勾选或者用ChatFrame_AddChannel
JoinPermanentChannel('大脚世界频道')
JoinPermanentChannel('大脚世界频道1')
JoinPermanentChannel('大脚世界频道2')
JoinPermanentChannel('大脚世界频道3')
JoinPermanentChannel('大脚世界频道4')
JoinPermanentChannel('大脚世界频道5')
end
end
bfwf_update_dungeons_filter = function()
if BFWC_Filter_SavedConfigs.auto_filter_by_level then
local lv = bfwf_player.level
for _,d in ipairs(bfwf_dungeons) do
if lv>=d.lmin and lv<= d.lmax then
BFWC_Filter_SavedConfigs.dungeons[d.name] = true
else
BFWC_Filter_SavedConfigs.dungeons[d.name] = false
end
end
end
end
function BFFilter:OnLevelUp()
last_level = bfwf_player.level
bfwf_update_dungeons_filter()
end
--SendChatMessage不能随便设置文字颜色,物品、技能等链接可以带颜色,但链接的颜色和名称
--不能改,改了就会变成普通文字
bfwf_make_team_create_msg = function(avoid_kick)
local msg = ''
local idx = BFWC_Filter_SavedConfigs.last_orgteam
if not idx then
return ''
end
local orig_msg = BFWC_Filter_SavedConfigs.last_orgteam_note
if not orig_msg or string.len(orig_msg)==0 then
return ''
end
if avoid_kick then
local ws = bff_msg_split(BFWC_Filter_SavedConfigs.last_orgteam_note)
local cs = {'+','-','~','.','_','='}
local pos = math.random(1,#ws+1)
table.insert(ws,pos,' ')
table.insert(ws,cs[math.random(1,#cs)])
orig_msg = table.concat(ws)
end
if idx==1 then
return orig_msg
end
if idx==2 then
return '任务队,' .. orig_msg
end
local pos,_ = string.find(bfwf_dungeons[idx-2].name,'%(')
local name
if pos then
name = string.sub(bfwf_dungeons[idx-2].name,1,pos-1)
else
name = bfwf_dungeons[idx-2].name
end
local keys = bfwf_dungeons[idx-2].keys
if keys and keys[1] and keys[1]~=name then
name = name .. ',' .. string.upper(keys[1])
end
msg = '[' .. name .. '],' .. orig_msg
return msg
end
bfwf_make_wanted_job_msg = function(avoid_kick)
local msg = ''
local idx = BFWC_Filter_SavedConfigs.last_job
if not idx then
return ''
end
local orig_msg = BFWC_Filter_SavedConfigs.last_job_note
if not orig_msg or string.len(orig_msg)==0 then
return ''
end
if avoid_kick then
local ws = bff_msg_split(BFWC_Filter_SavedConfigs.last_job_note)
local cs = {'+','-','~','.','_','='}
local pos = math.random(1,#ws+1)
table.insert(ws,pos,' ')
table.insert(ws,cs[math.random(1,#cs)])
orig_msg = table.concat(ws)
end
if idx==1 then
return orig_msg
end
if idx==2 then
return '任务队,' .. orig_msg
end
local pos,_ = string.find(bfwf_dungeons[idx-2].name,'%(')
local name
if pos then
name = string.sub(bfwf_dungeons[idx-2].name,1,pos-1)
else
name = bfwf_dungeons[idx-2].name
end
local keys = bfwf_dungeons[idx-2].keys
if keys and keys[1] and keys[1]~=name then
name = name .. ',' .. string.upper(keys[1])
end
msg = '[' .. name .. '],' .. orig_msg
return msg
end
local last_team_msg_time = 0
local last_wanted_job_time = 0
bfwf_finish_org_team = function()
if not bfwf_orging_team then
return
end
bfwf_orging_team = false
DEFAULT_CHAT_FRAME:AddMessage('|cff0099ff[BFFilter]|r|cffffd100组队完成!!!!!!|r')
local msg = bfwf_make_team_create_msg(true)
if string.len(msg or '')==0 then
return
end
local bf_channel_num = BFFGetChannelID(BFWC_Filter_SavedConfigs.send_msg_channel)
if not bf_channel_num then
return
end
msg = '[已满员]'..msg
SendChatMessage(msg,'CHANNEL',nil,bf_channel_num)
end
bfwf_send_team_create_msg = function()
if not bfwf_orging_team then
return
end
local nmem = GetNumGroupMembers()
if nmem>=bfwf_org_team_count and BFWC_Filter_SavedConfigs.auto_fin_org_team~='no' then
bfwf_finish_org_team()
return
end
local msg = bfwf_make_team_create_msg(true)
if string.len(msg or '')==0 then
return
end
local bf_channel_num = BFFGetChannelID(BFWC_Filter_SavedConfigs.send_msg_channel)
if not bf_channel_num then
return
end
local now = GetTime()
local dt = now-last_team_msg_time
if dt<(BFWC_Filter_SavedConfigs.interval_orgteam or 15) then
return
end
last_team_msg_time = now
SendChatMessage(msg,'CHANNEL',nil,bf_channel_num)
end
bfwf_send_wanted_job_msg = function()
if bfwf_orging_team then
return
end
if not bfwf_waiting_job then
return
end
if GetNumGroupMembers()>0 then
bfwf_waiting_job = false
return
end
local msg = bfwf_make_wanted_job_msg(true)
if string.len(msg or '')==0 then
return
end
local bf_channel_num = BFFGetChannelID(BFWC_Filter_SavedConfigs.send_msg_channel)
if not bf_channel_num then
return
end
local now = GetTime()
local dt = now-last_wanted_job_time
if dt<(BFWC_Filter_SavedConfigs.interval_wanted_job or 15) then
return
end
last_wanted_job_time = now
SendChatMessage(msg,'CHANNEL',nil,bf_channel_num)
end