Download
(10 Kb)
Download
Updated: 03/22/24 04:02 PM
Compatibility:
Scions of Ithelia (9.3.0)
Updated:03/22/24 04:02 PM
Created:05/28/19 09:18 AM
Monthly downloads:79,173
Total downloads:1,704,773
Favorites:1,256
MD5:
Categories:Libraries, Data Mods
9.3.0
LibChatMessage  Updated this week!  Popular! (More than 5000 hits)
Version: 1.2.1
by: sirinsidiator [More]
For years addon authors have abused the debug methods d(), df() and CHAT_SYSTEM:AddMessage() to show messages in chat or even added text directly to the chat buffer, preventing other addons from interacting with the output. LibChatMessage offers an easy alternative that uses the same method as the vanilla UI to print system messages.

Features

Chat Messages
The main purpose of the library is to provide an easy API that can be used to print messages in chat. This is done via so called chat proxy objects. Each addon can create their own proxy and call the Print and Printf method (similar to d() and df()).

Addon Tag
The library will automatically prefix each message with a tag provided to each chat proxy instance by their addon. Users can choose if they want the tag to be the full addon name or a shortened string.

Time Prefix
The library can also print the current time in front of each chat message. This is disabled by default to avoid compatibility issues with other chat addons, but can be enabled via the settings explained below.

Chat History
Another feature of the library is to store all incoming chat messages and restore them again at UI load. This is also disabled by default to avoid compatibility problems (especially with pChat). Unlike with pChat the history is saved in raw form, meaning that any modifications to the message made by addons are not stored and instead applied when the messages are restored. This also means that information like the guild name is lost when the player leaves a guild and can lead to restored messages showing no or even a different guild name.

Custom Chat Links
Starting with version 1.2.0, the library offers a way for addons to send arbitrary data links in chat.

Known Issue/Drawback
  • If you register a chat link, but do not handle it, an error will occur, if the user clicks it.
  • Chat bubbles will show raw data. We can not modify them.
  • In order to display custom links in the chat input box, the lib sets all types of markup as allowed. this means that the text shown in the box may look different from what is actually being sent or visible to users without the library. For example a single | (pipe) character won't show until the message is sent and using color markup will change the text color in the input field, but show up as raw text in the chat once sent.

Quick Start
Add LibChatMessage as a dependency to your addon manifest:
Code:
## DependsOn: LibChatMessage
Afterwards you can create a chat proxy and print messages like so:
Lua Code:
  1. local chat = LibChatMessage("MyAddon", "MA") -- long and short tag to identify who is printing the message
  2. chat:Print("Simple message") -- instead of d()
  3. chat:Printf("Formatted %s", "message") -- instead of df()
  4. chat:SetTagColor("ff0000"):Print("Message with a different tag color") -- To change the tag color for e.g. warnings. The message itself can be colored with a color tag, although I can't really recommend doing that
  5. chat:SetEnabled(false) -- in case the output of this ChatProxy should be enabled. Could be used when a settings is supposed to disable chat messages for an addon
  6. chat:Print("Ignored message") -- won't show up

Settings
LibChatMessage offers several settings to allow players to control the look of the output. The settings can be changed via the "/chatmessage" slash command, or via the libraries API. Using the slash command with an invalid command will print the following message to chat:
Code:
/chatmessage <command> [argument]
<time>      [on/off]           Enables or disables the time prefix
<chat>      [on/off]           Controls the time prefix on regular chat
<format>    [auto/12h/24h]     Changes the used time format
<tag>       [off/short/long]   Changes the length of the used tag
<history>   [on/off]           Restore old chat after login
<age>       [seconds]          The maximum age of restored chat
Example: /chatmessage tag short
Using a command without an argument will print the current state of the setting to chat.

API Reference

