ChatFrame.lua

ChatFrame.lua (8.2.0.30993; unchanged since 8.2.0.30920)
  1. MESSAGE_SCROLLBUTTON_INITIAL_DELAY = 0;
  2. MESSAGE_SCROLLBUTTON_SCROLL_DELAY = 0.05;
  3. CHAT_BUTTON_FLASH_TIME = 0.5;
  4. CHAT_TELL_ALERT_TIME = 300;
  5. NUM_CHAT_WINDOWS = 10;
  6. DEFAULT_CHAT_FRAME = ChatFrame1;
  7. CHAT_FOCUS_OVERRIDE = nil;
  8. NUM_REMEMBERED_TELLS = 10;
  9. MAX_WOW_CHAT_CHANNELS = 20;
  10. CHAT_TIMESTAMP_FORMAT = nil; -- gets set from Interface Options
  11. CHAT_SHOW_IME = false;
  12. MAX_CHARACTER_NAME_BYTES = 305;
  13. --DEBUG FIXME FOR TESTING
  14. CHAT_OPTIONS = {
  15. ONE_EDIT_AT_A_TIME = "old"
  16. };
  17. -- Table for event indexed chatFilters.
  18. -- Format ["CHAT_MSG_SYSTEM"] = { function1, function2, function3 }
  19. -- filter, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11 = function1 (self, event, ...) if filter then return true end return false, ... end
  20. local chatFilters = {};
  21. -- These hash tables are to improve performance of common lookups
  22. -- if you change what these tables point to (ie slash command, emote, chat)
  23. -- then you need to invalidate the entry in the hash table
  24. local hash_SecureCmdList = {}
  25. --Note: These need to remain global for AddOns
  26. hash_SlashCmdList = {} --[localizedCommand] -> function
  27. hash_EmoteTokenList = {}
  28. hash_ChatTypeInfoList = {} --[localizedCommand] -> identifier (Stores all slash commands)
  29. ChatTypeInfo = { };
  30. ChatTypeInfo["SYSTEM"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  31. ChatTypeInfo["SAY"] = { sticky = 1, flashTab = false, flashTabOnGeneral = false };
  32. ChatTypeInfo["PARTY"] = { sticky = 1, flashTab = false, flashTabOnGeneral = false };
  33. ChatTypeInfo["RAID"] = { sticky = 1, flashTab = false, flashTabOnGeneral = false };
  34. ChatTypeInfo["GUILD"] = { sticky = 1, flashTab = false, flashTabOnGeneral = false };
  35. ChatTypeInfo["OFFICER"] = { sticky = 1, flashTab = false, flashTabOnGeneral = false };
  36. ChatTypeInfo["YELL"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  37. ChatTypeInfo["WHISPER"] = { sticky = 1, flashTab = true, flashTabOnGeneral = true };
  38. ChatTypeInfo["SMART_WHISPER"] = ChatTypeInfo["WHISPER"];
  39. ChatTypeInfo["WHISPER_INFORM"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  40. ChatTypeInfo["REPLY"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  41. ChatTypeInfo["EMOTE"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  42. ChatTypeInfo["TEXT_EMOTE"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  43. ChatTypeInfo["MONSTER_SAY"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  44. ChatTypeInfo["MONSTER_PARTY"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  45. ChatTypeInfo["MONSTER_YELL"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  46. ChatTypeInfo["MONSTER_WHISPER"] = { sticky = 0, flashTab = true, flashTabOnGeneral = true };
  47. ChatTypeInfo["MONSTER_EMOTE"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  48. ChatTypeInfo["CHANNEL"] = { sticky = 1, flashTab = false, flashTabOnGeneral = false };
  49. ChatTypeInfo["CHANNEL_JOIN"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  50. ChatTypeInfo["CHANNEL_LEAVE"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  51. ChatTypeInfo["CHANNEL_LIST"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  52. ChatTypeInfo["CHANNEL_NOTICE"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  53. ChatTypeInfo["CHANNEL_NOTICE_USER"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  54. ChatTypeInfo["TARGETICONS"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  55. ChatTypeInfo["AFK"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  56. ChatTypeInfo["DND"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  57. ChatTypeInfo["IGNORED"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  58. ChatTypeInfo["SKILL"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  59. ChatTypeInfo["LOOT"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  60. ChatTypeInfo["CURRENCY"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  61. ChatTypeInfo["MONEY"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  62. ChatTypeInfo["OPENING"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  63. ChatTypeInfo["TRADESKILLS"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  64. ChatTypeInfo["PET_INFO"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  65. ChatTypeInfo["COMBAT_MISC_INFO"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  66. ChatTypeInfo["COMBAT_XP_GAIN"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  67. ChatTypeInfo["COMBAT_HONOR_GAIN"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  68. ChatTypeInfo["COMBAT_FACTION_CHANGE"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  69. ChatTypeInfo["BG_SYSTEM_NEUTRAL"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  70. ChatTypeInfo["BG_SYSTEM_ALLIANCE"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  71. ChatTypeInfo["BG_SYSTEM_HORDE"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  72. ChatTypeInfo["RAID_LEADER"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  73. ChatTypeInfo["RAID_WARNING"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  74. ChatTypeInfo["RAID_BOSS_WHISPER"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  75. ChatTypeInfo["RAID_BOSS_EMOTE"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  76. ChatTypeInfo["QUEST_BOSS_EMOTE"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  77. ChatTypeInfo["FILTERED"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  78. ChatTypeInfo["INSTANCE_CHAT"] = { sticky = 1, flashTab = false, flashTabOnGeneral = false };
  79. ChatTypeInfo["INSTANCE_CHAT_LEADER"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  80. ChatTypeInfo["RESTRICTED"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  81. ChatTypeInfo["CHANNEL1"] = { sticky = 1, flashTab = false, flashTabOnGeneral = false };
  82. ChatTypeInfo["CHANNEL2"] = { sticky = 1, flashTab = false, flashTabOnGeneral = false };
  83. ChatTypeInfo["CHANNEL3"] = { sticky = 1, flashTab = false, flashTabOnGeneral = false };
  84. ChatTypeInfo["CHANNEL4"] = { sticky = 1, flashTab = false, flashTabOnGeneral = false };
  85. ChatTypeInfo["CHANNEL5"] = { sticky = 1, flashTab = false, flashTabOnGeneral = false };
  86. ChatTypeInfo["CHANNEL6"] = { sticky = 1, flashTab = false, flashTabOnGeneral = false };
  87. ChatTypeInfo["CHANNEL7"] = { sticky = 1, flashTab = false, flashTabOnGeneral = false };
  88. ChatTypeInfo["CHANNEL8"] = { sticky = 1, flashTab = false, flashTabOnGeneral = false };
  89. ChatTypeInfo["CHANNEL9"] = { sticky = 1, flashTab = false, flashTabOnGeneral = false };
  90. ChatTypeInfo["CHANNEL10"] = { sticky = 1, flashTab = false, flashTabOnGeneral = false };
  91. ChatTypeInfo["CHANNEL11"] = { sticky = 1, flashTab = false, flashTabOnGeneral = false };
  92. ChatTypeInfo["CHANNEL12"] = { sticky = 1, flashTab = false, flashTabOnGeneral = false };
  93. ChatTypeInfo["CHANNEL13"] = { sticky = 1, flashTab = false, flashTabOnGeneral = false };
  94. ChatTypeInfo["CHANNEL14"] = { sticky = 1, flashTab = false, flashTabOnGeneral = false };
  95. ChatTypeInfo["CHANNEL15"] = { sticky = 1, flashTab = false, flashTabOnGeneral = false };
  96. ChatTypeInfo["CHANNEL16"] = { sticky = 1, flashTab = false, flashTabOnGeneral = false };
  97. ChatTypeInfo["CHANNEL17"] = { sticky = 1, flashTab = false, flashTabOnGeneral = false };
  98. ChatTypeInfo["CHANNEL18"] = { sticky = 1, flashTab = false, flashTabOnGeneral = false };
  99. ChatTypeInfo["CHANNEL19"] = { sticky = 1, flashTab = false, flashTabOnGeneral = false };
  100. ChatTypeInfo["CHANNEL20"] = { sticky = 1, flashTab = false, flashTabOnGeneral = false };
  101. ChatTypeInfo["ACHIEVEMENT"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  102. ChatTypeInfo["GUILD_ACHIEVEMENT"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  103. ChatTypeInfo["PARTY_LEADER"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  104. ChatTypeInfo["BN_WHISPER"] = { sticky = 1, flashTab = true, flashTabOnGeneral = true };
  105. ChatTypeInfo["BN_WHISPER_INFORM"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  106. ChatTypeInfo["BN_ALERT"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  107. ChatTypeInfo["BN_BROADCAST"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  108. ChatTypeInfo["BN_BROADCAST_INFORM"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  109. ChatTypeInfo["BN_INLINE_TOAST_ALERT"] = { sticky = 0, flashTab = true, flashTabOnGeneral = false };
  110. ChatTypeInfo["BN_INLINE_TOAST_BROADCAST"] = { sticky = 0, flashTab = true, flashTabOnGeneral = false };
  111. ChatTypeInfo["BN_INLINE_TOAST_BROADCAST_INFORM"] = { sticky = 0, flashTab = true, flashTabOnGeneral = false };
  112. ChatTypeInfo["BN_WHISPER_PLAYER_OFFLINE"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  113. ChatTypeInfo["PET_BATTLE_COMBAT_LOG"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  114. ChatTypeInfo["PET_BATTLE_INFO"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  115. ChatTypeInfo["GUILD_ITEM_LOOTED"] = ChatTypeInfo["GUILD_ACHIEVEMENT"];
  116. ChatTypeInfo["COMMUNITIES_CHANNEL"] = { sticky = 0, flashTab = false, flashTabOnGeneral = false };
  117. --NEW_CHAT_TYPE -Add the info here.
  118. ChatTypeGroup = {};
  119. ChatTypeGroup["SYSTEM"] = {
  120. "CHAT_MSG_SYSTEM",
  121. "TIME_PLAYED_MSG",
  122. "PLAYER_LEVEL_UP",
  123. "UNIT_LEVEL",
  124. "CHARACTER_POINTS_CHANGED",
  125. "CHAT_MSG_BN_WHISPER_PLAYER_OFFLINE",
  126. "QUEST_TURNED_IN",
  127. };
  128. ChatTypeGroup["SAY"] = {
  129. "CHAT_MSG_SAY",
  130. };
  131. ChatTypeGroup["EMOTE"] = {
  132. "CHAT_MSG_EMOTE",
  133. "CHAT_MSG_TEXT_EMOTE",
  134. };
  135. ChatTypeGroup["YELL"] = {
  136. "CHAT_MSG_YELL",
  137. };
  138. ChatTypeGroup["WHISPER"] = {
  139. "CHAT_MSG_WHISPER",
  140. "CHAT_MSG_WHISPER_INFORM",
  141. "CHAT_MSG_AFK",
  142. "CHAT_MSG_DND",
  143. };
  144. ChatTypeGroup["PARTY"] = {
  145. "CHAT_MSG_PARTY",
  146. "CHAT_MSG_MONSTER_PARTY",
  147. };
  148. ChatTypeGroup["PARTY_LEADER"] = {
  149. "CHAT_MSG_PARTY_LEADER",
  150. };
  151. ChatTypeGroup["RAID"] = {
  152. "CHAT_MSG_RAID",
  153. };
  154. ChatTypeGroup["RAID_LEADER"] = {
  155. "CHAT_MSG_RAID_LEADER",
  156. };
  157. ChatTypeGroup["RAID_WARNING"] = {
  158. "CHAT_MSG_RAID_WARNING",
  159. };
  160. ChatTypeGroup["INSTANCE_CHAT"] = {
  161. "CHAT_MSG_INSTANCE_CHAT",
  162. };
  163. ChatTypeGroup["INSTANCE_CHAT_LEADER"] = {
  164. "CHAT_MSG_INSTANCE_CHAT_LEADER",
  165. };
  166. ChatTypeGroup["GUILD"] = {
  167. "CHAT_MSG_GUILD",
  168. "GUILD_MOTD",
  169. };
  170. ChatTypeGroup["OFFICER"] = {
  171. "CHAT_MSG_OFFICER",
  172. };
  173. ChatTypeGroup["MONSTER_SAY"] = {
  174. "CHAT_MSG_MONSTER_SAY",
  175. };
  176. ChatTypeGroup["MONSTER_YELL"] = {
  177. "CHAT_MSG_MONSTER_YELL",
  178. };
  179. ChatTypeGroup["MONSTER_EMOTE"] = {
  180. "CHAT_MSG_MONSTER_EMOTE",
  181. };
  182. ChatTypeGroup["MONSTER_WHISPER"] = {
  183. "CHAT_MSG_MONSTER_WHISPER",
  184. };
  185. ChatTypeGroup["MONSTER_BOSS_EMOTE"] = {
  186. "CHAT_MSG_RAID_BOSS_EMOTE",
  187. };
  188. ChatTypeGroup["MONSTER_BOSS_WHISPER"] = {
  189. "CHAT_MSG_RAID_BOSS_WHISPER",
  190. };
  191. ChatTypeGroup["ERRORS"] = {
  192. "CHAT_MSG_RESTRICTED",
  193. "CHAT_MSG_FILTERED",
  194. };
  195. ChatTypeGroup["AFK"] = {
  196. "CHAT_MSG_AFK",
  197. };
  198. ChatTypeGroup["DND"] = {
  199. "CHAT_MSG_DND",
  200. };
  201. ChatTypeGroup["IGNORED"] = {
  202. "CHAT_MSG_IGNORED",
  203. };
  204. ChatTypeGroup["BG_HORDE"] = {
  205. "CHAT_MSG_BG_SYSTEM_HORDE",
  206. };
  207. ChatTypeGroup["BG_ALLIANCE"] = {
  208. "CHAT_MSG_BG_SYSTEM_ALLIANCE",
  209. };
  210. ChatTypeGroup["BG_NEUTRAL"] = {
  211. "CHAT_MSG_BG_SYSTEM_NEUTRAL",
  212. };
  213. ChatTypeGroup["COMBAT_XP_GAIN"] = {
  214. "CHAT_MSG_COMBAT_XP_GAIN";
  215. }
  216. ChatTypeGroup["COMBAT_HONOR_GAIN"] = {
  217. "CHAT_MSG_COMBAT_HONOR_GAIN";
  218. }
  219. ChatTypeGroup["COMBAT_FACTION_CHANGE"] = {
  220. "CHAT_MSG_COMBAT_FACTION_CHANGE";
  221. };
  222. ChatTypeGroup["SKILL"] = {
  223. "CHAT_MSG_SKILL",
  224. };
  225. ChatTypeGroup["LOOT"] = {
  226. "CHAT_MSG_LOOT",
  227. };
  228. ChatTypeGroup["CURRENCY"] = {
  229. "CHAT_MSG_CURRENCY",
  230. };
  231. ChatTypeGroup["MONEY"] = {
  232. "CHAT_MSG_MONEY",
  233. };
  234. ChatTypeGroup["OPENING"] = {
  235. "CHAT_MSG_OPENING";
  236. };
  237. ChatTypeGroup["TRADESKILLS"] = {
  238. "CHAT_MSG_TRADESKILLS";
  239. };
  240. ChatTypeGroup["PET_INFO"] = {
  241. "CHAT_MSG_PET_INFO";
  242. };
  243. ChatTypeGroup["COMBAT_MISC_INFO"] = {
  244. "CHAT_MSG_COMBAT_MISC_INFO";
  245. };
  246. ChatTypeGroup["ACHIEVEMENT"] = {
  247. "CHAT_MSG_ACHIEVEMENT";
  248. };
  249. ChatTypeGroup["GUILD_ACHIEVEMENT"] = {
  250. "CHAT_MSG_GUILD_ACHIEVEMENT",
  251. "CHAT_MSG_GUILD_ITEM_LOOTED",
  252. };
  253. ChatTypeGroup["CHANNEL"] = {
  254. "CHAT_MSG_CHANNEL_JOIN",
  255. "CHAT_MSG_CHANNEL_LEAVE",
  256. "CHAT_MSG_CHANNEL_NOTICE",
  257. "CHAT_MSG_CHANNEL_NOTICE_USER",
  258. "CHAT_MSG_CHANNEL_LIST",
  259. };
  260. ChatTypeGroup["COMMUNITIES_CHANNEL"] = {
  261. "CHAT_MSG_COMMUNITIES_CHANNEL",
  262. }
  263. ChatTypeGroup["TARGETICONS"] = {
  264. "CHAT_MSG_TARGETICONS"
  265. };
  266. ChatTypeGroup["BN_WHISPER"] = {
  267. "CHAT_MSG_BN_WHISPER",
  268. "CHAT_MSG_BN_WHISPER_INFORM",
  269. };
  270. ChatTypeGroup["BN_INLINE_TOAST_ALERT"] = {
  271. "CHAT_MSG_BN_INLINE_TOAST_ALERT",
  272. "CHAT_MSG_BN_INLINE_TOAST_BROADCAST",
  273. "CHAT_MSG_BN_INLINE_TOAST_BROADCAST_INFORM",
  274. };
  275. ChatTypeGroup["PET_BATTLE_COMBAT_LOG"] = {
  276. "CHAT_MSG_PET_BATTLE_COMBAT_LOG",
  277. };
  278. ChatTypeGroup["PET_BATTLE_INFO"] = {
  279. "CHAT_MSG_PET_BATTLE_INFO",
  280. };
  281. --NEW_CHAT_TYPE - Add the chat type above.
  282. ChatTypeGroupInverted = {};
  283. for group, values in pairs(ChatTypeGroup) do
  284. for _, value in pairs(values) do
  285. ChatTypeGroupInverted[value] = group;
  286. end
  287. end
  288. CHAT_CATEGORY_LIST = {
  289. PARTY = { "PARTY_LEADER", "PARTY_GUIDE", "MONSTER_PARTY" },
  290. RAID = { "RAID_LEADER", "RAID_WARNING" },
  291. GUILD = { "GUILD_ACHIEVEMENT", "GUILD_ITEM_LOOTED" },
  292. WHISPER = { "WHISPER_INFORM", "AFK", "DND" },
  293. CHANNEL = { "CHANNEL_JOIN", "CHANNEL_LEAVE", "CHANNEL_NOTICE", "CHANNEL_USER" },
  294. INSTANCE_CHAT = { "INSTANCE_CHAT_LEADER" },
  295. BN_WHISPER = { "BN_WHISPER_INFORM" },
  296. };
  297. CHAT_INVERTED_CATEGORY_LIST = {};
  298. for category, sublist in pairs(CHAT_CATEGORY_LIST) do
  299. for _, item in pairs(sublist) do
  300. CHAT_INVERTED_CATEGORY_LIST[item] = category;
  301. end
  302. end
  303. function Chat_GetChatFrame(chatFrameIndex)
  304. return _G["ChatFrame"..chatFrameIndex];
  305. end
  306. function Chat_GetChatCategory(chatType)
  307. return CHAT_INVERTED_CATEGORY_LIST[chatType] or chatType;
  308. end
  309. function Chat_GetChannelColor(chatInfo)
  310. return chatInfo.r, chatInfo.g, chatInfo.b;
  311. end
  312. function Chat_GetCommunitiesChannelName(clubId, streamId)
  313. return ("Community:%s:%s"):format(tostring(clubId), tostring(streamId));
  314. end
  315. local function Chat_GetCommunitiesChannel(clubId, streamId)
  316. local communitiesChannelName = Chat_GetCommunitiesChannelName(clubId, streamId);
  317. for i = 1, MAX_WOW_CHAT_CHANNELS do
  318. local channelID, channelName = GetChannelName(i);
  319. if channelName and channelName == communitiesChannelName then
  320. return "CHANNEL"..i;
  321. end
  322. end
  323. return nil;
  324. end
  325. function Chat_GetCommunitiesChannelColor(clubId, streamId)
  326. local channel = Chat_GetCommunitiesChannel(clubId, streamId);
  327. if channel then
  328. local chatInfo = ChatTypeInfo[channel];
  329. if chatInfo then
  330. return Chat_GetChannelColor(chatInfo);
  331. end
  332. end
  333. local clubInfo = C_Club.GetClubInfo(clubId);
  334. if clubInfo then
  335. if clubInfo.clubType == Enum.ClubType.Guild then
  336. local streamInfo = C_Club.GetStreamInfo(clubId, streamId);
  337. local chatInfoType = (streamInfo and streamInfo.streamType == Enum.ClubStreamType.Officer) and "OFFICER" or "GUILD";
  338. return Chat_GetChannelColor(ChatTypeInfo[chatInfoType]);
  339. elseif clubInfo.clubType == Enum.ClubType.BattleNet then
  340. return BATTLENET_FONT_COLOR:GetRGB();
  341. end
  342. end
  343. return DEFAULT_CHAT_CHANNEL_COLOR:GetRGB();
  344. end
  345. -- list of text emotes that we want to show on the Emote submenu (these have anims)
  346. EmoteList = {
  347. "WAVE",
  348. "BOW",
  349. "DANCE",
  350. "APPLAUD",
  351. "BEG",
  352. "CHICKEN",
  353. "CRY",
  354. "EAT",
  355. "FLEX",
  356. "KISS",
  357. "LAUGH",
  358. "POINT",
  359. "ROAR",
  360. "RUDE",
  361. "SALUTE",
  362. "SHY",
  363. "TALK",
  364. "STAND",
  365. "SIT",
  366. "SLEEP",
  367. "KNEEL",
  368. };
  369. -- list of text emotes that we want to show on the Speech submenu (these have sounds)
  370. TextEmoteSpeechList = {
  371. "HELPME",
  372. "INCOMING",
  373. "CHARGE",
  374. "FLEE",
  375. "ATTACKMYTARGET",
  376. "OOM",
  377. "FOLLOW",
  378. "WAIT",
  379. "HEALME",
  380. "CHEER",
  381. "OPENFIRE",
  382. "RASP",
  383. "HELLO",
  384. "BYE",
  385. "NOD",
  386. "NO",
  387. "THANK",
  388. "WELCOME",
  389. "CONGRATULATE",
  390. "FLIRT",
  391. "JOKE",
  392. "TRAIN",
  393. };
  394. -- These are text emote tokens - add new ones at the bottom of the list!
  395. EMOTE1_TOKEN = "AGREE";
  396. EMOTE2_TOKEN = "AMAZE";
  397. EMOTE3_TOKEN = "ANGRY";
  398. EMOTE4_TOKEN = "APOLOGIZE";
  399. EMOTE5_TOKEN = "APPLAUD";
  400. EMOTE6_TOKEN = "BASHFUL";
  401. EMOTE7_TOKEN = "BECKON";
  402. EMOTE8_TOKEN = "BEG";
  403. EMOTE9_TOKEN = "BITE";
  404. EMOTE10_TOKEN = "BLEED";
  405. EMOTE11_TOKEN = "BLINK";
  406. EMOTE12_TOKEN = "BLUSH";
  407. EMOTE13_TOKEN = "BONK";
  408. EMOTE14_TOKEN = "BORED";
  409. EMOTE15_TOKEN = "BOUNCE";
  410. EMOTE16_TOKEN = "BRB";
  411. EMOTE17_TOKEN = "BOW";
  412. EMOTE18_TOKEN = "BURP";
  413. EMOTE19_TOKEN = "BYE";
  414. EMOTE20_TOKEN = "CACKLE";
  415. EMOTE21_TOKEN = "CHEER";
  416. EMOTE22_TOKEN = "CHICKEN";
  417. EMOTE23_TOKEN = "CHUCKLE";
  418. EMOTE24_TOKEN = "CLAP";
  419. EMOTE25_TOKEN = "CONFUSED";
  420. EMOTE26_TOKEN = "CONGRATULATE";
  421. EMOTE27_TOKEN = "UNUSED";
  422. EMOTE28_TOKEN = "COUGH";
  423. EMOTE29_TOKEN = "COWER";
  424. EMOTE30_TOKEN = "CRACK";
  425. EMOTE31_TOKEN = "CRINGE";
  426. EMOTE32_TOKEN = "CRY";
  427. EMOTE33_TOKEN = "CURIOUS";
  428. EMOTE34_TOKEN = "CURTSEY";
  429. EMOTE35_TOKEN = "DANCE";
  430. EMOTE36_TOKEN = "DRINK";
  431. EMOTE37_TOKEN = "DROOL";
  432. EMOTE38_TOKEN = "EAT";
  433. EMOTE39_TOKEN = "EYE";
  434. EMOTE40_TOKEN = "FART";
  435. EMOTE41_TOKEN = "FIDGET";
  436. EMOTE42_TOKEN = "FLEX";
  437. EMOTE43_TOKEN = "FROWN";
  438. EMOTE44_TOKEN = "GASP";
  439. EMOTE45_TOKEN = "GAZE";
  440. EMOTE46_TOKEN = "GIGGLE";
  441. EMOTE47_TOKEN = "GLARE";
  442. EMOTE48_TOKEN = "GLOAT";
  443. EMOTE49_TOKEN = "GREET";
  444. EMOTE50_TOKEN = "GRIN";
  445. EMOTE51_TOKEN = "GROAN";
  446. EMOTE52_TOKEN = "GROVEL";
  447. EMOTE53_TOKEN = "GUFFAW";
  448. EMOTE54_TOKEN = "HAIL";
  449. EMOTE55_TOKEN = "HAPPY";
  450. EMOTE56_TOKEN = "HELLO";
  451. EMOTE57_TOKEN = "HUG";
  452. EMOTE58_TOKEN = "HUNGRY";
  453. EMOTE59_TOKEN = "KISS";
  454. EMOTE60_TOKEN = "KNEEL";
  455. EMOTE61_TOKEN = "LAUGH";
  456. EMOTE62_TOKEN = "LAYDOWN";
  457. EMOTE63_TOKEN = "MASSAGE";
  458. EMOTE64_TOKEN = "MOAN";
  459. EMOTE65_TOKEN = "MOON";
  460. EMOTE66_TOKEN = "MOURN";
  461. EMOTE67_TOKEN = "NO";
  462. EMOTE68_TOKEN = "NOD";
  463. EMOTE69_TOKEN = "NOSEPICK";
  464. EMOTE70_TOKEN = "PANIC";
  465. EMOTE71_TOKEN = "PEER";
  466. EMOTE72_TOKEN = "PLEAD";
  467. EMOTE73_TOKEN = "POINT";
  468. EMOTE74_TOKEN = "POKE";
  469. EMOTE75_TOKEN = "PRAY";
  470. EMOTE76_TOKEN = "ROAR";
  471. EMOTE77_TOKEN = "ROFL";
  472. EMOTE78_TOKEN = "RUDE";
  473. EMOTE79_TOKEN = "SALUTE";
  474. EMOTE80_TOKEN = "SCRATCH";
  475. EMOTE81_TOKEN = "SEXY";
  476. EMOTE82_TOKEN = "SHAKE";
  477. EMOTE83_TOKEN = "SHOUT";
  478. EMOTE84_TOKEN = "SHRUG";
  479. EMOTE85_TOKEN = "SHY";
  480. EMOTE86_TOKEN = "SIGH";
  481. EMOTE87_TOKEN = "SIT";
  482. EMOTE88_TOKEN = "SLEEP";
  483. EMOTE89_TOKEN = "SNARL";
  484. EMOTE90_TOKEN = "SPIT";
  485. EMOTE91_TOKEN = "STARE";
  486. EMOTE92_TOKEN = "SURPRISED";
  487. EMOTE93_TOKEN = "SURRENDER";
  488. EMOTE94_TOKEN = "TALK";
  489. EMOTE95_TOKEN = "TALKEX";
  490. EMOTE96_TOKEN = "TALKQ";
  491. EMOTE97_TOKEN = "TAP";
  492. EMOTE98_TOKEN = "THANK";
  493. EMOTE99_TOKEN = "THREATEN";
  494. EMOTE100_TOKEN = "TIRED";
  495. EMOTE101_TOKEN = "VICTORY";
  496. EMOTE102_TOKEN = "WAVE";
  497. EMOTE103_TOKEN = "WELCOME";
  498. EMOTE104_TOKEN = "WHINE";
  499. EMOTE105_TOKEN = "WHISTLE";
  500. EMOTE106_TOKEN = "WORK";
  501. EMOTE107_TOKEN = "YAWN";
  502. EMOTE108_TOKEN = "BOGGLE";
  503. EMOTE109_TOKEN = "CALM";
  504. EMOTE110_TOKEN = "COLD";
  505. EMOTE111_TOKEN = "COMFORT";
  506. EMOTE112_TOKEN = "CUDDLE";
  507. EMOTE113_TOKEN = "DUCK";
  508. EMOTE114_TOKEN = "INSULT";
  509. EMOTE115_TOKEN = "INTRODUCE";
  510. EMOTE116_TOKEN = "JK";
  511. EMOTE117_TOKEN = "LICK";
  512. EMOTE118_TOKEN = "LISTEN";
  513. EMOTE119_TOKEN = "LOST";
  514. EMOTE120_TOKEN = "MOCK";
  515. EMOTE121_TOKEN = "PONDER";
  516. EMOTE122_TOKEN = "POUNCE";
  517. EMOTE123_TOKEN = "PRAISE";
  518. EMOTE124_TOKEN = "PURR";
  519. EMOTE125_TOKEN = "PUZZLE";
  520. EMOTE126_TOKEN = "RAISE";
  521. EMOTE127_TOKEN = "READY";
  522. EMOTE128_TOKEN = "SHIMMY";
  523. EMOTE129_TOKEN = "SHIVER";
  524. EMOTE130_TOKEN = "SHOO";
  525. EMOTE131_TOKEN = "SLAP";
  526. EMOTE132_TOKEN = "SMIRK";
  527. EMOTE133_TOKEN = "SNIFF";
  528. EMOTE134_TOKEN = "SNUB";
  529. EMOTE135_TOKEN = "SOOTHE";
  530. EMOTE136_TOKEN = "STINK";
  531. EMOTE137_TOKEN = "TAUNT";
  532. EMOTE138_TOKEN = "TEASE";
  533. EMOTE139_TOKEN = "THIRSTY";
  534. EMOTE140_TOKEN = "VETO";
  535. EMOTE141_TOKEN = "SNICKER";
  536. EMOTE142_TOKEN = "TICKLE";
  537. EMOTE143_TOKEN = "STAND";
  538. EMOTE144_TOKEN = "VIOLIN";
  539. EMOTE145_TOKEN = "SMILE";
  540. EMOTE146_TOKEN = "RASP";
  541. EMOTE147_TOKEN = "GROWL";
  542. EMOTE148_TOKEN = "BARK";
  543. EMOTE149_TOKEN = "PITY";
  544. EMOTE150_TOKEN = "SCARED";
  545. EMOTE151_TOKEN = "FLOP";
  546. EMOTE152_TOKEN = "LOVE";
  547. EMOTE153_TOKEN = "MOO";
  548. EMOTE154_TOKEN = "COMMEND";
  549. EMOTE155_TOKEN = "TRAIN";
  550. EMOTE156_TOKEN = "HELPME";
  551. EMOTE157_TOKEN = "INCOMING";
  552. EMOTE158_TOKEN = "OPENFIRE";
  553. EMOTE159_TOKEN = "CHARGE";
  554. EMOTE160_TOKEN = "FLEE";
  555. EMOTE161_TOKEN = "ATTACKMYTARGET";
  556. EMOTE162_TOKEN = "OOM";
  557. EMOTE163_TOKEN = "FOLLOW";
  558. EMOTE164_TOKEN = "WAIT";
  559. EMOTE165_TOKEN = "FLIRT";
  560. EMOTE166_TOKEN = "HEALME";
  561. EMOTE167_TOKEN = "JOKE";
  562. EMOTE168_TOKEN = "WINK";
  563. EMOTE169_TOKEN = "PAT";
  564. EMOTE170_TOKEN = "GOLFCLAP";
  565. EMOTE171_TOKEN = "MOUNTSPECIAL";
  566. EMOTE304_TOKEN = "INCOMING";
  567. EMOTE306_TOKEN = "FLEE";
  568. EMOTE368_TOKEN = "BLAME"
  569. EMOTE369_TOKEN = "BLANK"
  570. EMOTE370_TOKEN = "BRANDISH"
  571. EMOTE371_TOKEN = "BREATH"
  572. EMOTE372_TOKEN = "DISAGREE"
  573. EMOTE373_TOKEN = "DOUBT"
  574. EMOTE374_TOKEN = "EMBARRASS"
  575. EMOTE375_TOKEN = "ENCOURAGE"
  576. EMOTE376_TOKEN = "ENEMY"
  577. EMOTE377_TOKEN = "EYEBROW"
  578. EMOTE380_TOKEN = "HIGHFIVE"
  579. EMOTE381_TOKEN = "ABSENT"
  580. EMOTE382_TOKEN = "ARM"
  581. EMOTE383_TOKEN = "AWE"
  582. EMOTE384_TOKEN = "BACKPACK"
  583. EMOTE385_TOKEN = "BADFEELING"
  584. EMOTE386_TOKEN = "CHALLENGE"
  585. EMOTE387_TOKEN = "CHUG"
  586. EMOTE389_TOKEN = "DING"
  587. EMOTE390_TOKEN = "FACEPALM"
  588. EMOTE391_TOKEN = "FAINT"
  589. EMOTE392_TOKEN = "GO"
  590. EMOTE393_TOKEN = "GOING"
  591. EMOTE394_TOKEN = "GLOWER"
  592. EMOTE395_TOKEN = "HEADACHE"
  593. EMOTE396_TOKEN = "HICCUP"
  594. EMOTE398_TOKEN = "HISS"
  595. EMOTE399_TOKEN = "HOLDHAND"
  596. EMOTE401_TOKEN = "HURRY"
  597. EMOTE402_TOKEN = "IDEA"
  598. EMOTE403_TOKEN = "JEALOUS"
  599. EMOTE404_TOKEN = "LUCK"
  600. EMOTE405_TOKEN = "MAP"
  601. EMOTE406_TOKEN = "MERCY"
  602. EMOTE407_TOKEN = "MUTTER"
  603. EMOTE408_TOKEN = "NERVOUS"
  604. EMOTE409_TOKEN = "OFFER"
  605. EMOTE410_TOKEN = "PET"
  606. EMOTE411_TOKEN = "PINCH"
  607. EMOTE413_TOKEN = "PROUD"
  608. EMOTE414_TOKEN = "PROMISE"
  609. EMOTE415_TOKEN = "PULSE"
  610. EMOTE416_TOKEN = "PUNCH"
  611. EMOTE417_TOKEN = "POUT"
  612. EMOTE418_TOKEN = "REGRET"
  613. EMOTE420_TOKEN = "REVENGE"
  614. EMOTE421_TOKEN = "ROLLEYES"
  615. EMOTE422_TOKEN = "RUFFLE"
  616. EMOTE423_TOKEN = "SAD"
  617. EMOTE424_TOKEN = "SCOFF"
  618. EMOTE425_TOKEN = "SCOLD"
  619. EMOTE426_TOKEN = "SCOWL"
  620. EMOTE427_TOKEN = "SEARCH"
  621. EMOTE428_TOKEN = "SHAKEFIST"
  622. EMOTE429_TOKEN = "SHIFTY"
  623. EMOTE430_TOKEN = "SHUDDER"
  624. EMOTE431_TOKEN = "SIGNAL"
  625. EMOTE432_TOKEN = "SILENCE"
  626. EMOTE433_TOKEN = "SING"
  627. EMOTE434_TOKEN = "SMACK"
  628. EMOTE435_TOKEN = "SNEAK"
  629. EMOTE436_TOKEN = "SNEEZE"
  630. EMOTE437_TOKEN = "SNORT"
  631. EMOTE438_TOKEN = "SQUEAL"
  632. EMOTE440_TOKEN = "SUSPICIOUS"
  633. EMOTE441_TOKEN = "THINK"
  634. EMOTE442_TOKEN = "TRUCE"
  635. EMOTE443_TOKEN = "TWIDDLE"
  636. EMOTE444_TOKEN = "WARN"
  637. EMOTE445_TOKEN = "SNAP"
  638. EMOTE446_TOKEN = "CHARM"
  639. EMOTE447_TOKEN = "COVEREARS"
  640. EMOTE448_TOKEN = "CROSSARMS"
  641. EMOTE449_TOKEN = "LOOK"
  642. EMOTE450_TOKEN = "OBJECT"
  643. EMOTE451_TOKEN = "SWEAT"
  644. EMOTE452_TOKEN = "YW"
  645. EMOTE453_TOKEN = "READ"
  646. EMOTE454_TOKEN = "FORTHEALLIANCE"
  647. EMOTE455_TOKEN = "FORTHEHORDE"
  648. EMOTE517_TOKEN = "WHOA"
  649. EMOTE518_TOKEN = "OOPS"
  650. EMOTE521_TOKEN = "MEOW"
  651. EMOTE522_TOKEN = "BOOP"
  652. -- NOTE: The indices used to iterate the tokens may not be contiguous, keep that in mind when updating this value.
  653. local MAXEMOTEINDEX = 522;
  654. ICON_LIST = {
  655. "|TInterface\\TargetingFrame\\UI-RaidTargetingIcon_1:",
  656. "|TInterface\\TargetingFrame\\UI-RaidTargetingIcon_2:",
  657. "|TInterface\\TargetingFrame\\UI-RaidTargetingIcon_3:",
  658. "|TInterface\\TargetingFrame\\UI-RaidTargetingIcon_4:",
  659. "|TInterface\\TargetingFrame\\UI-RaidTargetingIcon_5:",
  660. "|TInterface\\TargetingFrame\\UI-RaidTargetingIcon_6:",
  661. "|TInterface\\TargetingFrame\\UI-RaidTargetingIcon_7:",
  662. "|TInterface\\TargetingFrame\\UI-RaidTargetingIcon_8:",
  663. }
  664. --Links tags from Global Strings to indicies for entries in ICON_LIST. This way addons can easily replace icons
  665. ICON_TAG_LIST =
  666. {
  667. [strlower(ICON_TAG_RAID_TARGET_STAR1)] = 1,
  668. [strlower(ICON_TAG_RAID_TARGET_STAR2)] = 1,
  669. [strlower(ICON_TAG_RAID_TARGET_STAR3)] = 1,
  670. [strlower(ICON_TAG_RAID_TARGET_CIRCLE1)] = 2,
  671. [strlower(ICON_TAG_RAID_TARGET_CIRCLE2)] = 2,
  672. [strlower(ICON_TAG_RAID_TARGET_CIRCLE3)] = 2,
  673. [strlower(ICON_TAG_RAID_TARGET_DIAMOND1)] = 3,
  674. [strlower(ICON_TAG_RAID_TARGET_DIAMOND2)] = 3,
  675. [strlower(ICON_TAG_RAID_TARGET_DIAMOND3)] = 3,
  676. [strlower(ICON_TAG_RAID_TARGET_TRIANGLE1)] = 4,
  677. [strlower(ICON_TAG_RAID_TARGET_TRIANGLE2)] = 4,
  678. [strlower(ICON_TAG_RAID_TARGET_TRIANGLE3)] = 4,
  679. [strlower(ICON_TAG_RAID_TARGET_MOON1)] = 5,
  680. [strlower(ICON_TAG_RAID_TARGET_MOON2)] = 5,
  681. [strlower(ICON_TAG_RAID_TARGET_MOON3)] = 5,
  682. [strlower(ICON_TAG_RAID_TARGET_SQUARE1)] = 6,
  683. [strlower(ICON_TAG_RAID_TARGET_SQUARE2)] = 6,
  684. [strlower(ICON_TAG_RAID_TARGET_SQUARE3)] = 6,
  685. [strlower(ICON_TAG_RAID_TARGET_CROSS1)] = 7,
  686. [strlower(ICON_TAG_RAID_TARGET_CROSS2)] = 7,
  687. [strlower(ICON_TAG_RAID_TARGET_CROSS3)] = 7,
  688. [strlower(ICON_TAG_RAID_TARGET_SKULL1)] = 8,
  689. [strlower(ICON_TAG_RAID_TARGET_SKULL2)] = 8,
  690. [strlower(ICON_TAG_RAID_TARGET_SKULL3)] = 8,
  691. [strlower(RAID_TARGET_1)] = 1,
  692. [strlower(RAID_TARGET_2)] = 2,
  693. [strlower(RAID_TARGET_3)] = 3,
  694. [strlower(RAID_TARGET_4)] = 4,
  695. [strlower(RAID_TARGET_5)] = 5,
  696. [strlower(RAID_TARGET_6)] = 6,
  697. [strlower(RAID_TARGET_7)] = 7,
  698. [strlower(RAID_TARGET_8)] = 8,
  699. }
  700. GROUP_TAG_LIST =
  701. {
  702. [strlower(GROUP1_CHAT_TAG1)] = 1,
  703. [strlower(GROUP1_CHAT_TAG2)] = 1,
  704. [strlower(GROUP2_CHAT_TAG1)] = 2,
  705. [strlower(GROUP2_CHAT_TAG2)] = 2,
  706. [strlower(GROUP3_CHAT_TAG1)] = 3,
  707. [strlower(GROUP3_CHAT_TAG2)] = 3,
  708. [strlower(GROUP4_CHAT_TAG1)] = 4,
  709. [strlower(GROUP4_CHAT_TAG2)] = 4,
  710. [strlower(GROUP5_CHAT_TAG1)] = 5,
  711. [strlower(GROUP5_CHAT_TAG2)] = 5,
  712. [strlower(GROUP6_CHAT_TAG1)] = 6,
  713. [strlower(GROUP6_CHAT_TAG2)] = 6,
  714. [strlower(GROUP7_CHAT_TAG1)] = 7,
  715. [strlower(GROUP7_CHAT_TAG2)] = 7,
  716. [strlower(GROUP8_CHAT_TAG1)] = 8,
  717. [strlower(GROUP8_CHAT_TAG2)] = 8,
  718. --Language independent:
  719. ["g1"] = 1;
  720. ["g2"] = 2;
  721. ["g3"] = 3;
  722. ["g4"] = 4;
  723. ["g5"] = 5;
  724. ["g6"] = 6;
  725. ["g7"] = 7;
  726. ["g8"] = 8;
  727. };
  728. GROUP_LANGUAGE_INDEPENDENT_STRINGS =
  729. {
  730. "g1",
  731. "g2",
  732. "g3",
  733. "g4",
  734. "g5",
  735. "g6",
  736. "g7",
  737. "g8",
  738. };
  739. local MAX_COMMUNITY_NAME_LENGTH = 12;
  740. local MAX_COMMUNITY_NAME_LENGTH_NO_CHANNEL = 24;
  741. function ChatFrame_TruncateToMaxLength(text, maxLength)
  742. local length = strlenutf8(text);
  743. if ( length > maxLength ) then
  744. return text:sub(1, maxLength - 2).."...";
  745. end
  746. return text;
  747. end
  748. function ChatFrame_ResolvePrefixedChannelName(communityChannel)
  749. local prefix, communityChannel = communityChannel:match("(%d+. )(.*)");
  750. return prefix..ChatFrame_ResolveChannelName(communityChannel);
  751. end
  752. function ChatFrame_GetCommunityAndStreamFromChannel(communityChannel)
  753. local clubId, streamId = communityChannel:match("(%d+)%:(%d+)");
  754. return tonumber(clubId), tonumber(streamId);
  755. end
  756. function ChatFrame_ResolveChannelName(communityChannel)
  757. local clubId, streamId = ChatFrame_GetCommunityAndStreamFromChannel(communityChannel);
  758. if not clubId or not streamId then
  759. return communityChannel;
  760. end
  761. return ChatFrame_GetCommunityAndStreamName(clubId, streamId);
  762. end
  763. function ChatFrame_GetCommunityAndStreamName(clubId, streamId)
  764. local streamInfo = C_Club.GetStreamInfo(clubId, streamId);
  765. if streamInfo and (streamInfo.streamType == Enum.ClubStreamType.Guild or streamInfo.streamType == Enum.ClubStreamType.Officer) then
  766. return streamInfo.name;
  767. end
  768. local streamName = streamInfo and ChatFrame_TruncateToMaxLength(streamInfo.name, MAX_COMMUNITY_NAME_LENGTH) or "";
  769. local clubInfo = C_Club.GetClubInfo(clubId);
  770. if streamInfo and streamInfo.streamType == Enum.ClubStreamType.General then
  771. local communityName = clubInfo and ChatFrame_TruncateToMaxLength(clubInfo.shortName or clubInfo.name, MAX_COMMUNITY_NAME_LENGTH_NO_CHANNEL) or "";
  772. return communityName;
  773. else
  774. local communityName = clubInfo and ChatFrame_TruncateToMaxLength(clubInfo.shortName or clubInfo.name, MAX_COMMUNITY_NAME_LENGTH) or "";
  775. return communityName.." - "..streamName;
  776. end
  777. end
  778. --
  779. -- CastSequence support
  780. --
  781. local CastSequenceManager;
  782. local CastSequenceTable = {};
  783. local CastSequenceFreeList = {};
  784. local function CreateCanonicalActions(entry, ...)
  785. entry.spells = {};
  786. entry.spellNames = {};
  787. entry.spellID = {};
  788. entry.items = {};
  789. local count = 0;
  790. for i=1, select("#", ...) do
  791. local action = strlower(strtrim((select(i, ...))));
  792. if ( action and action ~="" ) then
  793. count = count + 1;
  794. if ( GetItemInfo(action) or select(3, SecureCmdItemParse(action)) ) then
  795. local spellName, spellID = GetItemSpell(action);
  796. entry.items[count] = action;
  797. entry.spells[count] = strlower(spellName or "");
  798. entry.spellNames[count] = entry.spells[count];
  799. entry.spellID[count] = spellID;
  800. else
  801. entry.spells[count] = action;
  802. entry.spellNames[count] = gsub(action, "!*(.*)", "%1");
  803. entry.spellID[count] = select(7, GetSpellInfo(action));
  804. end
  805. end
  806. end
  807. end
  808. local function SetCastSequenceIndex(entry, index)
  809. entry.index = index;
  810. entry.pending = nil;
  811. end
  812. local function ResetCastSequence(sequence, entry)
  813. SetCastSequenceIndex(entry, 1);
  814. CastSequenceFreeList[sequence] = entry;
  815. CastSequenceTable[sequence] = nil;
  816. end
  817. local function SetNextCastSequence(sequence, entry)
  818. if ( entry.index == #entry.spells ) then
  819. ResetCastSequence(sequence, entry);
  820. else
  821. SetCastSequenceIndex(entry, entry.index + 1);
  822. end
  823. end
  824. local function CastSequenceManager_OnEvent(self, event, ...)
  825. -- Reset all sequences when the player dies
  826. if ( event == "PLAYER_DEAD" ) then
  827. for sequence, entry in pairs(CastSequenceTable) do
  828. ResetCastSequence(sequence, entry);
  829. end
  830. return;
  831. end
  832. -- Increment sequences for spells which succeed.
  833. if ( event == "UNIT_SPELLCAST_SENT" or
  834. event == "UNIT_SPELLCAST_SUCCEEDED" or
  835. event == "UNIT_SPELLCAST_INTERRUPTED" or
  836. event == "UNIT_SPELLCAST_FAILED" or
  837. event == "UNIT_SPELLCAST_FAILED_QUIET" ) then
  838. local unit, castID, spellID;
  839. if event == "UNIT_SPELLCAST_SENT" then
  840. local target;
  841. unit, target, castID, spellID = ...;
  842. else
  843. unit, castID, spellID = ...;
  844. end
  845. if ( unit == "player" or unit == "pet" ) then
  846. local overrideSpellID = FindSpellOverrideByID(spellID);
  847. local baseSpellID = FindBaseSpellByID(spellID);
  848. for sequence, entry in pairs(CastSequenceTable) do
  849. local entrySpellID = entry.spellID[entry.index];
  850. if ( entrySpellID == overrideSpellID or entrySpellID == baseSpellID ) then
  851. if ( event == "UNIT_SPELLCAST_SENT" ) then
  852. entry.pending = castID;
  853. elseif ( entry.pending == castID ) then
  854. entry.pending = nil;
  855. if ( event == "UNIT_SPELLCAST_SUCCEEDED" ) then
  856. SetNextCastSequence(sequence, entry);
  857. end
  858. end
  859. end
  860. end
  861. end
  862. return;
  863. end
  864. -- Handle reset events
  865. local reset = "";
  866. if ( event == "PLAYER_TARGET_CHANGED" ) then
  867. reset = "target";
  868. elseif ( event == "PLAYER_REGEN_ENABLED" ) then
  869. reset = "combat";
  870. end
  871. for sequence, entry in pairs(CastSequenceTable) do
  872. if ( strfind(entry.reset, reset, 1, true) ) then
  873. ResetCastSequence(sequence, entry);
  874. end
  875. end
  876. end
  877. local function CastSequenceManager_OnUpdate(self, elapsed)
  878. elapsed = self.elapsed + elapsed;
  879. if ( elapsed < 1 ) then
  880. self.elapsed = elapsed;
  881. return;
  882. end
  883. for sequence, entry in pairs(CastSequenceTable) do
  884. if ( entry.timeout ) then
  885. if ( elapsed >= entry.timeout ) then
  886. ResetCastSequence(sequence, entry);
  887. else
  888. entry.timeout = entry.timeout - elapsed;
  889. end
  890. end
  891. end
  892. self.elapsed = 0;
  893. end
  894. local function ExecuteCastSequence(sequence, target)
  895. if ( not CastSequenceManager ) then
  896. CastSequenceManager = CreateFrame("Frame");
  897. CastSequenceManager.elapsed = 0;
  898. CastSequenceManager:RegisterEvent("PLAYER_DEAD");
  899. CastSequenceManager:RegisterEvent("UNIT_SPELLCAST_SENT");
  900. CastSequenceManager:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED");
  901. CastSequenceManager:RegisterEvent("UNIT_SPELLCAST_INTERRUPTED");
  902. CastSequenceManager:RegisterEvent("UNIT_SPELLCAST_FAILED");
  903. CastSequenceManager:RegisterEvent("UNIT_SPELLCAST_FAILED_QUIET");
  904. CastSequenceManager:RegisterEvent("PLAYER_TARGET_CHANGED");
  905. CastSequenceManager:RegisterEvent("PLAYER_REGEN_ENABLED");
  906. CastSequenceManager:SetScript("OnEvent", CastSequenceManager_OnEvent);
  907. CastSequenceManager:SetScript("OnUpdate", CastSequenceManager_OnUpdate);
  908. end
  909. local entry = CastSequenceTable[sequence];
  910. if ( not entry ) then
  911. entry = CastSequenceFreeList[sequence];
  912. if ( not entry ) then
  913. local reset, spells = strmatch(sequence, "^reset=([^%s]+)%s*(.*)");
  914. if ( not reset ) then
  915. spells = sequence;
  916. end
  917. entry = {};
  918. CreateCanonicalActions(entry, strsplit(",", spells));
  919. entry.reset = strlower(reset or "");
  920. end
  921. CastSequenceTable[sequence] = entry;
  922. entry.index = 1;
  923. end
  924. -- Don't do anything if this entry is still pending
  925. if ( entry.pending ) then
  926. return;
  927. end
  928. -- See if modified click restarts the sequence
  929. if ( (IsShiftKeyDown() and strfind(entry.reset, "shift", 1, true)) or
  930. (IsControlKeyDown() and strfind(entry.reset, "ctrl", 1, true)) or
  931. (IsAltKeyDown() and strfind(entry.reset, "alt", 1, true)) ) then
  932. SetCastSequenceIndex(entry, 1);
  933. end
  934. -- Reset the timeout each time the sequence is used
  935. local timeout = strmatch(entry.reset, "(%d+)");
  936. if ( timeout ) then
  937. entry.timeout = CastSequenceManager.elapsed + tonumber(timeout);
  938. end
  939. -- Execute the sequence!
  940. local item, spell = entry.items[entry.index], entry.spells[entry.index];
  941. if ( item ) then
  942. local name, bag, slot = SecureCmdItemParse(item);
  943. if ( slot ) then
  944. local spellID;
  945. if ( name ) then
  946. local spellName;
  947. spellName, spellID = GetItemSpell(name);
  948. spell = strlower(spellName or "");
  949. else
  950. spell = "";
  951. end
  952. entry.spellNames[entry.index] = spell;
  953. entry.spellID[entry.index] = spellID;
  954. end
  955. if ( IsEquippableItem(name) and not IsEquippedItem(name) ) then
  956. EquipItemByName(name);
  957. else
  958. SecureCmdUseItem(name, bag, slot, target);
  959. end
  960. else
  961. CastSpellByName(spell, target);
  962. end
  963. end
  964. function QueryCastSequence(sequence)
  965. local index = 1;
  966. local item, spell;
  967. local entry = CastSequenceTable[sequence];
  968. if ( entry ) then
  969. if ( (IsShiftKeyDown() and strfind(entry.reset, "shift", 1, true)) or
  970. (IsControlKeyDown() and strfind(entry.reset, "ctrl", 1, true)) or
  971. (IsAltKeyDown() and strfind(entry.reset, "alt", 1, true)) ) then
  972. index = 1;
  973. else
  974. index = entry.index;
  975. end
  976. item, spell = entry.items[index], entry.spells[index];
  977. else
  978. entry = CastSequenceFreeList[sequence];
  979. if ( entry ) then
  980. item, spell = entry.items[index], entry.spells[index];
  981. else
  982. local reset, spells = strmatch(sequence, "^reset=([^%s]+)%s*(.*)");
  983. if ( not reset ) then
  984. spells = sequence;
  985. end
  986. local action = strlower(strtrim((strsplit(",", spells))));
  987. if ( select(3, SecureCmdItemParse(action)) or GetItemInfo(action) ) then
  988. item, spell = action, strlower(GetItemSpell(action) or "");
  989. else
  990. item, spell = nil, action;
  991. end
  992. end
  993. end
  994. if ( item ) then
  995. local name, bag, slot = SecureCmdItemParse(item);
  996. if ( slot ) then
  997. if ( name ) then
  998. spell = strlower(GetItemSpell(name) or "");
  999. else
  1000. spell = "";
  1001. end
  1002. end
  1003. end
  1004. return index, item, spell;
  1005. end
  1006. local CastRandomManager;
  1007. local CastRandomTable = {};
  1008. local function CastRandomManager_OnEvent(self, event, ...)
  1009. local unit, castID, spellID = ...;
  1010. if ( unit == "player" ) then
  1011. local name = strlower(GetSpellInfo(spellID));
  1012. local rank = strlower(GetSpellSubtext(spellID) or "");
  1013. local nameplus = name.."()";
  1014. local fullname = name.."("..rank..")";
  1015. for sequence, entry in pairs(CastRandomTable) do
  1016. if ( entry.pending and entry.value ) then
  1017. local entryName = strlower(entry.value);
  1018. if ( entryName == name or entryName == nameplus or entryName == fullname ) then
  1019. entry.pending = nil;
  1020. if ( event == "UNIT_SPELLCAST_SUCCEEDED" ) then
  1021. entry.value = nil;
  1022. end
  1023. end
  1024. end
  1025. end
  1026. end
  1027. end
  1028. local function ExecuteCastRandom(actions)
  1029. if ( not CastRandomManager ) then
  1030. CastRandomManager = CreateFrame("Frame");
  1031. CastRandomManager:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED");
  1032. CastRandomManager:RegisterEvent("UNIT_SPELLCAST_INTERRUPTED");
  1033. CastRandomManager:RegisterEvent("UNIT_SPELLCAST_FAILED");
  1034. CastRandomManager:RegisterEvent("UNIT_SPELLCAST_FAILED_QUIET");
  1035. CastRandomManager:SetScript("OnEvent", CastRandomManager_OnEvent);
  1036. end
  1037. local entry = CastRandomTable[actions];
  1038. if ( not entry ) then
  1039. entry = {};
  1040. CreateCanonicalActions(entry, strsplit(",", actions));
  1041. CastRandomTable[actions] = entry;
  1042. end
  1043. if ( not entry.value ) then
  1044. entry.value = entry.spellNames[random(#entry.spellNames)];
  1045. end
  1046. entry.pending = true;
  1047. return entry.value;
  1048. end
  1049. function GetRandomArgument(...)
  1050. return (select(random(select("#", ...)), ...));
  1051. end
  1052. -- Slash commands that are protected from tampering
  1053. local SecureCmdList = { };
  1054. function IsSecureCmd(command)
  1055. command = strupper(command);
  1056. -- first check the hash table
  1057. if ( hash_SecureCmdList[command] ) then
  1058. return true;
  1059. end
  1060. for index, value in pairs(SecureCmdList) do
  1061. local i = 1;
  1062. local cmdString = _G["SLASH_"..index..i];
  1063. while ( cmdString ) do
  1064. cmdString = strupper(cmdString);
  1065. if ( cmdString == command ) then
  1066. return true;
  1067. end
  1068. i = i + 1;
  1069. cmdString = _G["SLASH_"..index..i];
  1070. end
  1071. end
  1072. end
  1073. function SecureCmdItemParse(item)
  1074. if ( not item ) then
  1075. return nil, nil, nil;
  1076. end
  1077. local bag, slot = strmatch(item, "^(%d+)%s+(%d+)$");
  1078. if ( not bag ) then
  1079. slot = strmatch(item, "^(%d+)$");
  1080. end
  1081. if ( bag ) then
  1082. item = GetContainerItemLink(bag, slot);
  1083. elseif ( slot ) then
  1084. item = GetInventoryItemLink("player", slot);
  1085. end
  1086. return item, bag, slot;
  1087. end
  1088. function SecureCmdUseItem(name, bag, slot, target)
  1089. if ( bag ) then
  1090. UseContainerItem(bag, slot, target);
  1091. elseif ( slot ) then
  1092. UseInventoryItem(slot, target);
  1093. else
  1094. UseItemByName(name, target);
  1095. end
  1096. end
  1097. --These functions are terrible, but they support legacy slash commands.
  1098. function ValueToBoolean(valueToCheck, defaultValue, defaultReturn)
  1099. if ( type(valueToCheck) == "nil" ) then
  1100. return false;
  1101. elseif ( type(valueToCheck) == "boolean" ) then
  1102. return valueToCheck;
  1103. elseif ( type(valueToCheck) == "number" ) then
  1104. return valueToCheck ~= 0;
  1105. elseif ( type(valueToCheck) == "string" ) then
  1106. return StringToBoolean(valueToCheck, defaultReturn);
  1107. else
  1108. return defaultReturn;
  1109. end
  1110. end
  1111. function StringToBoolean(stringToCheck, defaultReturn)
  1112. stringToCheck = string.lower(stringToCheck);
  1113. local firstChar = string.sub(stringToCheck, 1, 1);
  1114. if ( firstChar == "0" or firstChar == "n" or firstChar == "f" or stringToCheck == "off" or stringToCheck == "disabled" ) then
  1115. return false;
  1116. elseif ( firstChar == "1" or firstChar == "2" or firstChar == "3" or firstChar == "4" or firstChar == "5" or
  1117. firstChar == "6" or firstChar == "7" or firstChar == "8" or firstChar == "9" or firstChar == "y" or
  1118. firstChar == "t" or stringToCheck == "on" or stringToCheck == "enabled" ) then
  1119. return true;
  1120. end
  1121. return defaultReturn;
  1122. end
  1123. SecureCmdList["STARTATTACK"] = function(msg)
  1124. local action, target = SecureCmdOptionParse(msg);
  1125. if ( action ) then
  1126. if ( not target or target == "target" ) then
  1127. target = action;
  1128. end
  1129. StartAttack(target);
  1130. end
  1131. end
  1132. SecureCmdList["STOPATTACK"] = function(msg)
  1133. if ( SecureCmdOptionParse(msg) ) then
  1134. StopAttack();
  1135. end
  1136. end
  1137. -- We want to prefer spells for /cast and items for /use but we can use either
  1138. SecureCmdList["CAST"] = function(msg)
  1139. local action, target = SecureCmdOptionParse(msg);
  1140. if ( action ) then
  1141. local spellExists = DoesSpellExist(action)
  1142. local name, bag, slot = SecureCmdItemParse(action);
  1143. if ( spellExists ) then
  1144. CastSpellByName(action, target);
  1145. elseif ( slot or GetItemInfo(name) ) then
  1146. SecureCmdUseItem(name, bag, slot, target);
  1147. end
  1148. end
  1149. end
  1150. SecureCmdList["USE"] = function(msg)
  1151. local action, target = SecureCmdOptionParse(msg);
  1152. if ( action ) then
  1153. local name, bag, slot = SecureCmdItemParse(action);
  1154. if ( slot or GetItemInfo(name) ) then
  1155. SecureCmdUseItem(name, bag, slot, target);
  1156. else
  1157. CastSpellByName(action, target);
  1158. end
  1159. end
  1160. end
  1161. SecureCmdList["CASTRANDOM"] = function(msg)
  1162. local actions, target = SecureCmdOptionParse(msg);
  1163. if ( actions ) then
  1164. local action = ExecuteCastRandom(actions);
  1165. local name, bag, slot = SecureCmdItemParse(action);
  1166. if ( slot or GetItemInfo(name) ) then
  1167. SecureCmdUseItem(name, bag, slot, target);
  1168. else
  1169. CastSpellByName(action, target);
  1170. end
  1171. end
  1172. end
  1173. SecureCmdList["USERANDOM"] = SecureCmdList["CASTRANDOM"];
  1174. SecureCmdList["CASTSEQUENCE"] = function(msg)
  1175. local sequence, target = SecureCmdOptionParse(msg);
  1176. if ( sequence and sequence ~= "" ) then
  1177. ExecuteCastSequence(sequence, target);
  1178. end
  1179. end
  1180. SecureCmdList["STOPCASTING"] = function(msg)
  1181. if ( SecureCmdOptionParse(msg) ) then
  1182. SpellStopCasting();
  1183. end
  1184. end
  1185. SecureCmdList["STOPSPELLTARGET"] = function(msg)
  1186. if ( SecureCmdOptionParse(msg) ) then
  1187. SpellStopTargeting();
  1188. end
  1189. end
  1190. SecureCmdList["CANCELAURA"] = function(msg)
  1191. local spell = SecureCmdOptionParse(msg);
  1192. if ( spell ) then
  1193. CancelSpellByName(spell);
  1194. end
  1195. end
  1196. SecureCmdList["CANCELFORM"] = function(msg)
  1197. if ( SecureCmdOptionParse(msg) ) then
  1198. CancelShapeshiftForm();
  1199. end
  1200. end
  1201. SecureCmdList["EQUIP"] = function(msg)
  1202. local item = SecureCmdOptionParse(msg);
  1203. if ( item ) then
  1204. EquipItemByName((SecureCmdItemParse(item)));
  1205. end
  1206. end
  1207. SecureCmdList["EQUIP_TO_SLOT"] = function(msg)
  1208. local action = SecureCmdOptionParse(msg);
  1209. if ( action ) then
  1210. local slot, item = strmatch(action, "^(%d+)%s+(.*)");
  1211. if ( item ) then
  1212. if ( PaperDoll_IsEquippedSlot(slot) ) then
  1213. EquipItemByName(SecureCmdItemParse(item), slot);
  1214. else
  1215. -- user specified a bad slot number (slot that you can't equip an item to)
  1216. ChatFrame_DisplayUsageError(format(ERROR_SLASH_EQUIP_TO_SLOT, EQUIPPED_FIRST, EQUIPPED_LAST));
  1217. end
  1218. elseif ( slot ) then
  1219. -- user specified a slot but not an item
  1220. ChatFrame_DisplayUsageError(format(ERROR_SLASH_EQUIP_TO_SLOT, EQUIPPED_FIRST, EQUIPPED_LAST));
  1221. end
  1222. end
  1223. end
  1224. SecureCmdList["CHANGEACTIONBAR"] = function(msg)
  1225. local page = SecureCmdOptionParse(msg);
  1226. if ( page and page ~= "" ) then
  1227. page = tonumber(page);
  1228. if (page and page >= 1 and page <= NUM_ACTIONBAR_PAGES) then
  1229. ChangeActionBarPage(page);
  1230. else
  1231. ChatFrame_DisplayUsageError(format(ERROR_SLASH_CHANGEACTIONBAR, 1, NUM_ACTIONBAR_PAGES));
  1232. end
  1233. end
  1234. end
  1235. SecureCmdList["SWAPACTIONBAR"] = function(msg)
  1236. local action = SecureCmdOptionParse(msg);
  1237. if ( action ) then
  1238. local a, b = strmatch(action, "(%d+)%s+(%d+)");
  1239. if ( a and b ) then
  1240. a = tonumber(a);
  1241. b = tonumber(b);
  1242. if ( ( a and a >= 1 and a <= NUM_ACTIONBAR_PAGES ) and ( b and b >= 1 and b <= NUM_ACTIONBAR_PAGES ) ) then
  1243. if ( GetActionBarPage() == a ) then
  1244. ChangeActionBarPage(b);
  1245. else
  1246. ChangeActionBarPage(a);
  1247. end
  1248. else
  1249. ChatFrame_DisplayUsageError(format(ERROR_SLASH_SWAPACTIONBAR, 1, NUM_ACTIONBAR_PAGES));
  1250. end
  1251. end
  1252. end
  1253. end
  1254. SecureCmdList["TARGET"] = function(msg)
  1255. local action, target = SecureCmdOptionParse(msg);
  1256. if ( action ) then
  1257. if ( not target or target == "target" ) then
  1258. target = action;
  1259. end
  1260. TargetUnit(target);
  1261. end
  1262. end
  1263. SecureCmdList["TARGET_EXACT"] = function(msg)
  1264. local action, target = SecureCmdOptionParse(msg);
  1265. if ( action ) then
  1266. if ( not target or target == "target" ) then
  1267. target = action;
  1268. end
  1269. TargetUnit(target, true);
  1270. end
  1271. end
  1272. SecureCmdList["TARGET_NEAREST_ENEMY"] = function(msg)
  1273. local action = SecureCmdOptionParse(msg);
  1274. if ( action ) then
  1275. TargetNearestEnemy(ValueToBoolean(action, false));
  1276. end
  1277. end
  1278. SecureCmdList["TARGET_NEAREST_ENEMY_PLAYER"] = function(msg)
  1279. local action = SecureCmdOptionParse(msg);
  1280. if ( action ) then
  1281. TargetNearestEnemyPlayer(ValueToBoolean(action, false));
  1282. end
  1283. end
  1284. SecureCmdList["TARGET_NEAREST_FRIEND"] = function(msg)
  1285. local action = SecureCmdOptionParse(msg);
  1286. if ( action ) then
  1287. TargetNearestFriend(ValueToBoolean(action, false));
  1288. end
  1289. end
  1290. SecureCmdList["TARGET_NEAREST_FRIEND_PLAYER"] = function(msg)
  1291. local action = SecureCmdOptionParse(msg);
  1292. if ( action ) then
  1293. TargetNearestFriendPlayer(ValueToBoolean(action, false));
  1294. end
  1295. end
  1296. SecureCmdList["TARGET_NEAREST_PARTY"] = function(msg)
  1297. local action = SecureCmdOptionParse(msg);
  1298. if ( action ) then
  1299. TargetNearestPartyMember(ValueToBoolean(action, false));
  1300. end
  1301. end
  1302. SecureCmdList["TARGET_NEAREST_RAID"] = function(msg)
  1303. local action = SecureCmdOptionParse(msg);
  1304. if ( action ) then
  1305. TargetNearestRaidMember(ValueToBoolean(action, false));
  1306. end
  1307. end
  1308. SecureCmdList["CLEARTARGET"] = function(msg)
  1309. if ( SecureCmdOptionParse(msg) ) then
  1310. ClearTarget();
  1311. end
  1312. end
  1313. SecureCmdList["TARGET_LAST_TARGET"] = function(msg)
  1314. if ( SecureCmdOptionParse(msg) ) then
  1315. TargetLastTarget();
  1316. end
  1317. end
  1318. SecureCmdList["TARGET_LAST_ENEMY"] = function(msg)
  1319. local action = SecureCmdOptionParse(msg);
  1320. if ( action ) then
  1321. TargetLastEnemy(action);
  1322. end
  1323. end
  1324. SecureCmdList["TARGET_LAST_FRIEND"] = function(msg)
  1325. local action = SecureCmdOptionParse(msg);
  1326. if ( action ) then
  1327. TargetLastFriend(action);
  1328. end
  1329. end
  1330. SecureCmdList["ASSIST"] = function(msg)
  1331. if ( msg == "" ) then
  1332. AssistUnit();
  1333. else
  1334. local action, target = SecureCmdOptionParse(msg);
  1335. if ( action ) then
  1336. if ( not target ) then
  1337. target = action;
  1338. end
  1339. AssistUnit(target);
  1340. end
  1341. end
  1342. end
  1343. SecureCmdList["FOCUS"] = function(msg)
  1344. if ( msg == "" ) then
  1345. FocusUnit();
  1346. else
  1347. local action, target = SecureCmdOptionParse(msg);
  1348. if ( action ) then
  1349. if ( not target or target == "focus" ) then
  1350. target = action;
  1351. end
  1352. FocusUnit(target);
  1353. end
  1354. end
  1355. end
  1356. SecureCmdList["CLEARFOCUS"] = function(msg)
  1357. if ( SecureCmdOptionParse(msg) ) then
  1358. ClearFocus();
  1359. end
  1360. end
  1361. SecureCmdList["MAINTANKON"] = function(msg)
  1362. local action, target = SecureCmdOptionParse(msg);
  1363. if ( action ) then
  1364. if ( not target ) then
  1365. target = action;
  1366. end
  1367. if ( target == "" ) then
  1368. target = "target";
  1369. end
  1370. SetPartyAssignment("MAINTANK", target);
  1371. end
  1372. end
  1373. SecureCmdList["MAINTANKOFF"] = function(msg)
  1374. local action, target = SecureCmdOptionParse(msg);
  1375. if ( action ) then
  1376. if ( not target ) then
  1377. target = action;
  1378. end
  1379. if ( target == "" ) then
  1380. target = "target";
  1381. end
  1382. ClearPartyAssignment("MAINTANK", target);
  1383. end
  1384. end
  1385. SecureCmdList["MAINASSISTON"] = function(msg)
  1386. local action, target = SecureCmdOptionParse(msg);
  1387. if ( action ) then
  1388. if ( not target ) then
  1389. target = action;
  1390. end
  1391. if ( target == "" ) then
  1392. target = "target";
  1393. end
  1394. SetPartyAssignment("MAINASSIST", target);
  1395. end
  1396. end
  1397. SecureCmdList["MAINASSISTOFF"] = function(msg)
  1398. local action, target = SecureCmdOptionParse(msg);
  1399. if ( action ) then
  1400. if ( not target ) then
  1401. target = action;
  1402. end
  1403. if ( target == "" ) then
  1404. target = "target";
  1405. end
  1406. ClearPartyAssignment("MAINASSIST", target);
  1407. end
  1408. end
  1409. SecureCmdList["DUEL"] = function(msg)
  1410. StartDuel(msg)
  1411. end
  1412. SecureCmdList["DUEL_CANCEL"] = function(msg)
  1413. ForfeitDuel()
  1414. end
  1415. SecureCmdList["PET_ATTACK"] = function(msg)
  1416. local action, target = SecureCmdOptionParse(msg);
  1417. if ( action ) then
  1418. if ( not target or target == "pettarget" ) then
  1419. target = action;
  1420. end
  1421. PetAttack(target);
  1422. end
  1423. end
  1424. SecureCmdList["PET_FOLLOW"] = function(msg)
  1425. if ( SecureCmdOptionParse(msg) ) then
  1426. PetFollow();
  1427. end
  1428. end
  1429. SecureCmdList["PET_MOVE_TO"] = function(msg)
  1430. local action, target = SecureCmdOptionParse(msg);
  1431. if ( action ) then
  1432. PetMoveTo(target);
  1433. end
  1434. end
  1435. SecureCmdList["PET_STAY"] = function(msg)
  1436. if ( SecureCmdOptionParse(msg) ) then
  1437. PetWait();
  1438. end
  1439. end
  1440. SecureCmdList["PET_PASSIVE"] = function(msg)
  1441. if ( SecureCmdOptionParse(msg) ) then
  1442. PetPassiveMode();
  1443. end
  1444. end
  1445. SecureCmdList["PET_DEFENSIVE"] = function(msg)
  1446. if ( SecureCmdOptionParse(msg) ) then
  1447. PetDefensiveMode();
  1448. end
  1449. end
  1450. SecureCmdList["PET_AGGRESSIVE"] = function(msg)
  1451. if ( SecureCmdOptionParse(msg) ) then
  1452. PetAggressiveMode();
  1453. end
  1454. end
  1455. SecureCmdList["PET_ASSIST"] = function(msg)
  1456. if ( SecureCmdOptionParse(msg) ) then
  1457. PetAssistMode();
  1458. end
  1459. end
  1460. SecureCmdList["PET_AUTOCASTON"] = function(msg)
  1461. local spell = SecureCmdOptionParse(msg);
  1462. if ( spell ) then
  1463. EnableSpellAutocast(spell);
  1464. end
  1465. end
  1466. SecureCmdList["PET_AUTOCASTOFF"] = function(msg)
  1467. local spell = SecureCmdOptionParse(msg);
  1468. if ( spell ) then
  1469. DisableSpellAutocast(spell);
  1470. end
  1471. end
  1472. SecureCmdList["PET_AUTOCASTTOGGLE"] = function(msg)
  1473. local spell = SecureCmdOptionParse(msg);
  1474. if ( spell ) then
  1475. ToggleSpellAutocast(spell);
  1476. end
  1477. end
  1478. SecureCmdList["STOPMACRO"] = function(msg)
  1479. if ( SecureCmdOptionParse(msg) ) then
  1480. StopMacro();
  1481. end
  1482. end
  1483. SecureCmdList["CANCELQUEUEDSPELL"] = function(msg)
  1484. if ( SecureCmdOptionParse(msg) ) then
  1485. SpellCancelQueuedSpell();
  1486. end
  1487. end
  1488. SecureCmdList["CLICK"] = function(msg)
  1489. local action = SecureCmdOptionParse(msg);
  1490. if ( action and action ~= "" ) then
  1491. local name, mouseButton, down = strmatch(action, "([^%s]+)%s+([^%s]+)%s*(.*)");
  1492. if ( not name ) then
  1493. name = action;
  1494. end
  1495. local button = GetClickFrame(name);
  1496. if ( button and button:IsObjectType("Button") and not button:IsForbidden() ) then
  1497. button:Click(mouseButton, down);
  1498. end
  1499. end
  1500. end
  1501. SecureCmdList["EQUIP_SET"] = function(msg)
  1502. local set = SecureCmdOptionParse(msg);
  1503. if ( set and set ~= "" ) then
  1504. C_EquipmentSet.UseEquipmentSet(C_EquipmentSet.GetEquipmentSetID(set));
  1505. end
  1506. end
  1507. SecureCmdList["WORLD_MARKER"] = function(msg)
  1508. local marker = SecureCmdOptionParse(msg);
  1509. if ( tonumber(marker) ) then
  1510. PlaceRaidMarker(tonumber(marker));
  1511. end
  1512. end
  1513. SecureCmdList["CLEAR_WORLD_MARKER"] = function(msg)
  1514. local marker = SecureCmdOptionParse(msg);
  1515. if ( tonumber(marker) ) then
  1516. ClearRaidMarker(tonumber(marker));
  1517. elseif ( type(marker) == "string" and strtrim(strlower(marker)) == strlower(ALL) ) then
  1518. ClearRaidMarker(nil); --Clear all world markers.
  1519. end
  1520. end
  1521. SecureCmdList["SUMMON_BATTLE_PET"] = function(msg)
  1522. local pet = SecureCmdOptionParse(msg);
  1523. if ( type(pet) == "string" ) then
  1524. local _, petID = C_PetJournal.FindPetIDByName(string.trim(pet));
  1525. if ( petID ) then
  1526. C_PetJournal.SummonPetByGUID(petID);
  1527. else
  1528. C_PetJournal.SummonPetByGUID(pet);
  1529. end
  1530. end
  1531. end
  1532. SecureCmdList["RANDOMPET"] = function(msg)
  1533. if ( SecureCmdOptionParse(msg) ) then
  1534. C_PetJournal.SummonRandomPet(false);
  1535. end
  1536. end
  1537. SecureCmdList["RANDOMFAVORITEPET"] = function(msg)
  1538. if ( SecureCmdOptionParse(msg) ) then
  1539. C_PetJournal.SummonRandomPet(true);
  1540. end
  1541. end
  1542. SecureCmdList["DISMISSBATTLEPET"] = function(msg)
  1543. if ( SecureCmdOptionParse(msg) ) then
  1544. local petID = C_PetJournal.GetSummonedPetGUID();
  1545. if ( petID ) then
  1546. C_PetJournal.SummonPetByGUID(petID);
  1547. end
  1548. end
  1549. end
  1550. SecureCmdList["PET_DISMISS"] = function(msg)
  1551. if ( PetCanBeAbandoned() ) then
  1552. CastSpellByID(HUNTER_DISMISS_PET);
  1553. else
  1554. PetDismiss();
  1555. end
  1556. end
  1557. SecureCmdList["USE_TOY"] = function(msg)
  1558. local toyName = SecureCmdOptionParse(msg);
  1559. if ( toyName and toyName ~= "" ) then
  1560. UseToyByName(toyName)
  1561. end
  1562. end
  1563. SecureCmdList["LOGOUT"] = function(msg)
  1564. Logout();
  1565. end
  1566. SecureCmdList["QUIT"] = function(msg)
  1567. if (IsKioskModeEnabled()) then
  1568. return;
  1569. end
  1570. Quit();
  1571. end
  1572. function AddSecureCmd(cmd, cmdString)
  1573. if not issecure() then
  1574. error("Cannot call AddSecureCmd from insecure code");
  1575. end
  1576. hash_SecureCmdList[strupper(cmdString)] = cmd;
  1577. end
  1578. function AddSecureCmdAliases(cmd, ...)
  1579. for i = 1, select("#", ...) do
  1580. local cmdString = select(i, ...);
  1581. AddSecureCmd(cmd, cmdString);
  1582. end
  1583. end
  1584. -- Pre-populate the secure command hash table
  1585. for index, value in pairs(SecureCmdList) do
  1586. local i = 1;
  1587. local cmdString = "";
  1588. while cmdString do
  1589. cmdString = _G["SLASH_"..index..i];
  1590. if cmdString then
  1591. AddSecureCmd(value, cmdString);
  1592. i = i + 1;
  1593. end
  1594. end
  1595. end
  1596. -- Slash commands
  1597. SlashCmdList = { };
  1598. SlashCmdList["CONSOLE"] = function(msg)
  1599. forceinsecure();
  1600. ConsoleExec(msg);
  1601. end
  1602. SlashCmdList["CHATLOG"] = function(msg)
  1603. local info = ChatTypeInfo["SYSTEM"];
  1604. if ( LoggingChat() ) then
  1605. LoggingChat(false);
  1606. DEFAULT_CHAT_FRAME:AddMessage(CHATLOGDISABLED, info.r, info.g, info.b, info.id);
  1607. else
  1608. LoggingChat(true);
  1609. DEFAULT_CHAT_FRAME:AddMessage(CHATLOGENABLED, info.r, info.g, info.b, info.id);
  1610. end
  1611. end
  1612. SlashCmdList["COMBATLOG"] = function(msg)
  1613. local info = ChatTypeInfo["SYSTEM"];
  1614. if ( LoggingCombat() ) then
  1615. LoggingCombat(false);
  1616. DEFAULT_CHAT_FRAME:AddMessage(COMBATLOGDISABLED, info.r, info.g, info.b, info.id);
  1617. else
  1618. LoggingCombat(true);
  1619. DEFAULT_CHAT_FRAME:AddMessage(COMBATLOGENABLED, info.r, info.g, info.b, info.id);
  1620. end
  1621. end
  1622. SlashCmdList["INVITE"] = function(msg)
  1623. if(msg == "") then
  1624. msg = GetUnitName("target", true)
  1625. end
  1626. if( msg and (strlen(msg) > MAX_CHARACTER_NAME_BYTES) ) then
  1627. ChatFrame_DisplayUsageError(ERR_NAME_TOO_LONG2);
  1628. return;
  1629. end
  1630. if(msg == nil) then
  1631. ChatFrame_DisplayUsageError(ERR_NO_TARGET_OR_NAME);
  1632. return;
  1633. end
  1634. InviteToGroup(msg);
  1635. end
  1636. SlashCmdList["REQUEST_INVITE"] = function(msg)
  1637. if(msg == "") then
  1638. msg = GetUnitName("target", true)
  1639. end
  1640. if( msg and (strlen(msg) > MAX_CHARACTER_NAME_BYTES) ) then
  1641. ChatFrame_DisplayUsageError(ERR_NAME_TOO_LONG2);
  1642. return;
  1643. end
  1644. if(msg == nil) then
  1645. ChatFrame_DisplayUsageError(ERR_NO_TARGET_OR_NAME);
  1646. return;
  1647. end
  1648. RequestInviteFromUnit(msg);
  1649. end
  1650. SlashCmdList["UNINVITE"] = function(msg)
  1651. if(msg == "") then
  1652. msg = GetUnitName("target", true);
  1653. end
  1654. if(msg == nil) then
  1655. ChatFrame_DisplayUsageError(ERR_NO_TARGET_OR_NAME);
  1656. return;
  1657. end
  1658. UninviteUnit(msg);
  1659. end
  1660. SlashCmdList["PROMOTE"] = function(msg)
  1661. PromoteToLeader(msg);
  1662. end
  1663. SlashCmdList["REPLY"] = function(msg, editBox)
  1664. local lastTell = ChatEdit_GetLastTellTarget();
  1665. if ( lastTell ) then
  1666. msg = SubstituteChatMessageBeforeSend(msg);
  1667. SendChatMessage(msg, "WHISPER", editBox.languageID, lastTell);
  1668. else
  1669. -- error message
  1670. end
  1671. end
  1672. SlashCmdList["HELP"] = function(msg)
  1673. ChatFrame_DisplayHelpText(DEFAULT_CHAT_FRAME);
  1674. end
  1675. SlashCmdList["MACROHELP"] = function(msg)
  1676. ChatFrame_DisplayMacroHelpText(DEFAULT_CHAT_FRAME);
  1677. end
  1678. SlashCmdList["TIME"] = function(msg)
  1679. ChatFrame_DisplayGameTime(DEFAULT_CHAT_FRAME);
  1680. end
  1681. SlashCmdList["PLAYED"] = function(msg)
  1682. RequestTimePlayed();
  1683. end
  1684. SlashCmdList["FOLLOW"] = function(msg)
  1685. FollowUnit(msg);
  1686. end
  1687. SlashCmdList["TRADE"] = function(msg)
  1688. InitiateTrade("target");
  1689. end
  1690. SlashCmdList["INSPECT"] = function(msg)
  1691. InspectUnit("target");
  1692. end
  1693. SlashCmdList["JOIN"] = function(msg)
  1694. local name = gsub(msg, "%s*([^%s]+).*", "%1");
  1695. local password = gsub(msg, "%s*([^%s]+)%s*(.*)", "%2");
  1696. if(name == "") then
  1697. local joinhelp = CHAT_JOIN_HELP;
  1698. local info = ChatTypeInfo["SYSTEM"];
  1699. DEFAULT_CHAT_FRAME:AddMessage(joinhelp, info.r, info.g, info.b, info.id);
  1700. else
  1701. local zoneChannel, channelName = JoinPermanentChannel(name, password, DEFAULT_CHAT_FRAME:GetID(), 1);
  1702. if ( channelName ) then
  1703. name = channelName;
  1704. end
  1705. if ( not zoneChannel ) then
  1706. local info = ChatTypeInfo["CHANNEL"];
  1707. DEFAULT_CHAT_FRAME:AddMessage(CHAT_INVALID_NAME_NOTICE, info.r, info.g, info.b, info.id);
  1708. return;
  1709. end
  1710. local i = 1;
  1711. while ( DEFAULT_CHAT_FRAME.channelList[i] ) do
  1712. i = i + 1;
  1713. end
  1714. DEFAULT_CHAT_FRAME.channelList[i] = name;
  1715. DEFAULT_CHAT_FRAME.zoneChannelList[i] = zoneChannel;
  1716. end
  1717. end
  1718. SlashCmdList["LEAVE"] = function(msg)
  1719. local name = strmatch(msg, "%s*([^%s]+)");
  1720. if ( name ) then
  1721. LeaveChannelByName(name);
  1722. end
  1723. end
  1724. SlashCmdList["LIST_CHANNEL"] = function(msg)
  1725. local name = strmatch(msg, "%s*([^%s]+)");
  1726. if ( name ) then
  1727. ListChannelByName(name);
  1728. else
  1729. ListChannels();
  1730. end
  1731. end
  1732. SlashCmdList["CHAT_HELP"] =
  1733. function(msg)
  1734. ChatFrame_DisplayChatHelp(DEFAULT_CHAT_FRAME)
  1735. end
  1736. SlashCmdList["CHAT_PASSWORD"] =
  1737. function(msg)
  1738. local name = gsub(msg, "%s*([^%s]+).*", "%1");
  1739. local password = gsub(msg, "%s*([^%s]+)%s*(.*)", "%2");
  1740. SetChannelPassword(name, password);
  1741. end
  1742. SlashCmdList["CHAT_OWNER"] =
  1743. function(msg)
  1744. local channel = gsub(msg, "%s*([^%s]+).*", "%1");
  1745. local newOwner = gsub(msg, "%s*([^%s]+)%s*(.*)", "%2");
  1746. if ( not channel or not newOwner ) then
  1747. return;
  1748. end
  1749. local newOwnerLen = strlen(newOwner);
  1750. if ( newOwnerLen > MAX_CHARACTER_NAME_BYTES ) then
  1751. ChatFrame_DisplayUsageError(ERR_NAME_TOO_LONG2);
  1752. return;
  1753. end
  1754. if ( channel ~= "" ) then
  1755. if ( newOwnerLen > 0 ) then
  1756. SetChannelOwner(channel, newOwner);
  1757. else
  1758. DisplayChannelOwner(channel);
  1759. end
  1760. end
  1761. end
  1762. SlashCmdList["CHAT_MODERATOR"] =
  1763. function(msg)
  1764. local channel, player = strmatch(msg, "%s*([^%s]+)%s*(.*)");
  1765. if ( not channel or not player ) then
  1766. return;
  1767. end
  1768. if ( strlen(player) > MAX_CHARACTER_NAME_BYTES ) then
  1769. ChatFrame_DisplayUsageError(ERR_NAME_TOO_LONG2);
  1770. return;
  1771. end
  1772. ChannelModerator(channel, player);
  1773. end
  1774. SlashCmdList["CHAT_UNMODERATOR"] =
  1775. function(msg)
  1776. local channel, player = strmatch(msg, "%s*([^%s]+)%s*(.*)");
  1777. if ( not channel or not player ) then
  1778. return;
  1779. end
  1780. if ( strlen(player) > MAX_CHARACTER_NAME_BYTES ) then
  1781. ChatFrame_DisplayUsageError(ERR_NAME_TOO_LONG2);
  1782. return;
  1783. end
  1784. if ( channel and player ) then
  1785. ChannelUnmoderator(channel, player);
  1786. end
  1787. end
  1788. SlashCmdList["CHAT_CINVITE"] =
  1789. function(msg)
  1790. local channel, player = strmatch(msg, "%s*([^%s]+)%s*(.*)");
  1791. if ( not channel or not player ) then
  1792. return;
  1793. end
  1794. if ( channel and player ) then
  1795. if ( strlen(player) > MAX_CHARACTER_NAME_BYTES ) then
  1796. ChatFrame_DisplayUsageError(ERR_NAME_TOO_LONG2);
  1797. return;
  1798. end
  1799. ChannelInvite(channel, player);
  1800. end
  1801. end
  1802. SlashCmdList["CHAT_KICK"] =
  1803. function(msg)
  1804. local channel, player = strmatch(msg, "%s*([^%s]+)%s*(.*)");
  1805. if ( not channel or not player ) then
  1806. return;
  1807. end
  1808. if ( strlen(player) > MAX_CHARACTER_NAME_BYTES ) then
  1809. ChatFrame_DisplayUsageError(ERR_NAME_TOO_LONG2);
  1810. return;
  1811. end
  1812. if ( channel and player ) then
  1813. ChannelKick(channel, player);
  1814. end
  1815. end
  1816. SlashCmdList["CHAT_BAN"] =
  1817. function(msg)
  1818. local channel, player = strmatch(msg, "%s*([^%s]+)%s*(.*)");
  1819. if ( not channel or not player ) then
  1820. return;
  1821. end
  1822. if ( strlen(player) > MAX_CHARACTER_NAME_BYTES ) then
  1823. ChatFrame_DisplayUsageError(ERR_NAME_TOO_LONG2);
  1824. return;
  1825. end
  1826. if ( channel and player ) then
  1827. ChannelBan(channel, player);
  1828. end
  1829. end
  1830. SlashCmdList["CHAT_UNBAN"] =
  1831. function(msg)
  1832. local channel, player = strmatch(msg, "%s*([^%s]+)%s*(.*)");
  1833. if ( not channel or not player ) then
  1834. return;
  1835. end
  1836. if ( strlen(player) > MAX_CHARACTER_NAME_BYTES ) then
  1837. ChatFrame_DisplayUsageError(ERR_NAME_TOO_LONG2);
  1838. return;
  1839. end
  1840. if ( channel and player ) then
  1841. ChannelUnban(channel, player);
  1842. end
  1843. end
  1844. SlashCmdList["CHAT_ANNOUNCE"] =
  1845. function(msg)
  1846. local channel = strmatch(msg, "%s*([^%s]+)");
  1847. if ( channel ) then
  1848. ChannelToggleAnnouncements(channel);
  1849. end
  1850. end
  1851. SlashCmdList["GUILD_INVITE"] = function(msg)
  1852. if(msg == "") then
  1853. msg = GetUnitName("target", true);
  1854. end
  1855. if( msg and (strlen(msg) > MAX_CHARACTER_NAME_BYTES) ) then
  1856. ChatFrame_DisplayUsageError(ERR_NAME_TOO_LONG2);
  1857. return;
  1858. end
  1859. GuildInvite(msg);
  1860. end
  1861. SlashCmdList["GUILD_UNINVITE"] = function(msg)
  1862. if(msg == "") then
  1863. msg = UnitName("target");
  1864. end
  1865. if( msg and (strlen(msg) > MAX_CHARACTER_NAME_BYTES) ) then
  1866. ChatFrame_DisplayUsageError(ERR_NAME_TOO_LONG2);
  1867. return;
  1868. end
  1869. GuildUninvite(msg);
  1870. end
  1871. SlashCmdList["GUILD_PROMOTE"] = function(msg)
  1872. if( msg and (strlen(msg) > MAX_CHARACTER_NAME_BYTES) ) then
  1873. ChatFrame_DisplayUsageError(ERR_NAME_TOO_LONG2);
  1874. return;
  1875. end
  1876. GuildPromote(msg);
  1877. end
  1878. SlashCmdList["GUILD_DEMOTE"] = function(msg)
  1879. if( msg and (strlen(msg) > MAX_CHARACTER_NAME_BYTES) ) then
  1880. ChatFrame_DisplayUsageError(ERR_NAME_TOO_LONG2);
  1881. return;
  1882. end
  1883. GuildDemote(msg);
  1884. end
  1885. SlashCmdList["GUILD_LEADER"] = function(msg)
  1886. if( msg and (strlen(msg) > MAX_CHARACTER_NAME_BYTES) ) then
  1887. ChatFrame_DisplayUsageError(ERR_NAME_TOO_LONG2);
  1888. return;
  1889. end
  1890. GuildSetLeader(msg);
  1891. end
  1892. SlashCmdList["GUILD_MOTD"] = function(msg)
  1893. GuildSetMOTD(msg)
  1894. end
  1895. SlashCmdList["GUILD_LEAVE"] = function(msg)
  1896. GuildLeave();
  1897. end
  1898. SlashCmdList["GUILD_DISBAND"] = function(msg)
  1899. if ( IsGuildLeader() ) then
  1900. StaticPopup_Show("CONFIRM_GUILD_DISBAND");
  1901. end
  1902. end
  1903. SlashCmdList["GUILD_INFO"] = function(msg)
  1904. GuildInfo();
  1905. end
  1906. SlashCmdList["GUILD_ROSTER"] = function(msg)
  1907. if ( IsInGuild() ) then
  1908. GuildFrame_LoadUI();
  1909. if ( GuildFrame ) then
  1910. GuildFrameTab2:Click();
  1911. ShowUIPanel(GuildFrame);
  1912. end
  1913. end
  1914. end
  1915. --SlashCmdList["GUILD_HELP"] = function(msg)
  1916. -- ChatFrame_DisplayGuildHelp(DEFAULT_CHAT_FRAME);
  1917. --end
  1918. SlashCmdList["CHAT_AFK"] = function(msg)
  1919. SendChatMessage(msg, "AFK");
  1920. end
  1921. SlashCmdList["CHAT_DND"] = function(msg)
  1922. SendChatMessage(msg, "DND");
  1923. end
  1924. SlashCmdList["WHO"] = function(msg)
  1925. if (IsKioskModeEnabled()) then
  1926. return;
  1927. end
  1928. if ( msg == "" ) then
  1929. msg = WhoFrame_GetDefaultWhoCommand();
  1930. ShowWhoPanel();
  1931. end
  1932. WhoFrameEditBox:SetText(msg);
  1933. C_FriendList.SendWho(msg);
  1934. end
  1935. SlashCmdList["CHANNEL"] = function(msg, editBox)
  1936. msg = SubstituteChatMessageBeforeSend(msg);
  1937. SendChatMessage(msg, "CHANNEL", editBox.languageID, ChatEdit_GetChannelTarget(editBox));
  1938. end
  1939. SlashCmdList["FRIENDS"] = function(msg)
  1940. local player, note = strmatch(msg, "%s*([^%s]+)%s*(.*)");
  1941. if ( player ~= "" or UnitIsPlayer("target") ) then
  1942. C_FriendList.AddOrRemoveFriend(player, note);
  1943. else
  1944. ToggleFriendsPanel();
  1945. end
  1946. end
  1947. SlashCmdList["REMOVEFRIEND"] = function(msg)
  1948. C_FriendList.RemoveFriend(msg);
  1949. end
  1950. SlashCmdList["IGNORE"] = function(msg)
  1951. if ( msg ~= "" or UnitIsPlayer("target") ) then
  1952. local bNetIDAccount = BNet_GetBNetIDAccount(msg);
  1953. if ( bNetIDAccount ) then
  1954. if ( BNIsFriend(bNetIDAccount) ) then
  1955. SendSystemMessage(ERR_CANNOT_IGNORE_BN_FRIEND);
  1956. else
  1957. BNSetBlocked(bNetIDAccount, not BNIsBlocked(bNetIDAccount));
  1958. end
  1959. else
  1960. C_FriendList.AddOrDelIgnore(msg);
  1961. end
  1962. else
  1963. ToggleIgnorePanel();
  1964. end
  1965. end
  1966. SlashCmdList["UNIGNORE"] = function(msg)
  1967. if ( msg ~= "" or UnitIsPlayer("target") ) then
  1968. C_FriendList.DelIgnore(msg);
  1969. else
  1970. ToggleIgnorePanel();
  1971. end
  1972. end
  1973. SlashCmdList["SCRIPT"] = function(msg)
  1974. if ( not ScriptsDisallowedForBeta() ) then
  1975. if ( not AreDangerousScriptsAllowed() ) then
  1976. StaticPopup_Show("DANGEROUS_SCRIPTS_WARNING");
  1977. return;
  1978. end
  1979. RunScript(msg);
  1980. end
  1981. end
  1982. SlashCmdList["RANDOM"] = function(msg)
  1983. local num1 = gsub(msg, "(%s*)(%d+)(.*)", "%2", 1);
  1984. local rest = gsub(msg, "(%s*)(%d+)(.*)", "%3", 1);
  1985. local num2 = "";
  1986. local numSubs;
  1987. if ( rest ~= "" ) then
  1988. num2, numSubs = gsub(msg, "(%s*)(%d+)([-%s]+)(%d+)(.*)", "%4", 1);
  1989. if ( numSubs == 0 ) then
  1990. num2 = "";
  1991. end
  1992. end
  1993. if ( num1 == "" and num2 == "" ) then
  1994. RandomRoll("1", "100");
  1995. elseif ( num2 == "" ) then
  1996. RandomRoll("1", num1);
  1997. else
  1998. RandomRoll(num1, num2);
  1999. end
  2000. end
  2001. SlashCmdList["MACRO"] = function(msg)
  2002. ShowMacroFrame();
  2003. end
  2004. SlashCmdList["PVP"] = function(msg)
  2005. TogglePVP();
  2006. end
  2007. SlashCmdList["RAID_INFO"] = function(msg)
  2008. RaidFrame.slashCommand = 1;
  2009. if ( ( GetNumSavedInstances() + GetNumSavedWorldBosses() > 0 ) and not RaidInfoFrame:IsVisible() ) then
  2010. ToggleRaidFrame();
  2011. RaidInfoFrame:Show();
  2012. elseif ( not RaidFrame:IsVisible() ) then
  2013. ToggleRaidFrame();
  2014. end
  2015. end
  2016. SlashCmdList["READYCHECK"] = function(msg)
  2017. if ( UnitIsGroupLeader("player") or UnitIsGroupAssistant("player") ) then
  2018. DoReadyCheck();
  2019. end
  2020. end
  2021. --[[All of this information is obtainable through the armory now.
  2022. SlashCmdList["SAVEGUILDROSTER"] = function(msg)
  2023. SaveGuildRoster();
  2024. end]]
  2025. SlashCmdList["DUNGEONS"] = function(msg)
  2026. ToggleLFDParentFrame();
  2027. end
  2028. SlashCmdList["BENCHMARK"] = function(msg)
  2029. SetTaxiBenchmarkMode(ValueToBoolean(msg), true);
  2030. end
  2031. SlashCmdList["DISMOUNT"] = function(msg)
  2032. if ( SecureCmdOptionParse(msg) ) then
  2033. Dismount();
  2034. end
  2035. end
  2036. SlashCmdList["LEAVEVEHICLE"] = function(msg)
  2037. if ( SecureCmdOptionParse(msg) ) then
  2038. VehicleExit();
  2039. end
  2040. end
  2041. SlashCmdList["RESETCHAT"] = function(msg)
  2042. FCF_ResetAllWindows();
  2043. end
  2044. SlashCmdList["ENABLE_ADDONS"] = function(msg)
  2045. EnableAllAddOns(msg);
  2046. ReloadUI();
  2047. end
  2048. SlashCmdList["DISABLE_ADDONS"] = function(msg)
  2049. DisableAllAddOns(msg);
  2050. ReloadUI();
  2051. end
  2052. SlashCmdList["STOPWATCH"] = function(msg)
  2053. if ( not IsAddOnLoaded("Blizzard_TimeManager") ) then
  2054. UIParentLoadAddOn("Blizzard_TimeManager");
  2055. end
  2056. if ( StopwatchFrame ) then
  2057. local text = strmatch(msg, "%s*([^%s]+)%s*");
  2058. if ( text ) then
  2059. text = strlower(text);
  2060. -- in any of the following cases, the stopwatch will be shown
  2061. StopwatchFrame:Show();
  2062. -- try to match a command
  2063. local function MatchCommand(param, text)
  2064. local i, compare;
  2065. i = 1;
  2066. repeat
  2067. compare = _G[param..i];
  2068. if ( compare and compare == text ) then
  2069. return true;
  2070. end
  2071. i = i + 1;
  2072. until ( not compare );
  2073. return false;
  2074. end
  2075. if ( MatchCommand("SLASH_STOPWATCH_PARAM_PLAY", text) ) then
  2076. Stopwatch_Play();
  2077. return;
  2078. end
  2079. if ( MatchCommand("SLASH_STOPWATCH_PARAM_PAUSE", text) ) then
  2080. Stopwatch_Pause();
  2081. return;
  2082. end
  2083. if ( MatchCommand("SLASH_STOPWATCH_PARAM_STOP", text) ) then
  2084. Stopwatch_Clear();
  2085. return;
  2086. end
  2087. -- try to match a countdown
  2088. -- kinda ghetto, but hey, it's simple and it works =)
  2089. local hour, minute, second = strmatch(msg, "(%d+):(%d+):(%d+)");
  2090. if ( not hour ) then
  2091. minute, second = strmatch(msg, "(%d+):(%d+)");
  2092. if ( not minute ) then
  2093. second = strmatch(msg, "(%d+)");
  2094. end
  2095. end
  2096. Stopwatch_StartCountdown(tonumber(hour), tonumber(minute), tonumber(second));
  2097. else
  2098. Stopwatch_Toggle();
  2099. end
  2100. end
  2101. end
  2102. SlashCmdList["CALENDAR"] = function(msg)
  2103. if ( not IsAddOnLoaded("Blizzard_Calendar") ) then
  2104. UIParentLoadAddOn("Blizzard_Calendar");
  2105. end
  2106. if ( Calendar_Toggle ) then
  2107. Calendar_Toggle();
  2108. end
  2109. end
  2110. SlashCmdList["ACHIEVEMENTUI"] = function(msg)
  2111. ToggleAchievementFrame();
  2112. end
  2113. SlashCmdList["SET_TITLE"] = function(msg)
  2114. local name = SecureCmdOptionParse(msg);
  2115. if ( name and name ~= "") then
  2116. if(not SetTitleByName(name)) then
  2117. UIErrorsFrame:AddMessage(TITLE_DOESNT_EXIST, 1.0, 0.1, 0.1, 1.0);
  2118. end
  2119. else
  2120. SetCurrentTitle(-1)
  2121. end
  2122. end
  2123. SlashCmdList["USE_TALENT_SPEC"] = function(msg)
  2124. local group = SecureCmdOptionParse(msg);
  2125. if ( group ) then
  2126. local groupNumber = tonumber(group);
  2127. if ( groupNumber ) then
  2128. --SetActiveSpecGroup(groupNumber);
  2129. end
  2130. end
  2131. end
  2132. -- easier method to turn on/off errors for macros
  2133. SlashCmdList["UI_ERRORS_OFF"] = function(msg)
  2134. UIErrorsFrame:UnregisterEvent("UI_ERROR_MESSAGE");
  2135. SetCVar("Sound_EnableSFX", "0");
  2136. end
  2137. SlashCmdList["UI_ERRORS_ON"] = function(msg)
  2138. UIErrorsFrame:RegisterEvent("UI_ERROR_MESSAGE");
  2139. SetCVar("Sound_EnableSFX", "1");
  2140. end
  2141. SlashCmdList["FRAMESTACK"] = function(msg)
  2142. UIParentLoadAddOn("Blizzard_DebugTools");
  2143. local showHiddenArg, showRegionsArg, showAnchorsArg;
  2144. local pattern = "^%s*(%S+)(.*)$";
  2145. showHiddenArg, msg = string.match(msg or "", pattern);
  2146. showRegionsArg, msg = string.match(msg or "", pattern);
  2147. showAnchorsArg, msg = string.match(msg or "", pattern);
  2148. -- If no parameters are passed the defaults specified by these cvars are used instead.
  2149. local showHiddenDefault = FrameStackTooltip_IsShowHiddenEnabled();
  2150. local showRegionsDefault = FrameStackTooltip_IsShowRegionsEnabled();
  2151. local showAnchorsDefault = FrameStackTooltip_IsShowAnchorsEnabled();
  2152. local showHidden = StringToBoolean(showHiddenArg or "", showHiddenDefault);
  2153. local showRegions = StringToBoolean(showRegionsArg or "", showRegionsDefault);
  2154. local showAnchors = StringToBoolean(showAnchorsArg or "", showAnchorsDefault);
  2155. FrameStackTooltip_Toggle(showHidden, showRegions, showAnchors);
  2156. end
  2157. SlashCmdList["EVENTTRACE"] = function(msg)
  2158. UIParentLoadAddOn("Blizzard_DebugTools");
  2159. EventTraceFrame_HandleSlashCmd(msg);
  2160. end
  2161. if IsGMClient() then
  2162. SLASH_TEXELVIS1 = "/texelvis";
  2163. SLASH_TEXELVIS2 = "/tvis";
  2164. SlashCmdList["TEXELVIS"] = function(msg)
  2165. UIParentLoadAddOn("Blizzard_DebugTools");
  2166. TexelSnappingVisualizer:Show();
  2167. end
  2168. end
  2169. SlashCmdList["TABLEINSPECT"] = function(msg)
  2170. forceinsecure();
  2171. UIParentLoadAddOn("Blizzard_DebugTools");
  2172. local focusedTable = nil;
  2173. if msg ~= "" and msg ~= " " then
  2174. local focusedFunction = loadstring(("return %s"):format(msg));
  2175. focusedTable = focusedFunction and focusedFunction();
  2176. end
  2177. if focusedTable and type(focusedTable) == "table" then
  2178. DisplayTableInspectorWindow(focusedTable);
  2179. else
  2180. local highlightFrame = FrameStackTooltip:SetFrameStack();
  2181. if highlightFrame then
  2182. DisplayTableInspectorWindow(highlightFrame);
  2183. else
  2184. DisplayTableInspectorWindow(UIParent);
  2185. end
  2186. end
  2187. end
  2188. SlashCmdList["DUMP"] = function(msg)
  2189. if (not IsKioskModeEnabled() and not ScriptsDisallowedForBeta()) then
  2190. if ( not AreDangerousScriptsAllowed() ) then
  2191. StaticPopup_Show("DANGEROUS_SCRIPTS_WARNING");
  2192. return;
  2193. end
  2194. UIParentLoadAddOn("Blizzard_DebugTools");
  2195. DevTools_DumpCommand(msg);
  2196. end
  2197. end
  2198. SlashCmdList["RELOAD"] = function(msg)
  2199. ReloadUI();
  2200. end
  2201. SlashCmdList["WARGAME"] = function(msg)
  2202. -- Parameters are (playername, area, isTournamentMode). Since the player name can be multiple words,
  2203. -- we pass in theses parameters as a whitespace delimited string and let the C side tokenize it
  2204. StartWarGameByName(msg);
  2205. end
  2206. SlashCmdList["SPECTATOR_WARGAME"] = function(msg)
  2207. local target1, target2, size, area, isTournamentMode = strmatch(msg, "^([^%s]+)%s+([^%s]+)%s+([^%s]+)%s*([^%s]*)%s*([^%s]*)")
  2208. if (not target1 or not target2 or not size) then
  2209. return;
  2210. end
  2211. local bnetIDGameAccount1 = BNet_GetBNetIDAccountFromCharacterName(target1) or BNet_GetBNetIDAccount(target1);
  2212. if not bnetIDGameAccount1 then
  2213. ConsolePrint("Failed to find StartSpectatorWarGame target1:", target1);
  2214. end
  2215. local bnetIDGameAccount2 = BNet_GetBNetIDAccountFromCharacterName(target2) or BNet_GetBNetIDAccount(target2);
  2216. if not bnetIDGameAccount2 then
  2217. ConsolePrint("Failed to find StartSpectatorWarGame target2:", target2);
  2218. end
  2219. if (area == "" or area == "nil" or area == "0") then area = nil end
  2220. StartSpectatorWarGame(bnetIDGameAccount1 or target1, bnetIDGameAccount2 or target2, size, area, ValueToBoolean(isTournamentMode));
  2221. end
  2222. SlashCmdList["GUILDFINDER"] = function(msg)
  2223. if ( GameLimitedMode_IsActive() ) then
  2224. UIErrorsFrame:AddMessage(ERR_RESTRICTED_ACCOUNT_TRIAL, 1.0, 0.1, 0.1, 1.0);
  2225. else
  2226. ToggleGuildFinder();
  2227. end
  2228. end
  2229. SlashCmdList["TARGET_MARKER"] = function(msg)
  2230. local marker, target = SecureCmdOptionParse(msg);
  2231. if ( not target ) then
  2232. target = "target";
  2233. end
  2234. if ( tonumber(marker) ) then
  2235. SetRaidTarget(target, tonumber(marker)); --Using /tm 0 will clear the target marker.
  2236. end
  2237. end
  2238. SlashCmdList["OPEN_LOOT_HISTORY"] = function(msg)
  2239. ToggleLootHistoryFrame();
  2240. end
  2241. SlashCmdList["RAIDFINDER"] = function(msg)
  2242. PVEFrame_ToggleFrame("GroupFinderFrame", RaidFinderFrame);
  2243. end
  2244. SlashCmdList["SHARE"] = function(msg)
  2245. -- Allow if any social platforms are enabled (currently only Twitter)
  2246. if (C_Social.IsSocialEnabled()) then
  2247. SocialFrame_LoadUI();
  2248. Social_ToggleShow(msg);
  2249. end
  2250. end
  2251. SlashCmdList["API"] = function(msg)
  2252. APIDocumentation_LoadUI();
  2253. APIDocumentation:HandleSlashCommand(msg);
  2254. end
  2255. SlashCmdList["COMMENTATOR_OVERRIDE"] = function(msg)
  2256. if not IsAddOnLoaded("Blizzard_Commentator") then
  2257. return;
  2258. end
  2259. local originalName, overrideName = msg:match("^(%S-)%s+(.+)");
  2260. if not originalName or not overrideName then
  2261. DEFAULT_CHAT_FRAME:AddMessage(ERROR_SLASH_COMMENTATOROVERRIDE, YELLOW_FONT_COLOR.r, YELLOW_FONT_COLOR.g, YELLOW_FONT_COLOR.b);
  2262. DEFAULT_CHAT_FRAME:AddMessage(ERROR_SLASH_COMMENTATOROVERRIDE_EXAMPLE, YELLOW_FONT_COLOR.r, YELLOW_FONT_COLOR.g, YELLOW_FONT_COLOR.b);
  2263. return;
  2264. end
  2265. originalName = originalName:sub(1, 1):upper() .. originalName:sub(2, -1);
  2266. DEFAULT_CHAT_FRAME:AddMessage((SLASH_COMMENTATOROVERRIDE_SUCCESS):format(originalName, overrideName), YELLOW_FONT_COLOR.r, YELLOW_FONT_COLOR.g, YELLOW_FONT_COLOR.b);
  2267. C_Commentator.AddPlayerOverrideName(originalName, overrideName);
  2268. -- Also add character name without the realm if we got CharacterName-Realm.
  2269. -- Prepend possible realm separators with % so they are matched literally
  2270. local realmSeparateMatchList = string.gsub(REALM_SEPARATORS, ".", "%%%1");
  2271. local characterName = string.match(originalName, "(..-)["..realmSeparateMatchList.."].");
  2272. if characterName and characterName ~= originalName then
  2273. DEFAULT_CHAT_FRAME:AddMessage((SLASH_COMMENTATOROVERRIDE_SUCCESS):format(characterName, overrideName), YELLOW_FONT_COLOR.r, YELLOW_FONT_COLOR.g, YELLOW_FONT_COLOR.b);
  2274. C_Commentator.AddPlayerOverrideName(characterName, overrideName);
  2275. end
  2276. end
  2277. SlashCmdList["COMMENTATOR_NAMETEAM"] = function(msg)
  2278. if not IsAddOnLoaded("Blizzard_Commentator") then
  2279. return;
  2280. end
  2281. local teamIndex, teamName = msg:match("^(%d+) (.+)");
  2282. teamIndex = tonumber(teamIndex);
  2283. if not teamIndex or not teamName then
  2284. DEFAULT_CHAT_FRAME:AddMessage(ERROR_SLASH_COMMENTATOR_NAMETEAM, YELLOW_FONT_COLOR.r, YELLOW_FONT_COLOR.g, YELLOW_FONT_COLOR.b);
  2285. DEFAULT_CHAT_FRAME:AddMessage(ERROR_SLASH_COMMENTATOR_NAMETEAM_EXAMPLE, YELLOW_FONT_COLOR.r, YELLOW_FONT_COLOR.g, YELLOW_FONT_COLOR.b);
  2286. return;
  2287. end
  2288. if not C_Commentator.IsSpectating() then
  2289. DEFAULT_CHAT_FRAME:AddMessage(CONTEXT_ERROR_SLASH_COMMENTATOR_NAMETEAM, YELLOW_FONT_COLOR.r, YELLOW_FONT_COLOR.g, YELLOW_FONT_COLOR.b);
  2290. return;
  2291. else
  2292. DEFAULT_CHAT_FRAME:AddMessage((SLASH_COMMENTATOR_NAMETEAM_SUCCESS):format(teamIndex, teamName), YELLOW_FONT_COLOR.r, YELLOW_FONT_COLOR.g, YELLOW_FONT_COLOR.b);
  2293. end
  2294. CommentatorTeamDisplay:UpdateTeamName(teamIndex, teamName);
  2295. end
  2296. SlashCmdList["COMMENTATOR_ASSIGNPLAYER"] = function(msg)
  2297. if not IsAddOnLoaded("Blizzard_Commentator") then
  2298. return;
  2299. end
  2300. local playerName, teamName = msg:match("^(%S-)%s+(.+)");
  2301. if not playerName or not teamName then
  2302. DEFAULT_CHAT_FRAME:AddMessage(ERROR_SLASH_COMMENTATOR_ASSIGNPLAYER, YELLOW_FONT_COLOR.r, YELLOW_FONT_COLOR.g, YELLOW_FONT_COLOR.b);
  2303. DEFAULT_CHAT_FRAME:AddMessage(ERROR_SLASH_COMMENTATOR_ASSIGNPLAYER_EXAMPLE, YELLOW_FONT_COLOR.r, YELLOW_FONT_COLOR.g, YELLOW_FONT_COLOR.b);
  2304. return;
  2305. end
  2306. DEFAULT_CHAT_FRAME:AddMessage((SLASH_COMMENTATOR_ASSIGNPLAYER_SUCCESS):format(playerName, teamName), YELLOW_FONT_COLOR.r, YELLOW_FONT_COLOR.g, YELLOW_FONT_COLOR.b);
  2307. CommentatorTeamDisplay:AssignPlayerToTeam(playerName, teamName);
  2308. end
  2309. SlashCmdList["RESET_COMMENTATOR_SETTINGS"] = function(msg)
  2310. if not IsAddOnLoaded("Blizzard_Commentator") then
  2311. return;
  2312. end
  2313. PvPCommentator:SetDefaultCommentatorSettings();
  2314. end
  2315. SlashCmdList["VOICECHAT"] = function(msg)
  2316. if msg == "" then
  2317. local info = ChatTypeInfo["SYSTEM"];
  2318. DEFAULT_CHAT_FRAME:AddMessage(VOICE_COMMAND_SYNTAX, info.r, info.g, info.b, info.id);
  2319. return;
  2320. end
  2321. local name = msg;
  2322. local lowerName = string.lower(name);
  2323. if lowerName == string.lower(VOICE_LEAVE_COMMAND) then
  2324. local channelID = C_VoiceChat.GetActiveChannelID();
  2325. if channelID then
  2326. C_VoiceChat.DeactivateChannel(channelID);
  2327. end
  2328. return;
  2329. end
  2330. local channelType;
  2331. local communityID;
  2332. local streamID;
  2333. if lowerName == string.lower(PARTY) then
  2334. channelType = Enum.ChatChannelType.Private_Party;
  2335. elseif lowerName == string.lower(INSTANCE) then
  2336. channelType = Enum.ChatChannelType.Public_Party;
  2337. elseif lowerName == string.lower(GUILD) then
  2338. communityID, streamID = CommunitiesUtil.FindGuildStreamByType(Enum.ClubStreamType.Guild);
  2339. elseif lowerName == string.lower(OFFICER) then
  2340. communityID, streamID = CommunitiesUtil.FindGuildStreamByType(Enum.ClubStreamType.Officer);
  2341. else
  2342. local communityName, streamName = string.split(":", name);
  2343. communityID, streamID = CommunitiesUtil.FindCommunityAndStreamByName(communityName, streamName);
  2344. end
  2345. if channelType then
  2346. if channelType ~= C_VoiceChat.GetActiveChannelType() then
  2347. local activate = true;
  2348. ChannelFrame:TryJoinVoiceChannelByType(channelType, activate);
  2349. end
  2350. elseif communityID and streamID then
  2351. local activeChannelID = C_VoiceChat.GetActiveChannelID();
  2352. local communityStreamChannel = C_VoiceChat.GetChannelForCommunityStream(communityID, streamID);
  2353. local communityStreamChannelID = communityStreamChannel and communityStreamChannel.channelID;
  2354. if not activeChannelID or activeChannelID ~= communityStreamChannelID then
  2355. ChannelFrame:TryJoinCommunityStreamChannel(communityID, streamID);
  2356. end
  2357. end
  2358. end
  2359. SlashCmdList["COMMUNITY"] = function(msg)
  2360. if msg == "" then
  2361. local info = ChatTypeInfo["SYSTEM"];
  2362. DEFAULT_CHAT_FRAME:AddMessage(COMMUNITY_COMMAND_SYNTAX, info.r, info.g, info.b, info.id);
  2363. return;
  2364. end
  2365. local command, clubType = string.split(" ", string.lower(msg));
  2366. local loadCommunity = function()
  2367. if not CommunitiesFrame or not CommunitiesFrame:IsShown() then
  2368. Communities_LoadUI();
  2369. ToggleCommunitiesFrame();
  2370. end
  2371. end
  2372. if command == string.lower(COMMUNITY_COMMAND_JOIN) then
  2373. loadCommunity();
  2374. AddCommunitiesFlow_Toggle()
  2375. elseif command == string.lower(COMMUNITY_COMMAND_CREATE) then
  2376. if clubType == string.lower(COMMUNITY_COMMAND_CHARACTER) then
  2377. loadCommunity();
  2378. CommunitiesCreateCommunityDialog();
  2379. elseif clubType == string.lower(COMMUNITY_COMMAND_BATTLENET) then
  2380. loadCommunity();
  2381. CommunitiesCreateBattleNetDialog();
  2382. end
  2383. end
  2384. end
  2385. function ChatFrame_SetupListProxyTable(list)
  2386. if ( getmetatable(list) ) then
  2387. return;
  2388. end
  2389. setmetatable(list, { __index = {} });
  2390. end
  2391. function ChatFrame_ImportListToHash(list, hash)
  2392. for k, v in pairs(list) do
  2393. local i = 1;
  2394. local tag = _G["SLASH_"..k..i];
  2395. while(tag) do
  2396. tag = strupper(tag);
  2397. if ( hash ) then
  2398. hash[tag] = v;
  2399. end
  2400. hash_ChatTypeInfoList[tag] = k; --Also need to import it here for all types.
  2401. i = i + 1;
  2402. tag = _G["SLASH_"..k..i];
  2403. end
  2404. --Add the item we removed to the proxy table.
  2405. local proxyTable = getmetatable(list).__index;
  2406. proxyTable[k] = v;
  2407. end
  2408. table.wipe(list);
  2409. end
  2410. function ChatFrame_ImportEmoteTokensToHash()
  2411. -- Hook up per-faction emotes before we build the emote list hash.
  2412. local factionGroup = UnitFactionGroup("player");
  2413. if ( factionGroup == "Alliance" ) then
  2414. TextEmoteSpeechList[#TextEmoteSpeechList + 1] = "FORTHEALLIANCE";
  2415. elseif ( factionGroup == "Horde" ) then
  2416. TextEmoteSpeechList[#TextEmoteSpeechList + 1] = "FORTHEHORDE";
  2417. end
  2418. local i = 1;
  2419. local j = 1;
  2420. local cmdString = _G["EMOTE"..i.."_CMD"..j];
  2421. while ( i <= MAXEMOTEINDEX ) do
  2422. local token = _G["EMOTE"..i.."_TOKEN"];
  2423. -- if the code in here changes - change the corresponding code above
  2424. if ( token and cmdString) then
  2425. hash_EmoteTokenList[strupper(cmdString)] = token; -- add to hash
  2426. end
  2427. j = j + 1;
  2428. cmdString = _G["EMOTE"..i.."_CMD"..j];
  2429. if ( not cmdString ) then
  2430. i = i + 1;
  2431. j = 1;
  2432. cmdString = _G["EMOTE"..i.."_CMD"..j];
  2433. end
  2434. end
  2435. end
  2436. function ChatFrame_ImportAllListsToHash()
  2437. ChatFrame_ImportListToHash(SecureCmdList, hash_SecureCmdList);
  2438. ChatFrame_ImportListToHash(SlashCmdList, hash_SlashCmdList);
  2439. ChatFrame_ImportListToHash(ChatTypeInfo);
  2440. end
  2441. ChatFrame_SetupListProxyTable(SecureCmdList);
  2442. ChatFrame_SetupListProxyTable(SlashCmdList);
  2443. ChatFrame_SetupListProxyTable(ChatTypeInfo);
  2444. for index, value in pairs(ChatTypeInfo) do
  2445. value.r = 1.0;
  2446. value.g = 1.0;
  2447. value.b = 1.0;
  2448. value.id = GetChatTypeIndex(index);
  2449. end
  2450. ChatFrame_ImportAllListsToHash();
  2451. ChatFrame_ImportEmoteTokensToHash();
  2452. -- ChatFrame functions
  2453. function ChatFrame_OnLoad(self)
  2454. self:SetTimeVisible(120.0);
  2455. self:SetMaxLines(128);
  2456. self:SetFontObject(ChatFontNormal);
  2457. self:SetIndentedWordWrap(true);
  2458. self:SetJustifyH("LEFT");
  2459. self:RegisterEvent("PLAYER_ENTERING_WORLD");
  2460. self:RegisterEvent("UPDATE_CHAT_COLOR");
  2461. self:RegisterEvent("UPDATE_CHAT_WINDOWS");
  2462. self:RegisterEvent("CHAT_MSG_CHANNEL");
  2463. self:RegisterEvent("CHAT_MSG_COMMUNITIES_CHANNEL");
  2464. self:RegisterEvent("CLUB_REMOVED");
  2465. self:RegisterEvent("UPDATE_INSTANCE_INFO");
  2466. self:RegisterEvent("UPDATE_CHAT_COLOR_NAME_BY_CLASS");
  2467. self:RegisterEvent("VARIABLES_LOADED");
  2468. self:RegisterEvent("CHAT_SERVER_DISCONNECTED");
  2469. self:RegisterEvent("CHAT_SERVER_RECONNECTED");
  2470. self:RegisterEvent("BN_CONNECTED");
  2471. self:RegisterEvent("BN_DISCONNECTED");
  2472. self:RegisterEvent("PLAYER_REPORT_SUBMITTED");
  2473. self:RegisterEvent("NEUTRAL_FACTION_SELECT_RESULT");
  2474. self:RegisterEvent("CHARACTER_UPGRADE_SPELL_TIER_SET");
  2475. self:RegisterEvent("ALTERNATIVE_DEFAULT_LANGUAGE_CHANGED");
  2476. self.tellTimer = GetTime();
  2477. self.channelList = {};
  2478. self.zoneChannelList = {};
  2479. self.messageTypeList = {};
  2480. self.defaultLanguage = GetDefaultLanguage(); --If PLAYER_ENTERING_WORLD hasn't been called yet, this is nil, but it'll be fixed whent he event is fired.
  2481. self.alternativeDefaultLanguage = GetAlternativeDefaultLanguage();
  2482. end
  2483. function ChatFrame_RegisterForMessages(self, ...)
  2484. local messageGroup;
  2485. local index = 1;
  2486. for i=1, select("#", ...) do
  2487. messageGroup = ChatTypeGroup[select(i, ...)];
  2488. if ( messageGroup ) then
  2489. self.messageTypeList[index] = select(i, ...);
  2490. for index, value in pairs(messageGroup) do
  2491. self:RegisterEvent(value);
  2492. end
  2493. index = index + 1;
  2494. end
  2495. end
  2496. end
  2497. function ChatFrame_RegisterForChannels(self, ...)
  2498. local index = 1;
  2499. for i=1, select("#", ...), 2 do
  2500. self.channelList[index], self.zoneChannelList[index] = select(i, ...);
  2501. index = index + 1;
  2502. end
  2503. end
  2504. function ChatFrame_AddMessageGroup(chatFrame, group)
  2505. local info = ChatTypeGroup[group];
  2506. if ( info ) then
  2507. tinsert(chatFrame.messageTypeList, group);
  2508. for index, value in pairs(info) do
  2509. chatFrame:RegisterEvent(value);
  2510. end
  2511. AddChatWindowMessages(chatFrame:GetID(), group);
  2512. end
  2513. end
  2514. function ChatFrame_ContainsMessageGroup(chatFrame, group)
  2515. for i, messageType in pairs(chatFrame.messageTypeList) do
  2516. if group == messageType then
  2517. return true;
  2518. end
  2519. end
  2520. return false;
  2521. end
  2522. function ChatFrame_AddSingleMessageType(chatFrame, messageType)
  2523. local group = ChatTypeGroupInverted[messageType];
  2524. local info = ChatTypeGroup[group];
  2525. if ( info ) then
  2526. if (not tContains(chatFrame.messageTypeList, group)) then
  2527. tinsert(chatFrame.messageTypeList, group);
  2528. end
  2529. for index, value in pairs(info) do
  2530. if (value == messageType) then
  2531. chatFrame:RegisterEvent(value);
  2532. end
  2533. end
  2534. end
  2535. end
  2536. function ChatFrame_RemoveMessageGroup(chatFrame, group)
  2537. local info = ChatTypeGroup[group];
  2538. if ( info ) then
  2539. for index, value in pairs(chatFrame.messageTypeList) do
  2540. if ( strupper(value) == strupper(group) ) then
  2541. chatFrame.messageTypeList[index] = nil;
  2542. end
  2543. end
  2544. for index, value in pairs(info) do
  2545. chatFrame:UnregisterEvent(value);
  2546. end
  2547. RemoveChatWindowMessages(chatFrame:GetID(), group);
  2548. end
  2549. end
  2550. function ChatFrame_RemoveAllMessageGroups(chatFrame)
  2551. for index, value in pairs(chatFrame.messageTypeList) do
  2552. for eventIndex, eventValue in pairs(ChatTypeGroup[value]) do
  2553. chatFrame:UnregisterEvent(eventValue);
  2554. end
  2555. RemoveChatWindowMessages(chatFrame:GetID(), value);
  2556. end
  2557. chatFrame.messageTypeList = {};
  2558. end
  2559. function ChatFrame_ContainsChannel(chatFrame, channel)
  2560. for i, channelName in pairs(chatFrame.channelList) do
  2561. if channel == channelName then
  2562. return true;
  2563. end
  2564. end
  2565. return false;
  2566. end
  2567. function ChatFrame_AddNewCommunitiesChannel(chatFrameIndex, clubId, streamId, setEditBoxToChannel)
  2568. local clubInfo = C_Club.GetClubInfo(clubId);
  2569. if clubInfo then
  2570. C_Club.AddClubStreamChatChannel(clubId, streamId);
  2571. local channelColor = DEFAULT_CHAT_CHANNEL_COLOR;
  2572. local channelName = Chat_GetCommunitiesChannelName(clubId, streamId);
  2573. if clubInfo.clubType == Enum.ClubType.BattleNet then
  2574. channelColor = BATTLENET_FONT_COLOR;
  2575. local channel = Chat_GetCommunitiesChannel(clubId, streamId);
  2576. ChangeChatColor(channel, channelColor:GetRGB());
  2577. end
  2578. local chatFrame = _G["ChatFrame"..chatFrameIndex];
  2579. ChatFrame_AddCommunitiesChannel(chatFrame, channelName, channelColor, setEditBoxToChannel);
  2580. end
  2581. end
  2582. function ChatFrame_AddCommunitiesChannel(chatFrame, channelName, channelColor, setEditBoxToChannel)
  2583. local channelIndex = ChatFrame_AddChannel(chatFrame, channelName);
  2584. chatFrame:AddMessage(COMMUNITIES_CHANNEL_ADDED_TO_CHAT_WINDOW:format(channelIndex, ChatFrame_ResolveChannelName(channelName)), channelColor:GetRGB());
  2585. if setEditBoxToChannel then
  2586. chatFrame.editBox:SetAttribute("channelTarget", channelIndex);
  2587. chatFrame.editBox:SetAttribute("chatType", "CHANNEL");
  2588. chatFrame.editBox:SetAttribute("stickyType", "CHANNEL");
  2589. ChatEdit_UpdateHeader(chatFrame.editBox);
  2590. end
  2591. end
  2592. function ChatFrame_CanAddChannel()
  2593. return C_ChatInfo.GetNumActiveChannels() < MAX_WOW_CHAT_CHANNELS;
  2594. end
  2595. function ChatFrame_AddChannel(chatFrame, channel)
  2596. local channelIndex = nil;
  2597. local zoneChannel = AddChatWindowChannel(chatFrame:GetID(), channel);
  2598. if ( zoneChannel ) then
  2599. local i = 1;
  2600. while ( chatFrame.channelList[i] ) do
  2601. i = i + 1;
  2602. end
  2603. chatFrame.channelList[i] = channel;
  2604. chatFrame.zoneChannelList[i] = zoneChannel;
  2605. local localId = GetChannelName(channel);
  2606. channelIndex = localId;
  2607. end
  2608. return channelIndex;
  2609. end
  2610. function ChatFrame_GetCommunitiesChannelLocalID(clubId, streamId)
  2611. local channelName = Chat_GetCommunitiesChannelName(clubId, streamId);
  2612. local localID = GetChannelName(channelName);
  2613. return localID;
  2614. end
  2615. function ChatFrame_RemoveCommunitiesChannel(chatFrame, clubId, streamId, omitMessage)
  2616. local channelName = Chat_GetCommunitiesChannelName(clubId, streamId);
  2617. local channelIndex = ChatFrame_RemoveChannel(chatFrame, channelName);
  2618. if not omitMessage then
  2619. local r, g, b = Chat_GetCommunitiesChannelColor(clubId, streamId);
  2620. chatFrame:AddMessage(COMMUNITIES_CHANNEL_REMOVED_FROM_CHAT_WINDOW:format(channelIndex, ChatFrame_ResolveChannelName(channelName)), r, g, b);
  2621. end
  2622. end
  2623. function ChatFrame_RemoveChannel(chatFrame, channel)
  2624. for index, value in pairs(chatFrame.channelList) do
  2625. if ( strupper(channel) == strupper(value) ) then
  2626. chatFrame.channelList[index] = nil;
  2627. chatFrame.zoneChannelList[index] = nil;
  2628. end
  2629. end
  2630. local localId = GetChannelName(channel);
  2631. RemoveChatWindowChannel(chatFrame:GetID(), channel);
  2632. return localId;
  2633. end
  2634. function ChatFrame_RemoveAllChannels(chatFrame)
  2635. for index, value in pairs(chatFrame.channelList) do
  2636. RemoveChatWindowChannel(chatFrame:GetID(), value);
  2637. end
  2638. chatFrame.channelList = {};
  2639. chatFrame.zoneChannelList = {};
  2640. end
  2641. function ChatFrame_AddPrivateMessageTarget(chatFrame, chatTarget)
  2642. ChatFrame_RemoveExcludePrivateMessageTarget(chatFrame, chatTarget);
  2643. if ( chatFrame.privateMessageList ) then
  2644. chatFrame.privateMessageList[strlower(chatTarget)] = true;
  2645. else
  2646. chatFrame.privateMessageList = { [strlower(chatTarget)] = true };
  2647. end
  2648. end
  2649. function ChatFrame_RemovePrivateMessageTarget(chatFrame, chatTarget)
  2650. if ( chatFrame.privateMessageList ) then
  2651. chatFrame.privateMessageList[strlower(chatTarget)] = nil;
  2652. end
  2653. end
  2654. function ChatFrame_ExcludePrivateMessageTarget(chatFrame, chatTarget)
  2655. ChatFrame_RemovePrivateMessageTarget(chatFrame, chatTarget);
  2656. if ( chatFrame.excludePrivateMessageList ) then
  2657. chatFrame.excludePrivateMessageList[strlower(chatTarget)] = true;
  2658. else
  2659. chatFrame.excludePrivateMessageList = { [strlower(chatTarget)] = true };
  2660. end
  2661. end
  2662. function ChatFrame_RemoveExcludePrivateMessageTarget(chatFrame, chatTarget)
  2663. if ( chatFrame.excludePrivateMessageList ) then
  2664. chatFrame.excludePrivateMessageList[strlower(chatTarget)] = nil;
  2665. end
  2666. end
  2667. function ChatFrame_ReceiveAllPrivateMessages(chatFrame)
  2668. chatFrame.privateMessageList = nil;
  2669. chatFrame.excludePrivateMessageList = nil;
  2670. end
  2671. -- Set up a private editbox to handle macro execution
  2672. do
  2673. local function GetDefaultChatEditBox(field)
  2674. return DEFAULT_CHAT_FRAME.editBox;
  2675. end
  2676. local editbox = CreateFrame("Editbox", "MacroEditBox");
  2677. editbox:RegisterEvent("EXECUTE_CHAT_LINE");
  2678. editbox:SetScript("OnEvent",
  2679. function(self,event,line)
  2680. if ( event == "EXECUTE_CHAT_LINE" ) then
  2681. local defaulteditbox = securecall(GetDefaultChatEditBox);
  2682. self:SetAttribute("chatType", defaulteditbox:GetAttribute("chatType"));
  2683. self:SetAttribute("tellTarget", defaulteditbox:GetAttribute("tellTarget"));
  2684. self:SetAttribute("channelTarget", ChatEdit_GetChannelTarget(defaulteditbox));
  2685. self:SetText(line);
  2686. ChatEdit_SendText(self);
  2687. end
  2688. end
  2689. );
  2690. editbox:Hide();
  2691. end
  2692. function ChatFrame_OnEvent(self, event, ...)
  2693. if ( ChatFrame_ConfigEventHandler(self, event, ...) ) then
  2694. return;
  2695. end
  2696. if ( ChatFrame_SystemEventHandler(self, event, ...) ) then
  2697. return
  2698. end
  2699. if ( ChatFrame_MessageEventHandler(self, event, ...) ) then
  2700. return
  2701. end
  2702. end
  2703. function ChatFrame_UpdateColorByID(self, chatTypeID, r, g, b)
  2704. local function TransformColorByID(text, messageR, messageG, messageB, messageChatTypeID, messageAccessID, lineID)
  2705. if messageChatTypeID == chatTypeID then
  2706. return true, r, g, b;
  2707. end
  2708. return false;
  2709. end
  2710. self:AdjustMessageColors(TransformColorByID);
  2711. end
  2712. function ChatFrame_GetDefaultChatTarget(chatFrame)
  2713. if #chatFrame.messageTypeList == 1 and #chatFrame.channelList == 0 then
  2714. return chatFrame.messageTypeList[1], nil;
  2715. elseif #chatFrame.messageTypeList == 0 and #chatFrame.channelList == 1 then
  2716. local channelName = chatFrame.channelList[1];
  2717. local localID = GetChannelName(channelName);
  2718. if localID ~= 0 then
  2719. return "CHANNEL", localID;
  2720. else
  2721. return "CHANNEL", channelName;
  2722. end
  2723. end
  2724. return nil;
  2725. end
  2726. function ChatFrame_ConfigEventHandler(self, event, ...)
  2727. if ( event == "PLAYER_ENTERING_WORLD" ) then
  2728. self.defaultLanguage = GetDefaultLanguage();
  2729. self.alternativeDefaultLanguage = GetAlternativeDefaultLanguage();
  2730. return true;
  2731. elseif ( event == "NEUTRAL_FACTION_SELECT_RESULT" ) then
  2732. self.defaultLanguage = GetDefaultLanguage();
  2733. self.alternativeDefaultLanguage = GetAlternativeDefaultLanguage();
  2734. return true;
  2735. elseif ( event == "ALTERNATIVE_DEFAULT_LANGUAGE_CHANGED" ) then
  2736. self.alternativeDefaultLanguage = GetAlternativeDefaultLanguage();
  2737. return true;
  2738. elseif ( event == "UPDATE_CHAT_WINDOWS" ) then
  2739. local name, fontSize, r, g, b, a, shown, locked = FCF_GetChatWindowInfo(self:GetID());
  2740. if ( fontSize > 0 ) then
  2741. local fontFile, unused, fontFlags = self:GetFont();
  2742. self:SetFont(fontFile, fontSize, fontFlags);
  2743. end
  2744. if ( shown and not self.minimized ) then
  2745. self:Show();
  2746. end
  2747. -- Do more stuff!!!
  2748. ChatFrame_RegisterForMessages(self, GetChatWindowMessages(self:GetID()));
  2749. ChatFrame_RegisterForChannels(self, GetChatWindowChannels(self:GetID()));
  2750. local defaultChatType, defaultChannelTarget = ChatFrame_GetDefaultChatTarget(self);
  2751. if defaultChatType then
  2752. local editBox = self.editBox;
  2753. editBox:SetAttribute("chatType", defaultChatType);
  2754. editBox:SetAttribute("stickyType", defaultChatType);
  2755. editBox:SetAttribute("channelTarget", defaultChannelTarget);
  2756. ChatEdit_UpdateHeader(editBox);
  2757. end
  2758. -- GMOTD may have arrived before this frame registered for the event
  2759. if ( not self.checkedGMOTD and self:IsEventRegistered("GUILD_MOTD") ) then
  2760. self.checkedGMOTD = true;
  2761. ChatFrame_DisplayGMOTD(self, GetGuildRosterMOTD());
  2762. end
  2763. return true;
  2764. end
  2765. local arg1, arg2, arg3, arg4 = ...;
  2766. if ( event == "UPDATE_CHAT_COLOR" ) then
  2767. local info = ChatTypeInfo[strupper(arg1)];
  2768. if ( info ) then
  2769. info.r = arg2;
  2770. info.g = arg3;
  2771. info.b = arg4;
  2772. ChatFrame_UpdateColorByID(self, info.id, info.r, info.g, info.b);
  2773. if ( strupper(arg1) == "WHISPER" ) then
  2774. info = ChatTypeInfo["REPLY"];
  2775. if ( info ) then
  2776. info.r = arg2;
  2777. info.g = arg3;
  2778. info.b = arg4;
  2779. ChatFrame_UpdateColorByID(self, info.id, info.r, info.g, info.b);
  2780. end
  2781. end
  2782. end
  2783. return true;
  2784. elseif ( event == "UPDATE_CHAT_COLOR_NAME_BY_CLASS" ) then
  2785. local info = ChatTypeInfo[strupper(arg1)];
  2786. if ( info ) then
  2787. info.colorNameByClass = arg2;
  2788. if ( strupper(arg1) == "WHISPER" ) then
  2789. info = ChatTypeInfo["REPLY"];
  2790. if ( info ) then
  2791. info.colorNameByClass = arg2;
  2792. end
  2793. end
  2794. end
  2795. return true;
  2796. elseif ( event == "VARIABLES_LOADED" ) then
  2797. if ( GetCVarBool("chatMouseScroll") ) then
  2798. self:SetScript("OnMouseWheel", FloatingChatFrame_OnMouseScroll);
  2799. self:EnableMouseWheel(true);
  2800. end
  2801. self:UnregisterEvent("VARIABLES_LOADED");
  2802. return true;
  2803. end
  2804. end
  2805. function ChatFrame_SystemEventHandler(self, event, ...)
  2806. if ( event == "TIME_PLAYED_MSG" ) then
  2807. local arg1, arg2 = ...;
  2808. ChatFrame_DisplayTimePlayed(self, arg1, arg2);
  2809. return true;
  2810. elseif ( event == "PLAYER_LEVEL_UP" ) then
  2811. local level, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 = ...;
  2812. LevelUpDisplay_ChatPrint(self, level, LEVEL_UP_TYPE_CHARACTER)
  2813. return true;
  2814. elseif ( event == "QUEST_TURNED_IN" ) then
  2815. local questID, xp, money = ...;
  2816. if questID == WORLD_QUESTS_AVAILABLE_QUEST_ID then
  2817. LevelUpDisplay_ChatPrint(self, nil, TOAST_WORLD_QUESTS_UNLOCKED)
  2818. end
  2819. return true;
  2820. elseif (event == "UNIT_LEVEL" ) then
  2821. local arg1 = ...;
  2822. if (arg1 == "pet" and UnitName("pet") ~= UNKNOWNOBJECT) then
  2823. LevelUpDisplay_ChatPrint(self, UnitLevel("pet"), LEVEL_UP_TYPE_PET);
  2824. end
  2825. elseif ( event == "CHARACTER_UPGRADE_SPELL_TIER_SET" ) then
  2826. local tierIndex = ...;
  2827. if (tierIndex > 0) then
  2828. LevelUpDisplay_ChatPrint(self, tierIndex, LEVEL_UP_TYPE_SPELL_BUCKET);
  2829. end
  2830. return true;
  2831. elseif ( event == "CHARACTER_POINTS_CHANGED" ) then
  2832. local arg1 = ...;
  2833. local info = ChatTypeInfo["SYSTEM"];
  2834. return true;
  2835. elseif ( event == "GUILD_MOTD" ) then
  2836. ChatFrame_DisplayGMOTD(self, ...);
  2837. return true;
  2838. elseif ( event == "UPDATE_INSTANCE_INFO" ) then
  2839. if ( RaidFrame.hasRaidInfo ) then
  2840. local info = ChatTypeInfo["SYSTEM"];
  2841. if ( RaidFrame.slashCommand and GetNumSavedInstances() + GetNumSavedWorldBosses() == 0 and self == DEFAULT_CHAT_FRAME) then
  2842. self:AddMessage(NO_RAID_INSTANCES_SAVED, info.r, info.g, info.b, info.id);
  2843. RaidFrame.slashCommand = nil;
  2844. end
  2845. end
  2846. return true;
  2847. elseif ( event == "CHAT_SERVER_DISCONNECTED" ) then
  2848. local info = ChatTypeInfo["SYSTEM"];
  2849. local isInitialMessage = ...;
  2850. self:AddMessage(CHAT_SERVER_DISCONNECTED_MESSAGE, info.r, info.g, info.b, info.id);
  2851. return true;
  2852. elseif ( event == "CHAT_SERVER_RECONNECTED" ) then
  2853. local info = ChatTypeInfo["SYSTEM"];
  2854. self:AddMessage(CHAT_SERVER_RECONNECTED_MESSAGE, info.r, info.g, info.b, info.id);
  2855. return true;
  2856. elseif ( event == "BN_CONNECTED" ) then
  2857. local suppressNotification = ...;
  2858. local info = ChatTypeInfo["SYSTEM"];
  2859. if not suppressNotification then
  2860. self:AddMessage(BN_CHAT_CONNECTED, info.r, info.g, info.b, info.id);
  2861. end
  2862. elseif ( event == "BN_DISCONNECTED" ) then
  2863. local _, suppressNotification = ...;
  2864. local info = ChatTypeInfo["SYSTEM"];
  2865. if not suppressNotification then
  2866. self:AddMessage(BN_CHAT_DISCONNECTED, info.r, info.g, info.b, info.id);
  2867. end
  2868. elseif ( event == "PLAYER_REPORT_SUBMITTED" ) then
  2869. local guid = ...;
  2870. FCF_RemoveAllMessagesFromChanSender(self, guid);
  2871. return true;
  2872. elseif ( event == "CLUB_REMOVED" ) then
  2873. local clubId = ...;
  2874. local streamIDs = C_ChatInfo.GetClubStreamIDs(clubId);
  2875. for k, streamID in pairs(streamIDs) do
  2876. local channelName = Chat_GetCommunitiesChannelName(clubId, streamID);
  2877. for i = 1, FCF_GetNumActiveChatFrames() do
  2878. local chatWindow = _G["ChatFrame"..i];
  2879. if ChatFrame_ContainsChannel(chatWindow, channelName) then
  2880. local omitMessage = true;
  2881. ChatFrame_RemoveCommunitiesChannel(chatWindow, clubId, streamID, omitMessage);
  2882. end
  2883. end
  2884. end
  2885. end
  2886. end
  2887. function GetColoredName(event, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12)
  2888. local chatType = strsub(event, 10);
  2889. if ( strsub(chatType, 1, 7) == "WHISPER" ) then
  2890. chatType = "WHISPER";
  2891. end
  2892. if ( strsub(chatType, 1, 7) == "CHANNEL" ) then
  2893. chatType = "CHANNEL"..arg8;
  2894. end
  2895. local info = ChatTypeInfo[chatType];
  2896. --ambiguate guild chat names
  2897. if (chatType == "GUILD") then
  2898. arg2 = Ambiguate(arg2, "guild")
  2899. else
  2900. arg2 = Ambiguate(arg2, "none")
  2901. end
  2902. if ( arg12 and info and Chat_ShouldColorChatByClass(info) ) then
  2903. local localizedClass, englishClass, localizedRace, englishRace, sex = GetPlayerInfoByGUID(arg12)
  2904. if ( englishClass ) then
  2905. local classColorTable = RAID_CLASS_COLORS[englishClass];
  2906. if ( not classColorTable ) then
  2907. return arg2;
  2908. end
  2909. return string.format("\124cff%.2x%.2x%.2x", classColorTable.r*255, classColorTable.g*255, classColorTable.b*255)..arg2.."\124r"
  2910. end
  2911. end
  2912. return arg2;
  2913. end
  2914. function RemoveExtraSpaces(str)
  2915. return string.gsub(str, " +", " "); --Replace all instances of 5+ spaces with only 4 spaces.
  2916. end
  2917. function RemoveNewlines(str)
  2918. return string.gsub(str, "\n", "");
  2919. end
  2920. function ChatFrame_DisplayGMOTD(frame, gmotd)
  2921. if ( gmotd and (gmotd ~= "") ) then
  2922. local info = ChatTypeInfo["GUILD"];
  2923. local string = format(GUILD_MOTD_TEMPLATE, gmotd);
  2924. frame:AddMessage(string, info.r, info.g, info.b, info.id);
  2925. end
  2926. end
  2927. function ChatFrame_GetMobileEmbeddedTexture(r, g, b)
  2928. r, g, b = floor(r * 255), floor(g * 255), floor(b * 255);
  2929. return format("|TInterface\\ChatFrame\\UI-ChatIcon-ArmoryChat:14:14:0:0:16:16:0:16:0:16:%d:%d:%d|t", r, g, b);
  2930. end
  2931. function ChatFrame_CanChatGroupPerformExpressionExpansion(chatGroup)
  2932. if chatGroup == "RAID" then
  2933. return true;
  2934. end
  2935. if chatGroup == "INSTANCE_CHAT" then
  2936. return IsInRaid(LE_PARTY_CATEGORY_INSTANCE);
  2937. end
  2938. return false;
  2939. end
  2940. function ChatFrame_MessageEventHandler(self, event, ...)
  2941. if ( strsub(event, 1, 8) == "CHAT_MSG" ) then
  2942. local arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16, arg17 = ...;
  2943. if (arg16) then
  2944. -- hiding sender in letterbox: do NOT even show in chat window (only shows in cinematic frame)
  2945. return true;
  2946. end
  2947. local type = strsub(event, 10);
  2948. local info = ChatTypeInfo[type];
  2949. local filter = false;
  2950. if ( chatFilters[event] ) then
  2951. local newarg1, newarg2, newarg3, newarg4, newarg5, newarg6, newarg7, newarg8, newarg9, newarg10, newarg11, newarg12, newarg13, newarg14;
  2952. for _, filterFunc in next, chatFilters[event] do
  2953. filter, newarg1, newarg2, newarg3, newarg4, newarg5, newarg6, newarg7, newarg8, newarg9, newarg10, newarg11, newarg12, newarg13, newarg14 = filterFunc(self, event, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14);
  2954. if ( filter ) then
  2955. return true;
  2956. elseif ( newarg1 ) then
  2957. arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14 = newarg1, newarg2, newarg3, newarg4, newarg5, newarg6, newarg7, newarg8, newarg9, newarg10, newarg11, newarg12, newarg13, newarg14;
  2958. end
  2959. end
  2960. end
  2961. local coloredName = GetColoredName(event, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14);
  2962. local channelLength = strlen(arg4);
  2963. local infoType = type;
  2964. if ( (type == "COMMUNITIES_CHANNEL") or ((strsub(type, 1, 7) == "CHANNEL") and (type ~= "CHANNEL_LIST") and ((arg1 ~= "INVITE") or (type ~= "CHANNEL_NOTICE_USER"))) ) then
  2965. if ( arg1 == "WRONG_PASSWORD" ) then
  2966. local staticPopup = _G[StaticPopup_Visible("CHAT_CHANNEL_PASSWORD") or ""];
  2967. if ( staticPopup and strupper(staticPopup.data) == strupper(arg9) ) then
  2968. -- Don't display invalid password messages if we're going to prompt for a password (bug 102312)
  2969. return;
  2970. end
  2971. end
  2972. local found = 0;
  2973. for index, value in pairs(self.channelList) do
  2974. if ( channelLength > strlen(value) ) then
  2975. -- arg9 is the channel name without the number in front...
  2976. if ( ((arg7 > 0) and (self.zoneChannelList[index] == arg7)) or (strupper(value) == strupper(arg9)) ) then
  2977. found = 1;
  2978. infoType = "CHANNEL"..arg8;
  2979. info = ChatTypeInfo[infoType];
  2980. if ( (type == "CHANNEL_NOTICE") and (arg1 == "YOU_LEFT") ) then
  2981. self.channelList[index] = nil;
  2982. self.zoneChannelList[index] = nil;
  2983. end
  2984. break;
  2985. end
  2986. end
  2987. end
  2988. if ( (found == 0) or not info ) then
  2989. return true;
  2990. end
  2991. end
  2992. local chatGroup = Chat_GetChatCategory(type);
  2993. local chatTarget;
  2994. if ( chatGroup == "CHANNEL" ) then
  2995. chatTarget = tostring(arg8);
  2996. elseif ( chatGroup == "WHISPER" or chatGroup == "BN_WHISPER" ) then
  2997. if(not(strsub(arg2, 1, 2) == "|K")) then
  2998. chatTarget = strupper(arg2);
  2999. else
  3000. chatTarget = arg2;
  3001. end
  3002. end
  3003. if ( FCFManager_ShouldSuppressMessage(self, chatGroup, chatTarget) ) then
  3004. return true;
  3005. end
  3006. if ( chatGroup == "WHISPER" or chatGroup == "BN_WHISPER" ) then
  3007. if ( self.privateMessageList and not self.privateMessageList[strlower(arg2)] ) then
  3008. return true;
  3009. elseif ( self.excludePrivateMessageList and self.excludePrivateMessageList[strlower(arg2)]
  3010. and ( (chatGroup == "WHISPER" and GetCVar("whisperMode") ~= "popout_and_inline") or (chatGroup == "BN_WHISPER" and GetCVar("whisperMode") ~= "popout_and_inline") ) ) then
  3011. return true;
  3012. end
  3013. end
  3014. if (self.privateMessageList) then
  3015. -- Dedicated BN whisper windows need online/offline messages for only that player
  3016. if ( (chatGroup == "BN_INLINE_TOAST_ALERT" or chatGroup == "BN_WHISPER_PLAYER_OFFLINE") and not self.privateMessageList[strlower(arg2)] ) then
  3017. return true;
  3018. end
  3019. -- HACK to put certain system messages into dedicated whisper windows
  3020. if ( chatGroup == "SYSTEM") then
  3021. local matchFound = false;
  3022. local message = strlower(arg1);
  3023. for playerName, _ in pairs(self.privateMessageList) do
  3024. local playerNotFoundMsg = strlower(format(ERR_CHAT_PLAYER_NOT_FOUND_S, playerName));
  3025. local charOnlineMsg = strlower(format(ERR_FRIEND_ONLINE_SS, playerName, playerName));
  3026. local charOfflineMsg = strlower(format(ERR_FRIEND_OFFLINE_S, playerName));
  3027. if ( message == playerNotFoundMsg or message == charOnlineMsg or message == charOfflineMsg) then
  3028. matchFound = true;
  3029. break;
  3030. end
  3031. end
  3032. if (not matchFound) then
  3033. return true;
  3034. end
  3035. end
  3036. end
  3037. if ( type == "SYSTEM" or type == "SKILL" or type == "CURRENCY" or type == "MONEY" or
  3038. type == "OPENING" or type == "TRADESKILLS" or type == "PET_INFO" or type == "TARGETICONS" or type == "BN_WHISPER_PLAYER_OFFLINE") then
  3039. self:AddMessage(arg1, info.r, info.g, info.b, info.id);
  3040. elseif (type == "LOOT") then
  3041. -- Append [Share] hyperlink if this is a valid social item and you are the looter.
  3042. if (C_Social.IsSocialEnabled() and UnitGUID("player") == arg12) then
  3043. -- Because it is being placed inside another hyperlink (the shareitem link created below), we have to strip off the hyperlink markup
  3044. -- The item link markup will be added back in when the shareitem link is clicked (in ItemRef.lua) and then passed to the social panel
  3045. local itemID, strippedItemLink = GetItemInfoFromHyperlink(arg1);
  3046. if (itemID and C_Social.GetLastItem() == itemID) then
  3047. arg1 = arg1 .. " " .. Social_GetShareItemLink(strippedItemLink, true);
  3048. end
  3049. end
  3050. self:AddMessage(arg1, info.r, info.g, info.b, info.id);
  3051. elseif ( strsub(type,1,7) == "COMBAT_" ) then
  3052. self:AddMessage(arg1, info.r, info.g, info.b, info.id);
  3053. elseif ( strsub(type,1,6) == "SPELL_" ) then
  3054. self:AddMessage(arg1, info.r, info.g, info.b, info.id);
  3055. elseif ( strsub(type,1,10) == "BG_SYSTEM_" ) then
  3056. self:AddMessage(arg1, info.r, info.g, info.b, info.id);
  3057. elseif ( strsub(type,1,11) == "ACHIEVEMENT" ) then
  3058. -- Append [Share] hyperlink
  3059. if (arg12 == UnitGUID("player") and C_Social.IsSocialEnabled()) then
  3060. local achieveID = GetAchievementInfoFromHyperlink(arg1);
  3061. if (achieveID) then
  3062. arg1 = arg1 .. " " .. Social_GetShareAchievementLink(achieveID, true);
  3063. end
  3064. end
  3065. self:AddMessage(arg1:format(GetPlayerLink(arg2, ("[%s]"):format(coloredName))), info.r, info.g, info.b, info.id);
  3066. elseif ( strsub(type,1,18) == "GUILD_ACHIEVEMENT" ) then
  3067. local message = arg1:format(GetPlayerLink(arg2, ("[%s]"):format(coloredName)));
  3068. if (C_Social.IsSocialEnabled()) then
  3069. local achieveID = GetAchievementInfoFromHyperlink(arg1);
  3070. if (achieveID) then
  3071. local isGuildAchievement = select(12, GetAchievementInfo(achieveID));
  3072. if (isGuildAchievement) then
  3073. message = message .. " " .. Social_GetShareAchievementLink(achieveID, true);
  3074. end
  3075. end
  3076. end
  3077. self:AddMessage(message, info.r, info.g, info.b, info.id);
  3078. elseif ( type == "IGNORED" ) then
  3079. self:AddMessage(format(CHAT_IGNORED, arg2), info.r, info.g, info.b, info.id);
  3080. elseif ( type == "FILTERED" ) then
  3081. self:AddMessage(format(CHAT_FILTERED, arg2), info.r, info.g, info.b, info.id);
  3082. elseif ( type == "RESTRICTED" ) then
  3083. self:AddMessage(CHAT_RESTRICTED_TRIAL, info.r, info.g, info.b, info.id);
  3084. elseif ( type == "CHANNEL_LIST") then
  3085. if(channelLength > 0) then
  3086. self:AddMessage(format(_G["CHAT_"..type.."_GET"]..arg1, tonumber(arg8), arg4), info.r, info.g, info.b, info.id);
  3087. else
  3088. self:AddMessage(arg1, info.r, info.g, info.b, info.id);
  3089. end
  3090. elseif (type == "CHANNEL_NOTICE_USER") then
  3091. local globalstring = _G["CHAT_"..arg1.."_NOTICE_BN"];
  3092. if ( not globalstring ) then
  3093. globalstring = _G["CHAT_"..arg1.."_NOTICE"];
  3094. end
  3095. if not globalstring then
  3096. GMError(("Missing global string for %q"):format("CHAT_"..arg1.."_NOTICE_BN"));
  3097. return;
  3098. end
  3099. if(arg5 ~= "") then
  3100. -- TWO users in this notice (E.G. x kicked y)
  3101. self:AddMessage(format(globalstring, arg8, arg4, arg2, arg5), info.r, info.g, info.b, info.id);
  3102. elseif ( arg1 == "INVITE" ) then
  3103. self:AddMessage(format(globalstring, arg4, arg2), info.r, info.g, info.b, info.id);
  3104. else
  3105. self:AddMessage(format(globalstring, arg8, arg4, arg2), info.r, info.g, info.b, info.id);
  3106. end
  3107. if ( arg1 == "INVITE" and GetCVarBool("blockChannelInvites") ) then
  3108. self:AddMessage(CHAT_MSG_BLOCK_CHAT_CHANNEL_INVITE, info.r, info.g, info.b, info.id);
  3109. end
  3110. elseif (type == "CHANNEL_NOTICE") then
  3111. local globalstring;
  3112. if ( arg1 == "TRIAL_RESTRICTED" ) then
  3113. globalstring = CHAT_TRIAL_RESTRICTED_NOTICE_TRIAL;
  3114. else
  3115. globalstring = _G["CHAT_"..arg1.."_NOTICE_BN"];
  3116. if ( not globalstring ) then
  3117. globalstring = _G["CHAT_"..arg1.."_NOTICE"];
  3118. if not globalstring then
  3119. GMError(("Missing global string for %q"):format("CHAT_"..arg1.."_NOTICE"));
  3120. return;
  3121. end
  3122. end
  3123. end
  3124. local accessID = ChatHistory_GetAccessID(Chat_GetChatCategory(type), arg8);
  3125. local typeID = ChatHistory_GetAccessID(infoType, arg8, arg12);
  3126. self:AddMessage(format(globalstring, arg8, ChatFrame_ResolvePrefixedChannelName(arg4)), info.r, info.g, info.b, info.id, accessID, typeID);
  3127. elseif ( type == "BN_INLINE_TOAST_ALERT" ) then
  3128. local globalstring = _G["BN_INLINE_TOAST_"..arg1];
  3129. if not globalstring then
  3130. GMError(("Missing global string for %q"):format("BN_INLINE_TOAST_"..arg1));
  3131. return;
  3132. end
  3133. local message;
  3134. if ( arg1 == "FRIEND_REQUEST" ) then
  3135. message = globalstring;
  3136. elseif ( arg1 == "FRIEND_PENDING" ) then
  3137. message = format(BN_INLINE_TOAST_FRIEND_PENDING, BNGetNumFriendInvites());
  3138. elseif ( arg1 == "FRIEND_REMOVED" or arg1 == "BATTLETAG_FRIEND_REMOVED" ) then
  3139. message = format(globalstring, arg2);
  3140. elseif ( arg1 == "FRIEND_ONLINE" or arg1 == "FRIEND_OFFLINE") then
  3141. local _, accountName, battleTag, _, characterName, _, client = BNGetFriendInfoByID(arg13);
  3142. if (client and client ~= "") then
  3143. local _, _, battleTag = BNGetFriendInfoByID(arg13);
  3144. characterName = BNet_GetValidatedCharacterName(characterName, battleTag, client) or "";
  3145. local characterNameText = BNet_GetClientEmbeddedTexture(client, 14)..characterName;
  3146. local linkDisplayText = ("[%s] (%s)"):format(arg2, characterNameText);
  3147. local playerLink = GetBNPlayerLink(arg2, linkDisplayText, arg13, arg11, Chat_GetChatCategory(type), 0);
  3148. message = format(globalstring, playerLink);
  3149. else
  3150. local linkDisplayText = ("[%s]"):format(arg2);
  3151. local playerLink = GetBNPlayerLink(arg2, linkDisplayText, arg13, arg11, Chat_GetChatCategory(type), 0);
  3152. message = format(globalstring, playerLink);
  3153. end
  3154. else
  3155. local linkDisplayText = ("[%s]"):format(arg2);
  3156. local playerLink = GetBNPlayerLink(arg2, linkDisplayText, arg13, arg11, Chat_GetChatCategory(type), 0);
  3157. message = format(globalstring, playerLink);
  3158. end
  3159. self:AddMessage(message, info.r, info.g, info.b, info.id);
  3160. elseif ( type == "BN_INLINE_TOAST_BROADCAST" ) then
  3161. if ( arg1 ~= "" ) then
  3162. arg1 = RemoveNewlines(RemoveExtraSpaces(arg1));
  3163. local linkDisplayText = ("[%s]"):format(arg2);
  3164. local playerLink = GetBNPlayerLink(arg2, linkDisplayText, arg13, arg11, Chat_GetChatCategory(type), 0);
  3165. self:AddMessage(format(BN_INLINE_TOAST_BROADCAST, playerLink, arg1), info.r, info.g, info.b, info.id);
  3166. end
  3167. elseif ( type == "BN_INLINE_TOAST_BROADCAST_INFORM" ) then
  3168. if ( arg1 ~= "" ) then
  3169. arg1 = RemoveExtraSpaces(arg1);
  3170. self:AddMessage(BN_INLINE_TOAST_BROADCAST_INFORM, info.r, info.g, info.b, info.id);
  3171. end
  3172. else
  3173. local body;
  3174. local _, fontHeight = FCF_GetChatWindowInfo(self:GetID());
  3175. if ( fontHeight == 0 ) then
  3176. --fontHeight will be 0 if it's still at the default (14)
  3177. fontHeight = 14;
  3178. end
  3179. -- Add AFK/DND flags
  3180. local pflag;
  3181. if(arg6 ~= "") then
  3182. if ( arg6 == "GM" ) then
  3183. --If it was a whisper, dispatch it to the GMChat addon.
  3184. if ( type == "WHISPER" ) then
  3185. return;
  3186. end
  3187. --Add Blizzard Icon, this was sent by a GM
  3188. pflag = "|TInterface\\ChatFrame\\UI-ChatIcon-Blizz:12:20:0:0:32:16:4:28:0:16|t ";
  3189. elseif ( arg6 == "DEV" ) then
  3190. --Add Blizzard Icon, this was sent by a Dev
  3191. pflag = "|TInterface\\ChatFrame\\UI-ChatIcon-Blizz:12:20:0:0:32:16:4:28:0:16|t ";
  3192. else
  3193. pflag = _G["CHAT_FLAG_"..arg6];
  3194. end
  3195. else
  3196. pflag = "";
  3197. end
  3198. if ( type == "WHISPER_INFORM" and GMChatFrame_IsGM and GMChatFrame_IsGM(arg2) ) then
  3199. return;
  3200. end
  3201. local showLink = 1;
  3202. if ( strsub(type, 1, 7) == "MONSTER" or strsub(type, 1, 9) == "RAID_BOSS") then
  3203. showLink = nil;
  3204. else
  3205. arg1 = gsub(arg1, "%%", "%%%%");
  3206. end
  3207. -- Search for icon links and replace them with texture links.
  3208. arg1 = C_ChatInfo.ReplaceIconAndGroupExpressions(arg1, arg17, not ChatFrame_CanChatGroupPerformExpressionExpansion(chatGroup)); -- If arg17 is true, don't convert to raid icons
  3209. --Remove groups of many spaces
  3210. arg1 = RemoveExtraSpaces(arg1);
  3211. local playerLink;
  3212. local playerLinkDisplayText = coloredName;
  3213. local relevantDefaultLanguage = self.defaultLanguage;
  3214. if ( (type == "SAY") or (type == "YELL") ) then
  3215. relevantDefaultLanguage = self.alternativeDefaultLanguage;
  3216. end
  3217. local usingDifferentLanguage = (arg3 ~= "") and (arg3 ~= relevantDefaultLanguage);
  3218. local usingEmote = (type == "EMOTE") or (type == "TEXT_EMOTE");
  3219. if ( usingDifferentLanguage or not usingEmote ) then
  3220. playerLinkDisplayText = ("[%s]"):format(coloredName);
  3221. end
  3222. local isCommunityType = type == "COMMUNITIES_CHANNEL";
  3223. local playerName, lineID, bnetIDAccount = arg2, arg11, arg13;
  3224. if ( isCommunityType ) then
  3225. local isBattleNetCommunity = bnetIDAccount ~= nil and bnetIDAccount ~= 0;
  3226. local messageInfo, clubId, streamId, clubType = C_Club.GetInfoFromLastCommunityChatLine();
  3227. if (messageInfo ~= nil) then
  3228. if ( isBattleNetCommunity ) then
  3229. playerLink = GetBNPlayerCommunityLink(playerName, playerLinkDisplayText, bnetIDAccount, clubId, streamId, messageInfo.messageId.epoch, messageInfo.messageId.position);
  3230. else
  3231. playerLink = GetPlayerCommunityLink(playerName, playerLinkDisplayText, clubId, streamId, messageInfo.messageId.epoch, messageInfo.messageId.position);
  3232. end
  3233. else
  3234. playerLink = playerLinkDisplayText;
  3235. end
  3236. else
  3237. if ( type == "BN_WHISPER" or type == "BN_WHISPER_INFORM" ) then
  3238. playerLink = GetBNPlayerLink(playerName, playerLinkDisplayText, bnetIDAccount, lineID, chatGroup, chatTarget);
  3239. else
  3240. playerLink = GetPlayerLink(playerName, playerLinkDisplayText, lineID, chatGroup, chatTarget);
  3241. end
  3242. end
  3243. local message = arg1;
  3244. if ( arg14 ) then --isMobile
  3245. message = ChatFrame_GetMobileEmbeddedTexture(info.r, info.g, info.b)..message;
  3246. end
  3247. if ( usingDifferentLanguage ) then
  3248. local languageHeader = "["..arg3.."] ";
  3249. if ( showLink and (arg2 ~= "") ) then
  3250. body = format(_G["CHAT_"..type.."_GET"]..languageHeader..message, pflag..playerLink);
  3251. else
  3252. body = format(_G["CHAT_"..type.."_GET"]..languageHeader..message, pflag..arg2);
  3253. end
  3254. else
  3255. if ( not showLink or arg2 == "" ) then
  3256. if ( type == "TEXT_EMOTE" ) then
  3257. body = message;
  3258. else
  3259. body = format(_G["CHAT_"..type.."_GET"]..message, pflag..arg2, arg2);
  3260. end
  3261. else
  3262. if ( type == "EMOTE" ) then
  3263. body = format(_G["CHAT_"..type.."_GET"]..message, pflag..playerLink);
  3264. elseif ( type == "TEXT_EMOTE") then
  3265. body = string.gsub(message, arg2, pflag..playerLink, 1);
  3266. elseif (type == "GUILD_ITEM_LOOTED") then
  3267. body = string.gsub(message, "$s", GetPlayerLink(arg2, playerLinkDisplayText));
  3268. else
  3269. body = format(_G["CHAT_"..type.."_GET"]..message, pflag..playerLink);
  3270. end
  3271. end
  3272. end
  3273. -- Add Channel
  3274. if (channelLength > 0) then
  3275. body = "|Hchannel:channel:"..arg8.."|h["..ChatFrame_ResolvePrefixedChannelName(arg4).."]|h "..body;
  3276. end
  3277. --Add Timestamps
  3278. if ( CHAT_TIMESTAMP_FORMAT ) then
  3279. body = BetterDate(CHAT_TIMESTAMP_FORMAT, time())..body;
  3280. end
  3281. local accessID = ChatHistory_GetAccessID(chatGroup, chatTarget);
  3282. local typeID = ChatHistory_GetAccessID(infoType, chatTarget, arg12 or arg13);
  3283. self:AddMessage(body, info.r, info.g, info.b, info.id, accessID, typeID);
  3284. end
  3285. if ( type == "WHISPER" or type == "BN_WHISPER" ) then
  3286. --BN_WHISPER FIXME
  3287. ChatEdit_SetLastTellTarget(arg2, type);
  3288. if ( self.tellTimer and (GetTime() > self.tellTimer) ) then
  3289. PlaySound(SOUNDKIT.TELL_MESSAGE);
  3290. end
  3291. self.tellTimer = GetTime() + CHAT_TELL_ALERT_TIME;
  3292. --FCF_FlashTab(self);
  3293. FlashClientIcon();
  3294. end
  3295. if ( not self:IsShown() ) then
  3296. if ( (self == DEFAULT_CHAT_FRAME and info.flashTabOnGeneral) or (self ~= DEFAULT_CHAT_FRAME and info.flashTab) ) then
  3297. if ( not CHAT_OPTIONS.HIDE_FRAME_ALERTS or type == "WHISPER" or type == "BN_WHISPER" ) then --BN_WHISPER FIXME
  3298. if (not FCFManager_ShouldSuppressMessageFlash(self, chatGroup, chatTarget) ) then
  3299. FCF_StartAlertFlash(self);
  3300. end
  3301. end
  3302. end
  3303. end
  3304. return true;
  3305. end
  3306. end
  3307. function ChatFrame_AddMessageEventFilter (event, filter)
  3308. assert(event and filter);
  3309. if ( chatFilters[event] ) then
  3310. -- Only allow a filter to be added once
  3311. for index, filterFunc in next, chatFilters[event] do
  3312. if ( filterFunc == filter ) then
  3313. return;
  3314. end
  3315. end
  3316. else
  3317. chatFilters[event] = {};
  3318. end
  3319. tinsert(chatFilters[event], filter);
  3320. end
  3321. function ChatFrame_RemoveMessageEventFilter (event, filter)
  3322. assert(event and filter);
  3323. if ( chatFilters[event] ) then
  3324. for index, filterFunc in next, chatFilters[event] do
  3325. if ( filterFunc == filter ) then
  3326. tremove(chatFilters[event], index);
  3327. end
  3328. end
  3329. if ( #chatFilters[event] == 0 ) then
  3330. chatFilters[event] = nil;
  3331. end
  3332. end
  3333. end
  3334. function ChatFrame_GetMessageEventFilters (event)
  3335. assert(event);
  3336. return chatFilters[event];
  3337. end
  3338. function ChatFrame_OnUpdate(self, elapsedSec)
  3339. local flash = self.ScrollToBottomButton.Flash;
  3340. if flash then
  3341. local shouldFlash = not self:AtBottom();
  3342. if shouldFlash ~= UIFrameIsFlashing(flash) then
  3343. if shouldFlash then
  3344. UIFrameFlash(flash, .1, .1, -1, false, CHAT_BUTTON_FLASH_TIME, CHAT_BUTTON_FLASH_TIME);
  3345. FCF_FadeInScrollbar(self);
  3346. else
  3347. UIFrameFlashStop(flash);
  3348. end
  3349. end
  3350. end
  3351. end
  3352. function ChatFrame_OnHyperlinkShow(self, link, text, button)
  3353. SetItemRef(link, text, button, self);
  3354. end
  3355. function ChatFrame_OnMouseWheel(value)
  3356. if ( value > 0 ) then
  3357. SELECTED_DOCK_FRAME:ScrollUp();
  3358. elseif ( value < 0 ) then
  3359. SELECTED_DOCK_FRAME:ScrollDown();
  3360. end
  3361. end
  3362. function ChatFrame_SetChatFocusOverride(editBoxOverride)
  3363. CHAT_FOCUS_OVERRIDE = editBoxOverride;
  3364. end
  3365. function ChatFrame_GetChatFocusOverride()
  3366. return CHAT_FOCUS_OVERRIDE;
  3367. end
  3368. function ChatFrame_ClearChatFocusOverride()
  3369. CHAT_FOCUS_OVERRIDE = nil;
  3370. end
  3371. function ChatFrame_OpenChat(text, chatFrame, desiredCursorPosition)
  3372. if chatFrame == nil and CHAT_FOCUS_OVERRIDE ~= nil then
  3373. if CHAT_FOCUS_OVERRIDE.supportsSlashCommands or not text or strsub(text, 0, 1) ~= "/" then
  3374. CHAT_FOCUS_OVERRIDE:SetFocus();
  3375. CHAT_FOCUS_OVERRIDE:SetText(text);
  3376. return;
  3377. end
  3378. end
  3379. local editBox = ChatEdit_ChooseBoxForSend(chatFrame);
  3380. ChatEdit_ActivateChat(editBox);
  3381. editBox.setText = 1;
  3382. editBox.desiredCursorPosition = desiredCursorPosition;
  3383. editBox.text = text;
  3384. if ( editBox:GetAttribute("chatType") == editBox:GetAttribute("stickyType") ) then
  3385. if ( (editBox:GetAttribute("stickyType") == "PARTY") and (not IsInGroup(LE_PARTY_CATEGORY_HOME)) or
  3386. (editBox:GetAttribute("stickyType") == "RAID") and (not IsInRaid(LE_PARTY_CATEGORY_HOME)) or
  3387. (editBox:GetAttribute("stickyType") == "INSTANCE_CHAT") and (not IsInGroup(LE_PARTY_CATEGORY_INSTANCE))) then
  3388. editBox:SetAttribute("chatType", "SAY");
  3389. end
  3390. end
  3391. ChatEdit_UpdateHeader(editBox);
  3392. return editBox;
  3393. end
  3394. function ChatFrame_ScrollToBottom()
  3395. SELECTED_DOCK_FRAME:ScrollToBottom();
  3396. end
  3397. function ChatFrame_ScrollUp()
  3398. SELECTED_DOCK_FRAME:ScrollUp();
  3399. end
  3400. function ChatFrame_ScrollDown()
  3401. SELECTED_DOCK_FRAME:ScrollDown();
  3402. end
  3403. --used for chatframe and combat log
  3404. function MessageFrameScrollButton_OnLoad(self)
  3405. self.clickDelay = MESSAGE_SCROLLBUTTON_INITIAL_DELAY;
  3406. self:RegisterForClicks("LeftButtonDown", "LeftButtonUp", "RightButtonUp", "RightButtonDown");
  3407. end
  3408. --Controls scrolling for chatframe and combat log
  3409. function MessageFrameScrollButton_OnUpdate(self, elapsed)
  3410. if (self:GetButtonState() == "PUSHED") then
  3411. self.clickDelay = self.clickDelay - elapsed;
  3412. if ( self.clickDelay < 0 ) then
  3413. local name = self:GetName();
  3414. if ( name == self:GetParent():GetName().."DownButton" ) then
  3415. self:GetParent():GetParent():ScrollDown();
  3416. elseif ( name == self:GetParent():GetName().."UpButton" ) then
  3417. self:GetParent():GetParent():ScrollUp();
  3418. end
  3419. self.clickDelay = MESSAGE_SCROLLBUTTON_SCROLL_DELAY;
  3420. end
  3421. end
  3422. end
  3423. function ChatFrame_ToggleMenu()
  3424. ChatMenu:SetShown(not ChatMenu:IsShown());
  3425. end
  3426. function ChatFrameMenu_UpdateAnchorPoint()
  3427. --Update the menu anchor point
  3428. if ( FCF_GetButtonSide(DEFAULT_CHAT_FRAME) == "right" ) then
  3429. ChatMenu:ClearAllPoints();
  3430. ChatMenu:SetPoint("BOTTOMRIGHT", ChatFrameMenuButton, "TOPLEFT");
  3431. else
  3432. ChatMenu:ClearAllPoints();
  3433. ChatMenu:SetPoint("BOTTOMLEFT", ChatFrameMenuButton, "TOPRIGHT");
  3434. end
  3435. end
  3436. function ChatFrame_SendTell(name, chatFrame)
  3437. local editBox = ChatEdit_ChooseBoxForSend(chatFrame);
  3438. --DEBUG FIXME - for now, we're not going to remove spaces from names. We need to make sure X-server still works.
  3439. -- Remove spaces from the server name for slash command parsing
  3440. --name = gsub(name, " ", "");
  3441. if ( editBox ~= ChatEdit_GetActiveWindow() ) then
  3442. ChatFrame_OpenChat(SLASH_WHISPER1.." "..name.." ", chatFrame);
  3443. else
  3444. editBox:SetText(SLASH_WHISPER1.." "..name.." ");
  3445. end
  3446. ChatEdit_ParseText(editBox, 0);
  3447. end
  3448. function ChatFrame_SendBNetTell(tokenizedName)
  3449. local editBox = ChatEdit_ChooseBoxForSend();
  3450. editBox:SetAttribute("tellTarget", tokenizedName);
  3451. editBox:SetAttribute("chatType", "BN_WHISPER");
  3452. if ( editBox ~= ChatEdit_GetActiveWindow() ) then
  3453. ChatFrame_OpenChat("");
  3454. else
  3455. ChatEdit_UpdateHeader(editBox);
  3456. end
  3457. end
  3458. function ChatFrame_ReplyTell(chatFrame)
  3459. local editBox = ChatEdit_ChooseBoxForSend(chatFrame);
  3460. local lastTell, lastTellType = ChatEdit_GetLastTellTarget();
  3461. if ( lastTell ) then
  3462. --BN_WHISPER FIXME
  3463. editBox:SetAttribute("chatType", lastTellType);
  3464. editBox:SetAttribute("tellTarget", lastTell);
  3465. ChatEdit_UpdateHeader(editBox);
  3466. if ( editBox ~= ChatEdit_GetActiveWindow() ) then
  3467. ChatFrame_OpenChat("", chatFrame);
  3468. end
  3469. else
  3470. -- Error message
  3471. end
  3472. end
  3473. function ChatFrame_ReplyTell2(chatFrame)
  3474. local editBox = ChatEdit_ChooseBoxForSend(chatFrame);
  3475. local lastTold, lastToldType = ChatEdit_GetLastToldTarget();
  3476. if ( lastTold ) then
  3477. --BN_WHISPER FIXME
  3478. editBox:SetAttribute("chatType", lastToldType);
  3479. editBox:SetAttribute("tellTarget", lastTold);
  3480. ChatEdit_UpdateHeader(editBox);
  3481. if ( editBox ~= ChatEdit_GetActiveWindow() ) then
  3482. ChatFrame_OpenChat("", chatFrame);
  3483. end
  3484. else
  3485. -- Error message
  3486. end
  3487. end
  3488. function ChatFrame_DisplayHelpTextSimple(frame)
  3489. if ( not frame ) then
  3490. return;
  3491. end
  3492. local info = ChatTypeInfo["SYSTEM"];
  3493. frame:AddMessage(HELP_TEXT_SIMPLE, info.r, info.g, info.b, info.id);
  3494. end
  3495. function ChatFrame_DisplayHelpText(frame)
  3496. if ( not frame ) then
  3497. return;
  3498. end
  3499. local info = ChatTypeInfo["SYSTEM"];
  3500. local i = 1;
  3501. local text = _G["HELP_TEXT_LINE"..i];
  3502. while text do
  3503. frame:AddMessage(text, info.r, info.g, info.b, info.id);
  3504. i = i + 1;
  3505. text = _G["HELP_TEXT_LINE"..i];
  3506. end
  3507. end
  3508. function ChatFrame_DisplayMacroHelpText(frame)
  3509. if ( not frame ) then
  3510. return;
  3511. end
  3512. local info = ChatTypeInfo["SYSTEM"];
  3513. local i = 1;
  3514. local text = _G["MACRO_HELP_TEXT_LINE"..i];
  3515. while text do
  3516. frame:AddMessage(text, info.r, info.g, info.b, info.id);
  3517. i = i + 1;
  3518. text = _G["MACRO_HELP_TEXT_LINE"..i];
  3519. end
  3520. end
  3521. function ChatFrame_DisplayChatHelp(frame)
  3522. if ( not frame ) then
  3523. return;
  3524. end
  3525. local info = ChatTypeInfo["SYSTEM"];
  3526. local i = 1;
  3527. local text = _G["CHAT_HELP_TEXT_LINE"..i];
  3528. while text do
  3529. frame:AddMessage(text, info.r, info.g, info.b, info.id);
  3530. i = i + 1;
  3531. -- hack fix for removing a line without causing localization problems
  3532. if ( i == 15 ) then
  3533. i = i + 1;
  3534. end
  3535. text = _G["CHAT_HELP_TEXT_LINE"..i];
  3536. end
  3537. end
  3538. function ChatFrame_DisplayGuildHelp(frame)
  3539. if ( not frame ) then
  3540. return;
  3541. end
  3542. local info = ChatTypeInfo["SYSTEM"];
  3543. local i = 1;
  3544. local text = _G["GUILD_HELP_TEXT_LINE"..i];
  3545. while text do
  3546. frame:AddMessage(text, info.r, info.g, info.b, info.id);
  3547. i = i + 1;
  3548. text = _G["GUILD_HELP_TEXT_LINE"..i];
  3549. end
  3550. end
  3551. function ChatFrame_DisplayGameTime(frame)
  3552. if ( not frame ) then
  3553. return;
  3554. end
  3555. local info = ChatTypeInfo["SYSTEM"];
  3556. frame:AddMessage(GameTime_GetGameTime(true), info.r, info.g, info.b, info.id);
  3557. end
  3558. function ChatFrame_TimeBreakDown(time)
  3559. local days = floor(time / (60 * 60 * 24));
  3560. local hours = floor((time - (days * (60 * 60 * 24))) / (60 * 60));
  3561. local minutes = floor((time - (days * (60 * 60 * 24)) - (hours * (60 * 60))) / 60);
  3562. local seconds = mod(time, 60);
  3563. return days, hours, minutes, seconds;
  3564. end
  3565. function ChatFrame_DisplayTimePlayed(self, totalTime, levelTime)
  3566. local info = ChatTypeInfo["SYSTEM"];
  3567. local d;
  3568. local h;
  3569. local m;
  3570. local s;
  3571. d, h, m, s = ChatFrame_TimeBreakDown(totalTime);
  3572. local string = format(TIME_PLAYED_TOTAL, format(TIME_DAYHOURMINUTESECOND, d, h, m, s));
  3573. self:AddMessage(string, info.r, info.g, info.b, info.id);
  3574. d, h, m, s = ChatFrame_TimeBreakDown(levelTime);
  3575. local string = format(TIME_PLAYED_LEVEL, format(TIME_DAYHOURMINUTESECOND, d, h, m, s));
  3576. self:AddMessage(string, info.r, info.g, info.b, info.id);
  3577. end
  3578. function ChatFrame_ChatPageUp()
  3579. SELECTED_CHAT_FRAME:PageUp();
  3580. end
  3581. function ChatFrame_ChatPageDown()
  3582. SELECTED_CHAT_FRAME:PageDown();
  3583. end
  3584. function ChatFrame_DisplayUsageError(messageTag)
  3585. ChatFrame_DisplaySystemMessageInPrimary(messageTag);
  3586. end
  3587. function ChatFrame_DisplaySystemMessageInPrimary(messageTag)
  3588. local info = ChatTypeInfo["SYSTEM"];
  3589. DEFAULT_CHAT_FRAME:AddMessage(messageTag, info.r, info.g, info.b, info.id);
  3590. end
  3591. function ChatFrame_DisplaySystemMessageInCurrent(messageTag)
  3592. local info = ChatTypeInfo["SYSTEM"];
  3593. SELECTED_CHAT_FRAME:AddMessage(messageTag, info.r, info.g, info.b, info.id);
  3594. end
  3595. -- ChatEdit functions
  3596. local ChatEdit_LastTell = {};
  3597. local ChatEdit_LastTellType = {};
  3598. for i = 1, NUM_REMEMBERED_TELLS, 1 do
  3599. ChatEdit_LastTell[i] = "";
  3600. ChatEdit_LastTellType[i] = "";
  3601. end
  3602. local ChatEdit_LastTold;
  3603. local ChatEdit_LastToldType;
  3604. function ChatEdit_OnLoad(self)
  3605. self:SetFrameLevel(self.chatFrame:GetFrameLevel()+1);
  3606. self:SetAttribute("chatType", "SAY");
  3607. self:SetAttribute("stickyType", "SAY");
  3608. self.chatLanguage = GetDefaultLanguage();
  3609. self:RegisterEvent("UPDATE_CHAT_COLOR");
  3610. self.addSpaceToAutoComplete = true;
  3611. self.addHighlightedText = true;
  3612. if ( CHAT_OPTIONS.ONE_EDIT_AT_A_TIME == "many" ) then
  3613. self:Show();
  3614. end
  3615. local function ChatEditAutoComplete(editBox, fullText, nameInfo)
  3616. if nameInfo.bnetID ~= nil and nameInfo.bnetID ~= 0 then
  3617. editBox:SetAttribute("tellTarget", nameInfo.name);
  3618. editBox:SetAttribute("chatType", "BN_WHISPER");
  3619. editBox:SetText("");
  3620. ChatEdit_UpdateHeader(editBox);
  3621. return true;
  3622. end
  3623. return false;
  3624. end
  3625. AutoCompleteEditBox_SetCustomAutoCompleteFunction(self, ChatEditAutoComplete);
  3626. self:SetParent(UIParent);
  3627. end
  3628. function ChatEdit_OnEvent(self, event, ...)
  3629. if ( event == "UPDATE_CHAT_COLOR" ) then
  3630. local chatType = ...;
  3631. if ( self:IsShown() ) then
  3632. ChatEdit_UpdateHeader(self);
  3633. end
  3634. end
  3635. end
  3636. function ChatEdit_OnUpdate(self, elapsedSec)
  3637. if ( self.setText == 1) then
  3638. self:SetText(self.text);
  3639. self.setText = 0;
  3640. ChatEdit_ParseText(self, 0, true);
  3641. if self.desiredCursorPosition then
  3642. self:SetCursorPosition(self.desiredCursorPosition);
  3643. self.desiredCursorPosition = nil;
  3644. end
  3645. end
  3646. end
  3647. function ChatEdit_OnShow(self)
  3648. ChatEdit_ResetChatType(self);
  3649. end
  3650. function ChatEdit_ResetChatType(self)
  3651. if ( self:GetAttribute("chatType") == "PARTY" and (not IsInGroup(LE_PARTY_CATEGORY_HOME)) ) then
  3652. self:SetAttribute("chatType", "SAY");
  3653. end
  3654. if ( self:GetAttribute("chatType") == "RAID" and (not IsInRaid(LE_PARTY_CATEGORY_HOME)) ) then
  3655. self:SetAttribute("chatType", "SAY");
  3656. end
  3657. if ( (self:GetAttribute("chatType") == "GUILD" or self:GetAttribute("chatType") == "OFFICER") and not IsInGuild() ) then
  3658. self:SetAttribute("chatType", "SAY");
  3659. end
  3660. if ( self:GetAttribute("chatType") == "INSTANCE_CHAT" and (not IsInGroup(LE_PARTY_CATEGORY_INSTANCE)) ) then
  3661. self:SetAttribute("chatType", "SAY");
  3662. end
  3663. self.lastTabComplete = nil;
  3664. self.tabCompleteText = nil;
  3665. self.tabCompleteTableIndex = 1;
  3666. ChatEdit_UpdateHeader(self);
  3667. ChatEdit_OnInputLanguageChanged(self);
  3668. --[[if ( CHAT_OPTIONS.ONE_EDIT_AT_A_TIME == "old") then
  3669. self:SetFocus();
  3670. end]]
  3671. end
  3672. function ChatEdit_OnHide(self)
  3673. if ( ACTIVE_CHAT_EDIT_BOX == self ) then
  3674. ChatEdit_DeactivateChat(self);
  3675. end
  3676. if ( LAST_ACTIVE_CHAT_EDIT_BOX == self and self:IsShown() ) then --Our parent was hidden. Let's find a new default frame.
  3677. --We'll go with the active dock frame since people think of that as the primary chat.
  3678. ChatEdit_SetLastActiveWindow(FCFDock_GetSelectedWindow(GENERAL_CHAT_DOCK).editBox);
  3679. end
  3680. end
  3681. function ChatEdit_OnEditFocusGained(self)
  3682. ChatEdit_ActivateChat(self);
  3683. end
  3684. function ChatEdit_OnEditFocusLost(self)
  3685. AutoCompleteEditBox_OnEditFocusLost(self);
  3686. ChatEdit_DeactivateChat(self);
  3687. end
  3688. function ChatEdit_ActivateChat(editBox)
  3689. ChatFrame_ClearChatFocusOverride();
  3690. if ( ACTIVE_CHAT_EDIT_BOX and ACTIVE_CHAT_EDIT_BOX ~= editBox ) then
  3691. ChatEdit_DeactivateChat(ACTIVE_CHAT_EDIT_BOX);
  3692. end
  3693. ACTIVE_CHAT_EDIT_BOX = editBox;
  3694. ChatEdit_SetLastActiveWindow(editBox);
  3695. --Stop any sort of fading
  3696. UIFrameFadeRemoveFrame(editBox);
  3697. editBox:Show();
  3698. editBox:SetFocus();
  3699. editBox:SetFrameStrata("DIALOG");
  3700. editBox:Raise();
  3701. editBox.header:Show();
  3702. editBox.focusLeft:Show();
  3703. editBox.focusRight:Show();
  3704. editBox.focusMid:Show();
  3705. editBox:SetAlpha(1.0);
  3706. ChatEdit_UpdateHeader(editBox);
  3707. if ( CHAT_SHOW_IME ) then
  3708. _G[editBox:GetName().."Language"]:Show();
  3709. end
  3710. end
  3711. local function ChatEdit_SetDeactivated(editBox)
  3712. editBox:SetFrameStrata("LOW");
  3713. if ( GetCVar("chatStyle") == "classic" and not editBox.isGM ) then
  3714. editBox:Hide();
  3715. else
  3716. editBox:SetText("");
  3717. editBox.header:Hide();
  3718. if ( not editBox.isGM ) then
  3719. editBox:SetAlpha(0.35);
  3720. end
  3721. editBox:ClearFocus();
  3722. editBox.focusLeft:Hide();
  3723. editBox.focusRight:Hide();
  3724. editBox.focusMid:Hide();
  3725. ChatEdit_ResetChatTypeToSticky(editBox);
  3726. ChatEdit_ResetChatType(editBox);
  3727. end
  3728. _G[editBox:GetName().."Language"]:Hide();
  3729. end
  3730. function ChatEdit_DeactivateChat(editBox)
  3731. if ( ACTIVE_CHAT_EDIT_BOX == editBox ) then
  3732. ACTIVE_CHAT_EDIT_BOX = nil;
  3733. end
  3734. ChatEdit_SetDeactivated(editBox);
  3735. end
  3736. function ChatEdit_ChooseBoxForSend(preferredChatFrame)
  3737. if ( GetCVar("chatStyle") == "classic" ) then
  3738. return DEFAULT_CHAT_FRAME.editBox;
  3739. elseif ( preferredChatFrame and preferredChatFrame:IsShown() ) then
  3740. return preferredChatFrame.editBox;
  3741. elseif ( ChatEdit_GetLastActiveWindow() and ChatEdit_GetLastActiveWindow():GetParent():IsShown() ) then
  3742. return ChatEdit_GetLastActiveWindow();
  3743. else
  3744. return FCFDock_GetSelectedWindow(GENERAL_CHAT_DOCK).editBox;
  3745. end
  3746. end
  3747. function ChatEdit_SetLastActiveWindow(editBox)
  3748. local previousValue = LAST_ACTIVE_CHAT_EDIT_BOX;
  3749. if ( LAST_ACTIVE_CHAT_EDIT_BOX and not LAST_ACTIVE_CHAT_EDIT_BOX.isGM and LAST_ACTIVE_CHAT_EDIT_BOX ~= editBox ) then
  3750. if ( GetCVar("chatStyle") == "im" ) then
  3751. LAST_ACTIVE_CHAT_EDIT_BOX:Hide();
  3752. end
  3753. end
  3754. LAST_ACTIVE_CHAT_EDIT_BOX = editBox;
  3755. if ( editBox and GetCVar("chatStyle") == "im" and ACTIVE_CHAT_EDIT_BOX ~= editBox ) then
  3756. editBox:Show();
  3757. ChatEdit_SetDeactivated(editBox);
  3758. end
  3759. if ( previousValue ) then
  3760. FCFClickAnywhereButton_UpdateState(previousValue.chatFrame.clickAnywhereButton);
  3761. end
  3762. if ( editBox ) then
  3763. FCFClickAnywhereButton_UpdateState(editBox.chatFrame.clickAnywhereButton);
  3764. end
  3765. end
  3766. function ChatEdit_GetActiveWindow()
  3767. return ACTIVE_CHAT_EDIT_BOX;
  3768. end
  3769. function ChatEdit_GetLastActiveWindow()
  3770. return LAST_ACTIVE_CHAT_EDIT_BOX;
  3771. end
  3772. function ChatEdit_FocusActiveWindow()
  3773. local active = ChatEdit_GetActiveWindow()
  3774. if ( active ) then
  3775. ChatEdit_ActivateChat(active);
  3776. end
  3777. end
  3778. function ChatEdit_LinkItem(itemID, itemLink)
  3779. if ( not itemLink ) then
  3780. itemLink = select(2, GetItemInfo(itemID));
  3781. end
  3782. if ( itemLink ) then
  3783. if ( ChatEdit_GetActiveWindow() ) then
  3784. ChatEdit_InsertLink(itemLink);
  3785. else
  3786. ChatFrame_OpenChat(itemLink);
  3787. end
  3788. end
  3789. end
  3790. function ChatEdit_InsertLink(text)
  3791. if ( not text ) then
  3792. return false;
  3793. end
  3794. local activeWindow = ChatEdit_GetActiveWindow();
  3795. if ( activeWindow ) then
  3796. activeWindow:Insert(text);
  3797. return true;
  3798. end
  3799. if ( BrowseName and BrowseName:IsVisible() ) then
  3800. local item;
  3801. if ( strfind(text, "battlepet:") ) then
  3802. local petName = strmatch(text, "%[(.+)%]");
  3803. item = petName;
  3804. elseif ( strfind(text, "item:", 1, true) ) then
  3805. item = GetItemInfo(text);
  3806. end
  3807. if ( item ) then
  3808. BrowseName:SetText(item);
  3809. return true;
  3810. end
  3811. end
  3812. if ( MacroFrameText and MacroFrameText:HasFocus() ) then
  3813. local item;
  3814. if ( strfind(text, "item:", 1, true) ) then
  3815. item = GetItemInfo(text);
  3816. end
  3817. local cursorPosition = MacroFrameText:GetCursorPosition();
  3818. if (cursorPosition == 0 or strsub(MacroFrameText:GetText(), cursorPosition, cursorPosition) == "\n" ) then
  3819. if ( item ) then
  3820. if ( GetItemSpell(text) ) then
  3821. MacroFrameText:Insert(SLASH_USE1.." "..item.."\n");
  3822. else
  3823. MacroFrameText:Insert(SLASH_EQUIP1.." "..item.."\n");
  3824. end
  3825. else
  3826. MacroFrameText:Insert(SLASH_CAST1.." "..text.."\n");
  3827. end
  3828. else
  3829. MacroFrameText:Insert(item or text);
  3830. end
  3831. return true;
  3832. end
  3833. if ( TradeSkillFrame and TradeSkillFrame.SearchBox:HasFocus() ) then
  3834. local item;
  3835. if ( strfind(text, "item:", 1, true) ) then
  3836. item = GetItemInfo(text);
  3837. end
  3838. if ( item ) then
  3839. TradeSkillFrame.SearchBox:SetText(item);
  3840. return true;
  3841. end
  3842. end
  3843. if ( CommunitiesFrame and CommunitiesFrame.ChatEditBox:HasFocus() ) then
  3844. CommunitiesFrame.ChatEditBox:Insert(text);
  3845. return true;
  3846. end
  3847. return false;
  3848. end
  3849. function ChatEdit_TryInsertChatLink(link)
  3850. if ( IsModifiedClick("CHATLINK") and link ) then
  3851. return ChatEdit_InsertLink(link);
  3852. end
  3853. end
  3854. function ChatEdit_TryInsertQuestLinkForQuestID(questID)
  3855. return ChatEdit_TryInsertChatLink(GetQuestLink(questID));
  3856. end
  3857. function ChatEdit_GetChannelTarget(editBox)
  3858. local channelTarget = editBox:GetAttribute("channelTarget"); -- may be a name or an index
  3859. if channelTarget == nil then
  3860. return 0;
  3861. end
  3862. local localID = GetChannelName(channelTarget);
  3863. return localID;
  3864. end
  3865. function ChatEdit_GetLastTellTarget()
  3866. for i=1, #ChatEdit_LastTell do
  3867. local value = ChatEdit_LastTell[i];
  3868. if ( value ~= "" ) then
  3869. return value, ChatEdit_LastTellType[i];
  3870. end
  3871. end
  3872. return nil;
  3873. end
  3874. function ChatEdit_SetLastTellTarget(target, chatType)
  3875. local found = #ChatEdit_LastTell;
  3876. for i=1, #ChatEdit_LastTell do
  3877. local tellTarget, tellChatType = ChatEdit_LastTell[i], ChatEdit_LastTellType[i];
  3878. if ( strupper(target) == strupper(tellTarget) and strupper(chatType) == strupper(tellChatType) ) then
  3879. found = i;
  3880. break;
  3881. end
  3882. end
  3883. for i = found, 2, -1 do
  3884. ChatEdit_LastTell[i] = ChatEdit_LastTell[i-1];
  3885. ChatEdit_LastTellType[i] = ChatEdit_LastTellType[i-1];
  3886. end
  3887. ChatEdit_LastTell[1] = target;
  3888. ChatEdit_LastTellType[1] = chatType;
  3889. end
  3890. function ChatEdit_GetNextTellTarget(target, chatType)
  3891. if ( not target or target == "" ) then
  3892. return ChatEdit_LastTell[1], ChatEdit_LastTellType[1];
  3893. end
  3894. for i = 1, #ChatEdit_LastTell - 1, 1 do
  3895. if ( ChatEdit_LastTell[i] == "" ) then
  3896. break;
  3897. elseif ( strupper(target) == strupper(ChatEdit_LastTell[i]) and
  3898. strupper(chatType) == strupper(ChatEdit_LastTellType[i]) ) then
  3899. if ( ChatEdit_LastTell[i+1] ~= "" ) then
  3900. return ChatEdit_LastTell[i+1], ChatEdit_LastTellType[i+1];
  3901. else
  3902. break;
  3903. end
  3904. end
  3905. end
  3906. return ChatEdit_LastTell[1], ChatEdit_LastTellType[1];
  3907. end
  3908. function ChatEdit_GetLastToldTarget()
  3909. return ChatEdit_LastTold, ChatEdit_LastToldType;
  3910. end
  3911. function ChatEdit_SetLastToldTarget(name, chatType)
  3912. ChatEdit_LastTold = name;
  3913. ChatEdit_LastToldType = chatType;
  3914. end
  3915. function ChatEdit_UpdateHeader(editBox)
  3916. local type = editBox:GetAttribute("chatType");
  3917. if ( not type ) then
  3918. return;
  3919. end
  3920. local info = ChatTypeInfo[type];
  3921. local header = _G[editBox:GetName().."Header"];
  3922. local headerSuffix = _G[editBox:GetName().."HeaderSuffix"];
  3923. if ( not header ) then
  3924. return;
  3925. end
  3926. header:SetWidth(0);
  3927. --BN_WHISPER FIXME
  3928. if ( type == "SMART_WHISPER" ) then
  3929. --If we have a bnetIDAccount or this name, it's a BN whisper.
  3930. if ( BNet_GetBNetIDAccount(editBox:GetAttribute("tellTarget")) ) then
  3931. editBox:SetAttribute("chatType", "BN_WHISPER");
  3932. else
  3933. editBox:SetAttribute("chatType", "WHISPER");
  3934. end
  3935. ChatEdit_UpdateHeader(editBox);
  3936. return;
  3937. elseif ( type == "WHISPER" ) then
  3938. header:SetFormattedText(CHAT_WHISPER_SEND, editBox:GetAttribute("tellTarget"));
  3939. elseif ( type == "BN_WHISPER" ) then
  3940. local name = editBox:GetAttribute("tellTarget");
  3941. header:SetFormattedText(CHAT_BN_WHISPER_SEND, name);
  3942. elseif ( type == "EMOTE" ) then
  3943. header:SetFormattedText(CHAT_EMOTE_SEND, UnitName("player"));
  3944. elseif ( type == "CHANNEL" ) then
  3945. local localID, channelName, instanceID, isCommunitiesChannel = GetChannelName(ChatEdit_GetChannelTarget(editBox));
  3946. if ( channelName ) then
  3947. if ( isCommunitiesChannel ) then
  3948. channelName = ChatFrame_ResolveChannelName(channelName);
  3949. elseif ( instanceID > 0 ) then
  3950. channelName = channelName.." "..instanceID;
  3951. end
  3952. info = ChatTypeInfo["CHANNEL"..localID];
  3953. editBox:SetAttribute("channelTarget", localID);
  3954. header:SetFormattedText(CHAT_CHANNEL_SEND, localID, channelName);
  3955. end
  3956. elseif ( (type == "PARTY") and
  3957. (not IsInGroup(LE_PARTY_CATEGORY_HOME) and IsInGroup(LE_PARTY_CATEGORY_INSTANCE)) ) then
  3958. --Smartly switch to instance chat
  3959. editBox:SetAttribute("chatType", "INSTANCE_CHAT");
  3960. ChatEdit_UpdateHeader(editBox);
  3961. return;
  3962. elseif ( (type == "RAID") and
  3963. (not IsInRaid(LE_PARTY_CATEGORY_HOME) and IsInRaid(LE_PARTY_CATEGORY_INSTANCE)) ) then
  3964. --Smartly switch to instance chat
  3965. editBox:SetAttribute("chatType", "INSTANCE_CHAT");
  3966. ChatEdit_UpdateHeader(editBox);
  3967. return;
  3968. elseif ( (type == "INSTANCE_CHAT") and
  3969. (IsInGroup(LE_PARTY_CATEGORY_HOME) and not IsInGroup(LE_PARTY_CATEGORY_INSTANCE)) )then
  3970. if ( IsInRaid(LE_PARTY_CATEGORY_HOME) ) then
  3971. editBox:SetAttribute("chatType", "RAID");
  3972. else
  3973. editBox:SetAttribute("chatType", "PARTY");
  3974. end
  3975. ChatEdit_UpdateHeader(editBox);
  3976. return;
  3977. else
  3978. header:SetText(_G["CHAT_"..type.."_SEND"]);
  3979. end
  3980. local headerWidth = (header:GetRight() or 0) - (header:GetLeft() or 0);
  3981. local editBoxWidth = (editBox:GetRight() or 0) - (editBox:GetLeft() or 0);
  3982. if ( headerWidth > editBoxWidth / 2 ) then
  3983. header:SetWidth(editBoxWidth / 2);
  3984. headerSuffix:Show();
  3985. else
  3986. headerSuffix:Hide();
  3987. end
  3988. header:SetTextColor(info.r, info.g, info.b);
  3989. headerSuffix:SetTextColor(info.r, info.g, info.b);
  3990. editBox:SetTextInsets(15 + header:GetWidth() + (headerSuffix:IsShown() and headerSuffix:GetWidth() or 0), 13, 0, 0);
  3991. editBox:SetTextColor(info.r, info.g, info.b);
  3992. editBox.focusLeft:SetVertexColor(info.r, info.g, info.b);
  3993. editBox.focusRight:SetVertexColor(info.r, info.g, info.b);
  3994. editBox.focusMid:SetVertexColor(info.r, info.g, info.b);
  3995. end
  3996. function ChatEdit_AddHistory(editBox)
  3997. local text = "";
  3998. local type = editBox:GetAttribute("chatType");
  3999. local header = _G["SLASH_"..type.."1"];
  4000. if ( header ) then
  4001. text = header;
  4002. end
  4003. if ( type == "WHISPER" ) then
  4004. text = text.." "..editBox:GetAttribute("tellTarget");
  4005. elseif ( type == "CHANNEL" ) then
  4006. text = "/"..ChatEdit_GetChannelTarget(editBox);
  4007. end
  4008. local editBoxText = editBox:GetText();
  4009. if ( editBoxText ~= "" ) then
  4010. text = text.." "..editBox:GetText();
  4011. end
  4012. if ( text ~= "" ) then
  4013. editBox:AddHistoryLine(text);
  4014. end
  4015. end
  4016. function ChatEdit_SendText(editBox, addHistory)
  4017. ChatEdit_ParseText(editBox, 1);
  4018. local type = editBox:GetAttribute("chatType");
  4019. local text = editBox:GetText();
  4020. if ( strfind(text, "%s*[^%s]+") ) then
  4021. text = SubstituteChatMessageBeforeSend(text);
  4022. --BN_WHISPER FIXME
  4023. if ( type == "WHISPER") then
  4024. local target = editBox:GetAttribute("tellTarget");
  4025. ChatEdit_SetLastToldTarget(target, type);
  4026. SendChatMessage(text, type, editBox.languageID, target);
  4027. elseif ( type == "BN_WHISPER" ) then
  4028. local target = editBox:GetAttribute("tellTarget");
  4029. local bnetIDAccount = BNet_GetBNetIDAccount(target);
  4030. if ( bnetIDAccount ) then
  4031. ChatEdit_SetLastToldTarget(target, type);
  4032. BNSendWhisper(bnetIDAccount, text);
  4033. else
  4034. local info = ChatTypeInfo["SYSTEM"]
  4035. editBox.chatFrame:AddMessage(format(BN_UNABLE_TO_RESOLVE_NAME, target), info.r, info.g, info.b);
  4036. end
  4037. elseif ( type == "CHANNEL") then
  4038. SendChatMessage(text, type, editBox.languageID, ChatEdit_GetChannelTarget(editBox));
  4039. else
  4040. SendChatMessage(text, type, editBox.languageID);
  4041. end
  4042. if ( addHistory ) then
  4043. ChatEdit_AddHistory(editBox);
  4044. end
  4045. end
  4046. end
  4047. function ChatEdit_OnEnterPressed(self)
  4048. if(AutoCompleteEditBox_OnEnterPressed(self)) then
  4049. return;
  4050. end
  4051. ChatEdit_SendText(self, 1);
  4052. local type = self:GetAttribute("chatType");
  4053. local chatFrame = self:GetParent();
  4054. if ( chatFrame.isTemporary and chatFrame.chatType ~= "PET_BATTLE_COMBAT_LOG" ) then --Temporary window sticky types never change.
  4055. self:SetAttribute("stickyType", chatFrame.chatType);
  4056. --BN_WHISPER FIXME
  4057. if ( chatFrame.chatType == "WHISPER" or chatFrame.chatType == "BN_WHISPER" ) then
  4058. self:SetAttribute("tellTarget", chatFrame.chatTarget);
  4059. end
  4060. elseif ( ChatTypeInfo[type].sticky == 1 ) then
  4061. self:SetAttribute("stickyType", type);
  4062. end
  4063. ChatEdit_ClearChat(self);
  4064. end
  4065. function ChatEdit_ClearChat(editBox)
  4066. ChatEdit_ResetChatTypeToSticky(editBox);
  4067. if ( not editBox.isGM and (GetCVar("chatStyle") ~= "im" or editBox == MacroEditBox) ) then
  4068. editBox:SetText("");
  4069. editBox:Hide();
  4070. else
  4071. ChatEdit_DeactivateChat(editBox);
  4072. end
  4073. end
  4074. function ChatEdit_OnEscapePressed(editBox)
  4075. if ( not AutoCompleteEditBox_OnEscapePressed(editBox) ) then
  4076. ChatEdit_ClearChat(editBox);
  4077. end
  4078. end
  4079. function ChatEdit_ResetChatTypeToSticky(editBox)
  4080. editBox:SetAttribute("chatType", editBox:GetAttribute("stickyType"));
  4081. end
  4082. function ChatEdit_OnSpacePressed(self)
  4083. ChatEdit_ParseText(self, 0);
  4084. end
  4085. function ChatEdit_CustomTabPressed(self)
  4086. end
  4087. local tabCompleteTables = { hash_ChatTypeInfoList, hash_EmoteTokenList };
  4088. function ChatEdit_SecureTabPressed(self)
  4089. local chatType = self:GetAttribute("chatType");
  4090. if ( chatType == "WHISPER" or chatType == "BN_WHISPER" ) then
  4091. local newTarget, newTargetType = ChatEdit_GetNextTellTarget(self:GetAttribute("tellTarget"), chatType);
  4092. if ( newTarget and newTarget ~= "" ) then
  4093. self:SetAttribute("chatType", newTargetType);
  4094. self:SetAttribute("tellTarget", newTarget);
  4095. ChatEdit_UpdateHeader(self);
  4096. end
  4097. return;
  4098. end
  4099. local text = self.tabCompleteText;
  4100. if ( not text ) then
  4101. text = self:GetText();
  4102. self.tabCompleteText = text;
  4103. end
  4104. if ( strsub(text, 1, 1) ~= "/" ) then
  4105. return;
  4106. end
  4107. ChatFrame_ImportAllListsToHash();
  4108. local lastTabComplete = self.lastTabComplete;
  4109. -- If the string is in the format "/cmd blah", command will be "/cmd"
  4110. local command = strmatch(text, "^(/[^%s]+)") or "";
  4111. local cmdString = lastTabComplete;
  4112. repeat --The outer loop lets us go through multiple hash tables of commands.
  4113. repeat --Loop through this table to find matching items.
  4114. cmdString = next(tabCompleteTables[self.tabCompleteTableIndex], cmdString);
  4115. until ( not cmdString or strfind(cmdString, strupper(command), 1, 1) ); --Either we finished going through this table or we found a match.
  4116. if ( not cmdString ) then --Nothing else in the current table, move to the next one.
  4117. self.tabCompleteTableIndex = self.tabCompleteTableIndex + 1;
  4118. end
  4119. until ( cmdString or self.tabCompleteTableIndex > #tabCompleteTables );
  4120. self.lastTabComplete = cmdString;
  4121. if ( cmdString ) then
  4122. self.ignoreTextChange = 1;
  4123. self:SetText(strlower(cmdString));
  4124. else
  4125. self.tabCompleteTableIndex = 1;
  4126. self:SetText(self.tabCompleteText);
  4127. end
  4128. end
  4129. function ChatEdit_OnTabPressed(self)
  4130. if ( not AutoCompleteEditBox_OnTabPressed(self) ) then
  4131. if ( securecall("ChatEdit_CustomTabPressed", self) ) then
  4132. return;
  4133. end
  4134. ChatEdit_SecureTabPressed(self);
  4135. end
  4136. end
  4137. function ChatEdit_OnTextChanged(self, userInput)
  4138. ChatEdit_ParseText(self, 0);
  4139. if ( not self.ignoreTextChange ) then
  4140. self.lastTabComplete = nil;
  4141. self.tabCompleteText = nil;
  4142. self.tabCompleteTableIndex = 1;
  4143. end
  4144. self.ignoreTextChange = nil;
  4145. local regex = "^((/[^%s]+)%s+(.+))"
  4146. local full, command, target = strmatch(self:GetText(), regex);
  4147. if ( not target or (strsub(target, 1, 1) == "|") ) then
  4148. AutoComplete_HideIfAttachedTo(self);
  4149. return;
  4150. end
  4151. if ( userInput ) then
  4152. self.autoCompleteXOffset = 35;
  4153. AutoComplete_Update(self, target, self:GetUTF8CursorPosition() - strlenutf8(command) - 1);
  4154. end
  4155. end
  4156. local symbols = {"%%", "%*", "%+", "%-", "%?", "%(", "%)", "%[", "%]", "%$", "%^"} --% has to be escaped first or everything is ruined
  4157. local replacements = {"%%%%", "%%%*", "%%%+", "%%%-", "%%%?", "%%%(", "%%%)", "%%%[", "%%%]", "%%%$", "%%%^"}
  4158. function escapePatternSymbols(text)
  4159. for i=1, #symbols do
  4160. text = text:gsub(symbols[i], replacements[i])
  4161. end
  4162. return text
  4163. end
  4164. function ChatEdit_OnChar(self)
  4165. local regex = "^((/[^%s]+)%s+(.+))$"
  4166. local text, command, target = strmatch(self:GetText(), regex);
  4167. if (command) then
  4168. self.command = command
  4169. else
  4170. self.command = nil;
  4171. end
  4172. if (command and target and self.autoCompleteSource and self.autoCompleteParams) then --if they typed a command with a autocompletable target
  4173. local utf8Position = self:GetUTF8CursorPosition();
  4174. local allowFullMatch = false;
  4175. local nameToShow = self.autoCompleteSource(target, 1, utf8Position, allowFullMatch, unpack(self.autoCompleteParams))[1];
  4176. if (nameToShow and nameToShow.name) then
  4177. local name = Ambiguate(nameToShow.name, "all");
  4178. --We're going to be setting the text programatically which will clear the userInput flag on the editBox.
  4179. --So we want to manually update the dropdown before we change the text.
  4180. AutoComplete_Update(self, target, utf8Position - strlenutf8(command) - 1);
  4181. target = escapePatternSymbols(target)
  4182. local highlightRegex = "^"..target.."(.*)";
  4183. local nameEnding = name:match(highlightRegex)
  4184. if (not nameEnding) then
  4185. return;
  4186. end
  4187. local newText = text..nameEnding;
  4188. self:SetText(newText);
  4189. self:HighlightText(strlen(text), strlen(newText));
  4190. self:SetCursorPosition(strlen(text));
  4191. end
  4192. end
  4193. end
  4194. function ChatEdit_OnTextSet(self)
  4195. ChatEdit_ParseText(self, 0);
  4196. end
  4197. function ChatEdit_LanguageShow()
  4198. CHAT_SHOW_IME = true;
  4199. end
  4200. function ChatEdit_OnInputLanguageChanged(self)
  4201. local button = _G[self:GetName().."Language"];
  4202. local variable = _G["INPUT_"..self:GetInputLanguage()];
  4203. button:SetText(variable);
  4204. end
  4205. local function processChatType(editBox, msg, index, send)
  4206. local autoCompleteInfo = AUTOCOMPLETE_LIST[index];
  4207. if ( autoCompleteInfo ) then
  4208. AutoCompleteEditBox_SetAutoCompleteSource(editBox, GetAutoCompleteResults, autoCompleteInfo.include, autoCompleteInfo.exclude);
  4209. else
  4210. AutoCompleteEditBox_SetAutoCompleteSource(editBox, nil);
  4211. end
  4212. -- this is a special function for "ChatEdit_HandleChatType"
  4213. if ( ChatTypeInfo[index] ) then
  4214. if ( index == "WHISPER" or index == "SMART_WHISPER" ) then
  4215. local targetFound, target, chatType, parsedMsg = ChatEdit_ExtractTellTarget(editBox, msg, index);
  4216. if ( targetFound ) then
  4217. editBox:SetAttribute("tellTarget", target);
  4218. editBox:SetAttribute("chatType", chatType);
  4219. editBox:SetText(parsedMsg);
  4220. ChatEdit_UpdateHeader(editBox);
  4221. elseif ( send == 1 ) then
  4222. ChatEdit_ClearChat(editBox);
  4223. end
  4224. elseif ( index == "REPLY" ) then
  4225. local lastTell, lastTellType = ChatEdit_GetLastTellTarget();
  4226. if ( lastTell ) then
  4227. --BN_WHISPER FIXME
  4228. editBox:SetAttribute("chatType", lastTellType);
  4229. editBox:SetAttribute("tellTarget", lastTell);
  4230. editBox:SetText(msg);
  4231. ChatEdit_UpdateHeader(editBox);
  4232. else
  4233. if ( send == 1 ) then
  4234. ChatEdit_ClearChat(editBox);
  4235. end
  4236. end
  4237. elseif (index == "CHANNEL") then
  4238. ChatEdit_ExtractChannel(editBox, msg);
  4239. else
  4240. editBox:SetAttribute("chatType", index);
  4241. editBox:SetText(msg);
  4242. ChatEdit_UpdateHeader(editBox);
  4243. end
  4244. return true;
  4245. end
  4246. return false;
  4247. end
  4248. function ChatEdit_HandleChatType(editBox, msg, command, send)
  4249. local channel = strmatch(command, "/([0-9]+)");
  4250. if( channel ) then
  4251. local chanNum = tonumber(channel);
  4252. if ( chanNum > 0 and chanNum <= MAX_WOW_CHAT_CHANNELS ) then
  4253. local channelNum, channelName = GetChannelName(channel);
  4254. if ( channelNum > 0 ) then
  4255. editBox:SetAttribute("channelTarget", channelNum);
  4256. editBox:SetAttribute("chatType", "CHANNEL");
  4257. editBox:SetText(msg);
  4258. ChatEdit_UpdateHeader(editBox);
  4259. return true;
  4260. end
  4261. end
  4262. else
  4263. -- first check the hash table
  4264. ChatFrame_ImportAllListsToHash();
  4265. if ( hash_ChatTypeInfoList[command] ) then
  4266. return processChatType(editBox, msg, hash_ChatTypeInfoList[command], send);
  4267. end
  4268. end
  4269. --This isn't one we found in our list, so we're not going to autocomplete.
  4270. AutoCompleteEditBox_SetAutoCompleteSource(editBox, nil);
  4271. return false;
  4272. end
  4273. function ChatEdit_ParseText(editBox, send, parseIfNoSpaces)
  4274. local text = editBox:GetText();
  4275. if ( text == "" ) then
  4276. return;
  4277. end
  4278. if ( strsub(text, 1, 1) ~= "/" ) then
  4279. return;
  4280. end
  4281. --Do not bother parsing if there is no space in the message and we aren't sending.
  4282. if ( send ~= 1 and not parseIfNoSpaces and not strfind(text, "%s") ) then
  4283. return;
  4284. end
  4285. -- If the string is in the format "/cmd blah", command will be "/cmd"
  4286. local command = strmatch(text, "^(/[^%s]+)") or "";
  4287. local msg = "";
  4288. if ( command ~= text ) then
  4289. msg = strsub(text, strlen(command) + 2);
  4290. end
  4291. command = strupper(command);
  4292. -- Check and see if we've got secure commands to run before we look for chat types or slash commands.
  4293. -- This hash table is prepopulated, unlike the other ones, since nobody can add secure commands. (See line 1205 or thereabouts)
  4294. -- We don't want this code to run unless send is 1, but we need ChatEdit_HandleChatType to run when send is 1 as well, which is why we
  4295. -- didn't just move ChatEdit_HandleChatType inside the send == 0 conditional, which could have also solved the problem with insecure
  4296. -- code having the ability to affect secure commands.
  4297. if ( send == 1 and hash_SecureCmdList[command] ) then
  4298. hash_SecureCmdList[command](strtrim(msg));
  4299. editBox:AddHistoryLine(text);
  4300. ChatEdit_ClearChat(editBox);
  4301. return;
  4302. end
  4303. ChatFrame_ImportAllListsToHash();
  4304. -- Handle chat types. No need for a securecall here, since we should be done with anything secure.
  4305. if ( ChatEdit_HandleChatType(editBox, msg, command, send) ) then
  4306. return;
  4307. end
  4308. if ( send == 0 ) then
  4309. return;
  4310. end
  4311. -- Check the hash tables for slash commands and emotes to see if we've run this before.
  4312. if ( hash_SlashCmdList[command] ) then
  4313. -- if the code in here changes - change the corresponding code below
  4314. hash_SlashCmdList[command](strtrim(msg), editBox);
  4315. editBox:AddHistoryLine(text);
  4316. ChatEdit_ClearChat(editBox);
  4317. return;
  4318. elseif ( hash_EmoteTokenList[command] ) then
  4319. -- if the code in here changes - change the corresponding code below
  4320. local restricted = DoEmote(hash_EmoteTokenList[command], msg);
  4321. -- If the emote is restricted, we want to treat it as if the player entered an unrecognized chat command.
  4322. if ( not restricted ) then
  4323. editBox:AddHistoryLine(text);
  4324. ChatEdit_ClearChat(editBox);
  4325. return;
  4326. end
  4327. end
  4328. -- Unrecognized chat command, show simple help text
  4329. if ( editBox.chatFrame ) then
  4330. ChatFrame_DisplayHelpTextSimple(editBox.chatFrame);
  4331. end
  4332. -- Reset the chat type and clear the edit box's contents
  4333. ChatEdit_ClearChat(editBox);
  4334. return;
  4335. end
  4336. function SubstituteChatMessageBeforeSend(msg)
  4337. for tag in string.gmatch(msg, "%b{}") do
  4338. local term = strlower(string.gsub(tag, "[{}]", ""));
  4339. if ( GROUP_TAG_LIST[term] ) then
  4340. local groupIndex = GROUP_TAG_LIST[term];
  4341. msg = string.gsub(msg, tag, "{"..GROUP_LANGUAGE_INDEPENDENT_STRINGS[groupIndex].."}");
  4342. end
  4343. end
  4344. return msg;
  4345. end
  4346. function ChatEdit_ExtractTellTarget(editBox, msg, chatType)
  4347. local tellTargetExtractionAutoComplete;
  4348. if ( chatType == "WHISPER" ) then
  4349. tellTargetExtractionAutoComplete = AUTOCOMPLETE_LIST.WHISPER_EXTRACT;
  4350. else
  4351. tellTargetExtractionAutoComplete = AUTOCOMPLETE_LIST.SMART_WHISPER_EXTRACT;
  4352. end
  4353. -- Grab the string after the slash command
  4354. local target = strmatch(msg, "%s*(.*)");
  4355. --If we haven't even finished one word, we aren't done.
  4356. if ( not target or not strfind(target, "%s") ) then
  4357. return false;
  4358. end
  4359. if ( strsub(target, 1, 1) == "|" ) then
  4360. return false;
  4361. end
  4362. if ( #GetAutoCompleteResults(target, 1, 0, true, tellTargetExtractionAutoComplete.include, tellTargetExtractionAutoComplete.exclude) > 0 ) then
  4363. --Even if there's a space, we still want to let the person keep typing -- they may be trying to type whatever is in AutoComplete.
  4364. return false;
  4365. end
  4366. --Keep pulling off everything after the last space until we either have something on the AutoComplete list or only a single word is left.
  4367. while ( strfind(target, "%s") ) do
  4368. --Pull off everything after the last space.
  4369. target = strmatch(target, "(.+)%s+[^%s]*");
  4370. if ( #GetAutoCompleteResults(target, 1, 0, true, tellTargetExtractionAutoComplete.include, tellTargetExtractionAutoComplete.exclude) > 0 ) then
  4371. break;
  4372. end
  4373. end
  4374. msg = strsub(msg, strlen(target) + 2);
  4375. if ( chatType ~= "WHISPER" and BNet_GetBNetIDAccount(target) ) then --"WHISPER" forces character whisper
  4376. chatType = "BN_WHISPER";
  4377. else
  4378. chatType = "WHISPER";
  4379. end
  4380. return true, target, chatType, msg;
  4381. end
  4382. function ChatEdit_ExtractChannel(editBox, msg)
  4383. local target = strmatch(msg, "%s*([^%s]+)");
  4384. if ( not target ) then
  4385. return;
  4386. end
  4387. local channelNum, channelName = GetChannelName(target);
  4388. if ( channelNum <= 0 ) then
  4389. return;
  4390. end
  4391. msg = strsub(msg, strlen(target) + 2);
  4392. editBox:SetAttribute("channelTarget", channelNum);
  4393. editBox:SetAttribute("chatType", "CHANNEL");
  4394. editBox:SetText(msg);
  4395. ChatEdit_UpdateHeader(editBox);
  4396. end
  4397. -- Chat menu functions
  4398. function ChatMenu_SetChatType(chatFrame, type)
  4399. local editBox = ChatFrame_OpenChat("");
  4400. editBox:SetAttribute("chatType", type);
  4401. ChatEdit_UpdateHeader(editBox);
  4402. end
  4403. function ChatMenu_Say(self)
  4404. ChatMenu_SetChatType(self:GetParent().chatFrame, "SAY");
  4405. end
  4406. function ChatMenu_Party(self)
  4407. ChatMenu_SetChatType(self:GetParent().chatFrame, "PARTY");
  4408. end
  4409. function ChatMenu_Raid(self)
  4410. ChatMenu_SetChatType(self:GetParent().chatFrame, "RAID");
  4411. end
  4412. function ChatMenu_InstanceChat(self)
  4413. ChatMenu_SetChatType(self:GetParent().chatFrame, "INSTANCE_CHAT");
  4414. end
  4415. function ChatMenu_Guild(self)
  4416. ChatMenu_SetChatType(self:GetParent().chatFrame, "GUILD");
  4417. end
  4418. function ChatMenu_Yell(self)
  4419. ChatMenu_SetChatType(self:GetParent().chatFrame, "YELL");
  4420. end
  4421. function ChatMenu_Whisper(self)
  4422. local editBox = ChatFrame_OpenChat(SLASH_SMART_WHISPER1.." ");
  4423. editBox:SetText(SLASH_SMART_WHISPER1.." "..editBox:GetText());
  4424. end
  4425. function ChatMenu_Emote(self)
  4426. ChatMenu_SetChatType(self:GetParent().chatFrame, "EMOTE");
  4427. end
  4428. function ChatMenu_Reply(self)
  4429. ChatFrame_ReplyTell();
  4430. end
  4431. function ChatMenu_VoiceMacro(self)
  4432. ChatMenu_SetChatType(self:GetParent().chatFrame, "YELL");
  4433. end
  4434. function ChatMenu_OnLoad(self)
  4435. self.chatFrame = DEFAULT_CHAT_FRAME;
  4436. UIMenu_Initialize(self);
  4437. UIMenu_AddButton(self, SAY_MESSAGE, SLASH_SAY1, ChatMenu_Say);
  4438. UIMenu_AddButton(self, PARTY_MESSAGE, SLASH_PARTY1, ChatMenu_Party);
  4439. UIMenu_AddButton(self, RAID_MESSAGE, SLASH_RAID1, ChatMenu_Raid);
  4440. UIMenu_AddButton(self, INSTANCE_CHAT_MESSAGE, SLASH_INSTANCE_CHAT1, ChatMenu_InstanceChat);
  4441. UIMenu_AddButton(self, GUILD_MESSAGE, SLASH_GUILD1, ChatMenu_Guild);
  4442. UIMenu_AddButton(self, YELL_MESSAGE, SLASH_YELL1, ChatMenu_Yell);
  4443. UIMenu_AddButton(self, WHISPER_MESSAGE, SLASH_SMART_WHISPER1, ChatMenu_Whisper);
  4444. UIMenu_AddButton(self, EMOTE_MESSAGE, SLASH_EMOTE1, ChatMenu_Emote, "EmoteMenu");
  4445. UIMenu_AddButton(self, REPLY_MESSAGE, SLASH_REPLY1, ChatMenu_Reply);
  4446. UIMenu_AddButton(self, LANGUAGE, nil, nil, "LanguageMenu");
  4447. UIMenu_AddButton(self, VOICEMACRO_LABEL, nil, nil, "VoiceMacroMenu");
  4448. UIMenu_AddButton(self, MACRO, SLASH_MACRO1, ShowMacroFrame);
  4449. UIMenu_AutoSize(self);
  4450. end
  4451. function ChatMenu_OnShow(self)
  4452. UIMenu_OnShow(self);
  4453. EmoteMenu:Hide();
  4454. LanguageMenu:Hide();
  4455. VoiceMacroMenu:Hide();
  4456. self:SetBackdropBorderColor(TOOLTIP_DEFAULT_COLOR.r, TOOLTIP_DEFAULT_COLOR.g, TOOLTIP_DEFAULT_COLOR.b);
  4457. self:SetBackdropColor(TOOLTIP_DEFAULT_BACKGROUND_COLOR.r, TOOLTIP_DEFAULT_BACKGROUND_COLOR.g, TOOLTIP_DEFAULT_BACKGROUND_COLOR.b);
  4458. end
  4459. function EmoteMenu_Click(self)
  4460. DoEmote(EmoteList[self:GetID()]);
  4461. ChatMenu:Hide();
  4462. end
  4463. function TextEmoteSort(token1, token2)
  4464. local i = 1;
  4465. local string1, string2;
  4466. local token = _G["EMOTE"..i.."_TOKEN"];
  4467. while ( i <= MAXEMOTEINDEX ) do
  4468. if ( token == token1 ) then
  4469. string1 = _G["EMOTE"..i.."_CMD1"];
  4470. if ( string2 ) then
  4471. break;
  4472. end
  4473. end
  4474. if ( token == token2 ) then
  4475. string2 = _G["EMOTE"..i.."_CMD1"];
  4476. if ( string1 ) then
  4477. break;
  4478. end
  4479. end
  4480. i = i + 1;
  4481. token = _G["EMOTE"..i.."_TOKEN"];
  4482. end
  4483. return string1 < string2;
  4484. end
  4485. function OnMenuLoad(self,list,func)
  4486. sort(list, TextEmoteSort);
  4487. UIMenu_Initialize(self);
  4488. self.parentMenu = "ChatMenu";
  4489. for index, value in pairs(list) do
  4490. local i = 1;
  4491. local token = _G["EMOTE"..i.."_TOKEN"];
  4492. while ( i < MAXEMOTEINDEX ) do
  4493. if ( token == value ) then
  4494. break;
  4495. end
  4496. i = i + 1;
  4497. token = _G["EMOTE"..i.."_TOKEN"];
  4498. end
  4499. local label = _G["EMOTE"..i.."_CMD1"];
  4500. if ( not label ) then
  4501. label = value;
  4502. end
  4503. UIMenu_AddButton(self, label, nil, func);
  4504. end
  4505. UIMenu_AutoSize(self);
  4506. end
  4507. function EmoteMenu_OnLoad(self)
  4508. OnMenuLoad(self, EmoteList, EmoteMenu_Click);
  4509. end
  4510. function LanguageMenu_OnLoad(self)
  4511. UIMenu_Initialize(self);
  4512. self.parentMenu = "ChatMenu";
  4513. self:RegisterEvent("PLAYER_ENTERING_WORLD");
  4514. self:RegisterEvent("LANGUAGE_LIST_CHANGED");
  4515. self:RegisterEvent("NEUTRAL_FACTION_SELECT_RESULT");
  4516. end
  4517. function VoiceMacroMenu_Click(self)
  4518. local emote = TextEmoteSpeechList[self:GetID()];
  4519. if (emote == EMOTE454_TOKEN or emote == EMOTE455_TOKEN) then
  4520. local faction = UnitFactionGroup("player", true);
  4521. if (faction == "Alliance") then
  4522. emote = EMOTE454_TOKEN;
  4523. elseif (faction == "Horde") then
  4524. emote = EMOTE455_TOKEN;
  4525. end
  4526. end
  4527. DoEmote(emote);
  4528. ChatMenu:Hide();
  4529. end
  4530. function VoiceMacroMenu_OnLoad(self)
  4531. OnMenuLoad(self, TextEmoteSpeechList, VoiceMacroMenu_Click);
  4532. end
  4533. function LanguageMenu_OnEvent(self, event, ...)
  4534. if ( event == "PLAYER_ENTERING_WORLD" ) then
  4535. self:Hide();
  4536. UIMenu_Initialize(self);
  4537. LanguageMenu_LoadLanguages(self);
  4538. self:GetParent().chatFrame.editBox.language, self:GetParent().chatFrame.editBox.languageID = GetDefaultLanguage();
  4539. return;
  4540. end
  4541. if ( event == "LANGUAGE_LIST_CHANGED" ) then
  4542. self:Hide();
  4543. UIMenu_Initialize(self);
  4544. LanguageMenu_LoadLanguages(self);
  4545. return;
  4546. end
  4547. if ( event == "NEUTRAL_FACTION_SELECT_RESULT" ) then
  4548. self:Hide();
  4549. self:GetParent().chatFrame.editBox.language, self:GetParent().chatFrame.editBox.languageID = GetDefaultLanguage();
  4550. return;
  4551. end
  4552. end
  4553. function LanguageMenu_LoadLanguages(self)
  4554. local numLanguages = GetNumLanguages();
  4555. local i;
  4556. local editBoxLanguageID = self:GetParent().chatFrame.editBox.languageID;
  4557. local languageKnown = false;
  4558. for i = 1, numLanguages, 1 do
  4559. local language, languageID = GetLanguageByIndex(i);
  4560. UIMenu_AddButton(self, language, nil, LanguageMenu_Click);
  4561. if ( languageID == editBoxLanguageID ) then
  4562. languageKnown = true;
  4563. end
  4564. end
  4565. if ( languageKnown ~= true ) then
  4566. self:GetParent().chatFrame.editBox.language, self:GetParent().chatFrame.editBox.languageID = GetLanguageByIndex(1);
  4567. end
  4568. UIMenu_AutoSize(self);
  4569. end
  4570. function LanguageMenu_Click(self)
  4571. self:GetParent():GetParent().chatFrame.editBox.language, self:GetParent():GetParent().chatFrame.editBox.languageID = GetLanguageByIndex(self:GetID());
  4572. ChatMenu:Hide();
  4573. end
  4574. function ChatFrame_ActivateCombatMessages(chatFrame)
  4575. ChatFrame_AddMessageGroup(chatFrame, "OPENING");
  4576. ChatFrame_AddMessageGroup(chatFrame, "TRADESKILLS");
  4577. ChatFrame_AddMessageGroup(chatFrame, "PET_INFO");
  4578. ChatFrame_AddMessageGroup(chatFrame, "COMBAT_MISC_INFO");
  4579. ChatFrame_AddMessageGroup(chatFrame, "COMBAT_XP_GAIN");
  4580. ChatFrame_AddMessageGroup(chatFrame, "COMBAT_HONOR_GAIN");
  4581. ChatFrame_AddMessageGroup(chatFrame, "COMBAT_FACTION_CHANGE");
  4582. end
  4583. function ChatChannelDropDown_Show(chatFrame, chatType, chatTarget, chatName)
  4584. HideDropDownMenu(1);
  4585. ChatChannelDropDown.initialize = ChatChannelDropDown_Initialize;
  4586. ChatChannelDropDown.displayMode = "MENU";
  4587. ChatChannelDropDown.chatType = chatType;
  4588. ChatChannelDropDown.chatTarget = chatTarget;
  4589. ChatChannelDropDown.chatName = chatName;
  4590. ChatChannelDropDown.chatFrame = chatFrame;
  4591. ToggleDropDownMenu(1, nil, ChatChannelDropDown, "cursor");
  4592. end
  4593. function ChatChannelDropDown_Initialize()
  4594. local frame = ChatChannelDropDown;
  4595. local info = UIDropDownMenu_CreateInfo();
  4596. info.text = ChatFrame_ResolveChannelName(frame.chatName);
  4597. info.notCheckable = true;
  4598. info.isTitle = true;
  4599. UIDropDownMenu_AddButton(info, 1);
  4600. local clubId, streamId = ChatFrame_GetCommunityAndStreamFromChannel(frame.chatName);
  4601. if clubId and streamId and C_Club.IsEnabled() then
  4602. info = UIDropDownMenu_CreateInfo();
  4603. info.text = CHAT_CHANNEL_DROP_DOWN_OPEN_COMMUNITIES_FRAME;
  4604. info.notCheckable = true;
  4605. info.func = function ()
  4606. if not CommunitiesFrame or not CommunitiesFrame:IsShown() then
  4607. ToggleCommunitiesFrame();
  4608. end
  4609. CommunitiesFrame:SelectStream(clubId, streamId);
  4610. CommunitiesFrame:SelectClub(clubId);
  4611. end;
  4612. UIDropDownMenu_AddButton(info);
  4613. end
  4614. info = UIDropDownMenu_CreateInfo();
  4615. info.text = MOVE_TO_NEW_WINDOW;
  4616. info.notCheckable = 1;
  4617. info.func = ChatChannelDropDown_PopOutChat;
  4618. info.arg1 = frame.chatType;
  4619. info.arg2 = frame.chatTarget;
  4620. if ( FCF_GetNumActiveChatFrames() == NUM_CHAT_WINDOWS ) then
  4621. info.disabled = 1;
  4622. end
  4623. UIDropDownMenu_AddButton(info);
  4624. end
  4625. function ChatChannelDropDown_PopOutChat(self, chatType, chatTarget)
  4626. local sourceChatFrame = ChatChannelDropDown.chatFrame;
  4627. local windowName;
  4628. if ( chatType == "CHANNEL" ) then
  4629. windowName = Chat_GetChannelShortcutName(chatTarget);
  4630. else
  4631. windowName = _G[chatType];
  4632. end
  4633. local frame = FCF_OpenNewWindow(windowName);
  4634. FCF_CopyChatSettings(frame, sourceChatFrame);
  4635. ChatFrame_RemoveAllMessageGroups(frame);
  4636. ChatFrame_RemoveAllChannels(frame);
  4637. ChatFrame_ReceiveAllPrivateMessages(frame);
  4638. ChatFrame_AddMessageGroup(frame, chatType);
  4639. if ( CHAT_CATEGORY_LIST[chatType] ) then
  4640. for _, chat in pairs(CHAT_CATEGORY_LIST[chatType]) do
  4641. ChatFrame_AddMessageGroup(frame, chat);
  4642. end
  4643. end
  4644. frame.editBox:SetAttribute("chatType", chatType);
  4645. frame.editBox:SetAttribute("stickyType", chatType);
  4646. if ( chatType == "CHANNEL" ) then
  4647. frame.editBox:SetAttribute("channelTarget", chatTarget);
  4648. ChatFrame_AddChannel(frame, Chat_GetChannelShortcutName(chatTarget));
  4649. end
  4650. if ( chatType == "PET_BATTLE_COMBAT_LOG" or chatType == "PET_BATTLE_INFO" ) then
  4651. frame.editBox:SetAttribute("chatType", "SAY");
  4652. frame.editBox:SetAttribute("stickyType", "SAY");
  4653. end
  4654. --Remove the things popped out from the source chat frame.
  4655. if ( chatType == "CHANNEL" ) then
  4656. ChatFrame_RemoveChannel(sourceChatFrame, Chat_GetChannelShortcutName(chatTarget));
  4657. else
  4658. ChatFrame_RemoveMessageGroup(sourceChatFrame, chatType);
  4659. if ( CHAT_CATEGORY_LIST[chatType] ) then
  4660. for _, chat in pairs(CHAT_CATEGORY_LIST[chatType]) do
  4661. ChatFrame_RemoveMessageGroup(sourceChatFrame, chat);
  4662. end
  4663. end
  4664. end
  4665. --Copy over messages
  4666. local accessID = ChatHistory_GetAccessID(chatType, chatTarget);
  4667. for i = 1, sourceChatFrame:GetNumMessages() do
  4668. local text, r, g, b, chatTypeID, messageAccessID, lineID = sourceChatFrame:GetMessageInfo(i);
  4669. if messageAccessID == accessID then
  4670. frame:AddMessage(text, r, g, b, chatTypeID, messageAccessID, lineID);
  4671. end
  4672. end
  4673. --Remove the messages from the old frame.
  4674. sourceChatFrame:RemoveMessagesByPredicate(function(text, r, g, b, chatTypeID, messageAccessID, lineID) return messageAccessID == accessID; end);
  4675. end
  4676. function Chat_GetChannelShortcutName(index)
  4677. local _, name = GetChannelName(index);
  4678. name = strtrim(name:match("([^%-]+)"));
  4679. return name;
  4680. end
  4681. function ChatChannelDropDown_PopInChat(self, chatType, chatTarget)
  4682. --PopOutChat_PopInChat(chatType, chatTarget);
  4683. end
  4684. function Chat_ShouldColorChatByClass(chatTypeInfo)
  4685. local override = ChatClassColorOverrideShown();
  4686. local colorByClass = chatTypeInfo and chatTypeInfo.colorNameByClass;
  4687. return override or (override == nil and colorByClass);
  4688. end
  4689. function Chat_GetColoredChatName(chatType, chatTarget)
  4690. if ( chatType == "CHANNEL" ) then
  4691. local info = ChatTypeInfo["CHANNEL"..chatTarget];
  4692. local colorString = format("|cff%02x%02x%02x", info.r * 255, info.g * 255, info.b * 255);
  4693. local chanNum, channelName = GetChannelName(chatTarget);
  4694. return format("%s|Hchannel:channel:%d|h[%d. %s]|h|r", colorString, chanNum, chanNum, gsub(channelName, "%s%-%s.*", "")); --The gsub removes zone-specific markings (e.g. "General - Ironforge" to "General")
  4695. elseif ( chatType == "WHISPER" ) then
  4696. local info = ChatTypeInfo["WHISPER"];
  4697. local colorString = format("|cff%02x%02x%02x", info.r * 255, info.g * 255, info.b * 255);
  4698. return format("%s[%s] |Hplayer:%3$s|h[%3$s]|h|r", colorString, _G[chatType], chatTarget);
  4699. else
  4700. local info = ChatTypeInfo[chatType];
  4701. local colorString = format("|cff%02x%02x%02x", info.r * 255, info.g * 255, info.b * 255);
  4702. return format("%s|Hchannel:%s|h[%s]|h|r", colorString, chatType, _G[chatType]);
  4703. end
  4704. end
  4705. --------------------------------------------------------------------------------
  4706. -- Social share link functions
  4707. --------------------------------------------------------------------------------
  4708. SHARE_ICON_COLOR = "ffffd200";
  4709. SHARE_ICON_TEXT = "|TInterface\\ChatFrame\\UI-ChatIcon-Share:18:18|t";
  4710. function Social_GetShareItemLink(strippedItemLink, earned)
  4711. local earnedNum = 0;
  4712. if (earned) then
  4713. earnedNum = 1;
  4714. end
  4715. return format("|c%s|Hshareitem:%s:%d|h%s|h|r", SHARE_ICON_COLOR, strippedItemLink, earnedNum, SHARE_ICON_TEXT);
  4716. end
  4717. function Social_GetShareAchievementLink(achievementID, earned)
  4718. local earnedNum = 0;
  4719. if (earned) then
  4720. earnedNum = 1;
  4721. end
  4722. return format("|c%s|Hshareachieve:%d:%d|h%s|h|r", SHARE_ICON_COLOR, achievementID, earnedNum, SHARE_ICON_TEXT);
  4723. end
  4724. function Social_GetShareScreenshotLink()
  4725. local index = C_Social.GetLastScreenshotIndex();
  4726. return format("|c%s|Hsharess:%d|h%s|h|r", SHARE_ICON_COLOR, index, SHARE_ICON_TEXT);
  4727. end