-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibChat3.lua
526 lines (403 loc) · 18.4 KB
/
libChat3.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
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
--[[
This Add-on is not created by, affiliated with or sponsored by ZeniMax
Media Inc. or its affiliates. The Elder Scrolls® and related logos are
registered trademarks or trademarks of ZeniMax Media Inc. in the United
States and/or other countries. All rights reserved.
You can read the full terms at https://account.elderscrollsonline.com/add-on-terms
This software is under : CreativeCommons CC BY-NC-SA 4.0
Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0)
You are free to:
Share — copy and redistribute the material in any medium or format
Adapt — remix, transform, and build upon the material
The licensor cannot revoke these freedoms as long as you follow the license terms.
Under the following terms:
Attribution — You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
NonCommercial — You may not use the material for commercial purposes.
ShareAlike — If you remix, transform, or build upon the material, you must distribute your contributions under the same license as the original.
No additional restrictions — You may not apply legal terms or technological measures that legally restrict others from doing anything the license permits.
Please read full licence at :
http://creativecommons.org/licenses/by-nc-sa/4.0/legalcode
LibChat2 is a library which must be embedded into an ESO Addon, throught its manifest like this :
path/libChat2/libChat2.lua
LibChat2 require LibStub to work
Last Author: Ayantir --> Version: 9 and inferior
-----
Filename: libChat3.lua
Version: 10
Author: Provision
Mini :
| message |
| {___1___} | {Sender} | {___2___} | {Text} | {___3___} |
| BfAll | playerLink | text | ..... |
Full :
| | ___1___ | {Sender} | ___2___ | {Text} | ___3___ |
| Position : | BeforeAll | {OptEsoFormat} | BeforeSender | | AfterSender | {OptEsoFormat} | BeforeText | | AfterText | {OptEsoFormat} | ............ |
| Index : | DDS_ | Text_ | | DDS_ | Text_ | | Text_ | DDS_ | | DDS_ | Text_ | | Text_ | DDS_ | | ............ |
| Variable : | channelLink | | playerLink | | text | | ............ |
*{OptEsoFormat} = {OptionnalESOUIFormat}
-----
CHAT_SYSTEM does not permit to get 2 libraries running together and using ChatBox, the first loaded into memory will rewrite EVERYTHING and other addons will fail
- If you REWRITE message, you're hugely prompted to use LibChat2, without it, you'll surely kill other chat Addons
eg: Append some text, rewrite sender name, rewrite colors, etc
- DO NOT USE this library if you don't REWRITE the message sent
- If you only APPEND something with a d() or a AddMessage(), you don't need LibChat2
WARNING using registerFormat() : This method should only be called when rewriting from + text + infos (colors, chanCode, etc), please only use this method if your addon REWRITE the WHOLE message
If you need to rewrite From, please only use registerName
If you need to rewrite Text, please only use registerText
If you need to append text somewhere without changing the text sent, please use one of the following methods :
DDSBeforeAll, TextBeforeAll, DDSBeforeSender, TextBeforeSender, TextAfterSender, DDSAfterSender, DDSBeforeText, TextBeforeText, TextAfterText, DDSAfterText
Revisions of libChat
Minor = 1 : libChat-1
Minor = 2 : LibChat2 1.0
Minor = 3 : LibChat2 1.1
Minor = 4 : LibChat2 1.2
Minor = 5 : LibChat2 1.3 (internal release)
Minor = 6 : LibChat2 Justice
Minor = 7 : LibChat2 1.6
Minor = 8 : LibChat2 8
Minor = 9 : LibChat2 9
Minor = 10 : LibChat3 10 <-- Provision Update
Allow several addon listeners on one event (without conflict) :
- registerName
- registerText
- registerAppendDDSBeforeAll
- registerAppendTextBeforeAll
- registerAppendDDSBeforeSender
- registerAppendTextBeforeSender
- registerAppendDDSAfterSender
- registerAppendTextAfterSender
- registerAppendDDSBeforeText
- registerAppendTextBeforeText
- registerAppendDDSAfterText
- registerAppendTextAfterText
Old version : http://www.esoui.com/downloads/info740-libChat2.html
More info : http://www.esoui.com/downloads/__________.html
]]--
local LIB_NAME, LIB_VERSION = "libChat-1.0", 10
local libchat, oldminor = LibStub:NewLibrary(LIB_NAME, LIB_VERSION)
if not libchat then
return
end
-- local declaration
local PositionList = { "BeforeAll", "BeforeSender", "AfterSender", "BeforeText", "AfterText" }
local IndexList = { "DDS", "Text" }
local functionNameTemplate = "%s%s%s"
local storage = {
BeforeAll = { DDS = {}, Text = {} },
BeforeSender = { DDS = {}, Text = {} },
AfterSender = { DDS = {}, Text = {} },
BeforeText = { DDS = {}, Text = {} },
AfterText = { DDS = {}, Text = {} },
parser = {
Name = {},
Text = {},
Format = nil -- only one
}
}
local funcFriendStatus
local funcIgnoreAdd
local funcIgnoreRemove
local funcGroupMemberLeft
local funcGroupTypeChanged
-- Initialize Manager to trace Addons
if not libchat.manager then
libchat.manager = {}
end
-- Returns ZOS CustomerService Icon if needed
local function showCustomerService(isCustomerService)
if(isCustomerService) then
return "|t16:16:EsoUI/Art/ChatWindow/csIcon.dds|t"
end
return ""
end
-- Listens for EVENT_CHAT_MESSAGE_CHANNEL event from ZO_ChatSystem
function libchat:MessageChannelReceiver(channelID, from, text, isCustomerService, fromDisplayName)
local output = {
BeforeAll = { DDS = "", Text = "" },
BeforeSender = { DDS = "", Text = "" },
AfterSender = { DDS = "", Text = "" },
BeforeText = { DDS = "", Text = "" },
AfterText = { DDS = "", Text = "" }
}
local message
local originalFrom = from
local originalText = text
-- Get channel information
local ChanInfoArray = ZO_ChatSystem_GetChannelInfo()
local info = ChanInfoArray[channelID]
if not info or not info.format then
return
end
for _, position in ipairs(PositionList) do
for _, index in ipairs(IndexList) do
-- Function to append
local callbacks = storage[position][index]
for _, func in ipairs(callbacks) do
local str = func(channelID, from, text, isCustomerService, fromDisplayName)
output[position][index] = output[position][index] .. str
end
end
end
-- Function to affect From
for _, func in ipairs(storage.parser.Name) do
from = func(channelID, from, isCustomerService, fromDisplayName)
end
if not from then return end
-- Function to format text
for _, func in ipairs(storage.parser.Text) do
text = func(channelID, from, text, isCustomerService, fromDisplayName)
end
if not text then return end
-- Function to format message
if storage.parser.Format then
message = storage.parser.Format(channelID, from, text, isCustomerService, fromDisplayName, originalFrom, originalText, output.BeforeAll.DDS, output.BeforeAll.Text, output.BeforeSender.DDS, output.BeforeSender.Text, output.AfterSender.Text, output.AfterSender.DDS, output.BeforeText.DDS, output.BeforeText.Text, output.AfterText.Text, output.AfterText.DDS)
if not message then return end
else
-- Code to run with libChat loaded and Addon not registered to libchat - IT MUST BE ~SAME~ AS ESOUI -
-- Create channel link
local channelLink
if info.channelLinkable then
local channelName = GetChannelName(info.id)
channelLink = ZO_LinkHandler_CreateChannelLink(channelName)
end
-- Create player link
local playerLink
if info.playerLinkable and not from:find("%[") then
playerLink = output.BeforeSender.DDS .. output.BeforeSender.Text .. ZO_LinkHandler_CreatePlayerLink((from)) .. output.AfterSender.Text .. output.AfterSender.DDS
else
playerLink = output.BeforeSender.DDS .. output.BeforeSender.Text .. from .. output.AfterSender.Text .. output.AfterSender.DDS
end
text = output.BeforeText.DDS .. output.BeforeText.Text .. text .. output.AfterText.Text .. output.AfterText.DDS
-- Create default formatting
if channelLink then
message = output.BeforeAll.DDS .. output.BeforeAll.Text .. zo_strformat(info.format, channelLink, playerLink, text)
else
message = output.BeforeAll.DDS .. output.BeforeAll.Text .. zo_strformat(info.format, playerLink, text, showCustomerService(isCustomerService))
end
end
return message, info.saveTarget
end
-- Listens for EVENT_FRIEND_PLAYER_STATUS_CHANGED event from ZO_ChatSystem
local function libChatFriendPlayerStatusChangedReceiver(displayName, characterName, oldStatus, newStatus)
-- If function registrered in Addon, code will run
local friendStatusMessage
if funcFriendStatus then
friendStatusMessage = funcFriendStatus(displayName, characterName, oldStatus, newStatus)
if friendStatusMessage then
return friendStatusMessage
else
return
end
else
-- Code to run with libChat loaded and Addon not registered to libchat - IT MUST BE ~SAME~ AS ESOUI -
local wasOnline = oldStatus ~= PLAYER_STATUS_OFFLINE
local isOnline = newStatus ~= PLAYER_STATUS_OFFLINE
-- DisplayName is linkable
local displayNameLink = ZO_LinkHandler_CreateDisplayNameLink(displayName)
-- CharacterName is linkable
local characterNameLink = ZO_LinkHandler_CreateCharacterLink(characterName)
-- Not connected before and Connected now (no messages for Away/Busy)
if(not wasOnline and isOnline) then
-- Return
return zo_strformat(SI_FRIENDS_LIST_FRIEND_CHARACTER_LOGGED_ON, displayNameLink, characterNameLink)
-- Connected before and Offline now
elseif(wasOnline and not isOnline) then
return zo_strformat(SI_FRIENDS_LIST_FRIEND_CHARACTER_LOGGED_OFF, displayNameLink, characterNameLink)
end
end
end
-- Listens for EVENT_IGNORE_ADDED event from ZO_ChatSystem
local function libChatIgnoreAddedReceiver(displayName)
-- If function registrered in Addon, code will run
local ignoreAddMessage
if funcIgnoreAdd then
ignoreAddMessage = funcIgnoreAdd(displayName)
if ignoreAddMessage then
return ignoreAddMessage
else
return
end
else
-- Code to run with libChat loaded and Addon not registered to libchat - IT MUST BE ~SAME~ AS ESOUI -
-- DisplayName is linkable
local displayNameLink = ZO_LinkHandler_CreateDisplayNameLink(displayName)
ignoreAddMessage = zo_strformat(SI_FRIENDS_LIST_IGNORE_ADDED, displayNameLink)
end
return ignoreAddMessage
end
-- Listens for EVENT_IGNORE_REMOVED event from ZO_ChatSystem
local function libChatIgnoreRemovedReceiver(displayName)
-- If function registrered in Addon, code will run
local ignoreRemoveMessage
if funcIgnoreRemove then
ignoreRemoveMessage = funcIgnoreRemove(displayName)
if ignoreRemoveMessage then
return ignoreRemoveMessage
else
return
end
else
-- Code to run with libChat loaded and Addon not registered to libchat - IT MUST BE ~SAME~ AS ESOUI -
-- DisplayName is linkable
local displayNameLink = ZO_LinkHandler_CreateDisplayNameLink(displayName)
ignoreRemoveMessage = zo_strformat(SI_FRIENDS_LIST_IGNORE_REMOVED, displayNameLink)
end
return ignoreRemoveMessage
end
-- Listens for EVENT_GROUP_MEMBER_LEFT event from ZO_ChatSystem
local function libChatGroupMemberLeftReceiver(characterName, reason, isLocalPlayer, isLeader, memberDisplayName, actionRequiredVote)
-- If function registrered in Addon, code will run
local groupMemberLeftMessage
if funcGroupMemberLeft then
groupMemberLeftMessage = funcGroupMemberLeft(characterName, reason, isLocalPlayer, isLeader, memberDisplayName, actionRequiredVote)
if groupMemberLeftMessage then
return groupMemberLeftMessage
else
return
end
else
-- Code to run with libChat loaded and Addon not registered to libchat - IT MUST BE ~SAME~ AS ESOUI -
if reason == GROUP_LEAVE_REASON_KICKED and isLocalPlayer and actionRequiredVote then
groupMemberLeftMessage = GetString(SI_GROUP_ELECTION_KICK_PLAYER_PASSED)
end
end
return groupMemberLeftMessage
end
-- Listens for EVENT_GROUP_TYPE_CHANGED event from ZO_ChatSystem
local function libChatGroupTypeChangedReceiver(largeGroup)
-- If function registrered in Addon, code will run
local GroupTypeChangedMessage
if funcGroupTypeChanged then
GroupTypeChangedMessage = funcGroupTypeChanged(largeGroup)
if GroupTypeChangedMessage then
return GroupTypeChangedMessage
else
return
end
else
-- Code to run with libChat loaded and Addon not registered to libchat - IT MUST BE ~SAME~ AS ESOUI -
if largeGroup then
return GetString(SI_CHAT_ANNOUNCEMENT_IN_LARGE_GROUP)
else
return GetString(SI_CHAT_ANNOUNCEMENT_IN_SMALL_GROUP)
end
end
end
local function registerFunction(callback, funcToUse, position, index, ...)
if funcToUse == "registerName" then
table.insert(storage.parser.Name, callback)
elseif funcToUse == "registerText" then
table.insert(storage.parser.Text, callback)
elseif funcToUse == "registerFormat" then
storage.parser.Format = callback
elseif funcToUse == "registerAppend" then
table.insert(storage[position][index], callback)
funcToUse = "registerAppend" .. index .. position
-- old
elseif funcToUse == "registerFriendStatus" then
funcFriendStatus = callback
elseif funcToUse == "registerIgnoreAdd" then
funcIgnoreAdd = callback
elseif funcToUse == "registerIgnoreRemove" then
funcIgnoreRemove = callback
elseif funcToUse == "registerGroupMemberLeft" then
funcGroupMemberLeft = callback
elseif funcToUse == "registerGroupTypeChanged" then
funcGroupTypeChanged = callback
end
if not libchat.manager[funcToUse] then
libchat.manager[funcToUse] = {}
end
-- Adding the registration to manager
local addonName = select(1, ...)
-- AddonName registered!
if addonName then
if type(addonName) == "string" then
table.insert(libchat.manager[funcToUse], addonName)
else
table.insert(libchat.manager[funcToUse],"Anonymous AddOn")
end
-- AddonName not set, so.. Anonymous
else
table.insert(libchat.manager[funcToUse],"Anonymous AddOn")
end
end
-- Register a function to be called to modify MessageChannel Sender Name
function libchat:registerName(func, ...)
registerFunction(func, "registerName", nil, nil, ...)
end
-- Register a function to be called to modify MessageChannel Text
function libchat:registerText(func, ...)
registerFunction(func, "registerText", nil, nil, ...)
end
-- Register a function to be called to format MessageChannel whole Message
function libchat:registerFormat(func, ...)
registerFunction(func, "registerFormat", nil, nil, ...)
end
-- register functions to be called to format MessageChannel Message
local function createMyFunction(funcPrefix, position, index)
local functionName = functionNameTemplate:format(funcPrefix, index, position)
libchat[functionName] = function(self, func, ...)
registerFunction(func, funcPrefix, position, index, ...)
end
end
-- libchat:registerAppendDDSBeforeAll, libchat:registerAppendTextBeforeAll, libchat:registerAppendDDSBeforeSender, libchat:registerAppendTextBeforeSender,
-- libchat:registerAppendDDSAfterSender, libchat:registerAppendTextAfterSender, libchat:registerAppendDDSBeforeText, libchat:registerAppendTextBeforeText,
-- libchat:registerAppendDDSAfterText, libchat:registerAppendTextAfterText
for _, position in ipairs(PositionList) do
for _, index in ipairs(IndexList) do
createMyFunction("registerAppend", position, index)
end
end
-- Register a function to be called to format FriendStatus Message
function libchat:registerFriendStatus(func, ...)
registerFunction(func, "registerFriendStatus", nil, nil, ...)
end
-- Register a function to be called to format IgnoreAdd Message
function libchat:registerIgnoreAdd(func, ...)
registerFunction(func, "registerIgnoreAdd", nil, nil, ...)
end
-- Register a function to be called to format IgnoreRemove Message
function libchat:registerIgnoreRemove(func, ...)
registerFunction(func, "registerIgnoreRemove", nil, nil, ...)
end
-- Register a function to be called to format GroupTypeChanged Message
function libchat:registerGroupMemberLeft(func, ...)
registerFunction(func, "registerGroupMemberLeft", nil, nil, ...)
end
-- Register a function to be called to format GroupTypeChanged Message
function libchat:registerGroupTypeChanged(func, ...)
registerFunction(func, "registerGroupTypeChanged", nil, nil, ...)
end
local function libchatdebug()
local message
CHAT_SYSTEM:AddMessage("---- libchat2 debug ----")
CHAT_SYSTEM:AddMessage("Note : 2 addons registering same method will provoke conflicts")
for keymanager, subarray in pairs(libchat.manager) do
message = keymanager .. " set with addon "
if keymanager == "registerFormat" then
message = message .. "WARNING : method overwrite Sender name and Message !"
end
for addonIndex, addonName in ipairs(subarray) do message = message .. " #" .. addonIndex .. " " .. addonName .. "," end
CHAT_SYSTEM:AddMessage(message)
end
CHAT_SYSTEM:AddMessage("---- end of libchat2 debug ----")
end
SLASH_COMMANDS["/libchat"] = libchatdebug
-- AddEventHandler to ZO_ChatSystem with same name than the original one cause the Event triggers library instead of ESOUI
ZO_ChatSystem_AddEventHandler(EVENT_CHAT_MESSAGE_CHANNEL, function(...) return libchat:MessageChannelReceiver(...) end)
ZO_ChatSystem_AddEventHandler(EVENT_FRIEND_PLAYER_STATUS_CHANGED, libChatFriendPlayerStatusChangedReceiver)
ZO_ChatSystem_AddEventHandler(EVENT_IGNORE_ADDED, libChatIgnoreAddedReceiver)
ZO_ChatSystem_AddEventHandler(EVENT_IGNORE_REMOVED, libChatIgnoreRemovedReceiver)
ZO_ChatSystem_AddEventHandler(EVENT_GROUP_MEMBER_LEFT, libChatGroupMemberLeftReceiver)
ZO_ChatSystem_AddEventHandler(EVENT_GROUP_TYPE_CHANGED, libChatGroupTypeChangedReceiver)
--[[
Not Yet
ZO_ChatSystem_AddEventHandler(EVENT_SERVER_SHUTDOWN_INFO, libChatFriendPlayerStatusChangedReceiver)
ZO_ChatSystem_AddEventHandler(EVENT_BROADCAST, libChatFriendPlayerStatusChangedReceiver)
ZO_ChatSystem_AddEventHandler(EVENT_QUEUE_FOR_CAMPAIGN_RESPONSE, libChatFriendPlayerStatusChangedReceiver)
ZO_ChatSystem_AddEventHandler(EVENT_STUCK_ERROR_ON_COOLDOWN, libChatFriendPlayerStatusChangedReceiver)
ZO_ChatSystem_AddEventHandler(EVENT_STUCK_ERROR_ALREADY_IN_PROGRESS, libChatFriendPlayerStatusChangedReceiver)
ZO_ChatSystem_AddEventHandler(EVENT_STUCK_ERROR_IN_COMBAT, libChatFriendPlayerStatusChangedReceiver)
ZO_ChatSystem_AddEventHandler(EVENT_STUCK_ERROR_INVALID_LOCATION, libChatFriendPlayerStatusChangedReceiver)
]]--