Create
Returns a new instance of ChatProxy with the given tags.
Code:
local chat = LibChatMessage.Create(longTag, shortTag)
or
Code:
local chat = LibChatMessage(longTag, shortTag)
ChatProxy:SetTagColor
Sets the color of the message tag for the next printed message (resets afterwards). Can be either a hex string ("ff0000") or a ZO_ColorDef object. Returns the ChatProxy instance so the call can be chained as shown in the quick start example.
Code:
local chat = chat:SetTagColor(color)
ChatProxy:Print
Method to a print regular messages to chat. The message will automatically be prefixed with the time and tag based on user preferences.
Code:
chat:Print(message)
ChatProxy:Printf
Method to print a message formatted via string.format to chat. The message will automatically be prefixed with the time and tag based on user preferences.
Code:
chat:Printf(formatString, ...)
ChatProxy:SetEnabled
Setter to turn this proxy off, so it no longer prints anything to chat when one of its methods is called. Can be used to easily enable or disable chat messages for an addon based on user preferences.
Code:
chat:SetEnabled(enabled)
ClearChat
Removes all messages from all chat windows.
Code:
LibChatMessage:ClearChat()
ClearHistory
Removes all stored messages from the chat history.
Code:
LibChatMessage:ClearHistory()
GetHistory
Returns the current chat history table.
Code:
LibChatMessage:GetHistory()
SetTimePrefixEnabled
Sets the time prefix feature enabled or disabled. Disabled by default as it may cause problems with other chat addons that have similar features.
Code:
LibChatMessage:SetTimePrefixEnabled(enabled)
IsTimePrefixEnabled
Returns true if the time prefix feature is enabled.
Code:
local enabled = LibChatMessage:IsTimePrefixEnabled()
SetRegularChatMessageTimePrefixEnabled
Sets the time prefix feature for player chat channels enabled or disabled. Enabled by default, but only counts if the time prefix feature itself is turned on.
Code:
LibChatMessage:SetTimePrefixEnabled(enabled)
IsRegularChatMessageTimePrefixEnabled
Returns true if the time prefix feature is enabled for player chat channels.
Code:
local enabled = LibChatMessage:IsTimePrefixEnabled()
TIME_FORMATS
An array containing the time formats passed to os.date for the time prefix.
  1. TIME_FORMAT_AUTO = "[%X]" - uses locale dependent formatting
  2. TIME_FORMAT_12 = "[%I:%M:%S %p]" - 12h time format
  3. TIME_FORMAT_24 = "[%T]" - 24h time format (ISO 8601)

SetTimePrefixFormat
Sets the format for the time prefix feature. Can be either one contained in TIME_FORMATS, or a custom format string. Custom strings should be wrapped in brackets.
Code:
LibChatMessage:SetTimePrefixFormat(format)
GetTimePrefixFormat
Returns the time prefix formatting string.
Code:
local format = LibChatMessage:GetTimePrefixFormat()
SetTagPrefixMode
Sets the mode used for the proxy tag for addon messages.
Available modes are:
  1. TAG_PREFIX_OFF - Disables showing a tag. The long tag will still be stored in the history in case it is enabled.
  2. TAG_PREFIX_LONG - Prints the long tag provided by an addon in front of the message
  3. TAG_PREFIX_SHORT - Prints the short tag provided by an addon in front of the message
