ChatFrame.lua

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