ChatFrame.lua

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