Code:
LibChatMessage:SetTagPrefixMode(mode)
GetTagPrefixMode
Returns the current message tag mode.
Code:
local mode = LibChatMessage:GetTagPrefixMode()
SetChatHistoryEnabled
Sets the chat history feature enabled or disabled on the next UI load. This feature is not compatible with pChat and disabled by default.
Code:
LibChatMessage:SetChatHistoryEnabled(enabled)
IsChatHistoryEnabled
Returns true if the message history will be enabled on the next UI load.
Code:
local enabled = LibChatMessage:IsChatHistoryEnabled()
IsChatHistoryActive
Returns true if the message history is active right now.
Code:
local enabled = LibChatMessage:IsChatHistoryActive()
SetChatHistoryMaxAge
Sets the maximum age for chat messages to be restored on UI load in seconds. Default is 3600s (= 1h).
Code:
LibChatMessage:SetChatHistoryMaxAge(maxAge)
GetChatHistoryMaxAge
Returns the maximum age for chat messages in the history.
Code:
local maxAge = LibChatMessage:GetChatHistoryMaxAge()
RegisterCustomChatLink
Register a link type to be valid. Optional with a reformatter function.
All unregistered chat links will be change to an "unknown" link with all data stripped off upon receiving them from chat channel.
If someone is posting a chat link to someone, not having the addon it belongs to, a message is shown in the upper right corner instead of causing an error.

Code:
LibChatMessage:RegisterCustomChatLink(YOUR_LINK_TYPE)
LibChatMessage:RegisterCustomChatLink(YOUR_LINK_TYPE, reformatLinkFunc)
The reformatter has the following signature:
Code:
local function reformatLink(linkStyle, linkType, data, displayText)
    return ZO_LinkHandler_CreateLinkWithFormat(displayText, nil, linkType, linkStyle, data)
end
LibChatMessage:RegisterCustomChatLink(YOUR_LINK_TYPE, reformatLink)
displayText - Text shown to the user
linkTyype - Your link type (YOUR_LINK_TYPE)
linkStyle - Built-in values: LINK_STYLE_BRACKETS, LINK_STYLE_DEFAULT (number)
data - remaining part of the chat link containing the data your provided. (string)

The reformatter function can be used to localize the displayText.
Your chat link must provide at least one data column.

After registering a link type, you MUST add a link click handler.
See https://wiki.esoui.com/How_to_create_custom_links.

Example
Code:
function addon:OnLinkClicked(link, button, text, color, linkType, ...)
    if linkType ~= YOUR_LINK_TYPE then
        return
    end
    if button == MOUSE_BUTTON_INDEX_LEFT then
        -- Do your stuff
    elseif button == MOUSE_BUTTON_INDEX_MIDDLE then
        -- Do your stuff
    end
    return true -- link has been handled
end

function addon:InitLinkHandler()
    LINK_HANDLER:RegisterCallback(LINK_HANDLER.LINK_CLICKED_EVENT, self.OnLinkClicked, self)
    LINK_HANDLER:RegisterCallback(LINK_HANDLER.LINK_MOUSE_UP_EVENT, self.OnLinkClicked, self)
end
The value of the "unknown" link type can be found here:
LibChatMessage.UNKNOWN_LINK_TYPE
v1.2.1
- fixed error on chat history restore due to corrupted saved variable after a very long addon generated message was printed
- updated for Scions of Ithelia

v1.2.0
- added support for custom chat links (thanks votan)
- updated for Blackwood

v1.1.3
- fixed error when events are received before saved variables are loaded

v1.1.2
- updated for chat system changes in game version 5.3.5 (temporary workaround has been removed)

v1.1.1
- fixed error when an addon tries to print a message during initialization

v1.1.0
- added temporary workaround for chat formatters not working. See description for details.
- updated for Harrowstorm

v1.0.1
- added missing IsLibrary flag
Archived Files (7)
File Name
Version
Size
Uploader
Date
1.2.0
10kB
sirinsidiator
04/22/21 01:33 PM
1.1.3
5kB
sirinsidiator
03/02/20 01:26 PM
1.1.2
5kB
sirinsidiator
03/02/20 12:10 PM
1.1.1
6kB
sirinsidiator
02/25/20 01:55 PM
1.1.0
6kB
sirinsidiator
02/24/20 02:43 AM
1.0.1
5kB
sirinsidiator
06/01/19 05:15 AM
1.0.0
5kB
sirinsidiator
05/28/19 09:18 AM


Post A Reply Comment Options
Unread 11/29/20, 05:03 PM  
marlonbrando
AddOn Author - Click to view AddOns

