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 :( |
http://wowprogramming.com/docs/events/CHAT_MSG_GUILD
Code:
local f = CreateFrame("Frame") |
Quote:
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? |
Those use different events.
http://wowprogramming.com/docs/events |
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:
|
Quote:
RegisterEvent("CHAT_MSG_GUILD") "channelString", channelNumber, "channelName" returns nil and nothing :( Quote:
|
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.
|
Quote:
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. |
Lua Code:
I try to use this and can hook/send message to any channel, but I don't know how to distinguish message from SAY from message of GUILD |
You can check if the event is CHAT_MSG_SAY or CHAT_MSG_GUILD (or something else) using the 'event' parameter.
Mind you, what you are doing is not a good idea. The way it is now, -everyone- running your addon will respond to this query - that can get quite spammy. You should allow people running the addon to send the info manually instead, or simply only register whispers. |
Another major problem with your code is that you are creating a new table every time you receive any chat message. Creating tables is quite expensive in Lua; your code basically has a memory leak, and will consume endlessly increasing amounts of memory.
Perhaps you should describe what you actually want to do (in words, not with code), so we can suggest the best way to do it. |
Quote:
This addon can send the information manually, but I want to add such a feature so people can get information without my participation. And I do not think that many people will be spamming requests, also this feature can be disabled. But in any case, I'll think about it. Quote:
I want an Addon send a "message" to the channel on which someone wrote "passphrase" (in my addon: "! Mop", "! Mists", "! Pandaria", "! Panda") Like this: [Guild][Player]: !mop [Guild][MyAddon]: message |
As phanx said, there is no reason to define your table inside your function because it will simply be created again and again. Put it outside of your function - there'll be no change in functionality.
What I'd also suggest is not iterating over your table to see if your msg argument matches the contents of your table at that index. Instead, declare a key-value table like this: Code:
local mas = { Code:
if mas[msg] then |
Quote:
It's for this: Quote:
Quote:
|
You do not need to use string.find, since it does not matter where in the message the keyword is located, only that it is in the keyrord.
Code:
if mas[msg] then Code:
msg = msg:lower():trim() Code:
msg = msg:lower() If you want to count how many keywords are in the message: Code:
msg = msg:lower() Code:
msg = msg:lower():trim() |
Lua Code:
|
All times are GMT -6. The time now is 09:22 AM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI