Go Back   WowAce Forums > Addon Chat > AddOn HELP!
AddOn HELP! Requests for assistance and misc bug reports go here.

Reply
 
Thread Tools
Old 10-16-2010   #1
DrKazza
Junior Member
 
Join Date: Oct 2008
Posts: 71
Default Help with hooks and chat events

I've finally done some digging and have found out that something very different is happening with the way that an event is being triggered though Rawhook.

I've borrowed this code from Forumname2 and cut it down so you can see what's going on:

Code:
ForumName2 = LibStub("AceAddon-3.0"):NewAddon("ForumName2", "AceHook-3.0", "AceEvent-3.0", "AceConsole-3.0")
local string_gsub, string_format, string_match, string_lower, table_insert, table_wipe = string.gsub, string.format, string.match, string.lower, tinsert, wipe

local defaults = {
	profile = {
		customNotes = {}, 
	}
}

local chatEvents = {
	["CHAT_MSG_CHANNEL"]        = true,
	["CHAT_MSG_SAY"]            = true,
	["CHAT_MSG_YELL"]           = true,
}

local selectedName, unitName, note

function ForumName2:OnInitialize()
	self.db = LibStub("AceDB-3.0"):New("ForumNameDB", defaults, true)
end

function ForumName2:OnEnable()
	self.db.profile.customNotes = {
		["Kaziopoeia"] = "Kaztest",
	}

	for i = 1, NUM_CHAT_WINDOWS do
		self:RawHook(_G["ChatFrame" .. i], "AddMessage", "AddMessage", true)
	end
end

function ForumName2:AddMessage(frame, msg, ...)
	if(chatEvents[event]) then
		local note = self.db.profile.customNotes[arg2]
		if note then
			msg = string_gsub(msg, "|h(.*)" .. arg2 .. "(.*)|h", "|h%1" .. arg2 .. " (gimp)" .. "%2|h", 1)
			self:Print(note.." found for "..arg2)
		else
			msg = string_gsub(msg, "|h(.*)" .. arg2 .. "(.*)|h", "|h%1" .. arg2 .. " (no gimp)" .. "%2|h", 1)
		end
	else
--		msg = msg..tostring(event)
		msg = msg.." "..tostring(arg2)
	end
	self.hooks[frame]["AddMessage"](frame, msg, ...)
end
if you look at the last few lines.. msg = msg..****
this USED to work passing events and args through to this function, however now, both event and arg are NIL.

Any idea what changed and how I can fix it.
I'm 99% sure that this problem affects Spamthrottle also

Thanks loads

Kaz

It's probably helpful to explain what I'm trying to do here..

If it's a non listed event then arg2 should be added to the end of the message (If i replace it with msg = msg.." test" then it successfully appends test... currently it sticks NIL at the end)
if the event turns out to be one of the listed ones then it will add a title (or gimp) as desired.
The whole code used to work perfectly, it's just the hook that's no longer passing through the event or the arguments thereof
__________________
Author of Old Instance Finder and Gimplist

Last edited by DrKazza; 10-16-2010 at 09:13 AM.
DrKazza is offline   Reply With Quote
Old 10-16-2010   #2
Orukxu
Newbie
 
Join Date: Dec 2009
Posts: 1
Default Re: Help with hooks and chat events

Looks like you're using arg1, arg2, etc. as globals in your orumName2:AddMessage() event handler. You need to change to new syntax. A quick fix should be this:

function ForumName2:AddMessage(frame, msg, ...)
local arg1, arg2 = ...;
if(chatEvents[event]) then
local note = self.db.profile.customNotes[arg2]
...etc...

This is according to this helpful forum post:
http://forums.worldofwarcraft.com/th...Id=25626580975

But also useful to me was the info in the following:
http://www.wowwiki.com/API_ChatFrame...ageEventFilter

Especially the first example filter implementation.

Note that I am by NO means an expert here, but I was able to get SpamThrottle back up and seemingly working. It should be approved shortly, so feel free to have a look in the updated code there when it appears.

Good luck!
-- Orukxu
Orukxu is offline   Reply With Quote
Old 10-16-2010   #3
DrKazza
Junior Member
 
Join Date: Oct 2008
Posts: 71
Default Re: Help with hooks and chat events

you rock dude, looks like the arg things will work fine... just need to work out how to get the event to feed though
__________________
Author of Old Instance Finder and Gimplist

Last edited by DrKazza; 10-16-2010 at 12:28 PM.
DrKazza is offline   Reply With Quote
Old 10-17-2010   #4
DrKazza
Junior Member
 
Join Date: Oct 2008
Posts: 71
Default Re: Help with hooks and chat events

Nah, no joy... I'll have to spend some time actually learning about hooks and registering events rather than just dragging and dropping code.

Thanks for the help anyway
__________________
Author of Old Instance Finder and Gimplist
DrKazza is offline   Reply With Quote
Old 10-17-2010   #5
Phanx
Seal Cub Clubbing Club
 
Phanx's Avatar
 
Join Date: May 2005
Location: United States
Posts: 8,266
Default Re: Help with hooks and chat events

If you're trying to modify messages being added to the chat frame, you should be using the chat filtering API that was added way back in patch 2.4, instead of trying to hook AddMessage.

http://www.wowwiki.com/API_ChatFrame...ageEventFilter
http://www.wowwiki.com/API_ChatFrame...ageEventFilter
__________________
Author/maintainer of Grid, PhanxChat, and many more. | PM me on CurseForge
Troubleshoot an addon | Turn any code into an addon | More addon resources
Need help with your code? Attach or paste your whole, real files.
Please don't PM me about addon bugs, requests, or code help. Post a comment, ticket, or thread instead!
Phanx is offline   Reply With Quote
Old 10-18-2010   #6
Farmbuyer
Amazing Member
 
Farmbuyer's Avatar
 
Join Date: Feb 2005
Posts: 1,122
Default Re: Help with hooks and chat events

The filters don't allow you to do as many rewrites as what AddMessage does. I haven't looked at the OP's code, but if he's trying to do anything to (for example) the [Name_Of_Channel] or [Name_Of_Player] tags, hooking AddMessage is required.
Farmbuyer is offline   Reply With Quote
Old 10-18-2010   #7
DrKazza
Junior Member
 
Join Date: Oct 2008
Posts: 71
Default Re: Help with hooks and chat events

Thanks guys... I had a peek and saw that this was a much better way of handling the code.
Seems that Forumname was written a long time ago and if re-written today would use that.

My addon's now fixed

Thanks loads for the help.
__________________
Author of Old Instance Finder and Gimplist
DrKazza is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

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

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

Forum Jump


All times are GMT. The time now is 11:37 AM.