Forum posts: 17
File comments: 137
Uploads: 8
Re: Re: Per chat-proxy ability to always include a prefix?

Originally Posted by sirinsidiator
Originally Posted by marlonbrando
I may be missing something but I don't see any way to add a prefix to messages without configuring it globally, i.e., LibChatMessage:SetTagPrefixMode(...). I'd like to be able to control this only for my add-on via something like chat:SetTagprefixMode(...) .

Is this possible or is something like this already there and I've missed it?
The tag prefix mode is a user setting, as such it's not supposed to be controlled by addons aside of when they offer a ui for the library. There is currently no way for a user to select it per addon either.
Ok. I'll add it manually. Thanks.
Report comment to moderator  
Reply With Quote
Unread 11/29/20, 12:17 PM  
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view AddOns

Forum posts: 1568
File comments: 1120
Uploads: 41
Re: Per chat-proxy ability to always include a prefix?

Originally Posted by marlonbrando
I may be missing something but I don't see any way to add a prefix to messages without configuring it globally, i.e., LibChatMessage:SetTagPrefixMode(...). I'd like to be able to control this only for my add-on via something like chat:SetTagprefixMode(...) .

Is this possible or is something like this already there and I've missed it?
The tag prefix mode is a user setting, as such it's not supposed to be controlled by addons aside of when they offer a ui for the library. There is currently no way for a user to select it per addon either.
Report comment to moderator  
Reply With Quote
Unread 11/29/20, 12:10 PM  
marlonbrando
AddOn Author - Click to view AddOns

Forum posts: 17
File comments: 137
Uploads: 8
Per chat-proxy ability to always include a prefix?

I may be missing something but I don't see any way to add a prefix to messages without configuring it globally, i.e., LibChatMessage:SetTagPrefixMode(...). I'd like to be able to control this only for my add-on via something like chat:SetTagprefixMode(...) .

Is this possible or is something like this already there and I've missed it?
Report comment to moderator  
Reply With Quote
Unread 07/22/20, 02:56 AM  
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view AddOns

Forum posts: 1568
File comments: 1120
Uploads: 41
Re: Out of date, but needed as a lib for other mods?

Originally Posted by JLE
Some of my other mods are not working because they depend on this particular one (LibChatMessage) - or another one of yours (LibMapPing) - and the game is saying they are out of date.

What's wrong? Do they not yet work with Greymoor installed? When can an update be expected?

Other mods of yours also appear to be only up to date with the "Harrowstorm" expansion, not with the full "Greymoor" chapter.
https://www.esoui.com/portal.php?id=218&a=faq&faqid=152
Report comment to moderator  
Reply With Quote
Unread 07/21/20, 07:38 PM  
JLE

Forum posts: 0
File comments: 42
Uploads: 0
Out of date, but needed as a lib for other mods?

Some of my other mods are not working because they depend on this particular one (LibChatMessage) - or another one of yours (LibMapPing) - and the game is saying they are out of date.

What's wrong? Do they not yet work with Greymoor installed? When can an update be expected?

Other mods of yours also appear to be only up to date with the "Harrowstorm" expansion, not with the full "Greymoor" chapter.
Report comment to moderator  
Reply With Quote
Unread 07/13/20, 08:34 PM  
TECHHNYNE

Forum posts: 0
File comments: 4
Uploads: 0
for some reason i cant get any of these addons to register they are all in my addon DIR
https://imgur.com/a/1PleUjN

Last edited by TECHHNYNE : 07/13/20 at 08:34 PM.
Report comment to moderator  
Reply With Quote
Unread 06/06/20, 10:41 AM  
drsneg

Forum posts: 0
File comments: 2
Uploads: 0
Re: Re: problem

Originally Posted by sirinsidiator
Originally Posted by drsneg
i installed the lastest version of this library. 1.1.3.
But in no one modes is not working. Please help. What i doing wrong?

