Thread Tools Display Modes
07-06-12, 02:47 PM   #1
Wishko
A Murloc Raider
AddOn Author - Click to view addons
Join Date: Sep 2010
Posts: 7
How to hook message from chat?

Anybody writes message to chat, for example:

[Guild][Name]: chatmessage

How I can hook message text, sender name and channel name from chat?

Thanks!
P.S.: sorry for my english, it's very bad
  Reply With Quote
07-06-12, 02:54 PM   #2
Haleth
This Space For Rent
 
Haleth's Avatar
Featured
Join Date: Sep 2008
Posts: 1,173
http://wowprogramming.com/docs/events/CHAT_MSG_GUILD

Code:
local f = CreateFrame("Frame")
f:RegisterEvent("CHAT_MSG_GUILD")
f:SetScript("OnEvent", function(self, event, message, sender, ...)
	...
end)
Edit: You'd have to register say, channel, whisper etc. as well if you want those.

Last edited by Haleth : 07-06-12 at 03:02 PM.
  Reply With Quote
07-07-12, 02:46 PM   #3
Wishko
A Murloc Raider
AddOn Author - Click to view addons
Join Date: Sep 2010
Posts: 7
Originally Posted by Haleth View Post
http://wowprogramming.com/docs/events/CHAT_MSG_GUILD

Code:
local f = CreateFrame("Frame")
f:RegisterEvent("CHAT_MSG_GUILD")
f:SetScript("OnEvent", function(self, event, message, sender, ...)
	...
end)
Edit: You'd have to register say, channel, whisper etc. as well if you want those.
Very big thanks!
I can get name of channel (trade, lfg, general), but I can't get name of guild, party, raid, say (recieving nil from channelString, channelNumber, channelName). How to get them?
  Reply With Quote
07-07-12, 02:52 PM   #4
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Those use different events.
http://wowprogramming.com/docs/events
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
07-08-12, 05:04 AM   #5
Wishko
A Murloc Raider
AddOn Author - Click to view addons
Join Date: Sep 2010
Posts: 7
Originally Posted by Seerah View Post
Those use different events.
http://wowprogramming.com/docs/events
I try to use they, but after
RegisterEvent("CHAT_MSG_GUILD")

"channelString", channelNumber, "channelName" returns nil and nothing

Originally Posted by p3lim View Post
What most people do is hook :AddMessage() on all chatframes (except combatlog), and parse that information.

It might be a bit advanced, but if you understand it, here is an example of how I do it in my chat addon:
And I try to use this. When I send a message to the channel (for example 2. Trade) I get this: "2 22: text", it is correct?

Last edited by Wishko : 07-08-12 at 05:15 AM.
  Reply With Quote
07-08-12, 06:28 AM   #6
Haleth
This Space For Rent
 
Haleth's Avatar
Featured
Join Date: Sep 2008
Posts: 1,173
Pretty sure that channel info is only returned for a channel event (general, trade, etc). You already know where the message was received if it's a guild message.
  Reply With Quote
07-09-12, 01:32 AM   #7
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by Wishko View Post
I try to use they, but after
RegisterEvent("CHAT_MSG_GUILD")

"channelString", channelNumber, "channelName" returns nil and nothing
You need to receive those arguments in your event handler. Different events pass different arguments. There is no "channelNumber" argument with the "CHAT_MSG_GUILD" event because guild chat does not have a number; only numbered channels like [2. Trade] have numbers.

If you want more specific help, you will need to show us your code, as is clearly stated in the only sticky thread at the top of this forum.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
07-07-12, 05:11 PM   #8
p3lim
A Pyroguard Emberseer
 
p3lim's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 1,710
What most people do is hook :AddMessage() on all chatframes (except combatlog), and parse that information.

It might be a bit advanced, but if you understand it, here is an example of how I do it in my chat addon:
Lua Code:
  1. local hooks = {}
  2. local abbrev = {
  3.     BATTLEGROUND = 'b',
  4.     OFFICER = 'o',
  5.     GUILD = 'g',
  6.     PARTY = 'p',
  7.     RAID = 'r',
  8. }
  9.  
  10. local function Abbreviate(channel)
  11.     -- Replaces channel name from the table above, or uses channel numbers
  12.     return string.format('|Hchannel:%s|h%s|h', channel, abbrev[channel] or channel:gsub('channel:', ''))
  13. end
  14.  
  15. local function AddMessage(self, message, ...)
  16.     message = message:gsub('|Hchannel:(.-)|h%[(.-)%]|h', Abbreviate)
  17.  
  18.     return hooks[self](self, message, ...)
  19. end
  20.  
  21. for index = 1, NUM_CHAT_WINDOWS do
  22.     if(index ~= 2) then
  23.         local frame = _G['ChatFrame'..index]
  24.         hooks[frame] = frame.AddMessage
  25.         frame.AddMessage = AddMessage
  26.     end
  27. end
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » How to hook message from chat?


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off