ChatFrame.lua

ChatFrame.lua (8.3.0.34963 vs 8.2.5.31960; click to toggle context display)
  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" },
    CHANNEL = { "CHANNEL_JOIN", "CHANNEL_LEAVE", "CHANNEL_NOTICE", "CHANNEL_USER" },
  293. CHANNEL = { "CHANNEL_JOIN", "CHANNEL_LEAVE", "CHANNEL_NOTICE", "CHANNEL_USER", "CHANNEL_NOTICE_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_DEFENSIVEASSIST"] = function(msg)
  1451. if ( SecureCmdOptionParse(msg) ) then
  1452. PetDefensiveAssistMode();
  1453. end
  1454. end
  1455. SecureCmdList["PET_AGGRESSIVE"] = function(msg)
  1456. if ( SecureCmdOptionParse(msg) ) then
  1457. PetAggressiveMode();
  1458. end
  1459. end
  1460. SecureCmdList["PET_ASSIST"] = function(msg)
  1461. if ( SecureCmdOptionParse(msg) ) then
  1462. PetAssistMode();
  1463. end
  1464. end
  1465. SecureCmdList["PET_AUTOCASTON"] = function(msg)
  1466. local spell = SecureCmdOptionParse(msg);
  1467. if ( spell ) then
  1468. EnableSpellAutocast(spell);
  1469. end
  1470. end
  1471. SecureCmdList["PET_AUTOCASTOFF"] = function(msg)
  1472. local spell = SecureCmdOptionParse(msg);
  1473. if ( spell ) then
  1474. DisableSpellAutocast(spell);
  1475. end
  1476. end
  1477. SecureCmdList["PET_AUTOCASTTOGGLE"] = function(msg)
  1478. local spell = SecureCmdOptionParse(msg);
  1479. if ( spell ) then
  1480. ToggleSpellAutocast(spell);
  1481. end
  1482. end
  1483. SecureCmdList["STOPMACRO"] = function(msg)
  1484. if ( SecureCmdOptionParse(msg) ) then
  1485. StopMacro();
  1486. end
  1487. end
  1488. SecureCmdList["CANCELQUEUEDSPELL"] = function(msg)
  1489. if ( SecureCmdOptionParse(msg) ) then
  1490. SpellCancelQueuedSpell();
  1491. end
  1492. end
  1493. SecureCmdList["CLICK"] = function(msg)
  1494. local action = SecureCmdOptionParse(msg);
  1495. if ( action and action ~= "" ) then
  1496. local name, mouseButton, down = strmatch(action, "([^%s]+)%s+([^%s]+)%s*(.*)");
  1497. if ( not name ) then
  1498. name = action;
  1499. end
  1500. local button = GetClickFrame(name);
  1501. if ( button and button:IsObjectType("Button") and not button:IsForbidden() ) then
  1502. button:Click(mouseButton, down);
  1503. end
  1504. end
  1505. end
  1506. SecureCmdList["EQUIP_SET"] = function(msg)
  1507. local set = SecureCmdOptionParse(msg);
  1508. if ( set and set ~= "" ) then
  1509. C_EquipmentSet.UseEquipmentSet(C_EquipmentSet.GetEquipmentSetID(set));
  1510. end
  1511. end
  1512. SecureCmdList["WORLD_MARKER"] = function(msg)
  1513. local marker = SecureCmdOptionParse(msg);
  1514. if ( tonumber(marker) ) then
  1515. PlaceRaidMarker(tonumber(marker));
  1516. end
  1517. end
  1518. SecureCmdList["CLEAR_WORLD_MARKER"] = function(msg)
  1519. local marker = SecureCmdOptionParse(msg);
  1520. if ( tonumber(marker) ) then
  1521. ClearRaidMarker(tonumber(marker));
  1522. elseif ( type(marker) == "string" and strtrim(strlower(marker)) == strlower(ALL) ) then
  1523. ClearRaidMarker(nil); --Clear all world markers.
  1524. end
  1525. end
  1526. SecureCmdList["SUMMON_BATTLE_PET"] = function(msg)
  1527. local pet = SecureCmdOptionParse(msg);
  1528. if ( type(pet) == "string" ) then
  1529. local _, petID = C_PetJournal.FindPetIDByName(string.trim(pet));
  1530. if ( petID ) then
  1531. C_PetJournal.SummonPetByGUID(petID);
  1532. else
  1533. C_PetJournal.SummonPetByGUID(pet);
  1534. end
  1535. end
  1536. end
  1537. SecureCmdList["RANDOMPET"] = function(msg)
  1538. if ( SecureCmdOptionParse(msg) ) then
  1539. C_PetJournal.SummonRandomPet(false);
  1540. end
  1541. end
  1542. SecureCmdList["RANDOMFAVORITEPET"] = function(msg)
  1543. if ( SecureCmdOptionParse(msg) ) then
  1544. C_PetJournal.SummonRandomPet(true);
  1545. end
  1546. end
  1547. SecureCmdList["DISMISSBATTLEPET"] = function(msg)
  1548. if ( SecureCmdOptionParse(msg) ) then
  1549. local petID = C_PetJournal.GetSummonedPetGUID();
  1550. if ( petID ) then
  1551. C_PetJournal.SummonPetByGUID(petID);
  1552. end
  1553. end
  1554. end
  1555. SecureCmdList["PET_DISMISS"] = function(msg)
  1556. if ( PetCanBeAbandoned() ) then
  1557. CastSpellByID(HUNTER_DISMISS_PET);
  1558. else
  1559. PetDismiss();
  1560. end
  1561. end
  1562. SecureCmdList["USE_TOY"] = function(msg)
  1563. local toyName = SecureCmdOptionParse(msg);
  1564. if ( toyName and toyName ~= "" ) then
  1565. UseToyByName(toyName)
  1566. end
  1567. end
  1568. SecureCmdList["LOGOUT"] = function(msg)
  1569. Logout();
  1570. end
  1571. SecureCmdList["QUIT"] = function(msg)
  1572. if (IsKioskModeEnabled()) then
  1573. return;
  1574. end
  1575. Quit();
  1576. end
  1577. SecureCmdList["GUILD_UNINVITE"] = function(msg)
  1578. if(msg == "") then
  1579. msg = UnitName("target");
  1580. end
  1581. if( msg and (strlen(msg) > MAX_CHARACTER_NAME_BYTES) ) then
  1582. ChatFrame_DisplayUsageError(ERR_NAME_TOO_LONG2);
  1583. return;
  1584. end
  1585. GuildUninvite(msg);
  1586. end
  1587. SecureCmdList["GUILD_PROMOTE"] = function(msg)
  1588. if( msg and (strlen(msg) > MAX_CHARACTER_NAME_BYTES) ) then
  1589. ChatFrame_DisplayUsageError(ERR_NAME_TOO_LONG2);
  1590. return;
  1591. end
  1592. GuildPromote(msg);
  1593. end
  1594. SecureCmdList["GUILD_DEMOTE"] = function(msg)
  1595. if( msg and (strlen(msg) > MAX_CHARACTER_NAME_BYTES) ) then
  1596. ChatFrame_DisplayUsageError(ERR_NAME_TOO_LONG2);
  1597. return;
  1598. end
  1599. GuildDemote(msg);
  1600. end
  1601. SecureCmdList["GUILD_LEADER"] = function(msg)
  1602. if( msg and (strlen(msg) > MAX_CHARACTER_NAME_BYTES) ) then
  1603. ChatFrame_DisplayUsageError(ERR_NAME_TOO_LONG2);
  1604. return;
  1605. end
  1606. GuildSetLeader(msg);
  1607. end
  1608. SecureCmdList["GUILD_LEAVE"] = function(msg)
  1609. GuildLeave();
  1610. end
  1611. SecureCmdList["GUILD_DISBAND"] = function(msg)
  1612. if ( IsGuildLeader() ) then
  1613. StaticPopup_Show("CONFIRM_GUILD_DISBAND");
  1614. end
  1615. end
  1616. function AddSecureCmd(cmd, cmdString)
  1617. if not issecure() then
  1618. error("Cannot call AddSecureCmd from insecure code");
  1619. end
  1620. hash_SecureCmdList[strupper(cmdString)] = cmd;
  1621. end
  1622. function AddSecureCmdAliases(cmd, ...)
  1623. for i = 1, select("#", ...) do
  1624. local cmdString = select(i, ...);
  1625. AddSecureCmd(cmd, cmdString);
  1626. end
  1627. end
  1628. -- Pre-populate the secure command hash table
  1629. for index, value in pairs(SecureCmdList) do
  1630. local i = 1;
  1631. local cmdString = "";
  1632. while cmdString do
  1633. cmdString = _G["SLASH_"..index..i];
  1634. if cmdString then
  1635. AddSecureCmd(value, cmdString);
  1636. i = i + 1;
  1637. end
  1638. end
  1639. end
  1640. -- Slash commands
  1641. SlashCmdList = { };
  1642. SlashCmdList["CONSOLE"] = function(msg)
  1643. forceinsecure();
  1644. ConsoleExec(msg);
  1645. end
  1646. SlashCmdList["CHATLOG"] = function(msg)
  1647. local info = ChatTypeInfo["SYSTEM"];
  1648. if ( LoggingChat() ) then
  1649. LoggingChat(false);
  1650. DEFAULT_CHAT_FRAME:AddMessage(CHATLOGDISABLED, info.r, info.g, info.b, info.id);
  1651. else
  1652. LoggingChat(true);
  1653. DEFAULT_CHAT_FRAME:AddMessage(CHATLOGENABLED, info.r, info.g, info.b, info.id);
  1654. end
  1655. end
  1656. SlashCmdList["COMBATLOG"] = function(msg)
  1657. local info = ChatTypeInfo["SYSTEM"];
  1658. if ( LoggingCombat() ) then
  1659. LoggingCombat(false);
  1660. DEFAULT_CHAT_FRAME:AddMessage(COMBATLOGDISABLED, info.r, info.g, info.b, info.id);
  1661. else
  1662. LoggingCombat(true);
  1663. DEFAULT_CHAT_FRAME:AddMessage(COMBATLOGENABLED, info.r, info.g, info.b, info.id);
  1664. end
  1665. end
  1666. SlashCmdList["INVITE"] = function(msg)
  1667. if(msg == "") then
  1668. msg = GetUnitName("target", true)
  1669. end
  1670. if( msg and (strlen(msg) > MAX_CHARACTER_NAME_BYTES) ) then
  1671. ChatFrame_DisplayUsageError(ERR_NAME_TOO_LONG2);
  1672. return;
  1673. end
  1674. if(msg == nil) then
  1675. ChatFrame_DisplayUsageError(ERR_NO_TARGET_OR_NAME);
  1676. return;
  1677. end
  1678. C_PartyInfo.InviteUnit(msg);
  1679. end
  1680. SlashCmdList["REQUEST_INVITE"] = function(msg)
  1681. if(msg == "") then
  1682. msg = GetUnitName("target", true)
  1683. end
  1684. if( msg and (strlen(msg) > MAX_CHARACTER_NAME_BYTES) ) then
  1685. ChatFrame_DisplayUsageError(ERR_NAME_TOO_LONG2);
  1686. return;
  1687. end
  1688. if(msg == nil) then
  1689. ChatFrame_DisplayUsageError(ERR_NO_TARGET_OR_NAME);
  1690. return;
  1691. end
  1692. C_PartyInfo.RequestInviteFromUnit(msg);
  1693. end
  1694. SlashCmdList["UNINVITE"] = function(msg)
  1695. if(msg == "") then
  1696. msg = GetUnitName("target", true);
  1697. end
  1698. if(msg == nil) then
  1699. ChatFrame_DisplayUsageError(ERR_NO_TARGET_OR_NAME);
  1700. return;
  1701. end
  1702. UninviteUnit(msg);
  1703. end
  1704. SlashCmdList["PROMOTE"] = function(msg)
  1705. PromoteToLeader(msg);
  1706. end
  1707. SlashCmdList["REPLY"] = function(msg, editBox)
  1708. local lastTell = ChatEdit_GetLastTellTarget();
  1709. if ( lastTell ) then
  1710. msg = SubstituteChatMessageBeforeSend(msg);
  1711. SendChatMessage(msg, "WHISPER", editBox.languageID, lastTell);
  1712. else
  1713. -- error message
  1714. end
  1715. end
  1716. SlashCmdList["HELP"] = function(msg)
  1717. ChatFrame_DisplayHelpText(DEFAULT_CHAT_FRAME);
  1718. end
  1719. SlashCmdList["MACROHELP"] = function(msg)
  1720. ChatFrame_DisplayMacroHelpText(DEFAULT_CHAT_FRAME);
  1721. end
  1722. SlashCmdList["TIME"] = function(msg)
  1723. ChatFrame_DisplayGameTime(DEFAULT_CHAT_FRAME);
  1724. end
  1725. SlashCmdList["PLAYED"] = function(msg)
  1726. RequestTimePlayed();
  1727. end
  1728. SlashCmdList["FOLLOW"] = function(msg)
  1729. FollowUnit(msg);
  1730. end
  1731. SlashCmdList["TRADE"] = function(msg)
  1732. InitiateTrade("target");
  1733. end
  1734. SlashCmdList["INSPECT"] = function(msg)
  1735. InspectUnit("target");
  1736. end
  1737. SlashCmdList["JOIN"] = function(msg)
  1738. local name = gsub(msg, "%s*([^%s]+).*", "%1");
  1739. local password = gsub(msg, "%s*([^%s]+)%s*(.*)", "%2");
  1740. if(name == "") then
  1741. local joinhelp = CHAT_JOIN_HELP;
  1742. local info = ChatTypeInfo["SYSTEM"];
  1743. DEFAULT_CHAT_FRAME:AddMessage(joinhelp, info.r, info.g, info.b, info.id);
  1744. else
  1745. local zoneChannel, channelName = JoinPermanentChannel(name, password, DEFAULT_CHAT_FRAME:GetID(), 1);
  1746. if ( channelName ) then
  1747. name = channelName;
  1748. end
  1749. if ( not zoneChannel ) then
  1750. local info = ChatTypeInfo["CHANNEL"];
  1751. DEFAULT_CHAT_FRAME:AddMessage(CHAT_INVALID_NAME_NOTICE, info.r, info.g, info.b, info.id);
  1752. return;
  1753. end
  1754. local i = 1;
  1755. while ( DEFAULT_CHAT_FRAME.channelList[i] ) do
  1756. i = i + 1;
  1757. end
  1758. DEFAULT_CHAT_FRAME.channelList[i] = name;
  1759. DEFAULT_CHAT_FRAME.zoneChannelList[i] = zoneChannel;
  1760. end
  1761. end
  1762. SlashCmdList["LEAVE"] = function(msg)
  1763. local name = strmatch(msg, "%s*([^%s]+)");
  1764. if ( name ) then
  1765. LeaveChannelByName(name);
  1766. end
  1767. end
  1768. SlashCmdList["LIST_CHANNEL"] = function(msg)
  1769. local name = strmatch(msg, "%s*([^%s]+)");
  1770. if ( name ) then
  1771. ListChannelByName(name);
  1772. else
  1773. ListChannels();
  1774. end
  1775. end
  1776. SlashCmdList["CHAT_HELP"] =
  1777. function(msg)
  1778. ChatFrame_DisplayChatHelp(DEFAULT_CHAT_FRAME)
  1779. end
  1780. SlashCmdList["CHAT_PASSWORD"] =
  1781. function(msg)
  1782. local name = gsub(msg, "%s*([^%s]+).*", "%1");
  1783. local password = gsub(msg, "%s*([^%s]+)%s*(.*)", "%2");
  1784. SetChannelPassword(name, password);
  1785. end
  1786. SlashCmdList["CHAT_OWNER"] =
  1787. function(msg)
  1788. local channel = gsub(msg, "%s*([^%s]+).*", "%1");
  1789. local newOwner = gsub(msg, "%s*([^%s]+)%s*(.*)", "%2");
  1790. if ( not channel or not newOwner ) then
  1791. return;
  1792. end
  1793. local newOwnerLen = strlen(newOwner);
  1794. if ( newOwnerLen > MAX_CHARACTER_NAME_BYTES ) then
  1795. ChatFrame_DisplayUsageError(ERR_NAME_TOO_LONG2);
  1796. return;
  1797. end
  1798. if ( channel ~= "" ) then
  1799. if ( newOwnerLen > 0 ) then
  1800. SetChannelOwner(channel, newOwner);
  1801. else
  1802. DisplayChannelOwner(channel);
  1803. end
  1804. end
  1805. end
  1806. SlashCmdList["CHAT_MODERATOR"] =
  1807. function(msg)
  1808. local channel, player = strmatch(msg, "%s*([^%s]+)%s*(.*)");
  1809. if ( not channel or not player ) then
  1810. return;
  1811. end
  1812. if ( strlen(player) > MAX_CHARACTER_NAME_BYTES ) then
  1813. ChatFrame_DisplayUsageError(ERR_NAME_TOO_LONG2);
  1814. return;
  1815. end
  1816. ChannelModerator(channel, player);
  1817. end
  1818. SlashCmdList["CHAT_UNMODERATOR"] =
  1819. function(msg)
  1820. local channel, player = strmatch(msg, "%s*([^%s]+)%s*(.*)");
  1821. if ( not channel or not player ) then
  1822. return;
  1823. end
  1824. if ( strlen(player) > MAX_CHARACTER_NAME_BYTES ) then
  1825. ChatFrame_DisplayUsageError(ERR_NAME_TOO_LONG2);
  1826. return;
  1827. end
  1828. if ( channel and player ) then
  1829. ChannelUnmoderator(channel, player);
  1830. end
  1831. end
  1832. SlashCmdList["CHAT_CINVITE"] =
  1833. function(msg)
  1834. local channel, player = strmatch(msg, "%s*([^%s]+)%s*(.*)");
  1835. if ( not channel or not player ) then
  1836. return;
  1837. end
  1838. if ( channel and player ) then
  1839. if ( strlen(player) > MAX_CHARACTER_NAME_BYTES ) then
  1840. ChatFrame_DisplayUsageError(ERR_NAME_TOO_LONG2);
  1841. return;
  1842. end
  1843. ChannelInvite(channel, player);
  1844. end
  1845. end
  1846. SlashCmdList["CHAT_KICK"] =
  1847. function(msg)
  1848. local channel, player = strmatch(msg, "%s*([^%s]+)%s*(.*)");
  1849. if ( not channel or not player ) then
  1850. return;
  1851. end
  1852. if ( strlen(player) > MAX_CHARACTER_NAME_BYTES ) then
  1853. ChatFrame_DisplayUsageError(ERR_NAME_TOO_LONG2);
  1854. return;
  1855. end
  1856. if ( channel and player ) then
  1857. ChannelKick(channel, player);
  1858. end
  1859. end
  1860. SlashCmdList["CHAT_BAN"] =
  1861. function(msg)
  1862. local channel, player = strmatch(msg, "%s*([^%s]+)%s*(.*)");
  1863. if ( not channel or not player ) then
  1864. return;
  1865. end
  1866. if ( strlen(player) > MAX_CHARACTER_NAME_BYTES ) then
  1867. ChatFrame_DisplayUsageError(ERR_NAME_TOO_LONG2);
  1868. return;
  1869. end
  1870. if ( channel and player ) then
  1871. ChannelBan(channel, player);
  1872. end
  1873. end
  1874. SlashCmdList["CHAT_UNBAN"] =
  1875. function(msg)
  1876. local channel, player = strmatch(msg, "%s*([^%s]+)%s*(.*)");
  1877. if ( not channel or not player ) then
  1878. return;
  1879. end
  1880. if ( strlen(player) > MAX_CHARACTER_NAME_BYTES ) then
  1881. ChatFrame_DisplayUsageError(ERR_NAME_TOO_LONG2);
  1882. return;
  1883. end
  1884. if ( channel and player ) then
  1885. ChannelUnban(channel, player);
  1886. end
  1887. end
  1888. SlashCmdList["CHAT_ANNOUNCE"] =
  1889. function(msg)
  1890. local channel = strmatch(msg, "%s*([^%s]+)");
  1891. if ( channel ) then
  1892. ChannelToggleAnnouncements(channel);
  1893. end
  1894. end
  1895. SlashCmdList["GUILD_INVITE"] = function(msg)
  1896. if(msg == "") then
  1897. msg = GetUnitName("target", true);
  1898. end
  1899. if( msg and (strlen(msg) > MAX_CHARACTER_NAME_BYTES) ) then
  1900. ChatFrame_DisplayUsageError(ERR_NAME_TOO_LONG2);
  1901. return;
  1902. end
  1903. GuildInvite(msg);
  1904. end
  1905. SlashCmdList["GUILD_UNINVITE"] = function(msg)
    if(msg == "") then
    msg = UnitName("target");
    end
    if( msg and (strlen(msg) > MAX_CHARACTER_NAME_BYTES) ) then
    ChatFrame_DisplayUsageError(ERR_NAME_TOO_LONG2);
    return;
    end
    GuildUninvite(msg);
    end
    SlashCmdList["GUILD_PROMOTE"] = function(msg)
    if( msg and (strlen(msg) > MAX_CHARACTER_NAME_BYTES) ) then
    ChatFrame_DisplayUsageError(ERR_NAME_TOO_LONG2);
    return;
    end
    GuildPromote(msg);
    end
    SlashCmdList["GUILD_DEMOTE"] = function(msg)
    if( msg and (strlen(msg) > MAX_CHARACTER_NAME_BYTES) ) then
    ChatFrame_DisplayUsageError(ERR_NAME_TOO_LONG2);
    return;
    end
    GuildDemote(msg);
    end
    SlashCmdList["GUILD_LEADER"] = function(msg)
    if( msg and (strlen(msg) > MAX_CHARACTER_NAME_BYTES) ) then
    ChatFrame_DisplayUsageError(ERR_NAME_TOO_LONG2);
    return;
    end
    GuildSetLeader(msg);
    end
  1906. SlashCmdList["GUILD_MOTD"] = function(msg)
  1907. GuildSetMOTD(msg)
  1908. end
  1909. SlashCmdList["GUILD_LEAVE"] = function(msg)
    GuildLeave();
    end
    SlashCmdList["GUILD_DISBAND"] = function(msg)
    if ( IsGuildLeader() ) then
    StaticPopup_Show("CONFIRM_GUILD_DISBAND");
    end
    end
  1910. SlashCmdList["GUILD_INFO"] = function(msg)
  1911. GuildInfo();
  1912. end
  1913. SlashCmdList["GUILD_ROSTER"] = function(msg)
  1914. if ( IsInGuild() ) then
  1915. GuildFrame_LoadUI();
  1916. if ( GuildFrame ) then
  1917. GuildFrameTab2:Click();
  1918. ShowUIPanel(GuildFrame);
  1919. end
  1920. end
  1921. end
  1922. --SlashCmdList["GUILD_HELP"] = function(msg)
  1923. -- ChatFrame_DisplayGuildHelp(DEFAULT_CHAT_FRAME);
  1924. --end
  1925. SlashCmdList["CHAT_AFK"] = function(msg)
  1926. SendChatMessage(msg, "AFK");
  1927. end
  1928. SlashCmdList["CHAT_DND"] = function(msg)
  1929. SendChatMessage(msg, "DND");
  1930. end
  1931. SlashCmdList["WHO"] = function(msg)
  1932. if (IsKioskModeEnabled()) then
  1933. return;
  1934. end
  1935. if ( msg == "" ) then
  1936. msg = WhoFrame_GetDefaultWhoCommand();
  1937. ShowWhoPanel();
  1938. end
  1939. WhoFrameEditBox:SetText(msg);
  1940. C_FriendList.SendWho(msg);
  1941. end
  1942. SlashCmdList["CHANNEL"] = function(msg, editBox)
  1943. msg = SubstituteChatMessageBeforeSend(msg);
  1944. SendChatMessage(msg, "CHANNEL", editBox.languageID, ChatEdit_GetChannelTarget(editBox));
  1945. end
  1946. SlashCmdList["FRIENDS"] = function(msg)
  1947. local player, note = strmatch(msg, "%s*([^%s]+)%s*(.*)");
  1948. if ( player ~= "" or UnitIsPlayer("target") ) then
  1949. C_FriendList.AddOrRemoveFriend(player, note);
  1950. else
  1951. ToggleFriendsPanel();
  1952. end
  1953. end
  1954. SlashCmdList["REMOVEFRIEND"] = function(msg)
  1955. C_FriendList.RemoveFriend(msg);
  1956. end
  1957. SlashCmdList["IGNORE"] = function(msg)
  1958. if ( msg ~= "" or UnitIsPlayer("target") ) then
  1959. local bNetIDAccount = BNet_GetBNetIDAccount(msg);
  1960. if ( bNetIDAccount ) then
  1961. if ( BNIsFriend(bNetIDAccount) ) then
  1962. SendSystemMessage(ERR_CANNOT_IGNORE_BN_FRIEND);
  1963. else
  1964. BNSetBlocked(bNetIDAccount, not BNIsBlocked(bNetIDAccount));
  1965. end
  1966. else
  1967. C_FriendList.AddOrDelIgnore(msg);
  1968. end
  1969. else
  1970. ToggleIgnorePanel();
  1971. end
  1972. end
  1973. SlashCmdList["UNIGNORE"] = function(msg)
  1974. if ( msg ~= "" or UnitIsPlayer("target") ) then
  1975. C_FriendList.DelIgnore(msg);
  1976. else
  1977. ToggleIgnorePanel();
  1978. end
  1979. end
  1980. SlashCmdList["SCRIPT"] = function(msg)
  1981. if ( not ScriptsDisallowedForBeta() ) then
  1982. if ( not AreDangerousScriptsAllowed() ) then
  1983. StaticPopup_Show("DANGEROUS_SCRIPTS_WARNING");
  1984. return;
  1985. end
  1986. RunScript(msg);
  1987. end
  1988. end
  1989. SlashCmdList["RANDOM"] = function(msg)
  1990. local num1 = gsub(msg, "(%s*)(%d+)(.*)", "%2", 1);
  1991. local rest = gsub(msg, "(%s*)(%d+)(.*)", "%3", 1);
  1992. local num2 = "";
  1993. local numSubs;
  1994. if ( rest ~= "" ) then
  1995. num2, numSubs = gsub(msg, "(%s*)(%d+)([-%s]+)(%d+)(.*)", "%4", 1);
  1996. if ( numSubs == 0 ) then
  1997. num2 = "";
  1998. end
  1999. end
  2000. if ( num1 == "" and num2 == "" ) then
  2001. RandomRoll("1", "100");
  2002. elseif ( num2 == "" ) then
  2003. RandomRoll("1", num1);
  2004. else
  2005. RandomRoll(num1, num2);
  2006. end
  2007. end
  2008. SlashCmdList["MACRO"] = function(msg)
  2009. ShowMacroFrame();
  2010. end
  2011. SlashCmdList["PVP"] = function(msg)
  2012. TogglePVP();
  2013. end
  2014. SlashCmdList["RAID_INFO"] = function(msg)
  2015. RaidFrame.slashCommand = 1;
  2016. if ( ( GetNumSavedInstances() + GetNumSavedWorldBosses() > 0 ) and not RaidInfoFrame:IsVisible() ) then
  2017. ToggleRaidFrame();
  2018. RaidInfoFrame:Show();
  2019. elseif ( not RaidFrame:IsVisible() ) then
  2020. ToggleRaidFrame();
  2021. end
  2022. end
  2023. SlashCmdList["READYCHECK"] = function(msg)
  2024. if ( UnitIsGroupLeader("player") or UnitIsGroupAssistant("player") ) then
  2025. DoReadyCheck();
  2026. end
  2027. end
  2028. --[[All of this information is obtainable through the armory now.
  2029. SlashCmdList["SAVEGUILDROSTER"] = function(msg)
  2030. SaveGuildRoster();
  2031. end]]
  2032. SlashCmdList["DUNGEONS"] = function(msg)
  2033. ToggleLFDParentFrame();
  2034. end
  2035. SlashCmdList["BENCHMARK"] = function(msg)
  2036. SetTaxiBenchmarkMode(ValueToBoolean(msg), true);
  2037. end
  2038. SlashCmdList["DISMOUNT"] = function(msg)
  2039. if ( SecureCmdOptionParse(msg) ) then
  2040. Dismount();
  2041. end
  2042. end
  2043. SlashCmdList["LEAVEVEHICLE"] = function(msg)
  2044. if ( SecureCmdOptionParse(msg) ) then
  2045. VehicleExit();
  2046. end
  2047. end
  2048. SlashCmdList["RESETCHAT"] = function(msg)
  2049. FCF_ResetAllWindows();
  2050. end
  2051. SlashCmdList["ENABLE_ADDONS"] = function(msg)
  2052. EnableAllAddOns(msg);
  2053. ReloadUI();
  2054. end
  2055. SlashCmdList["DISABLE_ADDONS"] = function(msg)
  2056. DisableAllAddOns(msg);
  2057. ReloadUI();
  2058. end
  2059. SlashCmdList["STOPWATCH"] = function(msg)
  2060. if ( not IsAddOnLoaded("Blizzard_TimeManager") ) then
  2061. UIParentLoadAddOn("Blizzard_TimeManager");
  2062. end
  2063. if ( StopwatchFrame ) then
  2064. local text = strmatch(msg, "%s*([^%s]+)%s*");
  2065. if ( text ) then
  2066. text = strlower(text);
  2067. -- in any of the following cases, the stopwatch will be shown
  2068. StopwatchFrame:Show();
  2069. -- try to match a command
  2070. local function MatchCommand(param, text)
  2071. local i, compare;
  2072. i = 1;
  2073. repeat
  2074. compare = _G[param..i];
  2075. if ( compare and compare == text ) then
  2076. return true;
  2077. end
  2078. i = i + 1;
  2079. until ( not compare );
  2080. return false;
  2081. end
  2082. if ( MatchCommand("SLASH_STOPWATCH_PARAM_PLAY", text) ) then
  2083. Stopwatch_Play();
  2084. return;
  2085. end
  2086. if ( MatchCommand("SLASH_STOPWATCH_PARAM_PAUSE", text) ) then
  2087. Stopwatch_Pause();
  2088. return;
  2089. end
  2090. if ( MatchCommand("SLASH_STOPWATCH_PARAM_STOP", text) ) then
  2091. Stopwatch_Clear();
  2092. return;
  2093. end
  2094. -- try to match a countdown
  2095. -- kinda ghetto, but hey, it's simple and it works =)
  2096. local hour, minute, second = strmatch(msg, "(%d+):(%d+):(%d+)");
  2097. if ( not hour ) then
  2098. minute, second = strmatch(msg, "(%d+):(%d+)");
  2099. if ( not minute ) then
  2100. second = strmatch(msg, "(%d+)");
  2101. end
  2102. end
  2103. Stopwatch_StartCountdown(tonumber(hour), tonumber(minute), tonumber(second));
  2104. else
  2105. Stopwatch_Toggle();
  2106. end
  2107. end
  2108. end
  2109. SlashCmdList["CALENDAR"] = function(msg)
  2110. if ( not IsAddOnLoaded("Blizzard_Calendar") ) then
  2111. UIParentLoadAddOn("Blizzard_Calendar");
  2112. end
  2113. if ( Calendar_Toggle ) then
  2114. Calendar_Toggle();
  2115. end
  2116. end
  2117. SlashCmdList["ACHIEVEMENTUI"] = function(msg)
  2118. ToggleAchievementFrame();
  2119. end
  2120. SlashCmdList["SET_TITLE"] = function(msg)
  2121. local name = SecureCmdOptionParse(msg);
  2122. if ( name and name ~= "") then
  2123. if(not SetTitleByName(name)) then
  2124. UIErrorsFrame:AddMessage(TITLE_DOESNT_EXIST, 1.0, 0.1, 0.1, 1.0);
  2125. end
  2126. else
  2127. SetCurrentTitle(-1)
  2128. end
  2129. end
  2130. SlashCmdList["USE_TALENT_SPEC"] = function(msg)
  2131. local group = SecureCmdOptionParse(msg);
  2132. if ( group ) then
  2133. local groupNumber = tonumber(group);
  2134. if ( groupNumber ) then
  2135. --SetActiveSpecGroup(groupNumber);
  2136. end
  2137. end
  2138. end
  2139. -- easier method to turn on/off errors for macros
  2140. SlashCmdList["UI_ERRORS_OFF"] = function(msg)
  2141. UIErrorsFrame:UnregisterEvent("UI_ERROR_MESSAGE");
  2142. SetCVar("Sound_EnableSFX", "0");
  2143. end
  2144. SlashCmdList["UI_ERRORS_ON"] = function(msg)
  2145. UIErrorsFrame:RegisterEvent("UI_ERROR_MESSAGE");
  2146. SetCVar("Sound_EnableSFX", "1");
  2147. end
  2148. SlashCmdList["FRAMESTACK"] = function(msg)
  2149. UIParentLoadAddOn("Blizzard_DebugTools");
  2150. local showHiddenArg, showRegionsArg, showAnchorsArg;
  2151. local pattern = "^%s*(%S+)(.*)$";
  2152. showHiddenArg, msg = string.match(msg or "", pattern);
  2153. showRegionsArg, msg = string.match(msg or "", pattern);
  2154. showAnchorsArg, msg = string.match(msg or "", pattern);
  2155. -- If no parameters are passed the defaults specified by these cvars are used instead.
  2156. local showHiddenDefault = FrameStackTooltip_IsShowHiddenEnabled();
  2157. local showRegionsDefault = FrameStackTooltip_IsShowRegionsEnabled();
  2158. local showAnchorsDefault = FrameStackTooltip_IsShowAnchorsEnabled();
  2159. local showHidden = StringToBoolean(showHiddenArg or "", showHiddenDefault);
  2160. local showRegions = StringToBoolean(showRegionsArg or "", showRegionsDefault);
  2161. local showAnchors = StringToBoolean(showAnchorsArg or "", showAnchorsDefault);
  2162. FrameStackTooltip_Toggle(showHidden, showRegions, showAnchors);
  2163. end
  2164. SlashCmdList["EVENTTRACE"] = function(msg)
  2165. UIParentLoadAddOn("Blizzard_DebugTools");
  2166. EventTraceFrame_HandleSlashCmd(msg);
  2167. end
  2168. if IsGMClient() then
  2169. SLASH_TEXELVIS1 = "/texelvis";
  2170. SLASH_TEXELVIS2 = "/tvis";
  2171. SlashCmdList["TEXELVIS"] = function(msg)
  2172. UIParentLoadAddOn("Blizzard_DebugTools");
  2173. TexelSnappingVisualizer:Show();
  2174. end
  2175. end
  2176. SlashCmdList["TABLEINSPECT"] = function(msg)
  2177. if ( IsKioskModeEnabled() or ScriptsDisallowedForBeta() ) then
  2178. return;
  2179. end
  2180. if ( not AreDangerousScriptsAllowed() ) then
  2181. StaticPopup_Show("DANGEROUS_SCRIPTS_WARNING");
  2182. return;
  2183. end
  2184. forceinsecure();
  2185. UIParentLoadAddOn("Blizzard_DebugTools");
  2186. local focusedTable = nil;
  2187. if msg ~= "" and msg ~= " " then
  2188. local focusedFunction = loadstring(("return %s"):format(msg));
  2189. focusedTable = focusedFunction and focusedFunction();
  2190. end
  2191. if focusedTable and type(focusedTable) == "table" then
  2192. DisplayTableInspectorWindow(focusedTable);
  2193. else
  2194. local highlightFrame = FrameStackTooltip:SetFrameStack();
  2195. if highlightFrame then
  2196. DisplayTableInspectorWindow(highlightFrame);
  2197. else
  2198. DisplayTableInspectorWindow(UIParent);
  2199. end
  2200. end
  2201. end
  2202. SlashCmdList["DUMP"] = function(msg)
  2203. if (not IsKioskModeEnabled() and not ScriptsDisallowedForBeta()) then
  2204. if ( not AreDangerousScriptsAllowed() ) then
  2205. StaticPopup_Show("DANGEROUS_SCRIPTS_WARNING");
  2206. return;
  2207. end
  2208. UIParentLoadAddOn("Blizzard_DebugTools");
  2209. DevTools_DumpCommand(msg);
  2210. end
  2211. end
  2212. SlashCmdList["RELOAD"] = function(msg)
  2213. ReloadUI();
  2214. end
  2215. SlashCmdList["WARGAME"] = function(msg)
  2216. -- Parameters are (playername, area, isTournamentMode). Since the player name can be multiple words,
  2217. -- we pass in theses parameters as a whitespace delimited string and let the C side tokenize it
  2218. StartWarGameByName(msg);
  2219. end
  2220. SlashCmdList["SPECTATOR_WARGAME"] = function(msg)
  2221. local target1, target2, size, area, isTournamentMode = strmatch(msg, "^([^%s]+)%s+([^%s]+)%s+([^%s]+)%s*([^%s]*)%s*([^%s]*)")
  2222. if (not target1 or not target2 or not size) then
  2223. return;
  2224. end
  2225. local bnetIDGameAccount1 = BNet_GetBNetIDAccountFromCharacterName(target1) or BNet_GetBNetIDAccount(target1);
  2226. if not bnetIDGameAccount1 then
  2227. ConsolePrint("Failed to find StartSpectatorWarGame target1:", target1);
  2228. end
  2229. local bnetIDGameAccount2 = BNet_GetBNetIDAccountFromCharacterName(target2) or BNet_GetBNetIDAccount(target2);
  2230. if not bnetIDGameAccount2 then
  2231. ConsolePrint("Failed to find StartSpectatorWarGame target2:", target2);
  2232. end
  2233. if (area == "" or area == "nil" or area == "0") then area = nil end
  2234. StartSpectatorWarGame(bnetIDGameAccount1 or target1, bnetIDGameAccount2 or target2, size, area, ValueToBoolean(isTournamentMode));
  2235. end
  2236. SlashCmdList["GUILDFINDER"] = function(msg)
  2237. if ( GameLimitedMode_IsActive() ) then
  2238. UIErrorsFrame:AddMessage(ERR_RESTRICTED_ACCOUNT_TRIAL, 1.0, 0.1, 0.1, 1.0);
  2239. else
  2240. ToggleGuildFinder();
  2241. end
  2242. end
  2243. SlashCmdList["TARGET_MARKER"] = function(msg)
  2244. local marker, target = SecureCmdOptionParse(msg);
  2245. if ( not target ) then
  2246. target = "target";
  2247. end
  2248. if ( tonumber(marker) ) then
  2249. SetRaidTarget(target, tonumber(marker)); --Using /tm 0 will clear the target marker.
  2250. end
  2251. end
  2252. SlashCmdList["OPEN_LOOT_HISTORY"] = function(msg)
  2253. ToggleLootHistoryFrame();
  2254. end
  2255. SlashCmdList["RAIDFINDER"] = function(msg)
  2256. PVEFrame_ToggleFrame("GroupFinderFrame", RaidFinderFrame);
  2257. end
  2258. SlashCmdList["SHARE"] = function(msg)
  2259. -- Allow if any social platforms are enabled (currently only Twitter)
  2260. if (C_Social.IsSocialEnabled()) then
  2261. SocialFrame_LoadUI();
  2262. Social_ToggleShow(msg);
  2263. end
  2264. end
  2265. SlashCmdList["API"] = function(msg)
  2266. APIDocumentation_LoadUI();
  2267. APIDocumentation:HandleSlashCommand(msg);
  2268. end
  2269. SlashCmdList["COMMENTATOR_OVERRIDE"] = function(msg)
  2270. if not IsAddOnLoaded("Blizzard_Commentator") then
  2271. return;
  2272. end
  2273. local originalName, overrideName = msg:match("^(%S-)%s+(.+)");
  2274. if not originalName or not overrideName then
  2275. DEFAULT_CHAT_FRAME:AddMessage(ERROR_SLASH_COMMENTATOROVERRIDE, YELLOW_FONT_COLOR.r, YELLOW_FONT_COLOR.g, YELLOW_FONT_COLOR.b);
  2276. DEFAULT_CHAT_FRAME:AddMessage(ERROR_SLASH_COMMENTATOROVERRIDE_EXAMPLE, YELLOW_FONT_COLOR.r, YELLOW_FONT_COLOR.g, YELLOW_FONT_COLOR.b);
  2277. return;
  2278. end
  2279. originalName = originalName:sub(1, 1):upper() .. originalName:sub(2, -1);
  2280. DEFAULT_CHAT_FRAME:AddMessage((SLASH_COMMENTATOROVERRIDE_SUCCESS):format(originalName, overrideName), YELLOW_FONT_COLOR.r, YELLOW_FONT_COLOR.g, YELLOW_FONT_COLOR.b);
  2281. C_Commentator.AddPlayerOverrideName(originalName, overrideName);
  2282. -- Also add character name without the realm if we got CharacterName-Realm.
  2283. -- Prepend possible realm separators with % so they are matched literally
  2284. local realmSeparateMatchList = string.gsub(REALM_SEPARATORS, ".", "%%%1");
  2285. local characterName = string.match(originalName, "(..-)["..realmSeparateMatchList.."].");
  2286. if characterName and characterName ~= originalName then
  2287. DEFAULT_CHAT_FRAME:AddMessage((SLASH_COMMENTATOROVERRIDE_SUCCESS):format(characterName, overrideName), YELLOW_FONT_COLOR.r, YELLOW_FONT_COLOR.g, YELLOW_FONT_COLOR.b);
  2288. C_Commentator.AddPlayerOverrideName(characterName, overrideName);
  2289. end
  2290. end
  2291. SlashCmdList["COMMENTATOR_NAMETEAM"] = function(msg)
  2292. if not IsAddOnLoaded("Blizzard_Commentator") then
  2293. return;
  2294. end
  2295. local teamIndex, teamName = msg:match("^(%d+) (.+)");
  2296. teamIndex = tonumber(teamIndex);
  2297. if not teamIndex or not teamName then
  2298. DEFAULT_CHAT_FRAME:AddMessage(ERROR_SLASH_COMMENTATOR_NAMETEAM, YELLOW_FONT_COLOR.r, YELLOW_FONT_COLOR.g, YELLOW_FONT_COLOR.b);
  2299. DEFAULT_CHAT_FRAME:AddMessage(ERROR_SLASH_COMMENTATOR_NAMETEAM_EXAMPLE, YELLOW_FONT_COLOR.r, YELLOW_FONT_COLOR.g, YELLOW_FONT_COLOR.b);
  2300. return;
  2301. end
  2302. if not C_Commentator.IsSpectating() then
  2303. DEFAULT_CHAT_FRAME:AddMessage(CONTEXT_ERROR_SLASH_COMMENTATOR_NAMETEAM, YELLOW_FONT_COLOR.r, YELLOW_FONT_COLOR.g, YELLOW_FONT_COLOR.b);
  2304. return;
  2305. else
  2306. DEFAULT_CHAT_FRAME:AddMessage((SLASH_COMMENTATOR_NAMETEAM_SUCCESS):format(teamIndex, teamName), YELLOW_FONT_COLOR.r, YELLOW_FONT_COLOR.g, YELLOW_FONT_COLOR.b);
  2307. end
  2308. CommentatorTeamDisplay:UpdateTeamName(teamIndex, teamName);
  2309. end
  2310. SlashCmdList["COMMENTATOR_ASSIGNPLAYER"] = function(msg)
  2311. if not IsAddOnLoaded("Blizzard_Commentator") then
  2312. return;
  2313. end
  2314. local playerName, teamName = msg:match("^(%S-)%s+(.+)");
  2315. if not playerName or not teamName then
  2316. DEFAULT_CHAT_FRAME:AddMessage(ERROR_SLASH_COMMENTATOR_ASSIGNPLAYER, YELLOW_FONT_COLOR.r, YELLOW_FONT_COLOR.g, YELLOW_FONT_COLOR.b);
  2317. DEFAULT_CHAT_FRAME:AddMessage(ERROR_SLASH_COMMENTATOR_ASSIGNPLAYER_EXAMPLE, YELLOW_FONT_COLOR.r, YELLOW_FONT_COLOR.g, YELLOW_FONT_COLOR.b);
  2318. return;
  2319. end
  2320. DEFAULT_CHAT_FRAME:AddMessage((SLASH_COMMENTATOR_ASSIGNPLAYER_SUCCESS):format(playerName, teamName), YELLOW_FONT_COLOR.r, YELLOW_FONT_COLOR.g, YELLOW_FONT_COLOR.b);
  2321. CommentatorTeamDisplay:AssignPlayerToTeam(playerName, teamName);
  2322. end
  2323. SlashCmdList["RESET_COMMENTATOR_SETTINGS"] = function(msg)
  2324. if not IsAddOnLoaded("Blizzard_Commentator") then
  2325. return;
  2326. end
  2327. PvPCommentator:SetDefaultCommentatorSettings();
  2328. end
  2329. SlashCmdList["VOICECHAT"] = function(msg)
  2330. if msg == "" then
  2331. local info = ChatTypeInfo["SYSTEM"];
  2332. DEFAULT_CHAT_FRAME:AddMessage(VOICE_COMMAND_SYNTAX, info.r, info.g, info.b, info.id);
  2333. return;
  2334. end
  2335. local name = msg;
  2336. local lowerName = string.lower(name);
  2337. if lowerName == string.lower(VOICE_LEAVE_COMMAND) then
  2338. local channelID = C_VoiceChat.GetActiveChannelID();
  2339. if channelID then
  2340. C_VoiceChat.DeactivateChannel(channelID);
  2341. end
  2342. return;
  2343. end
  2344. local channelType;
  2345. local communityID;
  2346. local streamID;
  2347. if lowerName == string.lower(PARTY) then
  2348. channelType = Enum.ChatChannelType.Private_Party;
  2349. elseif lowerName == string.lower(INSTANCE) then
  2350. channelType = Enum.ChatChannelType.Public_Party;
  2351. elseif lowerName == string.lower(GUILD) then
  2352. communityID, streamID = CommunitiesUtil.FindGuildStreamByType(Enum.ClubStreamType.Guild);
  2353. elseif lowerName == string.lower(OFFICER) then
  2354. communityID, streamID = CommunitiesUtil.FindGuildStreamByType(Enum.ClubStreamType.Officer);
  2355. else
  2356. local communityName, streamName = string.split(":", name);
  2357. communityID, streamID = CommunitiesUtil.FindCommunityAndStreamByName(communityName, streamName);
  2358. end
  2359. if channelType then
  2360. if channelType ~= C_VoiceChat.GetActiveChannelType() then
  2361. local activate = true;
  2362. ChannelFrame:TryJoinVoiceChannelByType(channelType, activate);
  2363. end
  2364. elseif communityID and streamID then
  2365. local activeChannelID = C_VoiceChat.GetActiveChannelID();
  2366. local communityStreamChannel = C_VoiceChat.GetChannelForCommunityStream(communityID, streamID);
  2367. local communityStreamChannelID = communityStreamChannel and communityStreamChannel.channelID;
  2368. if not activeChannelID or activeChannelID ~= communityStreamChannelID then
  2369. ChannelFrame:TryJoinCommunityStreamChannel(communityID, streamID);
  2370. end
  2371. end
  2372. end
  2373. SlashCmdList["COMMUNITY"] = function(msg)
  2374. if msg == "" then
  2375. local info = ChatTypeInfo["SYSTEM"];
  2376. DEFAULT_CHAT_FRAME:AddMessage(COMMUNITY_COMMAND_SYNTAX, info.r, info.g, info.b, info.id);
  2377. return;
  2378. end
  2379. local command, clubType = string.split(" ", string.lower(msg));
  2380. local loadCommunity = function()
  2381. if not CommunitiesFrame or not CommunitiesFrame:IsShown() then
  2382. Communities_LoadUI();
  2383. ToggleCommunitiesFrame();
  2384. end
  2385. end
  2386. if command == string.lower(COMMUNITY_COMMAND_JOIN) then
  2387. loadCommunity();
  2388. AddCommunitiesFlow_Toggle()
  2389. elseif command == string.lower(COMMUNITY_COMMAND_CREATE) then
  2390. if clubType == string.lower(COMMUNITY_COMMAND_CHARACTER) then
  2391. loadCommunity();
  2392. CommunitiesCreateCommunityDialog();
  2393. elseif clubType == string.lower(COMMUNITY_COMMAND_BATTLENET) then
  2394. loadCommunity();
  2395. CommunitiesCreateBattleNetDialog();
  2396. end
  2397. end
  2398. end
  2399. function ChatFrame_SetupListProxyTable(list)
  2400. if ( getmetatable(list) ) then
  2401. return;
  2402. end
  2403. setmetatable(list, { __index = {} });
  2404. end
  2405. function ChatFrame_ImportListToHash(list, hash)
  2406. for k, v in pairs(list) do
  2407. local i = 1;
  2408. local tag = _G["SLASH_"..k..i];
  2409. while(tag) do
  2410. tag = strupper(tag);
  2411. if ( hash ) then
  2412. hash[tag] = v;
  2413. end
  2414. hash_ChatTypeInfoList[tag] = k; --Also need to import it here for all types.
  2415. i = i + 1;
  2416. tag = _G["SLASH_"..k..i];
  2417. end
  2418. --Add the item we removed to the proxy table.
  2419. local proxyTable = getmetatable(list).__index;
  2420. proxyTable[k] = v;
  2421. end
  2422. table.wipe(list);
  2423. end
  2424. function ChatFrame_ImportEmoteTokensToHash()
  2425. -- Hook up per-faction emotes before we build the emote list hash.
  2426. local factionGroup = UnitFactionGroup("player");
  2427. if ( factionGroup == "Alliance" ) then
  2428. TextEmoteSpeechList[#TextEmoteSpeechList + 1] = "FORTHEALLIANCE";
  2429. elseif ( factionGroup == "Horde" ) then
  2430. TextEmoteSpeechList[#TextEmoteSpeechList + 1] = "FORTHEHORDE";
  2431. end
  2432. local i = 1;
  2433. local j = 1;
  2434. local cmdString = _G["EMOTE"..i.."_CMD"..j];
  2435. while ( i <= MAXEMOTEINDEX ) do
  2436. local token = _G["EMOTE"..i.."_TOKEN"];
  2437. -- if the code in here changes - change the corresponding code above
  2438. if ( token and cmdString) then
  2439. hash_EmoteTokenList[strupper(cmdString)] = token; -- add to hash
  2440. end
  2441. j = j + 1;
  2442. cmdString = _G["EMOTE"..i.."_CMD"..j];
  2443. if ( not cmdString ) then
  2444. i = i + 1;
  2445. j = 1;
  2446. cmdString = _G["EMOTE"..i.."_CMD"..j];
  2447. end
  2448. end
  2449. end
  2450. function ChatFrame_ImportAllListsToHash()
  2451. ChatFrame_ImportListToHash(SecureCmdList, hash_SecureCmdList);
  2452. ChatFrame_ImportListToHash(SlashCmdList, hash_SlashCmdList);
  2453. ChatFrame_ImportListToHash(ChatTypeInfo);
  2454. end
  2455. ChatFrame_SetupListProxyTable(SecureCmdList);
  2456. ChatFrame_SetupListProxyTable(SlashCmdList);
  2457. ChatFrame_SetupListProxyTable(ChatTypeInfo);
  2458. for index, value in pairs(ChatTypeInfo) do
  2459. value.r = 1.0;
  2460. value.g = 1.0;
  2461. value.b = 1.0;
  2462. value.id = GetChatTypeIndex(index);
  2463. end
  2464. ChatFrame_ImportAllListsToHash();
  2465. ChatFrame_ImportEmoteTokensToHash();
  2466. -- ChatFrame functions
  2467. function ChatFrame_OnLoad(self)
  2468. self:SetTimeVisible(120.0);
  2469. self:SetMaxLines(128);
  2470. self:SetFontObject(ChatFontNormal);
  2471. self:SetIndentedWordWrap(true);
  2472. self:SetJustifyH("LEFT");
  2473. self:RegisterEvent("PLAYER_ENTERING_WORLD");
  2474. self:RegisterEvent("UPDATE_CHAT_COLOR");
  2475. self:RegisterEvent("UPDATE_CHAT_WINDOWS");
  2476. self:RegisterEvent("CHAT_MSG_CHANNEL");
  2477. self:RegisterEvent("CHAT_MSG_COMMUNITIES_CHANNEL");
  2478. self:RegisterEvent("CLUB_REMOVED");
  2479. self:RegisterEvent("UPDATE_INSTANCE_INFO");
  2480. self:RegisterEvent("UPDATE_CHAT_COLOR_NAME_BY_CLASS");
  2481. self:RegisterEvent("VARIABLES_LOADED");
  2482. self:RegisterEvent("CHAT_SERVER_DISCONNECTED");
  2483. self:RegisterEvent("CHAT_SERVER_RECONNECTED");
  2484. self:RegisterEvent("BN_CONNECTED");
  2485. self:RegisterEvent("BN_DISCONNECTED");
  2486. self:RegisterEvent("PLAYER_REPORT_SUBMITTED");
  2487. self:RegisterEvent("NEUTRAL_FACTION_SELECT_RESULT");
  2488. self:RegisterEvent("CHARACTER_UPGRADE_SPELL_TIER_SET");
  2489. self:RegisterEvent("ALTERNATIVE_DEFAULT_LANGUAGE_CHANGED");
  2490. self.tellTimer = GetTime();
  2491. self.channelList = {};
  2492. self.zoneChannelList = {};
  2493. self.messageTypeList = {};
  2494. 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.
  2495. self.alternativeDefaultLanguage = GetAlternativeDefaultLanguage();
  2496. end
  2497. function ChatFrame_RegisterForMessages(self, ...)
  2498. local messageGroup;
  2499. local index = 1;
  2500. for i=1, select("#", ...) do
  2501. messageGroup = ChatTypeGroup[select(i, ...)];
  2502. if ( messageGroup ) then
  2503. self.messageTypeList[index] = select(i, ...);
  2504. for index, value in pairs(messageGroup) do
  2505. self:RegisterEvent(value);
  2506. end
  2507. index = index + 1;
  2508. end
  2509. end
  2510. end
  2511. function ChatFrame_RegisterForChannels(self, ...)
  2512. local index = 1;
  2513. for i=1, select("#", ...), 2 do
  2514. self.channelList[index], self.zoneChannelList[index] = select(i, ...);
  2515. index = index + 1;
  2516. end
  2517. end
  2518. function ChatFrame_AddMessageGroup(chatFrame, group)
  2519. local info = ChatTypeGroup[group];
  2520. if ( info ) then
  2521. tinsert(chatFrame.messageTypeList, group);
  2522. for index, value in pairs(info) do
  2523. chatFrame:RegisterEvent(value);
  2524. end
  2525. AddChatWindowMessages(chatFrame:GetID(), group);
  2526. end
  2527. end
  2528. function ChatFrame_ContainsMessageGroup(chatFrame, group)
  2529. for i, messageType in pairs(chatFrame.messageTypeList) do
  2530. if group == messageType then
  2531. return true;
  2532. end
  2533. end
  2534. return false;
  2535. end
  2536. function ChatFrame_AddSingleMessageType(chatFrame, messageType)
  2537. local group = ChatTypeGroupInverted[messageType];
  2538. local info = ChatTypeGroup[group];
  2539. if ( info ) then
  2540. if (not tContains(chatFrame.messageTypeList, group)) then
  2541. tinsert(chatFrame.messageTypeList, group);
  2542. end
  2543. for index, value in pairs(info) do
  2544. if (value == messageType) then
  2545. chatFrame:RegisterEvent(value);
  2546. end
  2547. end
  2548. end
  2549. end
  2550. function ChatFrame_RemoveMessageGroup(chatFrame, group)
  2551. local info = ChatTypeGroup[group];
  2552. if ( info ) then
  2553. for index, value in pairs(chatFrame.messageTypeList) do
  2554. if ( strupper(value) == strupper(group) ) then
  2555. chatFrame.messageTypeList[index] = nil;
  2556. end
  2557. end
  2558. for index, value in pairs(info) do
  2559. chatFrame:UnregisterEvent(value);
  2560. end
  2561. RemoveChatWindowMessages(chatFrame:GetID(), group);
  2562. end
  2563. end
  2564. function ChatFrame_RemoveAllMessageGroups(chatFrame)
  2565. for index, value in pairs(chatFrame.messageTypeList) do
  2566. for eventIndex, eventValue in pairs(ChatTypeGroup[value]) do
  2567. chatFrame:UnregisterEvent(eventValue);
  2568. end
  2569. RemoveChatWindowMessages(chatFrame:GetID(), value);
  2570. end
  2571. chatFrame.messageTypeList = {};
  2572. end
  2573. function ChatFrame_ContainsChannel(chatFrame, channel)
  2574. for i, channelName in pairs(chatFrame.channelList) do
  2575. if channel == channelName then
  2576. return true;
  2577. end
  2578. end
  2579. return false;
  2580. end
  2581. function ChatFrame_AddNewCommunitiesChannel(chatFrameIndex, clubId, streamId, setEditBoxToChannel)
  2582. local clubInfo = C_Club.GetClubInfo(clubId);
  2583. if clubInfo then
  2584. C_Club.AddClubStreamChatChannel(clubId, streamId);
  2585. local channelColor = DEFAULT_CHAT_CHANNEL_COLOR;
  2586. local channelName = Chat_GetCommunitiesChannelName(clubId, streamId);
  2587. if clubInfo.clubType == Enum.ClubType.BattleNet then
  2588. channelColor = BATTLENET_FONT_COLOR;
  2589. local channel = Chat_GetCommunitiesChannel(clubId, streamId);
  2590. ChangeChatColor(channel, channelColor:GetRGB());
  2591. end
  2592. local chatFrame = _G["ChatFrame"..chatFrameIndex];
  2593. ChatFrame_AddCommunitiesChannel(chatFrame, channelName, channelColor, setEditBoxToChannel);
  2594. end
  2595. end
  2596. function ChatFrame_AddCommunitiesChannel(chatFrame, channelName, channelColor, setEditBoxToChannel)
  2597. local channelIndex = ChatFrame_AddChannel(chatFrame, channelName);
  2598. chatFrame:AddMessage(COMMUNITIES_CHANNEL_ADDED_TO_CHAT_WINDOW:format(channelIndex, ChatFrame_ResolveChannelName(channelName)), channelColor:GetRGB());
  2599. if setEditBoxToChannel then
  2600. chatFrame.editBox:SetAttribute("channelTarget", channelIndex);
  2601. chatFrame.editBox:SetAttribute("chatType", "CHANNEL");
  2602. chatFrame.editBox:SetAttribute("stickyType", "CHANNEL");
  2603. ChatEdit_UpdateHeader(chatFrame.editBox);
  2604. end
  2605. end
  2606. function ChatFrame_CanAddChannel()
  2607. return C_ChatInfo.GetNumActiveChannels() < MAX_WOW_CHAT_CHANNELS;
  2608. end
  2609. function ChatFrame_AddChannel(chatFrame, channel)
  2610. local channelIndex = nil;
  2611. local zoneChannel = AddChatWindowChannel(chatFrame:GetID(), channel);
  2612. if ( zoneChannel ) then
  2613. local i = 1;
  2614. while ( chatFrame.channelList[i] ) do
  2615. i = i + 1;
  2616. end
  2617. chatFrame.channelList[i] = channel;
  2618. chatFrame.zoneChannelList[i] = zoneChannel;
  2619. local localId = GetChannelName(channel);
  2620. channelIndex = localId;
  2621. end
  2622. return channelIndex;
  2623. end
  2624. function ChatFrame_GetCommunitiesChannelLocalID(clubId, streamId)
  2625. local channelName = Chat_GetCommunitiesChannelName(clubId, streamId);
  2626. local localID = GetChannelName(channelName);
  2627. return localID;
  2628. end
  2629. function ChatFrame_RemoveCommunitiesChannel(chatFrame, clubId, streamId, omitMessage)
  2630. local channelName = Chat_GetCommunitiesChannelName(clubId, streamId);
  2631. local channelIndex = ChatFrame_RemoveChannel(chatFrame, channelName);
  2632. if not omitMessage then
  2633. local r, g, b = Chat_GetCommunitiesChannelColor(clubId, streamId);
  2634. chatFrame:AddMessage(COMMUNITIES_CHANNEL_REMOVED_FROM_CHAT_WINDOW:format(channelIndex, ChatFrame_ResolveChannelName(channelName)), r, g, b);
  2635. end
  2636. end
  2637. function ChatFrame_RemoveChannel(chatFrame, channel)
  2638. for index, value in pairs(chatFrame.channelList) do
  2639. if ( strupper(channel) == strupper(value) ) then
  2640. chatFrame.channelList[index] = nil;
  2641. chatFrame.zoneChannelList[index] = nil;
  2642. end
  2643. end
  2644. local localId = GetChannelName(channel);
  2645. RemoveChatWindowChannel(chatFrame:GetID(), channel);
  2646. return localId;
  2647. end
  2648. function ChatFrame_RemoveAllChannels(chatFrame)
  2649. for index, value in pairs(chatFrame.channelList) do
  2650. RemoveChatWindowChannel(chatFrame:GetID(), value);
  2651. end
  2652. chatFrame.channelList = {};
  2653. chatFrame.zoneChannelList = {};
  2654. end
  2655. function ChatFrame_AddPrivateMessageTarget(chatFrame, chatTarget)
  2656. ChatFrame_RemoveExcludePrivateMessageTarget(chatFrame, chatTarget);
  2657. if ( chatFrame.privateMessageList ) then
  2658. chatFrame.privateMessageList[strlower(chatTarget)] = true;
  2659. else
  2660. chatFrame.privateMessageList = { [strlower(chatTarget)] = true };
  2661. end
  2662. end
  2663. function ChatFrame_RemovePrivateMessageTarget(chatFrame, chatTarget)
  2664. if ( chatFrame.privateMessageList ) then
  2665. chatFrame.privateMessageList[strlower(chatTarget)] = nil;
  2666. end
  2667. end
  2668. function ChatFrame_ExcludePrivateMessageTarget(chatFrame, chatTarget)
  2669. ChatFrame_RemovePrivateMessageTarget(chatFrame, chatTarget);
  2670. if ( chatFrame.excludePrivateMessageList ) then
  2671. chatFrame.excludePrivateMessageList[strlower(chatTarget)] = true;
  2672. else
  2673. chatFrame.excludePrivateMessageList = { [strlower(chatTarget)] = true };
  2674. end
  2675. end
  2676. function ChatFrame_RemoveExcludePrivateMessageTarget(chatFrame, chatTarget)
  2677. if ( chatFrame.excludePrivateMessageList ) then
  2678. chatFrame.excludePrivateMessageList[strlower(chatTarget)] = nil;
  2679. end
  2680. end
  2681. function ChatFrame_ReceiveAllPrivateMessages(chatFrame)
  2682. chatFrame.privateMessageList = nil;
  2683. chatFrame.excludePrivateMessageList = nil;
  2684. end
  2685. -- Set up a private editbox to handle macro execution
  2686. do
  2687. local function GetDefaultChatEditBox(field)
  2688. return DEFAULT_CHAT_FRAME.editBox;
  2689. end
  2690. local editbox = CreateFrame("Editbox", "MacroEditBox");
  2691. editbox:RegisterEvent("EXECUTE_CHAT_LINE");
  2692. editbox:SetScript("OnEvent",
  2693. function(self,event,line)
  2694. if ( event == "EXECUTE_CHAT_LINE" ) then
  2695. local defaulteditbox = securecall(GetDefaultChatEditBox);
  2696. self:SetAttribute("chatType", defaulteditbox:GetAttribute("chatType"));
  2697. self:SetAttribute("tellTarget", defaulteditbox:GetAttribute("tellTarget"));
  2698. self:SetAttribute("channelTarget", ChatEdit_GetChannelTarget(defaulteditbox));
  2699. self:SetText(line);
  2700. ChatEdit_SendText(self);
  2701. end
  2702. end
  2703. );
  2704. editbox:Hide();
  2705. end
  2706. function ChatFrame_OnEvent(self, event, ...)
  2707. if ( ChatFrame_ConfigEventHandler(self, event, ...) ) then
  2708. return;
  2709. end
  2710. if ( ChatFrame_SystemEventHandler(self, event, ...) ) then
  2711. return
  2712. end
  2713. if ( ChatFrame_MessageEventHandler(self, event, ...) ) then
  2714. return
  2715. end
  2716. end
  2717. function ChatFrame_UpdateColorByID(self, chatTypeID, r, g, b)
  2718. local function TransformColorByID(text, messageR, messageG, messageB, messageChatTypeID, messageAccessID, lineID)
  2719. if messageChatTypeID == chatTypeID then
  2720. return true, r, g, b;
  2721. end
  2722. return false;
  2723. end
  2724. self:AdjustMessageColors(TransformColorByID);
  2725. end
  2726. function ChatFrame_GetDefaultChatTarget(chatFrame)
  2727. if #chatFrame.messageTypeList == 1 and #chatFrame.channelList == 0 then
  2728. return chatFrame.messageTypeList[1], nil;
  2729. elseif #chatFrame.messageTypeList == 0 and #chatFrame.channelList == 1 then
  2730. local channelName = chatFrame.channelList[1];
  2731. local localID = GetChannelName(channelName);
  2732. if localID ~= 0 then
  2733. return "CHANNEL", localID;
  2734. else
  2735. return "CHANNEL", channelName;
  2736. end
  2737. end
  2738. return nil;
  2739. end
  2740. function ChatFrame_ConfigEventHandler(self, event, ...)
  2741. if ( event == "PLAYER_ENTERING_WORLD" ) then
  2742. self.defaultLanguage = GetDefaultLanguage();
  2743. self.alternativeDefaultLanguage = GetAlternativeDefaultLanguage();
  2744. return true;
  2745. elseif ( event == "NEUTRAL_FACTION_SELECT_RESULT" ) then
  2746. self.defaultLanguage = GetDefaultLanguage();
  2747. self.alternativeDefaultLanguage = GetAlternativeDefaultLanguage();
  2748. return true;
  2749. elseif ( event == "ALTERNATIVE_DEFAULT_LANGUAGE_CHANGED" ) then
  2750. self.alternativeDefaultLanguage = GetAlternativeDefaultLanguage();
  2751. return true;
  2752. elseif ( event == "UPDATE_CHAT_WINDOWS" ) then
  2753. local name, fontSize, r, g, b, a, shown, locked = FCF_GetChatWindowInfo(self:GetID());
  2754. if ( fontSize > 0 ) then
  2755. local fontFile, unused, fontFlags = self:GetFont();
  2756. self:SetFont(fontFile, fontSize, fontFlags);
  2757. end
  2758. if ( shown and not self.minimized ) then
  2759. self:Show();
  2760. end
  2761. -- Do more stuff!!!
  2762. ChatFrame_RegisterForMessages(self, GetChatWindowMessages(self:GetID()));
  2763. ChatFrame_RegisterForChannels(self, GetChatWindowChannels(self:GetID()));
  2764. local defaultChatType, defaultChannelTarget = ChatFrame_GetDefaultChatTarget(self);
  2765. if defaultChatType then
  2766. local editBox = self.editBox;
  2767. editBox:SetAttribute("chatType", defaultChatType);
  2768. editBox:SetAttribute("stickyType", defaultChatType);
  2769. editBox:SetAttribute("channelTarget", defaultChannelTarget);
  2770. ChatEdit_UpdateHeader(editBox);
  2771. end
  2772. -- GMOTD may have arrived before this frame registered for the event
  2773. if ( not self.checkedGMOTD and self:IsEventRegistered("GUILD_MOTD") ) then
  2774. self.checkedGMOTD = true;
  2775. ChatFrame_DisplayGMOTD(self, GetGuildRosterMOTD());
  2776. end
  2777. return true;
  2778. end
  2779. local arg1, arg2, arg3, arg4 = ...;
  2780. if ( event == "UPDATE_CHAT_COLOR" ) then
  2781. local info = ChatTypeInfo[strupper(arg1)];
  2782. if ( info ) then
  2783. info.r = arg2;
  2784. info.g = arg3;
  2785. info.b = arg4;
  2786. ChatFrame_UpdateColorByID(self, info.id, info.r, info.g, info.b);
  2787. if ( strupper(arg1) == "WHISPER" ) then
  2788. info = ChatTypeInfo["REPLY"];
  2789. if ( info ) then
  2790. info.r = arg2;
  2791. info.g = arg3;
  2792. info.b = arg4;
  2793. ChatFrame_UpdateColorByID(self, info.id, info.r, info.g, info.b);
  2794. end
  2795. end
  2796. end
  2797. return true;
  2798. elseif ( event == "UPDATE_CHAT_COLOR_NAME_BY_CLASS" ) then
  2799. local info = ChatTypeInfo[strupper(arg1)];
  2800. if ( info ) then
  2801. info.colorNameByClass = arg2;
  2802. if ( strupper(arg1) == "WHISPER" ) then
  2803. info = ChatTypeInfo["REPLY"];
  2804. if ( info ) then
  2805. info.colorNameByClass = arg2;
  2806. end
  2807. end
  2808. end
  2809. return true;
  2810. elseif ( event == "VARIABLES_LOADED" ) then
  2811. if ( GetCVarBool("chatMouseScroll") ) then
  2812. self:SetScript("OnMouseWheel", FloatingChatFrame_OnMouseScroll);
  2813. self:EnableMouseWheel(true);
  2814. end
  2815. self:UnregisterEvent("VARIABLES_LOADED");
  2816. return true;
  2817. end
  2818. end
  2819. function ChatFrame_SystemEventHandler(self, event, ...)
  2820. if ( event == "TIME_PLAYED_MSG" ) then
  2821. local arg1, arg2 = ...;
  2822. ChatFrame_DisplayTimePlayed(self, arg1, arg2);
  2823. return true;
  2824. elseif ( event == "PLAYER_LEVEL_UP" ) then
  2825. local level, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 = ...;
  2826. LevelUpDisplay_ChatPrint(self, level, LEVEL_UP_TYPE_CHARACTER)
  2827. return true;
  2828. elseif ( event == "QUEST_TURNED_IN" ) then
  2829. local questID, xp, money = ...;
  2830. if questID == WORLD_QUESTS_AVAILABLE_QUEST_ID then
  2831. LevelUpDisplay_ChatPrint(self, nil, TOAST_WORLD_QUESTS_UNLOCKED)
  2832. end
  2833. return true;
  2834. elseif (event == "UNIT_LEVEL" ) then
  2835. local unit = ...;
  2836. if LevelUpDisplay_ShouldDisplayPetLevelUpdate(LevelUpDisplay, unit) then
  2837. LevelUpDisplay_ChatPrint(self, UnitLevel(unit), LEVEL_UP_TYPE_PET);
  2838. end
  2839. elseif ( event == "CHARACTER_UPGRADE_SPELL_TIER_SET" ) then
  2840. local tierIndex = ...;
  2841. if (tierIndex > 0) then
  2842. LevelUpDisplay_ChatPrint(self, tierIndex, LEVEL_UP_TYPE_SPELL_BUCKET);
  2843. end
  2844. return true;
  2845. elseif ( event == "CHARACTER_POINTS_CHANGED" ) then
  2846. local arg1 = ...;
  2847. local info = ChatTypeInfo["SYSTEM"];
  2848. return true;
  2849. elseif ( event == "GUILD_MOTD" ) then
  2850. ChatFrame_DisplayGMOTD(self, ...);
  2851. return true;
  2852. elseif ( event == "UPDATE_INSTANCE_INFO" ) then
  2853. if ( RaidFrame.hasRaidInfo ) then
  2854. local info = ChatTypeInfo["SYSTEM"];
  2855. if ( RaidFrame.slashCommand and GetNumSavedInstances() + GetNumSavedWorldBosses() == 0 and self == DEFAULT_CHAT_FRAME) then
  2856. self:AddMessage(NO_RAID_INSTANCES_SAVED, info.r, info.g, info.b, info.id);
  2857. RaidFrame.slashCommand = nil;
  2858. end
  2859. end
  2860. return true;
  2861. elseif ( event == "CHAT_SERVER_DISCONNECTED" ) then
  2862. local info = ChatTypeInfo["SYSTEM"];
  2863. local isInitialMessage = ...;
  2864. self:AddMessage(CHAT_SERVER_DISCONNECTED_MESSAGE, info.r, info.g, info.b, info.id);
  2865. return true;
  2866. elseif ( event == "CHAT_SERVER_RECONNECTED" ) then
  2867. local info = ChatTypeInfo["SYSTEM"];
  2868. self:AddMessage(CHAT_SERVER_RECONNECTED_MESSAGE, info.r, info.g, info.b, info.id);
  2869. return true;
  2870. elseif ( event == "BN_CONNECTED" ) then
  2871. local suppressNotification = ...;
  2872. local info = ChatTypeInfo["SYSTEM"];
  2873. if not suppressNotification then
  2874. self:AddMessage(BN_CHAT_CONNECTED, info.r, info.g, info.b, info.id);
  2875. end
  2876. elseif ( event == "BN_DISCONNECTED" ) then
  2877. local _, suppressNotification = ...;
  2878. local info = ChatTypeInfo["SYSTEM"];
  2879. if not suppressNotification then
  2880. self:AddMessage(BN_CHAT_DISCONNECTED, info.r, info.g, info.b, info.id);
  2881. end
  2882. elseif ( event == "PLAYER_REPORT_SUBMITTED" ) then
  2883. local guid = ...;
  2884. FCF_RemoveAllMessagesFromChanSender(self, guid);
  2885. return true;
  2886. elseif ( event == "CLUB_REMOVED" ) then
  2887. local clubId = ...;
  2888. local streamIDs = C_ChatInfo.GetClubStreamIDs(clubId);
  2889. for k, streamID in pairs(streamIDs) do
  2890. local channelName = Chat_GetCommunitiesChannelName(clubId, streamID);
  2891. for i = 1, FCF_GetNumActiveChatFrames() do
  2892. local chatWindow = _G["ChatFrame"..i];
  2893. if ChatFrame_ContainsChannel(chatWindow, channelName) then
  2894. local omitMessage = true;
  2895. ChatFrame_RemoveCommunitiesChannel(chatWindow, clubId, streamID, omitMessage);
  2896. end
  2897. end
  2898. end
  2899. end
  2900. end
  2901. function GetColoredName(event, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12)
  2902. local chatType = strsub(event, 10);
  2903. if ( strsub(chatType, 1, 7) == "WHISPER" ) then
  2904. chatType = "WHISPER";
  2905. end
  2906. if ( strsub(chatType, 1, 7) == "CHANNEL" ) then
  2907. chatType = "CHANNEL"..arg8;
  2908. end
  2909. local info = ChatTypeInfo[chatType];
  2910. --ambiguate guild chat names
  2911. if (chatType == "GUILD") then
  2912. arg2 = Ambiguate(arg2, "guild")
  2913. else
  2914. arg2 = Ambiguate(arg2, "none")
  2915. end
  2916. if ( arg12 and info and Chat_ShouldColorChatByClass(info) ) then
  2917. local localizedClass, englishClass, localizedRace, englishRace, sex = GetPlayerInfoByGUID(arg12)
  2918. if ( englishClass ) then
  2919. local classColorTable = RAID_CLASS_COLORS[englishClass];
  2920. if ( not classColorTable ) then
  2921. return arg2;
  2922. end
  2923. return string.format("\124cff%.2x%.2x%.2x", classColorTable.r*255, classColorTable.g*255, classColorTable.b*255)..arg2.."\124r"
  2924. end
  2925. end
  2926. return arg2;
  2927. end
  2928. function RemoveExtraSpaces(str)
  2929. return string.gsub(str, " +", " "); --Replace all instances of 5+ spaces with only 4 spaces.
  2930. end
  2931. function RemoveNewlines(str)
  2932. return string.gsub(str, "\n", "");
  2933. end
  2934. function ChatFrame_DisplayGMOTD(frame, gmotd)
  2935. if ( gmotd and (gmotd ~= "") ) then
  2936. local info = ChatTypeInfo["GUILD"];
  2937. local string = format(GUILD_MOTD_TEMPLATE, gmotd);
  2938. frame:AddMessage(string, info.r, info.g, info.b, info.id);
  2939. end
  2940. end
  2941. function ChatFrame_GetMobileEmbeddedTexture(r, g, b)
  2942. r, g, b = floor(r * 255), floor(g * 255), floor(b * 255);
  2943. return format("|TInterface\\ChatFrame\\UI-ChatIcon-ArmoryChat:14:14:0:0:16:16:0:16:0:16:%d:%d:%d|t", r, g, b);
  2944. end
  2945. function ChatFrame_CanChatGroupPerformExpressionExpansion(chatGroup)
  2946. if chatGroup == "RAID" then
  2947. return true;
  2948. end
  2949. if chatGroup == "INSTANCE_CHAT" then
  2950. return IsInRaid(LE_PARTY_CATEGORY_INSTANCE);
  2951. end
  2952. return false;
  2953. end
  2954. function ChatFrame_MessageEventHandler(self, event, ...)
  2955. if ( strsub(event, 1, 8) == "CHAT_MSG" ) then
  2956. local arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16, arg17 = ...;
  2957. if (arg16) then
  2958. -- hiding sender in letterbox: do NOT even show in chat window (only shows in cinematic frame)
  2959. return true;
  2960. end
  2961. local type = strsub(event, 10);
  2962. local info = ChatTypeInfo[type];
  2963. local filter = false;
  2964. if ( chatFilters[event] ) then
  2965. local newarg1, newarg2, newarg3, newarg4, newarg5, newarg6, newarg7, newarg8, newarg9, newarg10, newarg11, newarg12, newarg13, newarg14;
  2966. for _, filterFunc in next, chatFilters[event] do
  2967. 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);
  2968. if ( filter ) then
  2969. return true;
  2970. elseif ( newarg1 ) then
  2971. 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;
  2972. end
  2973. end
  2974. end
  2975. local coloredName = GetColoredName(event, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14);
  2976. local channelLength = strlen(arg4);
  2977. local infoType = type;
  2978. if ( (type == "COMMUNITIES_CHANNEL") or ((strsub(type, 1, 7) == "CHANNEL") and (type ~= "CHANNEL_LIST") and ((arg1 ~= "INVITE") or (type ~= "CHANNEL_NOTICE_USER"))) ) then
  2979. if ( arg1 == "WRONG_PASSWORD" ) then
  2980. local staticPopup = _G[StaticPopup_Visible("CHAT_CHANNEL_PASSWORD") or ""];
  2981. if ( staticPopup and strupper(staticPopup.data) == strupper(arg9) ) then
  2982. -- Don't display invalid password messages if we're going to prompt for a password (bug 102312)
  2983. return;
  2984. end
  2985. end
  2986. local found = 0;
  2987. for index, value in pairs(self.channelList) do
  2988. if ( channelLength > strlen(value) ) then
  2989. -- arg9 is the channel name without the number in front...
  2990. if ( ((arg7 > 0) and (self.zoneChannelList[index] == arg7)) or (strupper(value) == strupper(arg9)) ) then
  2991. found = 1;
  2992. infoType = "CHANNEL"..arg8;
  2993. info = ChatTypeInfo[infoType];
  2994. if ( (type == "CHANNEL_NOTICE") and (arg1 == "YOU_LEFT") ) then
  2995. self.channelList[index] = nil;
  2996. self.zoneChannelList[index] = nil;
  2997. end
  2998. break;
  2999. end
  3000. end
  3001. end
  3002. if ( (found == 0) or not info ) then
  3003. return true;
  3004. end
  3005. end
  3006. local chatGroup = Chat_GetChatCategory(type);
  3007. local chatTarget;
  3008. if ( chatGroup == "CHANNEL" ) then
  3009. chatTarget = tostring(arg8);
  3010. elseif ( chatGroup == "WHISPER" or chatGroup == "BN_WHISPER" ) then
  3011. if(not(strsub(arg2, 1, 2) == "|K")) then
  3012. chatTarget = strupper(arg2);
  3013. else
  3014. chatTarget = arg2;
  3015. end
  3016. end
  3017. if ( FCFManager_ShouldSuppressMessage(self, chatGroup, chatTarget) ) then
  3018. return true;
  3019. end
  3020. if ( chatGroup == "WHISPER" or chatGroup == "BN_WHISPER" ) then
  3021. if ( self.privateMessageList and not self.privateMessageList[strlower(arg2)] ) then
  3022. return true;
  3023. elseif ( self.excludePrivateMessageList and self.excludePrivateMessageList[strlower(arg2)]
  3024. and ( (chatGroup == "WHISPER" and GetCVar("whisperMode") ~= "popout_and_inline") or (chatGroup == "BN_WHISPER" and GetCVar("whisperMode") ~= "popout_and_inline") ) ) then
  3025. return true;
  3026. end
  3027. end
  3028. if (self.privateMessageList) then
  3029. -- Dedicated BN whisper windows need online/offline messages for only that player
  3030. if ( (chatGroup == "BN_INLINE_TOAST_ALERT" or chatGroup == "BN_WHISPER_PLAYER_OFFLINE") and not self.privateMessageList[strlower(arg2)] ) then
  3031. return true;
  3032. end
  3033. -- HACK to put certain system messages into dedicated whisper windows
  3034. if ( chatGroup == "SYSTEM") then
  3035. local matchFound = false;
  3036. local message = strlower(arg1);
  3037. for playerName, _ in pairs(self.privateMessageList) do
  3038. local playerNotFoundMsg = strlower(format(ERR_CHAT_PLAYER_NOT_FOUND_S, playerName));
  3039. local charOnlineMsg = strlower(format(ERR_FRIEND_ONLINE_SS, playerName, playerName));
  3040. local charOfflineMsg = strlower(format(ERR_FRIEND_OFFLINE_S, playerName));
  3041. if ( message == playerNotFoundMsg or message == charOnlineMsg or message == charOfflineMsg) then
  3042. matchFound = true;
  3043. break;
  3044. end
  3045. end
  3046. if (not matchFound) then
  3047. return true;
  3048. end
  3049. end
  3050. end
  3051. if ( type == "SYSTEM" or type == "SKILL" or type == "CURRENCY" or type == "MONEY" or
  3052. type == "OPENING" or type == "TRADESKILLS" or type == "PET_INFO" or type == "TARGETICONS" or type == "BN_WHISPER_PLAYER_OFFLINE") then
  3053. self:AddMessage(arg1, info.r, info.g, info.b, info.id);
  3054. elseif (type == "LOOT") then
  3055. -- Append [Share] hyperlink if this is a valid social item and you are the looter.
  3056. if (C_Social.IsSocialEnabled() and UnitGUID("player") == arg12) then
  3057. -- Because it is being placed inside another hyperlink (the shareitem link created below), we have to strip off the hyperlink markup
  3058. -- 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
  3059. local itemID, strippedItemLink = GetItemInfoFromHyperlink(arg1);
  3060. if (itemID and C_Social.GetLastItem() == itemID) then
  3061. arg1 = arg1 .. " " .. Social_GetShareItemLink(strippedItemLink, true);
  3062. end
  3063. end
  3064. self:AddMessage(arg1, info.r, info.g, info.b, info.id);
  3065. elseif ( strsub(type,1,7) == "COMBAT_" ) then
  3066. self:AddMessage(arg1, info.r, info.g, info.b, info.id);
  3067. elseif ( strsub(type,1,6) == "SPELL_" ) then
  3068. self:AddMessage(arg1, info.r, info.g, info.b, info.id);
  3069. elseif ( strsub(type,1,10) == "BG_SYSTEM_" ) then
  3070. self:AddMessage(arg1, info.r, info.g, info.b, info.id);
  3071. elseif ( strsub(type,1,11) == "ACHIEVEMENT" ) then
  3072. -- Append [Share] hyperlink
  3073. if (arg12 == UnitGUID("player") and C_Social.IsSocialEnabled()) then
  3074. local achieveID = GetAchievementInfoFromHyperlink(arg1);
  3075. if (achieveID) then
  3076. arg1 = arg1 .. " " .. Social_GetShareAchievementLink(achieveID, true);
  3077. end
  3078. end
  3079. self:AddMessage(arg1:format(GetPlayerLink(arg2, ("[%s]"):format(coloredName))), info.r, info.g, info.b, info.id);
  3080. elseif ( strsub(type,1,18) == "GUILD_ACHIEVEMENT" ) then
  3081. local message = arg1:format(GetPlayerLink(arg2, ("[%s]"):format(coloredName)));
  3082. if (C_Social.IsSocialEnabled()) then
  3083. local achieveID = GetAchievementInfoFromHyperlink(arg1);
  3084. if (achieveID) then
  3085. local isGuildAchievement = select(12, GetAchievementInfo(achieveID));
  3086. if (isGuildAchievement) then
  3087. message = message .. " " .. Social_GetShareAchievementLink(achieveID, true);
  3088. end
  3089. end
  3090. end
  3091. self:AddMessage(message, info.r, info.g, info.b, info.id);
  3092. elseif ( type == "IGNORED" ) then
  3093. self:AddMessage(format(CHAT_IGNORED, arg2), info.r, info.g, info.b, info.id);
  3094. elseif ( type == "FILTERED" ) then
  3095. self:AddMessage(format(CHAT_FILTERED, arg2), info.r, info.g, info.b, info.id);
  3096. elseif ( type == "RESTRICTED" ) then
  3097. self:AddMessage(CHAT_RESTRICTED_TRIAL, info.r, info.g, info.b, info.id);
  3098. elseif ( type == "CHANNEL_LIST") then
  3099. if(channelLength > 0) then
  3100. self:AddMessage(format(_G["CHAT_"..type.."_GET"]..arg1, tonumber(arg8), arg4), info.r, info.g, info.b, info.id);
  3101. else
  3102. self:AddMessage(arg1, info.r, info.g, info.b, info.id);
  3103. end
  3104. elseif (type == "CHANNEL_NOTICE_USER") then
  3105. local globalstring = _G["CHAT_"..arg1.."_NOTICE_BN"];
  3106. if ( not globalstring ) then
  3107. globalstring = _G["CHAT_"..arg1.."_NOTICE"];
  3108. end
  3109. if not globalstring then
  3110. GMError(("Missing global string for %q"):format("CHAT_"..arg1.."_NOTICE_BN"));
  3111. return;
  3112. end
  3113. if(arg5 ~= "") then
  3114. -- TWO users in this notice (E.G. x kicked y)
  3115. self:AddMessage(format(globalstring, arg8, arg4, arg2, arg5), info.r, info.g, info.b, info.id);
  3116. elseif ( arg1 == "INVITE" ) then
    self:AddMessage(format(globalstring, arg4, arg2), info.r, info.g, info.b, info.id);
  3117. local playerLink = GetPlayerLink(arg2, ("[%s]"):format(arg2), arg11);
  3118. local accessID = ChatHistory_GetAccessID(chatGroup, chatTarget);
  3119. local typeID = ChatHistory_GetAccessID(infoType, chatTarget, arg12);
  3120. self:AddMessage(format(globalstring, arg4, playerLink), info.r, info.g, info.b, info.id, accessID, typeID);
  3121. else
  3122. self:AddMessage(format(globalstring, arg8, arg4, arg2), info.r, info.g, info.b, info.id);
  3123. end
  3124. if ( arg1 == "INVITE" and GetCVarBool("blockChannelInvites") ) then
  3125. self:AddMessage(CHAT_MSG_BLOCK_CHAT_CHANNEL_INVITE, info.r, info.g, info.b, info.id);
  3126. end
  3127. elseif (type == "CHANNEL_NOTICE") then
  3128. local globalstring;
  3129. if ( arg1 == "TRIAL_RESTRICTED" ) then
  3130. globalstring = CHAT_TRIAL_RESTRICTED_NOTICE_TRIAL;
  3131. else
  3132. globalstring = _G["CHAT_"..arg1.."_NOTICE_BN"];
  3133. if ( not globalstring ) then
  3134. globalstring = _G["CHAT_"..arg1.."_NOTICE"];
  3135. if not globalstring then
  3136. GMError(("Missing global string for %q"):format("CHAT_"..arg1.."_NOTICE"));
  3137. return;
  3138. end
  3139. end
  3140. end
  3141. local accessID = ChatHistory_GetAccessID(Chat_GetChatCategory(type), arg8);
  3142. local typeID = ChatHistory_GetAccessID(infoType, arg8, arg12);
  3143. self:AddMessage(format(globalstring, arg8, ChatFrame_ResolvePrefixedChannelName(arg4)), info.r, info.g, info.b, info.id, accessID, typeID);
  3144. elseif ( type == "BN_INLINE_TOAST_ALERT" ) then
  3145. local globalstring = _G["BN_INLINE_TOAST_"..arg1];
  3146. if not globalstring then
  3147. GMError(("Missing global string for %q"):format("BN_INLINE_TOAST_"..arg1));
  3148. return;
  3149. end
  3150. local message;
  3151. if ( arg1 == "FRIEND_REQUEST" ) then
  3152. message = globalstring;
  3153. elseif ( arg1 == "FRIEND_PENDING" ) then
  3154. message = format(BN_INLINE_TOAST_FRIEND_PENDING, BNGetNumFriendInvites());
  3155. elseif ( arg1 == "FRIEND_REMOVED" or arg1 == "BATTLETAG_FRIEND_REMOVED" ) then
  3156. message = format(globalstring, arg2);
  3157. elseif ( arg1 == "FRIEND_ONLINE" or arg1 == "FRIEND_OFFLINE") then
  3158. local accountInfo = C_BattleNet.GetAccountInfoByID(arg13);
  3159. if accountInfo and accountInfo.gameAccountInfo.clientProgram ~= "" then
  3160. local characterName = BNet_GetValidatedCharacterNameWithClientEmbeddedTexture(accountInfo.gameAccountInfo.characterName, accountInfo.battleTag, accountInfo.gameAccountInfo.clientProgram, 14);
  3161. local linkDisplayText = ("[%s] (%s)"):format(arg2, characterName);
  3162. local playerLink = GetBNPlayerLink(arg2, linkDisplayText, arg13, arg11, Chat_GetChatCategory(type), 0);
  3163. message = format(globalstring, playerLink);
  3164. else
  3165. local linkDisplayText = ("[%s]"):format(arg2);
  3166. local playerLink = GetBNPlayerLink(arg2, linkDisplayText, arg13, arg11, Chat_GetChatCategory(type), 0);
  3167. message = format(globalstring, playerLink);
  3168. end
  3169. else
  3170. local linkDisplayText = ("[%s]"):format(arg2);
  3171. local playerLink = GetBNPlayerLink(arg2, linkDisplayText, arg13, arg11, Chat_GetChatCategory(type), 0);
  3172. message = format(globalstring, playerLink);
  3173. end
  3174. self:AddMessage(message, info.r, info.g, info.b, info.id);
  3175. elseif ( type == "BN_INLINE_TOAST_BROADCAST" ) then
  3176. if ( arg1 ~= "" ) then
  3177. arg1 = RemoveNewlines(RemoveExtraSpaces(arg1));
  3178. local linkDisplayText = ("[%s]"):format(arg2);
  3179. local playerLink = GetBNPlayerLink(arg2, linkDisplayText, arg13, arg11, Chat_GetChatCategory(type), 0);
  3180. self:AddMessage(format(BN_INLINE_TOAST_BROADCAST, playerLink, arg1), info.r, info.g, info.b, info.id);
  3181. end
  3182. elseif ( type == "BN_INLINE_TOAST_BROADCAST_INFORM" ) then
  3183. if ( arg1 ~= "" ) then
  3184. arg1 = RemoveExtraSpaces(arg1);
  3185. self:AddMessage(BN_INLINE_TOAST_BROADCAST_INFORM, info.r, info.g, info.b, info.id);
  3186. end
  3187. else
  3188. local body;
  3189. local _, fontHeight = FCF_GetChatWindowInfo(self:GetID());
  3190. if ( fontHeight == 0 ) then
  3191. --fontHeight will be 0 if it's still at the default (14)
  3192. fontHeight = 14;
  3193. end
  3194. -- Add AFK/DND flags
  3195. local pflag;
  3196. if(arg6 ~= "") then
  3197. if ( arg6 == "GM" ) then
  3198. --If it was a whisper, dispatch it to the GMChat addon.
  3199. if ( type == "WHISPER" ) then
  3200. return;
  3201. end
  3202. --Add Blizzard Icon, this was sent by a GM
  3203. pflag = "|TInterface\\ChatFrame\\UI-ChatIcon-Blizz:12:20:0:0:32:16:4:28:0:16|t ";
  3204. elseif ( arg6 == "DEV" ) then
  3205. --Add Blizzard Icon, this was sent by a Dev
  3206. pflag = "|TInterface\\ChatFrame\\UI-ChatIcon-Blizz:12:20:0:0:32:16:4:28:0:16|t ";
  3207. else
  3208. pflag = _G["CHAT_FLAG_"..arg6];
  3209. end
  3210. else
  3211. pflag = "";
  3212. end
  3213. if ( type == "WHISPER_INFORM" and GMChatFrame_IsGM and GMChatFrame_IsGM(arg2) ) then
  3214. return;
  3215. end
  3216. local showLink = 1;
  3217. if ( strsub(type, 1, 7) == "MONSTER" or strsub(type, 1, 9) == "RAID_BOSS") then
  3218. showLink = nil;
  3219. else
  3220. arg1 = gsub(arg1, "%%", "%%%%");
  3221. end
  3222. -- Search for icon links and replace them with texture links.
  3223. arg1 = C_ChatInfo.ReplaceIconAndGroupExpressions(arg1, arg17, not ChatFrame_CanChatGroupPerformExpressionExpansion(chatGroup)); -- If arg17 is true, don't convert to raid icons
  3224. --Remove groups of many spaces
  3225. arg1 = RemoveExtraSpaces(arg1);
  3226. local playerLink;
  3227. local playerLinkDisplayText = coloredName;
  3228. local relevantDefaultLanguage = self.defaultLanguage;
  3229. if ( (type == "SAY") or (type == "YELL") ) then
  3230. relevantDefaultLanguage = self.alternativeDefaultLanguage;
  3231. end
  3232. local usingDifferentLanguage = (arg3 ~= "") and (arg3 ~= relevantDefaultLanguage);
  3233. local usingEmote = (type == "EMOTE") or (type == "TEXT_EMOTE");
  3234. if ( usingDifferentLanguage or not usingEmote ) then
  3235. playerLinkDisplayText = ("[%s]"):format(coloredName);
  3236. end
  3237. local isCommunityType = type == "COMMUNITIES_CHANNEL";
  3238. local playerName, lineID, bnetIDAccount = arg2, arg11, arg13;
  3239. if ( isCommunityType ) then
  3240. local isBattleNetCommunity = bnetIDAccount ~= nil and bnetIDAccount ~= 0;
  3241. local messageInfo, clubId, streamId, clubType = C_Club.GetInfoFromLastCommunityChatLine();
  3242. if (messageInfo ~= nil) then
  3243. if ( isBattleNetCommunity ) then
  3244. playerLink = GetBNPlayerCommunityLink(playerName, playerLinkDisplayText, bnetIDAccount, clubId, streamId, messageInfo.messageId.epoch, messageInfo.messageId.position);
  3245. else
  3246. playerLink = GetPlayerCommunityLink(playerName, playerLinkDisplayText, clubId, streamId, messageInfo.messageId.epoch, messageInfo.messageId.position);
  3247. end
  3248. else
  3249. playerLink = playerLinkDisplayText;
  3250. end
  3251. else
  3252. if ( type == "BN_WHISPER" or type == "BN_WHISPER_INFORM" ) then
  3253. playerLink = GetBNPlayerLink(playerName, playerLinkDisplayText, bnetIDAccount, lineID, chatGroup, chatTarget);
  3254. else
  3255. playerLink = GetPlayerLink(playerName, playerLinkDisplayText, lineID, chatGroup, chatTarget);
  3256. end
  3257. end
  3258. local message = arg1;
  3259. if ( arg14 ) then --isMobile
  3260. message = ChatFrame_GetMobileEmbeddedTexture(info.r, info.g, info.b)..message;
  3261. end
  3262. if ( usingDifferentLanguage ) then
  3263. local languageHeader = "["..arg3.."] ";
  3264. if ( showLink and (arg2 ~= "") ) then
  3265. body = format(_G["CHAT_"..type.."_GET"]..languageHeader..message, pflag..playerLink);
  3266. else
  3267. body = format(_G["CHAT_"..type.."_GET"]..languageHeader..message, pflag..arg2);
  3268. end
  3269. else
  3270. if ( not showLink or arg2 == "" ) then
  3271. if ( type == "TEXT_EMOTE" ) then
  3272. body = message;
  3273. else
  3274. body = format(_G["CHAT_"..type.."_GET"]..message, pflag..arg2, arg2);
  3275. end
  3276. else
  3277. if ( type == "EMOTE" ) then
  3278. body = format(_G["CHAT_"..type.."_GET"]..message, pflag..playerLink);
  3279. elseif ( type == "TEXT_EMOTE") then
  3280. body = string.gsub(message, arg2, pflag..playerLink, 1);
  3281. elseif (type == "GUILD_ITEM_LOOTED") then
  3282. body = string.gsub(message, "$s", GetPlayerLink(arg2, playerLinkDisplayText));
  3283. else
  3284. body = format(_G["CHAT_"..type.."_GET"]..message, pflag..playerLink);
  3285. end
  3286. end
  3287. end
  3288. -- Add Channel
  3289. if (channelLength > 0) then
  3290. body = "|Hchannel:channel:"..arg8.."|h["..ChatFrame_ResolvePrefixedChannelName(arg4).."]|h "..body;
  3291. end
  3292. --Add Timestamps
  3293. if ( CHAT_TIMESTAMP_FORMAT ) then
  3294. body = BetterDate(CHAT_TIMESTAMP_FORMAT, time())..body;
  3295. end
  3296. local accessID = ChatHistory_GetAccessID(chatGroup, chatTarget);
  3297. local typeID = ChatHistory_GetAccessID(infoType, chatTarget, arg12 or arg13);
  3298. self:AddMessage(body, info.r, info.g, info.b, info.id, accessID, typeID);
  3299. end
  3300. if ( type == "WHISPER" or type == "BN_WHISPER" ) then
  3301. --BN_WHISPER FIXME
  3302. ChatEdit_SetLastTellTarget(arg2, type);
  3303. if ( self.tellTimer and (GetTime() > self.tellTimer) ) then
  3304. PlaySound(SOUNDKIT.TELL_MESSAGE);
  3305. end
  3306. self.tellTimer = GetTime() + CHAT_TELL_ALERT_TIME;
  3307. --FCF_FlashTab(self);
  3308. FlashClientIcon();
  3309. end
  3310. if ( not self:IsShown() ) then
  3311. if ( (self == DEFAULT_CHAT_FRAME and info.flashTabOnGeneral) or (self ~= DEFAULT_CHAT_FRAME and info.flashTab) ) then
  3312. if ( not CHAT_OPTIONS.HIDE_FRAME_ALERTS or type == "WHISPER" or type == "BN_WHISPER" ) then --BN_WHISPER FIXME
  3313. if (not FCFManager_ShouldSuppressMessageFlash(self, chatGroup, chatTarget) ) then
  3314. FCF_StartAlertFlash(self);
  3315. end
  3316. end
  3317. end
  3318. end
  3319. return true;
  3320. end
  3321. end
  3322. function ChatFrame_AddMessageEventFilter (event, filter)
  3323. assert(event and filter);
  3324. if ( chatFilters[event] ) then
  3325. -- Only allow a filter to be added once
  3326. for index, filterFunc in next, chatFilters[event] do
  3327. if ( filterFunc == filter ) then
  3328. return;
  3329. end
  3330. end
  3331. else
  3332. chatFilters[event] = {};
  3333. end
  3334. tinsert(chatFilters[event], filter);
  3335. end
  3336. function ChatFrame_RemoveMessageEventFilter (event, filter)
  3337. assert(event and filter);
  3338. if ( chatFilters[event] ) then
  3339. for index, filterFunc in next, chatFilters[event] do
  3340. if ( filterFunc == filter ) then
  3341. tremove(chatFilters[event], index);
  3342. end
  3343. end
  3344. if ( #chatFilters[event] == 0 ) then
  3345. chatFilters[event] = nil;
  3346. end
  3347. end
  3348. end
  3349. function ChatFrame_GetMessageEventFilters (event)
  3350. assert(event);
  3351. return chatFilters[event];
  3352. end
  3353. function ChatFrame_OnUpdate(self, elapsedSec)
  3354. local flash = self.ScrollToBottomButton.Flash;
  3355. if flash then
  3356. local shouldFlash = not self:AtBottom();
  3357. if shouldFlash ~= UIFrameIsFlashing(flash) then
  3358. if shouldFlash then
  3359. UIFrameFlash(flash, .1, .1, -1, false, CHAT_BUTTON_FLASH_TIME, CHAT_BUTTON_FLASH_TIME);
  3360. FCF_FadeInScrollbar(self);
  3361. else
  3362. UIFrameFlashStop(flash);
  3363. end
  3364. end
  3365. end
  3366. end
  3367. function ChatFrame_OnHyperlinkShow(self, link, text, button)
  3368. SetItemRef(link, text, button, self);
  3369. end
  3370. function ChatFrame_OnMouseWheel(value)
  3371. if ( value > 0 ) then
  3372. SELECTED_DOCK_FRAME:ScrollUp();
  3373. elseif ( value < 0 ) then
  3374. SELECTED_DOCK_FRAME:ScrollDown();
  3375. end
  3376. end
  3377. function ChatFrame_SetChatFocusOverride(editBoxOverride)
  3378. CHAT_FOCUS_OVERRIDE = editBoxOverride;
  3379. end
  3380. function ChatFrame_GetChatFocusOverride()
  3381. return CHAT_FOCUS_OVERRIDE;
  3382. end
  3383. function ChatFrame_ClearChatFocusOverride()
  3384. CHAT_FOCUS_OVERRIDE = nil;
  3385. end
  3386. function ChatFrame_OpenChat(text, chatFrame, desiredCursorPosition)
  3387. if chatFrame == nil and CHAT_FOCUS_OVERRIDE ~= nil then
  3388. if CHAT_FOCUS_OVERRIDE.supportsSlashCommands or not text or strsub(text, 0, 1) ~= "/" then
  3389. CHAT_FOCUS_OVERRIDE:SetFocus();
  3390. if text then
  3391. CHAT_FOCUS_OVERRIDE:SetText(text);
  3392. end
  3393. return;
  3394. end
  3395. end
  3396. local editBox = ChatEdit_ChooseBoxForSend(chatFrame);
  3397. ChatEdit_ActivateChat(editBox);
    editBox.setText = 1;
  3398. editBox.desiredCursorPosition = desiredCursorPosition;
  3399. if text then
  3400. editBox.text = text;
  3401. editBox.setText = 1;
  3402. end
  3403. if ( editBox:GetAttribute("chatType") == editBox:GetAttribute("stickyType") ) then
  3404. if ( (editBox:GetAttribute("stickyType") == "PARTY") and (not IsInGroup(LE_PARTY_CATEGORY_HOME)) or
  3405. (editBox:GetAttribute("stickyType") == "RAID") and (not IsInRaid(LE_PARTY_CATEGORY_HOME)) or
  3406. (editBox:GetAttribute("stickyType") == "INSTANCE_CHAT") and (not IsInGroup(LE_PARTY_CATEGORY_INSTANCE))) then
  3407. editBox:SetAttribute("chatType", "SAY");
  3408. end
  3409. end
  3410. ChatEdit_UpdateHeader(editBox);
  3411. return editBox;
  3412. end
  3413. function ChatFrame_ScrollToBottom()
  3414. SELECTED_DOCK_FRAME:ScrollToBottom();
  3415. end
  3416. function ChatFrame_ScrollUp()
  3417. SELECTED_DOCK_FRAME:ScrollUp();
  3418. end
  3419. function ChatFrame_ScrollDown()
  3420. SELECTED_DOCK_FRAME:ScrollDown();
  3421. end
  3422. --used for chatframe and combat log
  3423. function MessageFrameScrollButton_OnLoad(self)
  3424. self.clickDelay = MESSAGE_SCROLLBUTTON_INITIAL_DELAY;
  3425. self:RegisterForClicks("LeftButtonDown", "LeftButtonUp", "RightButtonUp", "RightButtonDown");
  3426. end
  3427. --Controls scrolling for chatframe and combat log
  3428. function MessageFrameScrollButton_OnUpdate(self, elapsed)
  3429. if (self:GetButtonState() == "PUSHED") then
  3430. self.clickDelay = self.clickDelay - elapsed;
  3431. if ( self.clickDelay < 0 ) then
  3432. local name = self:GetName();
  3433. if ( name == self:GetParent():GetName().."DownButton" ) then
  3434. self:GetParent():GetParent():ScrollDown();
  3435. elseif ( name == self:GetParent():GetName().."UpButton" ) then
  3436. self:GetParent():GetParent():ScrollUp();
  3437. end
  3438. self.clickDelay = MESSAGE_SCROLLBUTTON_SCROLL_DELAY;
  3439. end
  3440. end
  3441. end
  3442. function ChatFrame_ToggleMenu()
  3443. ChatMenu:SetShown(not ChatMenu:IsShown());
  3444. end
  3445. function ChatFrameMenu_UpdateAnchorPoint()
  3446. --Update the menu anchor point
  3447. if ( FCF_GetButtonSide(DEFAULT_CHAT_FRAME) == "right" ) then
  3448. ChatMenu:ClearAllPoints();
  3449. ChatMenu:SetPoint("BOTTOMRIGHT", ChatFrameMenuButton, "TOPLEFT");
  3450. else
  3451. ChatMenu:ClearAllPoints();
  3452. ChatMenu:SetPoint("BOTTOMLEFT", ChatFrameMenuButton, "TOPRIGHT");
  3453. end
  3454. end
  3455. function ChatFrame_SendTell(name, chatFrame)
  3456. local editBox = ChatEdit_ChooseBoxForSend(chatFrame);
  3457. --DEBUG FIXME - for now, we're not going to remove spaces from names. We need to make sure X-server still works.
  3458. -- Remove spaces from the server name for slash command parsing
  3459. --name = gsub(name, " ", "");
  3460. if ( editBox ~= ChatEdit_GetActiveWindow() ) then
  3461. ChatFrame_OpenChat(SLASH_WHISPER1.." "..name.." ", chatFrame);
  3462. else
  3463. editBox:SetText(SLASH_WHISPER1.." "..name.." ");
  3464. end
  3465. ChatEdit_ParseText(editBox, 0);
  3466. end
  3467. function ChatFrame_SendBNetTell(tokenizedName)
  3468. local editBox = ChatEdit_ChooseBoxForSend();
  3469. editBox:SetAttribute("tellTarget", tokenizedName);
  3470. editBox:SetAttribute("chatType", "BN_WHISPER");
  3471. if ( editBox ~= ChatEdit_GetActiveWindow() ) then
  3472. ChatFrame_OpenChat("");
  3473. else
  3474. ChatEdit_UpdateHeader(editBox);
  3475. end
  3476. end
  3477. function ChatFrame_ReplyTell(chatFrame)
  3478. local editBox = ChatEdit_ChooseBoxForSend(chatFrame);
  3479. local lastTell, lastTellType = ChatEdit_GetLastTellTarget();
  3480. if ( lastTell ) then
  3481. --BN_WHISPER FIXME
  3482. editBox:SetAttribute("chatType", lastTellType);
  3483. editBox:SetAttribute("tellTarget", lastTell);
  3484. ChatEdit_UpdateHeader(editBox);
  3485. if ( editBox ~= ChatEdit_GetActiveWindow() ) then
  3486. ChatFrame_OpenChat("", chatFrame);
  3487. end
  3488. else
  3489. -- Error message
  3490. end
  3491. end
  3492. function ChatFrame_ReplyTell2(chatFrame)
  3493. local editBox = ChatEdit_ChooseBoxForSend(chatFrame);
  3494. local lastTold, lastToldType = ChatEdit_GetLastToldTarget();
  3495. if ( lastTold ) then
  3496. --BN_WHISPER FIXME
  3497. editBox:SetAttribute("chatType", lastToldType);
  3498. editBox:SetAttribute("tellTarget", lastTold);
  3499. ChatEdit_UpdateHeader(editBox);
  3500. if ( editBox ~= ChatEdit_GetActiveWindow() ) then
  3501. ChatFrame_OpenChat("", chatFrame);
  3502. end
  3503. else
  3504. -- Error message
  3505. end
  3506. end
  3507. function ChatFrame_DisplayHelpTextSimple(frame)
  3508. if ( not frame ) then
  3509. return;
  3510. end
  3511. local info = ChatTypeInfo["SYSTEM"];
  3512. frame:AddMessage(HELP_TEXT_SIMPLE, info.r, info.g, info.b, info.id);
  3513. end
  3514. function ChatFrame_DisplayHelpText(frame)
  3515. if ( not frame ) then
  3516. return;
  3517. end
  3518. local info = ChatTypeInfo["SYSTEM"];
  3519. local i = 1;
  3520. local text = _G["HELP_TEXT_LINE"..i];
  3521. while text do
  3522. frame:AddMessage(text, info.r, info.g, info.b, info.id);
  3523. i = i + 1;
  3524. text = _G["HELP_TEXT_LINE"..i];
  3525. end
  3526. end
  3527. function ChatFrame_DisplayMacroHelpText(frame)
  3528. if ( not frame ) then
  3529. return;
  3530. end
  3531. local info = ChatTypeInfo["SYSTEM"];
  3532. local i = 1;
  3533. local text = _G["MACRO_HELP_TEXT_LINE"..i];
  3534. while text do
  3535. frame:AddMessage(text, info.r, info.g, info.b, info.id);
  3536. i = i + 1;
  3537. text = _G["MACRO_HELP_TEXT_LINE"..i];
  3538. end
  3539. end
  3540. function ChatFrame_DisplayChatHelp(frame)
  3541. if ( not frame ) then
  3542. return;
  3543. end
  3544. local info = ChatTypeInfo["SYSTEM"];
  3545. local i = 1;
  3546. local text = _G["CHAT_HELP_TEXT_LINE"..i];
  3547. while text do
  3548. frame:AddMessage(text, info.r, info.g, info.b, info.id);
  3549. i = i + 1;
  3550. -- hack fix for removing a line without causing localization problems
  3551. if ( i == 15 ) then
  3552. i = i + 1;
  3553. end
  3554. text = _G["CHAT_HELP_TEXT_LINE"..i];
  3555. end
  3556. end
  3557. function ChatFrame_DisplayGuildHelp(frame)
  3558. if ( not frame ) then
  3559. return;
  3560. end
  3561. local info = ChatTypeInfo["SYSTEM"];
  3562. local i = 1;
  3563. local text = _G["GUILD_HELP_TEXT_LINE"..i];
  3564. while text do
  3565. frame:AddMessage(text, info.r, info.g, info.b, info.id);
  3566. i = i + 1;
  3567. text = _G["GUILD_HELP_TEXT_LINE"..i];
  3568. end
  3569. end
  3570. function ChatFrame_DisplayGameTime(frame)
  3571. if ( not frame ) then
  3572. return;
  3573. end
  3574. local info = ChatTypeInfo["SYSTEM"];
  3575. frame:AddMessage(GameTime_GetGameTime(true), info.r, info.g, info.b, info.id);
  3576. end
  3577. function ChatFrame_TimeBreakDown(time)
  3578. local days = floor(time / (60 * 60 * 24));
  3579. local hours = floor((time - (days * (60 * 60 * 24))) / (60 * 60));
  3580. local minutes = floor((time - (days * (60 * 60 * 24)) - (hours * (60 * 60))) / 60);
  3581. local seconds = mod(time, 60);
  3582. return days, hours, minutes, seconds;
  3583. end
  3584. function ChatFrame_DisplayTimePlayed(self, totalTime, levelTime)
  3585. local info = ChatTypeInfo["SYSTEM"];
  3586. local d;
  3587. local h;
  3588. local m;
  3589. local s;
  3590. d, h, m, s = ChatFrame_TimeBreakDown(totalTime);
  3591. local string = format(TIME_PLAYED_TOTAL, format(TIME_DAYHOURMINUTESECOND, d, h, m, s));
  3592. self:AddMessage(string, info.r, info.g, info.b, info.id);
  3593. d, h, m, s = ChatFrame_TimeBreakDown(levelTime);
  3594. local string = format(TIME_PLAYED_LEVEL, format(TIME_DAYHOURMINUTESECOND, d, h, m, s));
  3595. self:AddMessage(string, info.r, info.g, info.b, info.id);
  3596. end
  3597. function ChatFrame_ChatPageUp()
  3598. SELECTED_CHAT_FRAME:PageUp();
  3599. end
  3600. function ChatFrame_ChatPageDown()
  3601. SELECTED_CHAT_FRAME:PageDown();
  3602. end
  3603. function ChatFrame_DisplayUsageError(messageTag)
  3604. ChatFrame_DisplaySystemMessageInPrimary(messageTag);
  3605. end
  3606. function ChatFrame_DisplaySystemMessageInPrimary(messageTag)
  3607. local info = ChatTypeInfo["SYSTEM"];
  3608. DEFAULT_CHAT_FRAME:AddMessage(messageTag, info.r, info.g, info.b, info.id);
  3609. end
  3610. function ChatFrame_DisplaySystemMessageInCurrent(messageTag)
  3611. local info = ChatTypeInfo["SYSTEM"];
  3612. SELECTED_CHAT_FRAME:AddMessage(messageTag, info.r, info.g, info.b, info.id);
  3613. end
  3614. -- ChatEdit functions
  3615. local ChatEdit_LastTell = {};
  3616. local ChatEdit_LastTellType = {};
  3617. for i = 1, NUM_REMEMBERED_TELLS, 1 do
  3618. ChatEdit_LastTell[i] = "";
  3619. ChatEdit_LastTellType[i] = "";
  3620. end
  3621. local ChatEdit_LastTold;
  3622. local ChatEdit_LastToldType;
  3623. function ChatEdit_OnLoad(self)
  3624. self:SetFrameLevel(self.chatFrame:GetFrameLevel()+1);
  3625. self:SetAttribute("chatType", "SAY");
  3626. self:SetAttribute("stickyType", "SAY");
  3627. self.chatLanguage = GetDefaultLanguage();
  3628. self:RegisterEvent("UPDATE_CHAT_COLOR");
  3629. self.addSpaceToAutoComplete = true;
  3630. self.addHighlightedText = true;
  3631. if ( CHAT_OPTIONS.ONE_EDIT_AT_A_TIME == "many" ) then
  3632. self:Show();
  3633. end
  3634. local function ChatEditAutoComplete(editBox, fullText, nameInfo)
  3635. if nameInfo.bnetID ~= nil and nameInfo.bnetID ~= 0 then
  3636. editBox:SetAttribute("tellTarget", nameInfo.name);
  3637. editBox:SetAttribute("chatType", "BN_WHISPER");
  3638. editBox:SetText("");
  3639. ChatEdit_UpdateHeader(editBox);
  3640. return true;
  3641. end
  3642. return false;
  3643. end
  3644. AutoCompleteEditBox_SetCustomAutoCompleteFunction(self, ChatEditAutoComplete);
  3645. self:SetParent(UIParent);
  3646. end
  3647. function ChatEdit_OnEvent(self, event, ...)
  3648. if ( event == "UPDATE_CHAT_COLOR" ) then
  3649. local chatType = ...;
  3650. if ( self:IsShown() ) then
  3651. ChatEdit_UpdateHeader(self);
  3652. end
  3653. end
  3654. end
  3655. function ChatEdit_OnUpdate(self, elapsedSec)
  3656. if ( self.setText == 1) then
  3657. self:SetText(self.text);
  3658. self.setText = 0;
  3659. ChatEdit_ParseText(self, 0, true);
  3660. if self.desiredCursorPosition then
  3661. self:SetCursorPosition(self.desiredCursorPosition);
  3662. self.desiredCursorPosition = nil;
  3663. end
  3664. end
  3665. end
  3666. function ChatEdit_OnShow(self)
  3667. ChatEdit_ResetChatType(self);
  3668. end
  3669. function ChatEdit_ResetChatType(self)
  3670. if ( self:GetAttribute("chatType") == "PARTY" and (not IsInGroup(LE_PARTY_CATEGORY_HOME)) ) then
  3671. self:SetAttribute("chatType", "SAY");
  3672. end
  3673. if ( self:GetAttribute("chatType") == "RAID" and (not IsInRaid(LE_PARTY_CATEGORY_HOME)) ) then
  3674. self:SetAttribute("chatType", "SAY");
  3675. end
  3676. if ( (self:GetAttribute("chatType") == "GUILD" or self:GetAttribute("chatType") == "OFFICER") and not IsInGuild() ) then
  3677. self:SetAttribute("chatType", "SAY");
  3678. end
  3679. if ( self:GetAttribute("chatType") == "INSTANCE_CHAT" and (not IsInGroup(LE_PARTY_CATEGORY_INSTANCE)) ) then
  3680. self:SetAttribute("chatType", "SAY");
  3681. end
  3682. self.lastTabComplete = nil;
  3683. self.tabCompleteText = nil;
  3684. self.tabCompleteTableIndex = 1;
  3685. ChatEdit_UpdateHeader(self);
  3686. ChatEdit_OnInputLanguageChanged(self);
  3687. --[[if ( CHAT_OPTIONS.ONE_EDIT_AT_A_TIME == "old") then
  3688. self:SetFocus();
  3689. end]]
  3690. end
  3691. function ChatEdit_OnHide(self)
  3692. if ( ACTIVE_CHAT_EDIT_BOX == self ) then
  3693. ChatEdit_DeactivateChat(self);
  3694. end
  3695. if ( LAST_ACTIVE_CHAT_EDIT_BOX == self and self:IsShown() ) then --Our parent was hidden. Let's find a new default frame.
  3696. --We'll go with the active dock frame since people think of that as the primary chat.
  3697. ChatEdit_SetLastActiveWindow(FCFDock_GetSelectedWindow(GENERAL_CHAT_DOCK).editBox);
  3698. end
  3699. end
  3700. function ChatEdit_OnEditFocusGained(self)
  3701. ChatEdit_ActivateChat(self);
  3702. end
  3703. function ChatEdit_OnEditFocusLost(self)
  3704. AutoCompleteEditBox_OnEditFocusLost(self);
  3705. if self:GetText() == "" then
  3706. ChatEdit_DeactivateChat(self);
  3707. end
  3708. end
  3709. function ChatEdit_ActivateChat(editBox)
  3710. ChatFrame_ClearChatFocusOverride();
  3711. if ( ACTIVE_CHAT_EDIT_BOX and ACTIVE_CHAT_EDIT_BOX ~= editBox ) then
  3712. ChatEdit_DeactivateChat(ACTIVE_CHAT_EDIT_BOX);
  3713. end
  3714. ACTIVE_CHAT_EDIT_BOX = editBox;
  3715. ChatEdit_SetLastActiveWindow(editBox);
  3716. --Stop any sort of fading
  3717. UIFrameFadeRemoveFrame(editBox);
  3718. editBox:Show();
  3719. editBox:SetFocus();
  3720. editBox:SetFrameStrata("DIALOG");
  3721. editBox:Raise();
  3722. editBox.header:Show();
  3723. editBox.focusLeft:Show();
  3724. editBox.focusRight:Show();
  3725. editBox.focusMid:Show();
  3726. editBox:SetAlpha(1.0);
  3727. ChatEdit_UpdateHeader(editBox);
  3728. if ( CHAT_SHOW_IME ) then
  3729. _G[editBox:GetName().."Language"]:Show();
  3730. end
  3731. end
  3732. local function ChatEdit_SetDeactivated(editBox)
  3733. editBox:SetFrameStrata("LOW");
  3734. if ( GetCVar("chatStyle") == "classic" and not editBox.isGM ) then
  3735. editBox:Hide();
  3736. else
  3737. editBox:SetText("");
  3738. editBox.header:Hide();
  3739. if ( not editBox.isGM ) then
  3740. editBox:SetAlpha(0.35);
  3741. end
  3742. editBox:ClearFocus();
  3743. editBox.focusLeft:Hide();
  3744. editBox.focusRight:Hide();
  3745. editBox.focusMid:Hide();
  3746. ChatEdit_ResetChatTypeToSticky(editBox);
  3747. ChatEdit_ResetChatType(editBox);
  3748. end
  3749. _G[editBox:GetName().."Language"]:Hide();
  3750. end
  3751. function ChatEdit_DeactivateChat(editBox)
  3752. if ( ACTIVE_CHAT_EDIT_BOX == editBox ) then
  3753. ACTIVE_CHAT_EDIT_BOX = nil;
  3754. end
  3755. ChatEdit_SetDeactivated(editBox);
  3756. end
  3757. function ChatEdit_ChooseBoxForSend(preferredChatFrame)
  3758. if ( GetCVar("chatStyle") == "classic" ) then
  3759. return DEFAULT_CHAT_FRAME.editBox;
  3760. elseif ( preferredChatFrame and preferredChatFrame:IsShown() ) then
  3761. return preferredChatFrame.editBox;
  3762. elseif ( ChatEdit_GetLastActiveWindow() and ChatEdit_GetLastActiveWindow():GetParent():IsShown() ) then
  3763. return ChatEdit_GetLastActiveWindow();
  3764. else
  3765. return FCFDock_GetSelectedWindow(GENERAL_CHAT_DOCK).editBox;
  3766. end
  3767. end
  3768. function ChatEdit_SetLastActiveWindow(editBox)
  3769. local previousValue = LAST_ACTIVE_CHAT_EDIT_BOX;
  3770. if ( LAST_ACTIVE_CHAT_EDIT_BOX and not LAST_ACTIVE_CHAT_EDIT_BOX.isGM and LAST_ACTIVE_CHAT_EDIT_BOX ~= editBox ) then
  3771. if ( GetCVar("chatStyle") == "im" ) then
  3772. LAST_ACTIVE_CHAT_EDIT_BOX:Hide();
  3773. end
  3774. end
  3775. LAST_ACTIVE_CHAT_EDIT_BOX = editBox;
  3776. if ( editBox and GetCVar("chatStyle") == "im" and ACTIVE_CHAT_EDIT_BOX ~= editBox ) then
  3777. editBox:Show();
  3778. ChatEdit_SetDeactivated(editBox);
  3779. end
  3780. if ( previousValue ) then
  3781. FCFClickAnywhereButton_UpdateState(previousValue.chatFrame.clickAnywhereButton);
  3782. end
  3783. if ( editBox ) then
  3784. FCFClickAnywhereButton_UpdateState(editBox.chatFrame.clickAnywhereButton);
  3785. end
  3786. end
  3787. function ChatEdit_GetActiveWindow()
  3788. return ACTIVE_CHAT_EDIT_BOX;
  3789. end
  3790. function ChatEdit_GetLastActiveWindow()
  3791. return LAST_ACTIVE_CHAT_EDIT_BOX;
  3792. end
  3793. function ChatEdit_FocusActiveWindow()
  3794. local active = ChatEdit_GetActiveWindow()
  3795. if ( active ) then
  3796. ChatEdit_ActivateChat(active);
  3797. end
  3798. end
  3799. function ChatEdit_LinkItem(itemID, itemLink)
  3800. if ( not itemLink ) then
  3801. itemLink = select(2, GetItemInfo(itemID));
  3802. end
  3803. if ( itemLink ) then
  3804. if ( ChatEdit_GetActiveWindow() ) then
  3805. ChatEdit_InsertLink(itemLink);
  3806. else
  3807. ChatFrame_OpenChat(itemLink);
  3808. end
  3809. end
  3810. end
  3811. function ChatEdit_InsertLink(text)
  3812. if ( not text ) then
  3813. return false;
  3814. end
  3815. local activeWindow = ChatEdit_GetActiveWindow();
    if ( activeWindow ) then
    activeWindow:Insert(text);
    return true;
    end
    if ( BrowseName and BrowseName:IsVisible() ) then
    local item;
    if ( strfind(text, "battlepet:") ) then
    local petName = strmatch(text, "%[(.+)%]");
    item = petName;
    elseif ( strfind(text, "item:", 1, true) ) then
    item = GetItemInfo(text);
    end
    if ( item ) then
    BrowseName:SetText(item);
    return true;
    end
    end
  3816. if ( MacroFrameText and MacroFrameText:HasFocus() ) then
  3817. local item;
  3818. if ( strfind(text, "item:", 1, true) ) then
  3819. item = GetItemInfo(text);
  3820. end
  3821. local cursorPosition = MacroFrameText:GetCursorPosition();
  3822. if (cursorPosition == 0 or strsub(MacroFrameText:GetText(), cursorPosition, cursorPosition) == "\n" ) then
  3823. if ( item ) then
  3824. if ( GetItemSpell(text) ) then
  3825. MacroFrameText:Insert(SLASH_USE1.." "..item.."\n");
  3826. else
  3827. MacroFrameText:Insert(SLASH_EQUIP1.." "..item.."\n");
  3828. end
  3829. else
  3830. MacroFrameText:Insert(SLASH_CAST1.." "..text.."\n");
  3831. end
  3832. else
  3833. MacroFrameText:Insert(item or text);
  3834. end
  3835. return true;
  3836. end
  3837. if ( TradeSkillFrame and TradeSkillFrame.SearchBox:HasFocus() ) then
  3838. local item;
  3839. if ( strfind(text, "item:", 1, true) ) then
  3840. item = GetItemInfo(text);
  3841. end
  3842. if ( item ) then
  3843. TradeSkillFrame.SearchBox:SetText(item);
  3844. return true;
  3845. end
  3846. end
  3847. if ( CommunitiesFrame and CommunitiesFrame.ChatEditBox:HasFocus() ) then
  3848. CommunitiesFrame.ChatEditBox:Insert(text);
  3849. return true;
  3850. end
  3851. local activeWindow = ChatEdit_GetActiveWindow();
  3852. if ( activeWindow ) then
  3853. activeWindow:Insert(text);
  3854. activeWindow:SetFocus();
  3855. return true;
  3856. end
  3857. if ( AuctionHouseFrame and AuctionHouseFrame:IsVisible() ) then
  3858. local item;
  3859. if ( strfind(text, "battlepet:") ) then
  3860. local petName = strmatch(text, "%[(.+)%]");
  3861. item = petName;
  3862. elseif ( strfind(text, "item:", 1, true) ) then
  3863. item = GetItemInfo(text);
  3864. end
  3865. if ( item ) then
  3866. if ( AuctionHouseFrame:SetSearchText(item) ) then
  3867. return true;
  3868. end
  3869. end
  3870. end
  3871. return false;
  3872. end
  3873. function ChatEdit_TryInsertChatLink(link)
  3874. if ( IsModifiedClick("CHATLINK") and link ) then
  3875. return ChatEdit_InsertLink(link);
  3876. end
  3877. end
  3878. function ChatEdit_TryInsertQuestLinkForQuestID(questID)
  3879. return ChatEdit_TryInsertChatLink(GetQuestLink(questID));
  3880. end
  3881. function ChatEdit_GetChannelTarget(editBox)
  3882. local channelTarget = editBox:GetAttribute("channelTarget"); -- may be a name or an index
  3883. if channelTarget == nil then
  3884. return 0;
  3885. end
  3886. local localID = GetChannelName(channelTarget);
  3887. return localID;
  3888. end
  3889. function ChatEdit_GetLastTellTarget()
  3890. for i=1, #ChatEdit_LastTell do
  3891. local value = ChatEdit_LastTell[i];
  3892. if ( value ~= "" ) then
  3893. return value, ChatEdit_LastTellType[i];
  3894. end
  3895. end
  3896. return nil;
  3897. end
  3898. function ChatEdit_SetLastTellTarget(target, chatType)
  3899. local found = #ChatEdit_LastTell;
  3900. for i=1, #ChatEdit_LastTell do
  3901. local tellTarget, tellChatType = ChatEdit_LastTell[i], ChatEdit_LastTellType[i];
  3902. if ( strupper(target) == strupper(tellTarget) and strupper(chatType) == strupper(tellChatType) ) then
  3903. found = i;
  3904. break;
  3905. end
  3906. end
  3907. for i = found, 2, -1 do
  3908. ChatEdit_LastTell[i] = ChatEdit_LastTell[i-1];
  3909. ChatEdit_LastTellType[i] = ChatEdit_LastTellType[i-1];
  3910. end
  3911. ChatEdit_LastTell[1] = target;
  3912. ChatEdit_LastTellType[1] = chatType;
  3913. end
  3914. function ChatEdit_GetNextTellTarget(target, chatType)
  3915. if ( not target or target == "" ) then
  3916. return ChatEdit_LastTell[1], ChatEdit_LastTellType[1];
  3917. end
  3918. for i = 1, #ChatEdit_LastTell - 1, 1 do
  3919. if ( ChatEdit_LastTell[i] == "" ) then
  3920. break;
  3921. elseif ( strupper(target) == strupper(ChatEdit_LastTell[i]) and
  3922. strupper(chatType) == strupper(ChatEdit_LastTellType[i]) ) then
  3923. if ( ChatEdit_LastTell[i+1] ~= "" ) then
  3924. return ChatEdit_LastTell[i+1], ChatEdit_LastTellType[i+1];
  3925. else
  3926. break;
  3927. end
  3928. end
  3929. end
  3930. return ChatEdit_LastTell[1], ChatEdit_LastTellType[1];
  3931. end
  3932. function ChatEdit_GetLastToldTarget()
  3933. return ChatEdit_LastTold, ChatEdit_LastToldType;
  3934. end
  3935. function ChatEdit_SetLastToldTarget(name, chatType)
  3936. ChatEdit_LastTold = name;
  3937. ChatEdit_LastToldType = chatType;
  3938. end
  3939. function ChatEdit_UpdateHeader(editBox)
  3940. local type = editBox:GetAttribute("chatType");
  3941. if ( not type ) then
  3942. return;
  3943. end
  3944. local info = ChatTypeInfo[type];
  3945. local header = _G[editBox:GetName().."Header"];
  3946. local headerSuffix = _G[editBox:GetName().."HeaderSuffix"];
  3947. if ( not header ) then
  3948. return;
  3949. end
  3950. header:SetWidth(0);
  3951. --BN_WHISPER FIXME
  3952. if ( type == "SMART_WHISPER" ) then
  3953. --If we have a bnetIDAccount or this name, it's a BN whisper.
  3954. if ( BNet_GetBNetIDAccount(editBox:GetAttribute("tellTarget")) ) then
  3955. editBox:SetAttribute("chatType", "BN_WHISPER");
  3956. else
  3957. editBox:SetAttribute("chatType", "WHISPER");
  3958. end
  3959. ChatEdit_UpdateHeader(editBox);
  3960. return;
  3961. elseif ( type == "WHISPER" ) then
  3962. header:SetFormattedText(CHAT_WHISPER_SEND, editBox:GetAttribute("tellTarget"));
  3963. elseif ( type == "BN_WHISPER" ) then
  3964. local name = editBox:GetAttribute("tellTarget");
  3965. header:SetFormattedText(CHAT_BN_WHISPER_SEND, name);
  3966. elseif ( type == "EMOTE" ) then
  3967. header:SetFormattedText(CHAT_EMOTE_SEND, UnitName("player"));
  3968. elseif ( type == "CHANNEL" ) then
  3969. local localID, channelName, instanceID, isCommunitiesChannel = GetChannelName(ChatEdit_GetChannelTarget(editBox));
  3970. if ( channelName ) then
  3971. if ( isCommunitiesChannel ) then
  3972. channelName = ChatFrame_ResolveChannelName(channelName);
  3973. elseif ( instanceID > 0 ) then
  3974. channelName = channelName.." "..instanceID;
  3975. end
  3976. info = ChatTypeInfo["CHANNEL"..localID];
  3977. editBox:SetAttribute("channelTarget", localID);
  3978. header:SetFormattedText(CHAT_CHANNEL_SEND, localID, channelName);
  3979. end
  3980. elseif ( (type == "PARTY") and
  3981. (not IsInGroup(LE_PARTY_CATEGORY_HOME) and IsInGroup(LE_PARTY_CATEGORY_INSTANCE)) ) then
  3982. --Smartly switch to instance chat
  3983. editBox:SetAttribute("chatType", "INSTANCE_CHAT");
  3984. ChatEdit_UpdateHeader(editBox);
  3985. return;
  3986. elseif ( (type == "RAID") and
  3987. (not IsInRaid(LE_PARTY_CATEGORY_HOME) and IsInRaid(LE_PARTY_CATEGORY_INSTANCE)) ) then
  3988. --Smartly switch to instance chat
  3989. editBox:SetAttribute("chatType", "INSTANCE_CHAT");
  3990. ChatEdit_UpdateHeader(editBox);
  3991. return;
  3992. elseif ( (type == "INSTANCE_CHAT") and
  3993. (IsInGroup(LE_PARTY_CATEGORY_HOME) and not IsInGroup(LE_PARTY_CATEGORY_INSTANCE)) )then
  3994. if ( IsInRaid(LE_PARTY_CATEGORY_HOME) ) then
  3995. editBox:SetAttribute("chatType", "RAID");
  3996. else
  3997. editBox:SetAttribute("chatType", "PARTY");
  3998. end
  3999. ChatEdit_UpdateHeader(editBox);
  4000. return;
  4001. else
  4002. header:SetText(_G["CHAT_"..type.."_SEND"]);
  4003. end
  4004. local headerWidth = (header:GetRight() or 0) - (header:GetLeft() or 0);
  4005. local editBoxWidth = (editBox:GetRight() or 0) - (editBox:GetLeft() or 0);
  4006. if ( headerWidth > editBoxWidth / 2 ) then
  4007. header:SetWidth(editBoxWidth / 2);
  4008. headerSuffix:Show();
  4009. else
  4010. headerSuffix:Hide();
  4011. end
  4012. header:SetTextColor(info.r, info.g, info.b);
  4013. headerSuffix:SetTextColor(info.r, info.g, info.b);
  4014. editBox:SetTextInsets(15 + header:GetWidth() + (headerSuffix:IsShown() and headerSuffix:GetWidth() or 0), 13, 0, 0);
  4015. editBox:SetTextColor(info.r, info.g, info.b);
  4016. editBox.focusLeft:SetVertexColor(info.r, info.g, info.b);
  4017. editBox.focusRight:SetVertexColor(info.r, info.g, info.b);
  4018. editBox.focusMid:SetVertexColor(info.r, info.g, info.b);
  4019. end
  4020. function ChatEdit_AddHistory(editBox)
  4021. local text = "";
  4022. local type = editBox:GetAttribute("chatType");
  4023. local header = _G["SLASH_"..type.."1"];
  4024. if ( header ) then
  4025. text = header;
  4026. end
  4027. if ( type == "WHISPER" ) then
  4028. text = text.." "..editBox:GetAttribute("tellTarget");
  4029. elseif ( type == "CHANNEL" ) then
  4030. text = "/"..ChatEdit_GetChannelTarget(editBox);
  4031. end
  4032. local editBoxText = editBox:GetText();
  4033. if ( editBoxText ~= "" ) then
  4034. text = text.." "..editBox:GetText();
  4035. end
  4036. if ( text ~= "" ) then
  4037. editBox:AddHistoryLine(text);
  4038. end
  4039. end
  4040. function ChatEdit_SendText(editBox, addHistory)
  4041. ChatEdit_ParseText(editBox, 1);
  4042. local type = editBox:GetAttribute("chatType");
  4043. local text = editBox:GetText();
  4044. if ( strfind(text, "%s*[^%s]+") ) then
  4045. text = SubstituteChatMessageBeforeSend(text);
  4046. --BN_WHISPER FIXME
  4047. if ( type == "WHISPER") then
  4048. local target = editBox:GetAttribute("tellTarget");
  4049. ChatEdit_SetLastToldTarget(target, type);
  4050. SendChatMessage(text, type, editBox.languageID, target);
  4051. elseif ( type == "BN_WHISPER" ) then
  4052. local target = editBox:GetAttribute("tellTarget");
  4053. local bnetIDAccount = BNet_GetBNetIDAccount(target);
  4054. if ( bnetIDAccount ) then
  4055. ChatEdit_SetLastToldTarget(target, type);
  4056. BNSendWhisper(bnetIDAccount, text);
  4057. else
  4058. local info = ChatTypeInfo["SYSTEM"]
  4059. editBox.chatFrame:AddMessage(format(BN_UNABLE_TO_RESOLVE_NAME, target), info.r, info.g, info.b);
  4060. end
  4061. elseif ( type == "CHANNEL") then
  4062. SendChatMessage(text, type, editBox.languageID, ChatEdit_GetChannelTarget(editBox));
  4063. else
  4064. SendChatMessage(text, type, editBox.languageID);
  4065. end
  4066. if ( addHistory ) then
  4067. ChatEdit_AddHistory(editBox);
  4068. end
  4069. end
  4070. end
  4071. function ChatEdit_OnEnterPressed(self)
  4072. if(AutoCompleteEditBox_OnEnterPressed(self)) then
  4073. return;
  4074. end
  4075. ChatEdit_SendText(self, 1);
  4076. local type = self:GetAttribute("chatType");
  4077. local chatFrame = self:GetParent();
  4078. if ( chatFrame.isTemporary and chatFrame.chatType ~= "PET_BATTLE_COMBAT_LOG" ) then --Temporary window sticky types never change.
  4079. self:SetAttribute("stickyType", chatFrame.chatType);
  4080. --BN_WHISPER FIXME
  4081. if ( chatFrame.chatType == "WHISPER" or chatFrame.chatType == "BN_WHISPER" ) then
  4082. self:SetAttribute("tellTarget", chatFrame.chatTarget);
  4083. end
  4084. elseif ( ChatTypeInfo[type].sticky == 1 ) then
  4085. self:SetAttribute("stickyType", type);
  4086. end
  4087. ChatEdit_ClearChat(self);
  4088. end
  4089. function ChatEdit_ClearChat(editBox)
  4090. ChatEdit_ResetChatTypeToSticky(editBox);
  4091. if ( not editBox.isGM and (GetCVar("chatStyle") ~= "im" or editBox == MacroEditBox) ) then
  4092. editBox:SetText("");
  4093. editBox:Hide();
  4094. else
  4095. ChatEdit_DeactivateChat(editBox);
  4096. end
  4097. end
  4098. function ChatEdit_OnEscapePressed(editBox)
  4099. if ( not AutoCompleteEditBox_OnEscapePressed(editBox) ) then
  4100. ChatEdit_ClearChat(editBox);
  4101. end
  4102. end
  4103. function ChatEdit_ResetChatTypeToSticky(editBox)
  4104. editBox:SetAttribute("chatType", editBox:GetAttribute("stickyType"));
  4105. end
  4106. function ChatEdit_OnSpacePressed(self)
  4107. ChatEdit_ParseText(self, 0);
  4108. end
  4109. function ChatEdit_CustomTabPressed(self)
  4110. end
  4111. local tabCompleteTables = { hash_ChatTypeInfoList, hash_EmoteTokenList };
  4112. function ChatEdit_SecureTabPressed(self)
  4113. local chatType = self:GetAttribute("chatType");
  4114. if ( chatType == "WHISPER" or chatType == "BN_WHISPER" ) then
  4115. local newTarget, newTargetType = ChatEdit_GetNextTellTarget(self:GetAttribute("tellTarget"), chatType);
  4116. if ( newTarget and newTarget ~= "" ) then
  4117. self:SetAttribute("chatType", newTargetType);
  4118. self:SetAttribute("tellTarget", newTarget);
  4119. ChatEdit_UpdateHeader(self);
  4120. end
  4121. return;
  4122. end
  4123. local text = self.tabCompleteText;
  4124. if ( not text ) then
  4125. text = self:GetText();
  4126. self.tabCompleteText = text;
  4127. end
  4128. if ( strsub(text, 1, 1) ~= "/" ) then
  4129. return;
  4130. end
  4131. ChatFrame_ImportAllListsToHash();
  4132. local lastTabComplete = self.lastTabComplete;
  4133. -- If the string is in the format "/cmd blah", command will be "/cmd"
  4134. local command = strmatch(text, "^(/[^%s]+)") or "";
  4135. local cmdString = lastTabComplete;
  4136. repeat --The outer loop lets us go through multiple hash tables of commands.
  4137. repeat --Loop through this table to find matching items.
  4138. cmdString = next(tabCompleteTables[self.tabCompleteTableIndex], cmdString);
  4139. until ( not cmdString or strfind(cmdString, strupper(command), 1, 1) ); --Either we finished going through this table or we found a match.
  4140. if ( not cmdString ) then --Nothing else in the current table, move to the next one.
  4141. self.tabCompleteTableIndex = self.tabCompleteTableIndex + 1;
  4142. end
  4143. until ( cmdString or self.tabCompleteTableIndex > #tabCompleteTables );
  4144. self.lastTabComplete = cmdString;
  4145. if ( cmdString ) then
  4146. self.ignoreTextChange = 1;
  4147. self:SetText(strlower(cmdString));
  4148. else
  4149. self.tabCompleteTableIndex = 1;
  4150. self:SetText(self.tabCompleteText);
  4151. end
  4152. end
  4153. function ChatEdit_OnTabPressed(self)
  4154. if ( not AutoCompleteEditBox_OnTabPressed(self) ) then
  4155. if ( securecall("ChatEdit_CustomTabPressed", self) ) then
  4156. return;
  4157. end
  4158. ChatEdit_SecureTabPressed(self);
  4159. end
  4160. end
  4161. function ChatEdit_OnTextChanged(self, userInput)
  4162. ChatEdit_ParseText(self, 0);
  4163. if ( not self.ignoreTextChange ) then
  4164. self.lastTabComplete = nil;
  4165. self.tabCompleteText = nil;
  4166. self.tabCompleteTableIndex = 1;
  4167. end
  4168. self.ignoreTextChange = nil;
  4169. local regex = "^((/[^%s]+)%s+(.+))"
  4170. local full, command, target = strmatch(self:GetText(), regex);
  4171. if ( not target or (strsub(target, 1, 1) == "|") or self.disallowAutoComplete) then
  4172. AutoComplete_HideIfAttachedTo(self);
  4173. return;
  4174. end
  4175. if ( userInput ) then
  4176. self.autoCompleteXOffset = 35;
  4177. AutoComplete_Update(self, target, self:GetUTF8CursorPosition() - strlenutf8(command) - 1);
  4178. end
  4179. end
  4180. local symbols = {"%%", "%*", "%+", "%-", "%?", "%(", "%)", "%[", "%]", "%$", "%^"} --% has to be escaped first or everything is ruined
  4181. local replacements = {"%%%%", "%%%*", "%%%+", "%%%-", "%%%?", "%%%(", "%%%)", "%%%[", "%%%]", "%%%$", "%%%^"}
  4182. function escapePatternSymbols(text)
  4183. for i=1, #symbols do
  4184. text = text:gsub(symbols[i], replacements[i])
  4185. end
  4186. return text
  4187. end
  4188. function ChatEdit_OnChar(self)
  4189. local regex = "^((/[^%s]+)(%s+)(.+))$"
  4190. local text, command, whitespace, target = strmatch(self:GetText(), regex);
  4191. if (command) then
  4192. self.command = command
  4193. else
  4194. self.command = nil;
  4195. end
  4196. if (command and target and self.autoCompleteSource and self.autoCompleteParams) then --if they typed a command with a autocompletable target
  4197. local utf8Position = self:GetUTF8CursorPosition();
  4198. local allowFullMatch = false;
  4199. local nameToShow = self.autoCompleteSource(target, 1, utf8Position, allowFullMatch, unpack(self.autoCompleteParams))[1];
  4200. if (nameToShow and nameToShow.name) then
  4201. local name = Ambiguate(nameToShow.name, "all");
  4202. --We're going to be setting the text programatically which will clear the userInput flag on the editBox.
  4203. --So we want to manually update the dropdown before we change the text.
  4204. AutoComplete_Update(self, target, utf8Position - strlenutf8(command) - strlen(whitespace));
  4205. if strsub(name, 1, 1) ~= "|" then
  4206. target = escapePatternSymbols(target);
  4207. local newTarget = name;
  4208. self:SetText(string.format("%s%s%s", command, whitespace, newTarget));
  4209. self:HighlightText(strlen(text), strlen(command) + strlen(whitespace) + strlen(newTarget));
  4210. end
  4211. end
  4212. end
  4213. end
  4214. function ChatEdit_OnTextSet(self)
  4215. ChatEdit_ParseText(self, 0);
  4216. end
  4217. function ChatEdit_LanguageShow()
  4218. CHAT_SHOW_IME = true;
  4219. end
  4220. function ChatEdit_OnInputLanguageChanged(self)
  4221. local button = _G[self:GetName().."Language"];
  4222. local variable = _G["INPUT_"..self:GetInputLanguage()];
  4223. button:SetText(variable);
  4224. end
  4225. local function processChatType(editBox, msg, index, send)
  4226. local autoCompleteInfo = AUTOCOMPLETE_LIST[index];
  4227. if ( autoCompleteInfo ) then
  4228. AutoCompleteEditBox_SetAutoCompleteSource(editBox, GetAutoCompleteResults, autoCompleteInfo.include, autoCompleteInfo.exclude);
  4229. else
  4230. AutoCompleteEditBox_SetAutoCompleteSource(editBox, nil);
  4231. end
  4232. -- this is a special function for "ChatEdit_HandleChatType"
  4233. if ( ChatTypeInfo[index] ) then
  4234. if ( index == "WHISPER" or index == "SMART_WHISPER" ) then
  4235. local targetFound, target, chatType, parsedMsg = ChatEdit_ExtractTellTarget(editBox, msg, index);
  4236. if ( targetFound ) then
  4237. editBox:SetAttribute("tellTarget", target);
  4238. editBox:SetAttribute("chatType", chatType);
  4239. editBox:SetText(parsedMsg);
  4240. ChatEdit_UpdateHeader(editBox);
  4241. elseif ( send == 1 ) then
  4242. ChatEdit_ClearChat(editBox);
  4243. end
  4244. elseif ( index == "REPLY" ) then
  4245. local lastTell, lastTellType = ChatEdit_GetLastTellTarget();
  4246. if ( lastTell ) then
  4247. --BN_WHISPER FIXME
  4248. editBox:SetAttribute("chatType", lastTellType);
  4249. editBox:SetAttribute("tellTarget", lastTell);
  4250. editBox:SetText(msg);
  4251. ChatEdit_UpdateHeader(editBox);
  4252. else
  4253. if ( send == 1 ) then
  4254. ChatEdit_ClearChat(editBox);
  4255. end
  4256. end
  4257. elseif (index == "CHANNEL") then
  4258. ChatEdit_ExtractChannel(editBox, msg);
  4259. else
  4260. editBox:SetAttribute("chatType", index);
  4261. editBox:SetText(msg);
  4262. ChatEdit_UpdateHeader(editBox);
  4263. end
  4264. return true;
  4265. end
  4266. return false;
  4267. end
  4268. function ChatEdit_HandleChatType(editBox, msg, command, send)
    local channel = strmatch(command, "/([0-9]+)");
  4269. local channel = strmatch(command, "/([0-9]+)$");
  4270. if( channel ) then
  4271. local chanNum = tonumber(channel);
  4272. if ( chanNum > 0 and chanNum <= MAX_WOW_CHAT_CHANNELS ) then
  4273. local channelNum, channelName = GetChannelName(channel);
  4274. if ( channelNum > 0 ) then
  4275. editBox:SetAttribute("channelTarget", channelNum);
  4276. editBox:SetAttribute("chatType", "CHANNEL");
  4277. editBox:SetText(msg);
  4278. ChatEdit_UpdateHeader(editBox);
  4279. return true;
  4280. end
  4281. end
  4282. else
  4283. -- first check the hash table
  4284. ChatFrame_ImportAllListsToHash();
  4285. if ( hash_ChatTypeInfoList[command] ) then
  4286. return processChatType(editBox, msg, hash_ChatTypeInfoList[command], send);
  4287. end
  4288. end
  4289. --This isn't one we found in our list, so we're not going to autocomplete.
  4290. AutoCompleteEditBox_SetAutoCompleteSource(editBox, nil);
  4291. return false;
  4292. end
  4293. function ChatEdit_ParseText(editBox, send, parseIfNoSpaces)
  4294. local text = editBox:GetText();
  4295. if ( text == "" ) then
  4296. return;
  4297. end
  4298. if ( strsub(text, 1, 1) ~= "/" ) then
  4299. return;
  4300. end
  4301. --Do not bother parsing if there is no space in the message and we aren't sending.
  4302. if ( send ~= 1 and not parseIfNoSpaces and not strfind(text, "%s") ) then
  4303. return;
  4304. end
  4305. -- If the string is in the format "/cmd blah", command will be "/cmd"
  4306. local command = strmatch(text, "^(/[^%s]+)") or "";
  4307. local msg = "";
  4308. if ( command ~= text ) then
  4309. msg = strsub(text, strlen(command) + 2);
  4310. msg = strmatch(msg, "^%s*(.*)$") or msg;
  4311. end
  4312. command = strupper(command);
  4313. -- Check and see if we've got secure commands to run before we look for chat types or slash commands.
  4314. -- This hash table is prepopulated, unlike the other ones, since nobody can add secure commands. (See line 1205 or thereabouts)
  4315. -- 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
  4316. -- didn't just move ChatEdit_HandleChatType inside the send == 0 conditional, which could have also solved the problem with insecure
  4317. -- code having the ability to affect secure commands.
  4318. if ( send == 1 and hash_SecureCmdList[command] ) then
  4319. hash_SecureCmdList[command](strtrim(msg));
  4320. editBox:AddHistoryLine(text);
  4321. ChatEdit_ClearChat(editBox);
  4322. return;
  4323. end
  4324. ChatFrame_ImportAllListsToHash();
  4325. -- Handle chat types. No need for a securecall here, since we should be done with anything secure.
  4326. if ( ChatEdit_HandleChatType(editBox, msg, command, send) ) then
  4327. return;
  4328. end
  4329. if ( send == 0 ) then
  4330. return;
  4331. end
  4332. -- Check the hash tables for slash commands and emotes to see if we've run this before.
  4333. if ( hash_SlashCmdList[command] ) then
  4334. -- if the code in here changes - change the corresponding code below
  4335. hash_SlashCmdList[command](strtrim(msg), editBox);
  4336. editBox:AddHistoryLine(text);
  4337. ChatEdit_ClearChat(editBox);
  4338. return;
  4339. elseif ( hash_EmoteTokenList[command] ) then
  4340. -- if the code in here changes - change the corresponding code below
  4341. local restricted = DoEmote(hash_EmoteTokenList[command], msg);
  4342. -- If the emote is restricted, we want to treat it as if the player entered an unrecognized chat command.
  4343. if ( not restricted ) then
  4344. editBox:AddHistoryLine(text);
  4345. ChatEdit_ClearChat(editBox);
  4346. return;
  4347. end
  4348. end
  4349. -- Unrecognized chat command, show simple help text
  4350. if ( editBox.chatFrame ) then
  4351. ChatFrame_DisplayHelpTextSimple(editBox.chatFrame);
  4352. end
  4353. -- Reset the chat type and clear the edit box's contents
  4354. ChatEdit_ClearChat(editBox);
  4355. return;
  4356. end
  4357. function SubstituteChatMessageBeforeSend(msg)
  4358. for tag in string.gmatch(msg, "%b{}") do
  4359. local term = strlower(string.gsub(tag, "[{}]", ""));
  4360. if ( GROUP_TAG_LIST[term] ) then
  4361. local groupIndex = GROUP_TAG_LIST[term];
  4362. msg = string.gsub(msg, tag, "{"..GROUP_LANGUAGE_INDEPENDENT_STRINGS[groupIndex].."}");
  4363. end
  4364. end
  4365. return msg;
  4366. end
  4367. function ChatEdit_ExtractTellTarget(editBox, msg, chatType)
  4368. local tellTargetExtractionAutoComplete;
  4369. if ( chatType == "WHISPER" ) then
  4370. tellTargetExtractionAutoComplete = AUTOCOMPLETE_LIST.WHISPER_EXTRACT;
  4371. else
  4372. tellTargetExtractionAutoComplete = AUTOCOMPLETE_LIST.SMART_WHISPER_EXTRACT;
  4373. end
  4374. -- Grab the string after the slash command
  4375. local target = strmatch(msg, "%s*(.*)");
  4376. --If we haven't even finished one word, we aren't done.
  4377. if ( not target or not strfind(target, "%s") ) then
  4378. return false;
  4379. end
  4380. if ( strsub(target, 1, 1) == "|" ) then
  4381. return false;
  4382. end
  4383. if ( #GetAutoCompleteResults(target, 1, 0, true, tellTargetExtractionAutoComplete.include, tellTargetExtractionAutoComplete.exclude) > 0 ) then
  4384. --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.
  4385. return false;
  4386. end
  4387. --Keep pulling off everything after the last space until we either have something on the AutoComplete list or only a single word is left.
  4388. while ( strfind(target, "%s") ) do
  4389. --Pull off everything after the last space.
  4390. target = strmatch(target, "(.+)%s+[^%s]*");
  4391. if ( #GetAutoCompleteResults(target, 1, 0, true, tellTargetExtractionAutoComplete.include, tellTargetExtractionAutoComplete.exclude) > 0 ) then
  4392. break;
  4393. end
  4394. end
  4395. msg = strsub(msg, strlen(target) + 2);
  4396. if ( chatType ~= "WHISPER" and BNet_GetBNetIDAccount(target) ) then --"WHISPER" forces character whisper
  4397. chatType = "BN_WHISPER";
  4398. else
  4399. chatType = "WHISPER";
  4400. end
  4401. return true, target, chatType, msg;
  4402. end
  4403. function ChatEdit_ExtractChannel(editBox, msg)
  4404. local target = strmatch(msg, "%s*([^%s]+)");
  4405. if ( not target ) then
  4406. return;
  4407. end
  4408. local channelNum, channelName = GetChannelName(target);
  4409. if ( channelNum <= 0 ) then
  4410. return;
  4411. end
  4412. msg = strsub(msg, strlen(target) + 2);
  4413. editBox:SetAttribute("channelTarget", channelNum);
  4414. editBox:SetAttribute("chatType", "CHANNEL");
  4415. editBox:SetText(msg);
  4416. ChatEdit_UpdateHeader(editBox);
  4417. end
  4418. -- Chat menu functions
  4419. function ChatMenu_SetChatType(chatFrame, type)
  4420. local editBox = ChatFrame_OpenChat("");
  4421. editBox:SetAttribute("chatType", type);
  4422. ChatEdit_UpdateHeader(editBox);
  4423. end
  4424. function ChatMenu_Say(self)
  4425. ChatMenu_SetChatType(self:GetParent().chatFrame, "SAY");
  4426. end
  4427. function ChatMenu_Party(self)
  4428. ChatMenu_SetChatType(self:GetParent().chatFrame, "PARTY");
  4429. end
  4430. function ChatMenu_Raid(self)
  4431. ChatMenu_SetChatType(self:GetParent().chatFrame, "RAID");
  4432. end
  4433. function ChatMenu_InstanceChat(self)
  4434. ChatMenu_SetChatType(self:GetParent().chatFrame, "INSTANCE_CHAT");
  4435. end
  4436. function ChatMenu_Guild(self)
  4437. ChatMenu_SetChatType(self:GetParent().chatFrame, "GUILD");
  4438. end
  4439. function ChatMenu_Yell(self)
  4440. ChatMenu_SetChatType(self:GetParent().chatFrame, "YELL");
  4441. end
  4442. function ChatMenu_Whisper(self)
  4443. local editBox = ChatFrame_OpenChat(SLASH_SMART_WHISPER1.." ");
  4444. editBox:SetText(SLASH_SMART_WHISPER1.." "..editBox:GetText());
  4445. end
  4446. function ChatMenu_Emote(self)
  4447. ChatMenu_SetChatType(self:GetParent().chatFrame, "EMOTE");
  4448. end
  4449. function ChatMenu_Reply(self)
  4450. ChatFrame_ReplyTell();
  4451. end
  4452. function ChatMenu_VoiceMacro(self)
  4453. ChatMenu_SetChatType(self:GetParent().chatFrame, "YELL");
  4454. end
  4455. function ChatMenu_OnLoad(self)
  4456. self.chatFrame = DEFAULT_CHAT_FRAME;
  4457. UIMenu_Initialize(self);
  4458. UIMenu_AddButton(self, SAY_MESSAGE, SLASH_SAY1, ChatMenu_Say);
  4459. UIMenu_AddButton(self, PARTY_MESSAGE, SLASH_PARTY1, ChatMenu_Party);
  4460. UIMenu_AddButton(self, RAID_MESSAGE, SLASH_RAID1, ChatMenu_Raid);
  4461. UIMenu_AddButton(self, INSTANCE_CHAT_MESSAGE, SLASH_INSTANCE_CHAT1, ChatMenu_InstanceChat);
  4462. UIMenu_AddButton(self, GUILD_MESSAGE, SLASH_GUILD1, ChatMenu_Guild);
  4463. UIMenu_AddButton(self, YELL_MESSAGE, SLASH_YELL1, ChatMenu_Yell);
  4464. UIMenu_AddButton(self, WHISPER_MESSAGE, SLASH_SMART_WHISPER1, ChatMenu_Whisper);
  4465. UIMenu_AddButton(self, EMOTE_MESSAGE, SLASH_EMOTE1, ChatMenu_Emote, "EmoteMenu");
  4466. UIMenu_AddButton(self, REPLY_MESSAGE, SLASH_REPLY1, ChatMenu_Reply);
  4467. UIMenu_AddButton(self, LANGUAGE, nil, nil, "LanguageMenu");
  4468. UIMenu_AddButton(self, VOICEMACRO_LABEL, nil, nil, "VoiceMacroMenu");
  4469. UIMenu_AddButton(self, MACRO, SLASH_MACRO1, ShowMacroFrame);
  4470. UIMenu_AutoSize(self);
  4471. end
  4472. function ChatMenu_OnShow(self)
  4473. UIMenu_OnShow(self);
  4474. EmoteMenu:Hide();
  4475. LanguageMenu:Hide();
  4476. VoiceMacroMenu:Hide();
  4477. self:SetBackdropBorderColor(TOOLTIP_DEFAULT_COLOR.r, TOOLTIP_DEFAULT_COLOR.g, TOOLTIP_DEFAULT_COLOR.b);
  4478. self:SetBackdropColor(TOOLTIP_DEFAULT_BACKGROUND_COLOR.r, TOOLTIP_DEFAULT_BACKGROUND_COLOR.g, TOOLTIP_DEFAULT_BACKGROUND_COLOR.b);
  4479. end
  4480. function EmoteMenu_Click(self)
  4481. DoEmote(EmoteList[self:GetID()]);
  4482. ChatMenu:Hide();
  4483. end
  4484. function TextEmoteSort(token1, token2)
  4485. local i = 1;
  4486. local string1, string2;
  4487. local token = _G["EMOTE"..i.."_TOKEN"];
  4488. while ( i <= MAXEMOTEINDEX ) do
  4489. if ( token == token1 ) then
  4490. string1 = _G["EMOTE"..i.."_CMD1"];
  4491. if ( string2 ) then
  4492. break;
  4493. end
  4494. end
  4495. if ( token == token2 ) then
  4496. string2 = _G["EMOTE"..i.."_CMD1"];
  4497. if ( string1 ) then
  4498. break;
  4499. end
  4500. end
  4501. i = i + 1;
  4502. token = _G["EMOTE"..i.."_TOKEN"];
  4503. end
  4504. return string1 < string2;
  4505. end
  4506. function OnMenuLoad(self,list,func)
  4507. sort(list, TextEmoteSort);
  4508. UIMenu_Initialize(self);
  4509. self.parentMenu = "ChatMenu";
  4510. for index, value in pairs(list) do
  4511. local i = 1;
  4512. local token = _G["EMOTE"..i.."_TOKEN"];
  4513. while ( i < MAXEMOTEINDEX ) do
  4514. if ( token == value ) then
  4515. break;
  4516. end
  4517. i = i + 1;
  4518. token = _G["EMOTE"..i.."_TOKEN"];
  4519. end
  4520. local label = _G["EMOTE"..i.."_CMD1"];
  4521. if ( not label ) then
  4522. label = value;
  4523. end
  4524. UIMenu_AddButton(self, label, nil, func);
  4525. end
  4526. UIMenu_AutoSize(self);
  4527. end
  4528. function EmoteMenu_OnLoad(self)
  4529. OnMenuLoad(self, EmoteList, EmoteMenu_Click);
  4530. end
  4531. function LanguageMenu_OnLoad(self)
  4532. UIMenu_Initialize(self);
  4533. self.parentMenu = "ChatMenu";
  4534. self:RegisterEvent("PLAYER_ENTERING_WORLD");
  4535. self:RegisterEvent("LANGUAGE_LIST_CHANGED");
  4536. self:RegisterEvent("NEUTRAL_FACTION_SELECT_RESULT");
  4537. end
  4538. function VoiceMacroMenu_Click(self)
  4539. local emote = TextEmoteSpeechList[self:GetID()];
  4540. if (emote == EMOTE454_TOKEN or emote == EMOTE455_TOKEN) then
  4541. local faction = UnitFactionGroup("player", true);
  4542. if (faction == "Alliance") then
  4543. emote = EMOTE454_TOKEN;
  4544. elseif (faction == "Horde") then
  4545. emote = EMOTE455_TOKEN;
  4546. end
  4547. end
  4548. DoEmote(emote);
  4549. ChatMenu:Hide();
  4550. end
  4551. function VoiceMacroMenu_OnLoad(self)
  4552. OnMenuLoad(self, TextEmoteSpeechList, VoiceMacroMenu_Click);
  4553. end
  4554. function LanguageMenu_OnEvent(self, event, ...)
  4555. if ( event == "PLAYER_ENTERING_WORLD" ) then
  4556. self:Hide();
  4557. UIMenu_Initialize(self);
  4558. LanguageMenu_LoadLanguages(self);
  4559. self:GetParent().chatFrame.editBox.language, self:GetParent().chatFrame.editBox.languageID = GetDefaultLanguage();
  4560. return;
  4561. end
  4562. if ( event == "LANGUAGE_LIST_CHANGED" ) then
  4563. self:Hide();
  4564. UIMenu_Initialize(self);
  4565. LanguageMenu_LoadLanguages(self);
  4566. return;
  4567. end
  4568. if ( event == "NEUTRAL_FACTION_SELECT_RESULT" ) then
  4569. self:Hide();
  4570. self:GetParent().chatFrame.editBox.language, self:GetParent().chatFrame.editBox.languageID = GetDefaultLanguage();
  4571. return;
  4572. end
  4573. end
  4574. function LanguageMenu_LoadLanguages(self)
  4575. local numLanguages = GetNumLanguages();
  4576. local i;
  4577. local editBoxLanguageID = self:GetParent().chatFrame.editBox.languageID;
  4578. local languageKnown = false;
  4579. for i = 1, numLanguages, 1 do
  4580. local language, languageID = GetLanguageByIndex(i);
  4581. UIMenu_AddButton(self, language, nil, LanguageMenu_Click);
  4582. if ( languageID == editBoxLanguageID ) then
  4583. languageKnown = true;
  4584. end
  4585. end
  4586. if ( languageKnown ~= true ) then
  4587. self:GetParent().chatFrame.editBox.language, self:GetParent().chatFrame.editBox.languageID = GetLanguageByIndex(1);
  4588. end
  4589. UIMenu_AutoSize(self);
  4590. end
  4591. function LanguageMenu_Click(self)
  4592. self:GetParent():GetParent().chatFrame.editBox.language, self:GetParent():GetParent().chatFrame.editBox.languageID = GetLanguageByIndex(self:GetID());
  4593. ChatMenu:Hide();
  4594. end
  4595. function ChatFrame_ActivateCombatMessages(chatFrame)
  4596. ChatFrame_AddMessageGroup(chatFrame, "OPENING");
  4597. ChatFrame_AddMessageGroup(chatFrame, "TRADESKILLS");
  4598. ChatFrame_AddMessageGroup(chatFrame, "PET_INFO");
  4599. ChatFrame_AddMessageGroup(chatFrame, "COMBAT_MISC_INFO");
  4600. ChatFrame_AddMessageGroup(chatFrame, "COMBAT_XP_GAIN");
  4601. ChatFrame_AddMessageGroup(chatFrame, "COMBAT_HONOR_GAIN");
  4602. ChatFrame_AddMessageGroup(chatFrame, "COMBAT_FACTION_CHANGE");
  4603. end
  4604. function ChatChannelDropDown_Show(chatFrame, chatType, chatTarget, chatName)
  4605. HideDropDownMenu(1);
  4606. ChatChannelDropDown.initialize = ChatChannelDropDown_Initialize;
  4607. ChatChannelDropDown.displayMode = "MENU";
  4608. ChatChannelDropDown.chatType = chatType;
  4609. ChatChannelDropDown.chatTarget = chatTarget;
  4610. ChatChannelDropDown.chatName = chatName;
  4611. ChatChannelDropDown.chatFrame = chatFrame;
  4612. ToggleDropDownMenu(1, nil, ChatChannelDropDown, "cursor");
  4613. end
  4614. function ChatChannelDropDown_Initialize()
  4615. local frame = ChatChannelDropDown;
  4616. local info = UIDropDownMenu_CreateInfo();
  4617. info.text = ChatFrame_ResolveChannelName(frame.chatName);
  4618. info.notCheckable = true;
  4619. info.isTitle = true;
  4620. UIDropDownMenu_AddButton(info, 1);
  4621. local clubId, streamId = ChatFrame_GetCommunityAndStreamFromChannel(frame.chatName);
  4622. if clubId and streamId and C_Club.IsEnabled() then
  4623. info = UIDropDownMenu_CreateInfo();
  4624. info.text = CHAT_CHANNEL_DROP_DOWN_OPEN_COMMUNITIES_FRAME;
  4625. info.notCheckable = true;
  4626. info.func = function ()
  4627. if not CommunitiesFrame or not CommunitiesFrame:IsShown() then
  4628. ToggleCommunitiesFrame();
  4629. end
  4630. CommunitiesFrame:SelectStream(clubId, streamId);
  4631. CommunitiesFrame:SelectClub(clubId);
  4632. end;
  4633. UIDropDownMenu_AddButton(info);
  4634. end
  4635. info = UIDropDownMenu_CreateInfo();
  4636. info.text = MOVE_TO_NEW_WINDOW;
  4637. info.notCheckable = 1;
  4638. info.func = ChatChannelDropDown_PopOutChat;
  4639. info.arg1 = frame.chatType;
  4640. info.arg2 = frame.chatTarget;
  4641. if ( FCF_GetNumActiveChatFrames() == NUM_CHAT_WINDOWS ) then
  4642. info.disabled = 1;
  4643. end
  4644. UIDropDownMenu_AddButton(info);
  4645. end
  4646. function ChatChannelDropDown_PopOutChat(self, chatType, chatTarget)
  4647. local sourceChatFrame = ChatChannelDropDown.chatFrame;
  4648. local windowName;
  4649. if ( chatType == "CHANNEL" ) then
  4650. windowName = Chat_GetChannelShortcutName(chatTarget);
  4651. else
  4652. windowName = _G[chatType];
  4653. end
  4654. local frame = FCF_OpenNewWindow(windowName);
  4655. FCF_CopyChatSettings(frame, sourceChatFrame);
  4656. ChatFrame_RemoveAllMessageGroups(frame);
  4657. ChatFrame_RemoveAllChannels(frame);
  4658. ChatFrame_ReceiveAllPrivateMessages(frame);
  4659. ChatFrame_AddMessageGroup(frame, chatType);
  4660. if ( CHAT_CATEGORY_LIST[chatType] ) then
  4661. for _, chat in pairs(CHAT_CATEGORY_LIST[chatType]) do
  4662. ChatFrame_AddMessageGroup(frame, chat);
  4663. end
  4664. end
  4665. frame.editBox:SetAttribute("chatType", chatType);
  4666. frame.editBox:SetAttribute("stickyType", chatType);
  4667. if ( chatType == "CHANNEL" ) then
  4668. frame.editBox:SetAttribute("channelTarget", chatTarget);
  4669. ChatFrame_AddChannel(frame, Chat_GetChannelShortcutName(chatTarget));
  4670. end
  4671. if ( chatType == "PET_BATTLE_COMBAT_LOG" or chatType == "PET_BATTLE_INFO" ) then
  4672. frame.editBox:SetAttribute("chatType", "SAY");
  4673. frame.editBox:SetAttribute("stickyType", "SAY");
  4674. end
  4675. --Remove the things popped out from the source chat frame.
  4676. if ( chatType == "CHANNEL" ) then
  4677. ChatFrame_RemoveChannel(sourceChatFrame, Chat_GetChannelShortcutName(chatTarget));
  4678. else
  4679. ChatFrame_RemoveMessageGroup(sourceChatFrame, chatType);
  4680. if ( CHAT_CATEGORY_LIST[chatType] ) then
  4681. for _, chat in pairs(CHAT_CATEGORY_LIST[chatType]) do
  4682. ChatFrame_RemoveMessageGroup(sourceChatFrame, chat);
  4683. end
  4684. end
  4685. end
  4686. --Copy over messages
  4687. local accessID = ChatHistory_GetAccessID(chatType, chatTarget);
  4688. for i = 1, sourceChatFrame:GetNumMessages() do
  4689. local text, r, g, b, chatTypeID, messageAccessID, lineID = sourceChatFrame:GetMessageInfo(i);
  4690. if messageAccessID == accessID then
  4691. frame:AddMessage(text, r, g, b, chatTypeID, messageAccessID, lineID);
  4692. end
  4693. end
  4694. --Remove the messages from the old frame.
  4695. sourceChatFrame:RemoveMessagesByPredicate(function(text, r, g, b, chatTypeID, messageAccessID, lineID) return messageAccessID == accessID; end);
  4696. end
  4697. function Chat_GetChannelShortcutName(index)
  4698. local _, name = GetChannelName(index);
  4699. name = strtrim(name:match("([^%-]+)"));
  4700. return name;
  4701. end
  4702. function ChatChannelDropDown_PopInChat(self, chatType, chatTarget)
  4703. --PopOutChat_PopInChat(chatType, chatTarget);
  4704. end
  4705. function Chat_ShouldColorChatByClass(chatTypeInfo)
  4706. local override = ChatClassColorOverrideShown();
  4707. local colorByClass = chatTypeInfo and chatTypeInfo.colorNameByClass;
  4708. return override or (override == nil and colorByClass);
  4709. end
  4710. function Chat_GetColoredChatName(chatType, chatTarget)
  4711. if ( chatType == "CHANNEL" ) then
  4712. local info = ChatTypeInfo["CHANNEL"..chatTarget];
  4713. local colorString = format("|cff%02x%02x%02x", info.r * 255, info.g * 255, info.b * 255);
  4714. local chanNum, channelName = GetChannelName(chatTarget);
  4715. 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")
  4716. elseif ( chatType == "WHISPER" ) then
  4717. local info = ChatTypeInfo["WHISPER"];
  4718. local colorString = format("|cff%02x%02x%02x", info.r * 255, info.g * 255, info.b * 255);
  4719. return format("%s[%s] |Hplayer:%3$s|h[%3$s]|h|r", colorString, _G[chatType], chatTarget);
  4720. else
  4721. local info = ChatTypeInfo[chatType];
  4722. local colorString = format("|cff%02x%02x%02x", info.r * 255, info.g * 255, info.b * 255);
  4723. return format("%s|Hchannel:%s|h[%s]|h|r", colorString, chatType, _G[chatType]);
  4724. end
  4725. end
  4726. --------------------------------------------------------------------------------
  4727. -- Social share link functions
  4728. --------------------------------------------------------------------------------
  4729. SHARE_ICON_COLOR = "ffffd200";
  4730. SHARE_ICON_TEXT = "|TInterface\\ChatFrame\\UI-ChatIcon-Share:18:18|t";
  4731. function Social_GetShareItemLink(strippedItemLink, earned)
  4732. local earnedNum = 0;
  4733. if (earned) then
  4734. earnedNum = 1;
  4735. end
  4736. return format("|c%s|Hshareitem:%s:%d|h%s|h|r", SHARE_ICON_COLOR, strippedItemLink, earnedNum, SHARE_ICON_TEXT);
  4737. end
  4738. function Social_GetShareAchievementLink(achievementID, earned)
  4739. local earnedNum = 0;
  4740. if (earned) then
  4741. earnedNum = 1;
  4742. end
  4743. return format("|c%s|Hshareachieve:%d:%d|h%s|h|r", SHARE_ICON_COLOR, achievementID, earnedNum, SHARE_ICON_TEXT);
  4744. end
  4745. function Social_GetShareScreenshotLink()
  4746. local index = C_Social.GetLastScreenshotIndex();
  4747. return format("|c%s|Hsharess:%d|h%s|h|r", SHARE_ICON_COLOR, index, SHARE_ICON_TEXT);
  4748. end