Sorry for russian language in gui.
You need to check the checkbox on the top right and reload the ui. Then it should work.
Thanks! It work!
Report comment to moderator  
Reply With Quote
Unread 06/06/20, 09:48 AM  
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view AddOns

Forum posts: 1568
File comments: 1120
Uploads: 41
Re: problem

Originally Posted by drsneg
i installed the lastest version of this library. 1.1.3.
But in no one modes is not working. Please help. What i doing wrong?

Sorry for russian language in gui.
You need to check the checkbox on the top right and reload the ui. Then it should work.
Report comment to moderator  
Reply With Quote
Unread 06/06/20, 07:24 AM  
drsneg

Forum posts: 0
File comments: 2
Uploads: 0
problem

i installed the lastest version of this library. 1.1.3.
But in no one modes is not working. Please help. What i doing wrong?

Sorry for russian language in gui.
Last edited by drsneg : 06/06/20 at 07:25 AM.
Report comment to moderator  
Reply With Quote
Unread 05/27/20, 02:42 AM  
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view AddOns

Forum posts: 1568
File comments: 1120
Uploads: 41
Originally Posted by Casterial
Code:
user:/AddOns/LibChatMessage/LibChatMessage.lua:528: function expected instead of nil
stack traceback:
user:/AddOns/LibChatMessage/LibChatMessage.lua:528: in function 'ReinitializeChatFormatters'
user:/AddOns/LibChatMessage/LibChatMessage.lua:586: in function 'func'
 EsoUI/Libraries/Globals/globalapi.lua:216: in function '(anonymous)'
This error points to an empty line in the code of the latest version. Make sure you update your addons!
Report comment to moderator  
Reply With Quote
Unread 05/26/20, 06:13 PM  
Casterial
AddOn Author - Click to view AddOns

Forum posts: 1
File comments: 64
Uploads: 5
Code:
user:/AddOns/LibChatMessage/LibChatMessage.lua:528: function expected instead of nil
stack traceback:
user:/AddOns/LibChatMessage/LibChatMessage.lua:528: in function 'ReinitializeChatFormatters'
user:/AddOns/LibChatMessage/LibChatMessage.lua:586: in function 'func'
EsoUI/Libraries/Globals/globalapi.lua:216: in function '(anonymous)'
Report comment to moderator  
Reply With Quote
Unread 04/28/20, 05:38 AM  
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view AddOns

Forum posts: 1568
File comments: 1120
Uploads: 41
Re: bug?

Originally Posted by tankslayer21
I get the chat error every time I enter the chat


EsoUI/Ingame/ChatSystem/Keyboard/KeyboardChatSystem.lua:370: operator - is not supported for nil - number
stack traceback:
EsoUI/Ingame/ChatSystem/Keyboard/KeyboardChatSystem.lua:370: in function 'ZO_ChatSystem:Maximize'
(tail call): ?
EsoUI/Ingame/ChatSystem/SharedChatSystem.lua:2001: in function 'SharedChatSystem:StartTextEntry'
EsoUI/Ingame/ChatSystem/SharedChatSystem.lua:2365: in function 'StartChatInput'
:1: in function '(main chunk)'
Please refer to this thread.
Report comment to moderator  
Reply With Quote
Unread 04/27/20, 06:47 PM  
Sharlikran
 
Sharlikran's Avatar
AddOn Author - Click to view AddOns

Forum posts: 628
File comments: 2004
Uploads: 15
Re: bug?

Originally Posted by tankslayer21
I get the chat error every time I enter the chat


