View Single Post
04-16-11, 04:48 PM   #6
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,326
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:
  1. local Send=SendChatMessage;
  2. local pieces={};
  3. function SendChatMessage(msg,chan,...)
  4.     chan=chan:upper();--    Convert to make checks easier (channel is case-insensitive)
  5.     if chan=="SAY" then
  6. --      Clear our piece table
  7.         table.wipe(pieces);
  8.  
  9. --      Remove empty emotes and strip all spaces around "*" (try to replace empty emotes with a single space)
  10.         msg=strtrim(msg):gsub("%s*%*%s*%*%s*"," "):gsub("%s*%*%s*","%*");
  11.  
  12. --      Split string (strsplit() isn't working the way we need it to)
  13.         for i in msg:gmatch("[^%*]+") do pieces[#pieces+1]=i; end
  14.         if msg:sub(1,1)=="*" then table.insert(pieces,1,""); end
  15.  
  16. --      Iterate through pieces
  17.         for i,j in ipairs(pieces) do
  18.             if #j>0 then--  Don't do anything if string is empty
  19.                 if i%2>0 then-- Evaluates to 1 if say, 0 if emote
  20.                     Send(j,chan);
  21.                 else
  22. --                  Try to separate command and args
  23.                     local cmd,arg=j:match("(%S+) (.+)");
  24.                     if not cmd then cmd=j; end
  25.  
  26. --                  This is tricky, we need to check if the emote slash command exists
  27.                     local token;
  28.                     local tokencheck,tokenid=EMOTE1_TOKEN,1;
  29.                     while tokencheck do
  30.                         local cmdcheck,cmdid=_G["EMOTE"..tokenid.."_CMD1"],1;
  31.                         while cmdcheck do
  32.                             local slashcmd=cmdcheck:sub(2):lower();--   Skip the slash for the emote command
  33.                             if slashcmd==cmd:lower() then-- Command matches, token found
  34.                                 token=tokencheck;
  35.                                 break;
  36.                             end
  37.  
  38. --                          Increment command
  39.                             cmdcheck,cmdid=_G["EMOTE"..tokenid.."_CMD"..(cmdid+1)],cmdid+1;
  40.                         end
  41.  
  42. --                      Break if token found
  43.                         if token then break; end
  44.  
  45. --                      Increment token
  46.                         tokencheck,tokenid=_G["EMOTE"..(tokenid+1).."_TOKEN"],tokenid+1;
  47.                     end
  48.  
  49.                     if token then
  50.                         DoEmote(token,arg);--   Performs the same emote operation as supported by chat
  51.                     else
  52.                         Send(j,"EMOTE");
  53.                     end
  54.                 end
  55.             end
  56.         end
  57.     else
  58.         Send(msg,chan,...);
  59.     end
  60. 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 : 04-19-11 at 12:35 PM.
  Reply With Quote