I put together some code to do exactly what was described. It only operates on /say and it will attempt to use the emote slash command if it finds one that matches, otherwise, it'll send the emote out through the emote channel. Theoreticly, the slash command emotes support a target argument that lets you specify what UnitID to target. This option has been added in to this code as well.
lua Code:
local Send=SendChatMessage;
local pieces={};
function SendChatMessage(msg,chan,...)
chan=chan:upper();-- Convert to make checks easier (channel is case-insensitive)
if chan=="SAY" then
-- Clear our piece table
table.wipe(pieces);
-- Remove empty emotes and strip all spaces around "*" (try to replace empty emotes with a single space)
msg=strtrim(msg):gsub("%s*%*%s*%*%s*"," "):gsub("%s*%*%s*","%*");
-- Split string (strsplit() isn't working the way we need it to)
for i in msg:gmatch("[^%*]+") do pieces[#pieces+1]=i; end
if msg:sub(1,1)=="*" then table.insert(pieces,1,""); end
-- Iterate through pieces
for i,j in ipairs(pieces) do
if #j>0 then-- Don't do anything if string is empty
if i%2>0 then-- Evaluates to 1 if say, 0 if emote
Send(j,chan);
else
-- Try to separate command and args
local cmd,arg=j:match("(%S+) (.+)");
if not cmd then cmd=j; end
-- This is tricky, we need to check if the emote slash command exists
local token;
local tokencheck,tokenid=EMOTE1_TOKEN,1;
while tokencheck do
local cmdcheck,cmdid=_G["EMOTE"..tokenid.."_CMD1"],1;
while cmdcheck do
local slashcmd=cmdcheck:sub(2):lower();-- Skip the slash for the emote command
if slashcmd==cmd:lower() then-- Command matches, token found
token=tokencheck;
break;
end
-- Increment command
cmdcheck,cmdid=_G["EMOTE"..tokenid.."_CMD"..(cmdid+1)],cmdid+1;
end
-- Break if token found
if token then break; end
-- Increment token
tokencheck,tokenid=_G["EMOTE"..(tokenid+1).."_TOKEN"],tokenid+1;
end
if token then
DoEmote(token,arg);-- Performs the same emote operation as supported by chat
else
Send(j,"EMOTE");
end
end
end
end
else
Send(msg,chan,...);
end
end