EsoUI/Ingame/ChatSystem/Keyboard/KeyboardChatSystem.lua:370: operator - is not supported for nil - number
stack traceback:
EsoUI/Ingame/ChatSystem/Keyboard/KeyboardChatSystem.lua:370: in function 'ZO_ChatSystem:Maximize'
(tail call): ?
EsoUI/Ingame/ChatSystem/SharedChatSystem.lua:2001: in function 'SharedChatSystem:StartTextEntry'
EsoUI/Ingame/ChatSystem/SharedChatSystem.lua:2365: in function 'StartChatInput'
:1: in function '(main chunk)'
I am not as good with LUA as I would like but with what programming I do, to me, that seems like you have a error caused by a mod but what you are seeing is what was on the "stack" as we say sometimes.

What I mean by that is say you have 104 mods installed. One of them caused an error. You do not know which one, and when the game tries to tell you it is not telling you all the errors one by one so you could start with the first issue and go down the list. What you are seeing is the last error on the stack, not what is causing the issue.

You are experiencing an error for sure but that's not the initial error. I have really really taken a lot of time to eliminate LibStub from all my mods and I even removed embedded libraries because authors have not removed them themselves yet. I make what I consider minor modifications.

I am using LibChatMessage and I have not altered it because I didn't feel it was needed. The mods that I have will be different from yours. However, the ones I have that seem to require LibChatMessage are; Awesome Guild Store, Craft Store, and LibGPS.

Out of those three I have altered only two of them. Awesome Guild Store and Craft Store. I don't know what other mods you might be using that require LibChatMessage. However, updating the mods I listed to the current versions would be a start. And update LibGPS also if you have not already.

I don't know if there is an easy way to spit out a exact list of your mods. I could say get me some screen shots but I have 104 mods so it would be multiple screen shots for me and I don't want to have you spam this forum with them.

I can't really give instructions on how to do this, but if you open a command prompt in your .\Documents\Elder Scrolls Online\live\AddOns folder and typed what I have listed below it would make a list of folders and that should indicate the mods you have installed fairly easily.

Code:
dir /A:D /B > modlist.txt
Last edited by Sharlikran : 04/27/20 at 09:55 PM.
Report comment to moderator  
Reply With Quote
Unread 04/27/20, 12:28 PM  
tankslayer21

Forum posts: 0
File comments: 1
Uploads: 0
bug?

I get the chat error every time I enter the chat


EsoUI/Ingame/ChatSystem/Keyboard/KeyboardChatSystem.lua:370: operator - is not supported for nil - number
stack traceback:
EsoUI/Ingame/ChatSystem/Keyboard/KeyboardChatSystem.lua:370: in function 'ZO_ChatSystem:Maximize'
(tail call): ?
EsoUI/Ingame/ChatSystem/SharedChatSystem.lua:2001: in function 'SharedChatSystem:StartTextEntry'
EsoUI/Ingame/ChatSystem/SharedChatSystem.lua:2365: in function 'StartChatInput'
:1: in function '(main chunk)'
Report comment to moderator  
Reply With Quote
Unread 04/25/20, 11:03 AM  
Lenox

Forum posts: 15
File comments: 29
Uploads: 0
Originally Posted by sirinsidiator
Originally Posted by Lenox
  1. How do I incrase the history from 3600 to 7200?

    I did /chatmessage LibChatMessage:SetChatHistoryMaxAge(7200) and got an error in chat.

  2. How do I enable time stamps ONLY for player chat? I don't need time stamps for system messages. I tried time off and chat on, but then no time was output anywhere.
ad 1) You are mixing two different things here. The chat command for setting the history is just "/chatmessage age 7200". You can type "/chatmessage" and it will print a help text to chat showing how it is used. "LibChatMessage:SetChatHistoryMaxAge(7200)" is how an addon author would set the age from code.

ad 2) This is currently not possible, but something I have planned for version 2.
Thank you so much! I'm looking forward to version 2.
Report comment to moderator  
Reply With Quote
Post A Reply



Category Jump:

Support AddOn Development!

You have just downloaded by the author . If you like this AddOn why not consider supporting the author? This author has set up a donation account. Donations ensure that authors can continue to develop useful tools for everyone.