Thread Tools Display Modes
07-08-15, 10:33 PM   #1
SimplyPresent
A Defias Bandit
Join Date: Jul 2015
Posts: 2
Adding a whisper message

Hey guys, I'm currently running the addon Cross Gambler, I want to add in a whisper function where there is a trigger word for !stats to the user to receive their current win or loss record. I can't seem to be able to activate the trigger word. Would someone be able to help me out? (new to this, taking over this project)

If you want to check out the addon, here it is.
http://www.curse.com/addons/wow/cross-gambling
  Reply With Quote
07-11-15, 12:48 PM   #2
Lombra
A Molten Giant
 
Lombra's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 554
You can easily do this using the builtin chat filtering system.
Code:
ChatFrame_AddMessageEventFilter("CHAT_MSG_WHISPER", function(frame, event, message, sender, ...)
	if message == "!stats" then
		SendChatMessage("Your stats are terrible.", "WHISPER", nil, sender)
		return true
	end
end)
__________________
Grab your sword and fight the Horde!
  Reply With Quote
07-13-15, 03:52 PM   #3
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,322
I've noticed many custom chat addons that replace the chatframes don't use Blizzard's chat filter system. This isn't guaranteed to work if a user is running one.

Chat filters also can run multiple times according to how many frames are set to receive whisper events. On the same note, if no chatframes are registered to receive whispers, the filter will never run. If you need to reliably have code run regardless of user settings or conflicts with other addons, you need to handle the event yourself.

Lua Code:
  1. local EventFrame=CreateFrame("Frame");
  2. EventFrame:RegisterEvent("CHAT_MSG_WHISPER");-- Need to register an event to receive it
  3. EventFrame:SetScript("OnEvent",function(self,event,msg,sender)
  4.     if msg:lower():find("!stats") then--    We're making sure the command is case insensitive by casting it to lowercase before running a pattern check
  5.         SendChatMessage("Your response here","WHISPER",nil,sender);
  6.     end
  7. end);
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 07-13-15 at 03:57 PM.
  Reply With Quote
07-23-15, 09:05 PM   #4
SimplyPresent
A Defias Bandit
Join Date: Jul 2015
Posts: 2
Yeah, didn't know I actually had to get the whisper shown to send the reply. Thanks a LOT.
You two saved me from a mess of annoyance.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Adding a whisper message

Thread Tools
Display Modes

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