Advertisement
Guest User

Untitled

a guest
Jun 19th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 37.58 KB | None | 0 0
  1. --[[----------------------------------------------
  2. Autorespond created by Ayradyss in the first and enhanced by Chef de Loup
  3.  
  4. The features of the mod in the following:
  5. - multiply responses with multiply keywords for each response
  6. - responses can be handled as text with links or as script code
  7. - several controls for each response for input and output of a response
  8. --]]-----------------------------------------------
  9.  
  10.  
  11. --[[-----------------------------------------------
  12. global variables
  13. --]]-----------------------------------------------
  14. AutoRespondMainOptions = {}; -- SavedVariable - MainOptions
  15. AutoRespondOptions = {}; -- SavedVariable - Responds and Options
  16.  
  17. local Realm; -- realm of active player
  18. local Player; -- name of active player
  19.  
  20. local getglobal = getglobal; -- Speed up ggvar
  21.  
  22. local VariablesLoaded = 1; -- flag to check if Variables was loaded
  23. local Initialized = nil; -- flag to check if previous initialize
  24.  
  25. local ActiveOption = 1; -- position of actual respond
  26. local AR_Version = "1.0.0 Reborn"; -- version of AR
  27.  
  28. local AR_SpamCheck = nil; -- status of spamcheck
  29. local AR_SpamList = {}; -- each entry consists of the name of the whisperer and the time of the last whisper
  30.  
  31. --[[--------------------------------------------------------------------------------------------
  32. functions for the main frame
  33. --]]--------------------------------------------------------------------------------------------
  34.  
  35.  
  36. --[[-----------------------------------------------
  37. function for registering main events and slashcommands of the mod
  38. --]]-----------------------------------------------
  39. function AutoRespond_OnLoad(event, self)
  40. -- register main events
  41. self:RegisterEvent("PLAYER_ENTERING_WORLD");
  42. self:RegisterEvent("PLAYER_LEAVING_WORLD");
  43. self:RegisterEvent("VARIABLES_LOADED");
  44.  
  45. -- register slashcommand and handler function
  46. SlashCmdList["AUTORESPOND"] = AutoRespond_SlashHandler;
  47. SLASH_AUTORESPOND1 = "/AutoRespond";
  48. SLASH_AUTORESPOND2 = "/ar";
  49.  
  50. VariablesLoaded = 1;
  51. AutoRespond_InitializeSetup();
  52. end
  53.  
  54.  
  55. --[[-----------------------------------------------
  56. function for initializing the mod
  57. this function only works once when all needed variables are loaded
  58. --]]-----------------------------------------------
  59. function AutoRespond_InitializeSetup()
  60. -- check if previous initialized or variables are not loaded
  61. if not Initialized and VariablesLoaded then
  62. -- get realm and playername
  63. Player = UnitFullName("player");
  64. Realm = GetRealmName();
  65.  
  66. -- initialize SavedVariables if not given
  67. if AutoRespondMainOptions[Realm] == nil then AutoRespondMainOptions[Realm] = {}; end
  68. if AutoRespondMainOptions[Realm][Player] == nil then
  69. AutoRespondMainOptions[Realm][Player] = { ActiveMod = 1, InFight = nil, Scaling = 1.0, SpamCheck = nil, SpamTimer = 1800.0 };
  70. end
  71.  
  72. if(AutoRespondOptions[Realm] == nil) then AutoRespondOptions[Realm] = {}; end
  73. if(AutoRespondOptions[Realm][Player] == nil) then
  74. AutoRespondOptions[Realm][Player] = {};
  75. table.insert( AutoRespondOptions[Realm][Player],{ Active = nil, Script = nil, Keywords = {AUTO_RESPOND_DEFAULT_KEYWORD_TEXT}, Response = {AUTO_RESPOND_DEFAULT_RESPONSE_TEXT}, Options = { Receive = { Guild = nil, Party = nil, Raid = nil, Friends = nil, Names = {} }, Tell = { Guild = nil, Party = nil, Raid = nil } } } );
  76. end
  77.  
  78. -- secure function for hooking
  79. hooksecurefunc("SetItemRef",AutoRespond_SetItemRef)
  80.  
  81. AutoRespondFrame:SetScale(AutoRespondMainOptions[Realm][Player]["Scaling"]);
  82.  
  83. -- Loaded Message
  84. DEFAULT_CHAT_FRAME:AddMessage(string.format(AUTO_RESPOND_LOADED_TEXT,AR_Version));
  85.  
  86. Initialized = 1;
  87. end
  88.  
  89. if VariablesLoaded and AutoRespondMainOptions[Realm][Player]["ActiveMod"] then
  90. AutoRespondFrame:RegisterEvent("CHAT_MSG_WHISPER")
  91. AutoRespondFrame:RegisterEvent("CHAT_MSG_BN_WHISPER")
  92. AutoRespondFrame:SetScript("OnEvent", AutoRespond_whispHandler);
  93. end
  94. end
  95.  
  96.  
  97. --[[-----------------------------------------------
  98. functions for handling the whisper
  99. --]]-----------------------------------------------
  100. function AutoRespond_whispHandler(_, _, msg, sender, _, _, _, status)
  101. local formatSenderApos = sender:gsub("%'", "") -- remove ' in realm name, if any
  102. local formatSenderSpc = sender:gsub(" ", "") -- remove space in realm name, if any
  103. print(formatSenderSpc, formatSenderApos);
  104.  
  105. if status == "GM" then
  106. DEFAULT_CHAT_FRAME:AddMessage("::: AutoRespond ::: GM MESSAGE DETECTED, NOT REPLYING"); -- Don't want to be auto replying and such to a GM
  107. else
  108. if AutoRespondMainOptions[Realm][Player]["InFight"] and UnitAffectingCombat("player") then
  109. SendChatMessage(AUTO_RESPOND_DEFAULT_INFIGHT_MESSAGE, "WHISPER", GetDefaultLanguage("player"), sender);
  110. else
  111. local respond_id = AutoRespond_CheckMessage(msg, 1);
  112.  
  113. if not AutoRespond_SpamCheck(sender, respond_id) then
  114. while respond_id do
  115. AutoRespond_SendRespond(sender, respond_id);
  116. respond_id = AutoRespond_CheckMessage(msg, respond_id+1);
  117. end
  118. end
  119. end
  120. end
  121. end
  122. --[[--------------------------------------------------------------------------------------------
  123. system functions for the mod
  124. --]]--------------------------------------------------------------------------------------------
  125.  
  126. --[[-----------------------------------------------
  127. hook function for getting links from chat links
  128. Parameter:
  129. link - the link of the item as itemid
  130. text - the link as text
  131. button - identifier of the button that was pressed
  132. --]]-----------------------------------------------
  133. function AutoRespond_SetItemRef(link,text,button)
  134. -- check if you should include the link in responsetext
  135. if ( IsShiftKeyDown() ) and ( AutoRespondFrame:IsVisible() ) then
  136. AutoRespondFrame_ResponseFrame_ScrollFrameResponse_ListResponse:Insert(text);
  137. end
  138. end
  139.  
  140.  
  141. --[[-----------------------------------------------
  142. slashhandler of the addon
  143. Parameter:
  144. msg - the message that was given with the slashcommand
  145. --]]-----------------------------------------------
  146. function AutoRespond_SlashHandler(msg)
  147. if string.find(msg,"options") then
  148. AutoRespondOptionsFrame:Show();
  149. else
  150. -- none of these above then just show the mainframe of the mod
  151. AutoRespondFrame:Show();
  152. end
  153. end
  154.  
  155.  
  156. --[[--------------------------------------------------------------------------------------------
  157. functions for the responses
  158. --]]--------------------------------------------------------------------------------------------
  159.  
  160.  
  161. --[[-----------------------------------------------
  162. function for checking of spam by time
  163. the function looks through the spam list and clears out-dated entries
  164. Parameter:
  165. who - the name of the whisperer
  166. id - id of the response if found
  167. Return
  168. returns nil if whisperer is not spamming else 1 to stop sending respond
  169. --]]-----------------------------------------------
  170. function AutoRespond_SpamCheck(who,id)
  171. local ret,timer = nil,AutoRespondMainOptions[Realm][Player]["SpamTimer"];
  172. if AutoRespondMainOptions[Realm][Player]["SpamCheck"] and id then
  173. for i,k in ipairs(AR_SpamList) do
  174. if GetTime() - k["Time"] >= timer then
  175. table.remove(AR_SpamList,i);
  176. else
  177. if k["Name"] == who then
  178. ret = 1;
  179. k["Time"] = GetTime();
  180. end
  181. end
  182. end
  183. if not ret then
  184. local w,t = who,GetTime();
  185. table.insert( AR_SpamList, { Name = w,Time = t } );
  186. end
  187. end
  188. return ret;
  189. end
  190.  
  191.  
  192. --[[-----------------------------------------------
  193. function for checking the whisper to get a response to
  194. Parameter:
  195. what - the message that was given in the whisper
  196. index - the index of the response to start from searching
  197. Return
  198. returns the index of a response that have a matching keyword to the whispered text
  199. the returned index could be the value of the passed index or higher
  200. if no match can be found the return value will be nil
  201. --]]-----------------------------------------------
  202. function AutoRespond_CheckMessage(what,index)
  203. local t = AutoRespondOptions[Realm][Player];
  204.  
  205. -- start at given respondindex until last respond
  206. for i=index,getn(t) do
  207. -- respond is active?
  208. if t[i]["Active"] then
  209. -- check if keyword(s) is found in whisper
  210. for k,v in ipairs(t[i]["Keywords"]) do
  211. if string.find(string.lower(what), string.lower(v), 1, true) then
  212. -- return immediately with index of matched respond
  213. return i;
  214. end
  215. end
  216. end
  217. end
  218. return nil;
  219. end
  220.  
  221.  
  222. --[[-----------------------------------------------
  223. function for checking the whisper options
  224. these options verify if the originator of the whisper is allowed to get the response
  225. Parameter:
  226. who - the originator of the whisper
  227. index - the index of the response to start from
  228. Return:
  229. nil - the originator should not get this response
  230. 1 - response can be send
  231. --]]-----------------------------------------------
  232. function AutoRespond_CheckCan(who,index)
  233. local skip,restrict = nil,nil;
  234. local t = AutoRespondOptions[Realm][Player][index]["Options"]["Receive"];
  235.  
  236. -- check for given names
  237. if t["Names"] then
  238. for i,v in ipairs(t["Names"]) do
  239. if string.lower(v) == string.lower(who) then
  240. skip = 1;
  241. end
  242. end
  243. restrict = 1;
  244. end
  245.  
  246. -- check for group restriction
  247. if t["Party"] and not skip then
  248. for i=1,GetNumPartyMembers() do
  249. if UnitName("party"..i) == who then
  250. skip = 1;
  251. end
  252. end
  253. restrict = 1;
  254. end
  255.  
  256. -- check for raid restriction
  257. if t["Raid"] and not skip then
  258. for i=1,GetNumRaidMembers() do
  259. if UnitName("raid"..i) == who then
  260. skip = 1;
  261. end
  262. end
  263. restrict = 1;
  264. end
  265.  
  266. -- check for friends restriction
  267. if t["Friends"] and not skip then
  268. for i=1,GetNumFriends() do
  269. if GetFriendInfo(i) == who then
  270. skip = 1;
  271. end
  272. end
  273. restrict = 1;
  274. end
  275.  
  276. -- check for guild restriction
  277. if t["Guild"] and not skip then
  278. for i=1, GetNumGuildMembers(true) do
  279. if GetGuildRosterInfo(i) == who then
  280. skip = 1;
  281. end
  282. end
  283. restrict = 1;
  284. end
  285.  
  286. if not restrict then
  287. return 1;
  288. else
  289. return skip;
  290. end
  291. end
  292.  
  293.  
  294. --[[-----------------------------------------------
  295. function for getting the response of a respond
  296. Parameter:
  297. index - the index of the respond the get the response from
  298. Return:
  299. returns the response or nil if no response is available
  300. --]]-----------------------------------------------
  301. function AutoRespondgetglobaletResponse(index)
  302. local t = nil;
  303. if(AutoRespondOptions[Realm][Player][index]["Response"]) then
  304. t = AutoRespondOptions[Realm][Player][index]["Response"];
  305. end
  306. return t;
  307. end
  308.  
  309.  
  310. --[[-----------------------------------------------
  311. function for responding
  312. Parameter:
  313. who - the name of the originator to respond to
  314. index - the index of the respond
  315. --]]-----------------------------------------------
  316. function AutoRespond_SendRespond(who,index)
  317. local formatSender = who:gsub("%'", "") -- remove ' in realm name, if any (hopefully)
  318.  
  319. -- check restrictions for originator
  320. if AutoRespond_CheckCan(formatSender,index) then
  321. local t = AutoRespondgetglobaletResponse(index);
  322. if t then
  323. -- if response is a script then use RunScript() else response by SendChatMessage()
  324. if AutoRespondOptions[Realm][Player][index]["Script"] then
  325. for i=1,getn(t) do
  326. RunScript(string.gsub(t[i],"$t","'"..formatSender.."'"));
  327. end
  328. else
  329. local channel,receiver = "WHISPER",formatSender;
  330. if AutoRespondOptions[Realm][Player][index]["Options"]["Tell"]["Guild"] then
  331. channel = "GUILD";
  332. receiver = nil;
  333. elseif AutoRespondOptions[Realm][Player][index]["Options"]["Tell"]["Party"] then
  334. channel = "PARTY";
  335. receiver = nil;
  336. elseif AutoRespondOptions[Realm][Player][index]["Options"]["Tell"]["Raid"] then
  337. channel = "RAID";
  338. receiver = nil;
  339. end
  340. for i=1,getn(t) do
  341. if receiver == UnitName("player") then
  342. DEFAULT_CHAT_FRAME:AddMessage("::: AutoRespond ::: "..string.gsub(t[i],"$t",formatSender));
  343. else
  344. SendChatMessage(string.gsub(t[i],"$t",formatSender), channel, GetDefaultLanguage("player"), receiver);
  345. end
  346. end
  347. end
  348. end
  349. end
  350. end
  351.  
  352. --[[-----------------------------------------------
  353. function to save the keyword(s) for the response
  354. --]]-----------------------------------------------
  355. function AutoRespond_SaveKeywords()
  356. local text = AutoRespondFrame_ResponseFrame_ListKeywords:GetText();
  357. if ActiveOption > 0 then
  358. if AutoRespondOptions[Realm][Player][ActiveOption] then
  359. -- delete old keywords
  360. if AutoRespondOptions[Realm][Player][ActiveOption]["Keywords"] then
  361. while getn(AutoRespondOptions[Realm][Player][ActiveOption]["Keywords"]) > 0 do
  362. table.remove(AutoRespondOptions[Realm][Player][ActiveOption]["Keywords"]);
  363. end
  364. end
  365. AutoRespondOptions[Realm][Player][ActiveOption]["Keywords"] = {};
  366.  
  367. -- check if text is given
  368. if text and (text ~= "") then
  369. for keyword in string.gmatch(text, "[^,]+") do
  370. AutoRespond_SaveToTable(strtrim(keyword), AutoRespondOptions[Realm][Player][ActiveOption]["Keywords"])
  371. end
  372. end
  373. end
  374. end
  375. end
  376.  
  377.  
  378. --[[-----------------------------------------------
  379. function to update the visible keywords
  380. --]]-----------------------------------------------
  381. function AutoRespond_UpdateKeywords()
  382. local text = "";
  383. if ActiveOption > 0 then
  384. if AutoRespondOptions[Realm][Player][ActiveOption] and AutoRespondOptions[Realm][Player][ActiveOption]["Keywords"] then
  385. local max = getn(AutoRespondOptions[Realm][Player][ActiveOption]["Keywords"]);
  386. for i,v in ipairs(AutoRespondOptions[Realm][Player][ActiveOption]["Keywords"]) do
  387. text = text..v;
  388. if i < max then
  389. text = text..", ";
  390. end
  391. end
  392. end
  393. end
  394. AutoRespondFrame_ResponseFrame_ListKeywords:SetText(text);
  395. end
  396.  
  397.  
  398. --[[-----------------------------------------------
  399. function setting the usability of the ButtonListKeywords
  400. --]]-----------------------------------------------
  401. function AutoRespond_UpdateButtonListKeywords()
  402. if ActiveOption == 0 then
  403. AutoRespondFrame_ResponseFrame_ButtonListKeywords:Disable();
  404. else
  405. AutoRespondFrame_ResponseFrame_ButtonListKeywords:Enable();
  406. end
  407. end
  408.  
  409.  
  410. --[[-----------------------------------------------
  411. function for saving the response text
  412. --]]-----------------------------------------------
  413. function AutoRespond_SaveResponse()
  414. local text = AutoRespondFrame_ResponseFrame_ScrollFrameResponse_ListResponse:GetText();
  415. if ActiveOption > 0 then
  416. if AutoRespondOptions[Realm][Player][ActiveOption] then
  417. -- delete old response
  418. if AutoRespondOptions[Realm][Player][ActiveOption]["Response"] then
  419. while getn(AutoRespondOptions[Realm][Player][ActiveOption]["Response"]) > 0 do
  420. table.remove(AutoRespondOptions[Realm][Player][ActiveOption]["Response"]);
  421. end
  422. end
  423. AutoRespondOptions[Realm][Player][ActiveOption]["Response"] = {};
  424.  
  425. if text and text~="" then
  426. for line in string.gmatch(text, "[^\r\n]+") do
  427. AutoRespond_SaveToTable(line,AutoRespondOptions[Realm][Player][ActiveOption]["Response"]);
  428. end
  429. end
  430. end
  431. end
  432. end
  433.  
  434.  
  435. --[[-----------------------------------------------
  436. function for saving text in a table
  437. Parameter:
  438. text - the text to save
  439. var - the table to save to
  440. --]]-----------------------------------------------
  441. function AutoRespond_SaveToTable(text,var)
  442. if text and (text ~= "") then
  443. table.insert(var,text);
  444. end
  445. end
  446.  
  447.  
  448. --[[-----------------------------------------------
  449. function to update the visible response
  450. --]]-----------------------------------------------
  451. function AutoRespond_UpdateResponse()
  452. local text = "";
  453. if ActiveOption > 0 then
  454. if AutoRespondOptions[Realm][Player][ActiveOption] and AutoRespondOptions[Realm][Player][ActiveOption]["Response"] then
  455. local max = getn(AutoRespondOptions[Realm][Player][ActiveOption]["Response"]);
  456. for i,v in ipairs(AutoRespondOptions[Realm][Player][ActiveOption]["Response"]) do
  457. text = text..v;
  458. if i < max then
  459. text = text.."\n";
  460. end
  461. end
  462. end
  463. end
  464. AutoRespondFrame_ResponseFrame_ScrollFrameResponse_ListResponse:SetText(text);
  465. end
  466.  
  467. function AutoRespond_UpdateButtonListResponse()
  468. if ActiveOption == 0 then
  469. AutoRespondFrame_ResponseFrame_ButtonListResponse:Disable();
  470. else
  471. AutoRespondFrame_ResponseFrame_ButtonListResponse:Enable();
  472. end
  473. end
  474.  
  475.  
  476. --[[-----------------------------------------------
  477. functions for the link button
  478. --]]-----------------------------------------------
  479. function AutoRespond_ButtonAddLinkOnShow()
  480. if ActiveOption == 0 then
  481. AutoRespondFrame_ResponseFrame_ButtonAddLink:Disable();
  482. else
  483. AutoRespondFrame_ResponseFrame_ButtonAddLink:Enable();
  484. end
  485. end
  486.  
  487. function AutoRespond_ButtonAddLinkOnClick()
  488. if CursorHasItem() then
  489. for i=0,4 do
  490. if GetBagName(i) then
  491. for j=1, GetContainerNumSlots(i) do
  492. local _,_,locked = GetContainerItemInfo(i,j);
  493. if locked and GetContainerItemLink(i,j) then
  494. AutoRespondFrame_ResponseFrame_ScrollFrameResponse_ListResponse:Insert(GetContainerItemLink(i,j));
  495. SetCursor(nil);
  496. return;
  497. end
  498. end
  499. end
  500. end
  501. SetCursor(nil);
  502. end
  503.  
  504. local temp = GetTradeSkillLine(1);
  505.  
  506. if temp then
  507. -- Link selected item
  508. local index = GetTradeSkillSelectionIndex();
  509. if (index) and (index < GetNumTradeSkills()) then
  510. local link = GetTradeSkillItemLink(index);
  511. if link then
  512. AutoRespondFrame_ResponseFrame_ScrollFrameResponse_ListResponse:Insert(link);
  513. else
  514. -- Link Profession when all of the selections are minimized
  515. local skillWindow = GetTradeSkillListLink();
  516. if skillWindow then
  517. AutoRespondFrame_ResponseFrame_ScrollFrameResponse_ListResponse:Insert(skillWindow);
  518. end
  519. end
  520. end
  521. else
  522. DEFAULT_CHAT_FRAME:AddMessage(AUTO_RESPOND_NO_LINK_ITEM); -- Can't find anything so error out
  523. end
  524. end
  525.  
  526.  
  527. --[[-----------------------------------------------
  528. functions for the reagent button
  529. --]]-----------------------------------------------
  530. function AutoRespond_ButtonAddReagentOnShow()
  531. if ActiveOption == 0 then
  532. AutoRespondFrame_ResponseFrame_ButtonAddReagent:Disable();
  533. else
  534. AutoRespondFrame_ResponseFrame_ButtonAddReagent:Enable();
  535. end
  536. end
  537.  
  538. function AutoRespond_ButtonAddReagentOnClick()
  539. local text = "";
  540. if GetTradeSkillLine(1) then
  541. local index = GetTradeSkillSelectionIndex();
  542.  
  543. if (index) and (index < GetNumTradeSkills()) then
  544. for i=1, GetTradeSkillNumReagents(index), 1 do
  545. local _,_,num = GetTradeSkillReagentInfo(index,i);
  546. text = text..num.."x"..GetTradeSkillReagentItemLink(index,i)..";";
  547. end
  548. end
  549.  
  550. else
  551. local index = GetTradeSkillSelectionIndex();
  552.  
  553. if (index) and (index < GetNumTradeSkills()) then
  554. for i=1,GetTradeSkillNumReagents(index), 1 do
  555. local _,_,num = GetTradeSkillReagentInfo(index, i);
  556. text = text..num.."x"..GetTradeSkillReagentItemLink(index, i)..";";
  557. end
  558. end
  559.  
  560. end
  561.  
  562. if text ~= "" then
  563. AutoRespondFrame_ResponseFrame_ScrollFrameResponse_ListResponse:Insert(text);
  564. end
  565. end
  566.  
  567.  
  568. --[[--------------------------------------------------------------------------------------------
  569. functions for the options of the response
  570. --]]--------------------------------------------------------------------------------------------
  571.  
  572.  
  573. --[[-----------------------------------------------
  574. functions for the active-option of the response
  575. --]]-----------------------------------------------
  576. function AutoRespond_UpdateActive()
  577. if ActiveOption == 0 then
  578. AutoRespondFrame_OptionsFrame_ButtonActive:Disable();
  579. else
  580. AutoRespondFrame_OptionsFrame_ButtonActive:Enable();
  581. AutoRespondFrame_OptionsFrame_ButtonActive:SetChecked(AutoRespondOptions[Realm][Player][ActiveOption]["Active"]);
  582. end
  583. end
  584.  
  585. function AutoRespond_ToggleActive()
  586. AutoRespondOptions[Realm][Player][ActiveOption]["Active"] = AutoRespondFrame_OptionsFrame_ButtonActive:GetChecked();
  587. end
  588.  
  589.  
  590. --[[-----------------------------------------------
  591. functions for the script-option of the response
  592. --]]-----------------------------------------------
  593. function AutoRespond_UpdateScript()
  594. if ActiveOption == 0 then
  595. AutoRespondFrame_OptionsFrame_ButtonScript:Disable();
  596. AutoRespondFrame_OptionsFrame_ButtonScript:SetChecked(nil);
  597. else
  598. AutoRespondFrame_OptionsFrame_ButtonScript:Enable();
  599. AutoRespondFrame_OptionsFrame_ButtonScript:SetChecked(AutoRespondOptions[Realm][Player][ActiveOption]["Script"]);
  600. end
  601. end
  602.  
  603. function AutoRespond_ToggleScript()
  604. AutoRespondOptions[Realm][Player][ActiveOption]["Script"] = AutoRespondFrame_OptionsFrame_ButtonScript:GetChecked();
  605. end
  606.  
  607.  
  608. --[[-----------------------------------------------
  609. functions for the CanGuild-option of the response
  610. --]]-----------------------------------------------
  611. function AutoRespond_InitCanGuild()
  612. if ActiveOption == 0 then
  613. AutoRespondFrame_OptionsFrame_ButtonCanGuild:Disable();
  614. AutoRespondFrame_OptionsFrame_ButtonCanGuild:SetChecked(nil);
  615. else
  616. AutoRespondFrame_OptionsFrame_ButtonCanGuild:Enable();
  617. AutoRespondFrame_OptionsFrame_ButtonCanGuild:SetChecked(AutoRespondOptions[Realm][Player][ActiveOption]["Options"]["Receive"]["Guild"]);
  618. end
  619. end
  620.  
  621. function AutoRespond_ToggleCanGuild()
  622. AutoRespondOptions[Realm][Player][ActiveOption]["Options"]["Receive"]["Guild"] = AutoRespondFrame_OptionsFrame_ButtonCanGuild:GetChecked();
  623. end
  624.  
  625.  
  626. --[[-----------------------------------------------
  627. functions for the CanParty-option of the response
  628. --]]-----------------------------------------------
  629. function AutoRespond_InitCanParty()
  630. if ActiveOption == 0 then
  631. AutoRespondFrame_OptionsFrame_ButtonCanParty:Disable();
  632. AutoRespondFrame_OptionsFrame_ButtonCanParty:SetChecked(nil);
  633. else
  634. AutoRespondFrame_OptionsFrame_ButtonCanParty:Enable();
  635. AutoRespondFrame_OptionsFrame_ButtonCanParty:SetChecked(AutoRespondOptions[Realm][Player][ActiveOption]["Options"]["Receive"]["Party"]);
  636. end
  637. end
  638.  
  639. function AutoRespond_ToggleCanParty()
  640. AutoRespondOptions[Realm][Player][ActiveOption]["Options"]["Receive"]["Party"] = AutoRespondFrame_OptionsFrame_ButtonCanParty:GetChecked();
  641. end
  642.  
  643.  
  644. --[[-----------------------------------------------
  645. functions for the CanRaid-option of the response
  646. --]]-----------------------------------------------
  647. function AutoRespond_InitCanRaid()
  648. if ActiveOption == 0 then
  649. AutoRespondFrame_OptionsFrame_ButtonCanRaid:Disable();
  650. AutoRespondFrame_OptionsFrame_ButtonCanRaid:SetChecked(nil);
  651. else
  652. AutoRespondFrame_OptionsFrame_ButtonCanRaid:Enable();
  653. AutoRespondFrame_OptionsFrame_ButtonCanRaid:SetChecked(AutoRespondOptions[Realm][Player][ActiveOption]["Options"]["Receive"]["Raid"]);
  654. end
  655. end
  656.  
  657. function AutoRespond_ToggleCanRaid()
  658. AutoRespondOptions[Realm][Player][ActiveOption]["Options"]["Receive"]["Raid"] = AutoRespondFrame_OptionsFrame_ButtonCanRaid:GetChecked();
  659. end
  660.  
  661.  
  662. --[[-----------------------------------------------
  663. functions for the CanFriends-option of the response
  664. --]]-----------------------------------------------
  665. function AutoRespond_InitCanFriends()
  666. if ActiveOption == 0 then
  667. AutoRespondFrame_OptionsFrame_ButtonCanFriends:Disable();
  668. AutoRespondFrame_OptionsFrame_ButtonCanFriends:SetChecked(nil);
  669. else
  670. AutoRespondFrame_OptionsFrame_ButtonCanFriends:Enable();
  671. AutoRespondFrame_OptionsFrame_ButtonCanFriends:SetChecked(AutoRespondOptions[Realm][Player][ActiveOption]["Options"]["Receive"]["Friends"]);
  672. end
  673. end
  674.  
  675. function AutoRespond_ToggleCanFriends()
  676. AutoRespondOptions[Realm][Player][ActiveOption]["Options"]["Receive"]["Friends"] = AutoRespondFrame_OptionsFrame_ButtonCanFriends:GetChecked();
  677. end
  678.  
  679.  
  680. --[[-----------------------------------------------
  681. functions for the CanNames-option of the response
  682. --]]-----------------------------------------------
  683. function AutoRespond_InitCanNames()
  684. local text = "";
  685. if ActiveOption > 0 then
  686. if AutoRespondOptions[Realm][Player][ActiveOption]["Options"]["Receive"]["Names"] then
  687. local max = getn(AutoRespondOptions[Realm][Player][ActiveOption]["Options"]["Receive"]["Names"]);
  688. for i,v in ipairs(AutoRespondOptions[Realm][Player][ActiveOption]["Options"]["Receive"]["Names"]) do
  689. text = text..v;
  690. if i < max then
  691. text = text..", ";
  692. end
  693. end
  694. end
  695. end
  696. AutoRespondFrame_OptionsFrame_ListCanNames:SetText(text);
  697. end
  698.  
  699. function AutoRespond_SaveCanNames()
  700. if AutoRespondOptions[Realm][Player][ActiveOption] and AutoRespondOptions[Realm][Player][ActiveOption]["Options"] and AutoRespondOptions[Realm][Player][ActiveOption]["Options"]["Receive"] then
  701. if AutoRespondFrame_OptionsFrame_ListCanNames:GetNumLetters() > 0 then
  702. AutoRespondOptions[Realm][Player][ActiveOption]["Options"]["Receive"]["Names"] = {};
  703. local function towords(word) if word then table.insert(AutoRespondOptions[Realm][Player][ActiveOption]["Options"]["Receive"]["Names"],word); end end
  704. if not string.find(string.gsub(AutoRespondFrame_OptionsFrame_ListCanNames:GetText(), "%w+", towords), "%S") then end;
  705. else
  706. AutoRespondOptions[Realm][Player][ActiveOption]["Options"]["Receive"]["Names"] = nil;
  707. end
  708. end
  709. end
  710.  
  711. function AutoRespond_UpdateButtonListCanNames()
  712. if ActiveOption == 0 then
  713. AutoRespondFrame_OptionsFrame_ListCanNames:Disable();
  714. else
  715. AutoRespondFrame_OptionsFrame_ListCanNames:Enable();
  716. end
  717. end
  718.  
  719.  
  720. --[[-----------------------------------------------
  721. functions for TellGuild-option of the reponse
  722. --]]-----------------------------------------------
  723. function AutoRespond_InitTellGuild()
  724. if ActiveOption == 0 then
  725. AutoRespondFrame_OptionsFrame_ButtonTellGuild:Disable();
  726. AutoRespondFrame_OptionsFrame_ButtonTellGuild:SetChecked(nil);
  727. else
  728. AutoRespondFrame_OptionsFrame_ButtonTellGuild:Enable();
  729. AutoRespondFrame_OptionsFrame_ButtonTellGuild:SetChecked(AutoRespondOptions[Realm][Player][ActiveOption]["Options"]["Tell"]["Guild"]);
  730. end
  731. end
  732.  
  733. function AutoRespond_ToggleTellGuild()
  734. AutoRespondOptions[Realm][Player][ActiveOption]["Options"]["Tell"]["Guild"] = AutoRespondFrame_OptionsFrame_ButtonTellGuild:GetChecked();
  735. end
  736.  
  737.  
  738. --[[-----------------------------------------------
  739. functions for TellParty-option of the reponse
  740. --]]-----------------------------------------------
  741. function AutoRespond_InitTellParty()
  742. if ActiveOption == 0 then
  743. AutoRespondFrame_OptionsFrame_ButtonTellParty:Disable();
  744. AutoRespondFrame_OptionsFrame_ButtonTellParty:SetChecked(nil);
  745. else
  746. AutoRespondFrame_OptionsFrame_ButtonTellParty:Enable();
  747. AutoRespondFrame_OptionsFrame_ButtonTellParty:SetChecked(AutoRespondOptions[Realm][Player][ActiveOption]["Options"]["Tell"]["Party"]);
  748. end
  749. end
  750.  
  751. function AutoRespond_ToggleTellParty()
  752. AutoRespondOptions[Realm][Player][ActiveOption]["Options"]["Tell"]["Party"] = AutoRespondFrame_OptionsFrame_ButtonTellParty:GetChecked();
  753. end
  754.  
  755.  
  756. --[[-----------------------------------------------
  757. functions for TellRaid-option of the reponse
  758. --]]-----------------------------------------------
  759. function AutoRespond_InitTellRaid()
  760. if ActiveOption == 0 then
  761. AutoRespondFrame_OptionsFrame_ButtonTellRaid:Disable();
  762. AutoRespondFrame_OptionsFrame_ButtonTellRaid:SetChecked(nil);
  763. else
  764. AutoRespondFrame_OptionsFrame_ButtonTellRaid:Enable();
  765. AutoRespondFrame_OptionsFrame_ButtonTellRaid:SetChecked(AutoRespondOptions[Realm][Player][ActiveOption]["Options"]["Tell"]["Raid"]);
  766. end
  767. end
  768.  
  769. function AutoRespond_ToggleTellRaid()
  770. AutoRespondOptions[Realm][Player][ActiveOption]["Options"]["Tell"]["Raid"] = AutoRespondFrame_OptionsFrame_ButtonTellRaid:GetChecked();
  771. end
  772.  
  773.  
  774. --[[--------------------------------------------------------------------------------------------
  775. functions for the whole Responds
  776. --]]--------------------------------------------------------------------------------------------
  777.  
  778. --[[-----------------------------------------------
  779. function to create a new respond
  780. --]]-----------------------------------------------
  781. function AutoRespond_ButtonNew()
  782. AutoRespondFrame:Hide();
  783.  
  784. table.insert( AutoRespondOptions[Realm][Player], { Active = nil, Script = nil, Keywords = {AUTO_RESPOND_DEFAULT_KEYWORD_TEXT}, Response = {AUTO_RESPOND_DEFAULT_RESPONSE_TEXT}, Options = { Receive = { Guild = nil, Party = nil, Raid = nil, Friends = nil, Names = {} }, Tell = { Guild = nil, Party = nil, Raid = nil } } } );
  785.  
  786. DEFAULT_CHAT_FRAME:AddMessage(AUTO_RESPOND_ADD_NEW_TEXT);
  787.  
  788. ActiveOption = getn(AutoRespondOptions[Realm][Player]);
  789.  
  790. AutoRespondFrame:Show();
  791. end
  792.  
  793.  
  794. --[[-----------------------------------------------
  795. function to check status for delete-button
  796. --]]-----------------------------------------------
  797. function AutoRespond_ButtonOnShow()
  798. if ActiveOption == 0 and getn(AutoRespondOptions[Realm][Player]) == 0 then
  799. AutoRespondFrame_ButtonDelete:Disable();
  800. else
  801. AutoRespondFrame_ButtonDelete:Enable();
  802. end
  803. end
  804.  
  805.  
  806. --[[-----------------------------------------------
  807. function to delete a respond
  808. --]]-----------------------------------------------
  809. function AutoRespond_ButtonDelete()
  810. local index = getn(AutoRespondOptions[Realm][Player]);
  811. if index >= ActiveOption and index > 0 then
  812. AutoRespondFrame:Hide();
  813. table.remove(AutoRespondOptions[Realm][Player],ActiveOption);
  814. DEFAULT_CHAT_FRAME:AddMessage(AUTO_RESPOND_DELETED_TEXT);
  815. if(ActiveOption == index) then
  816. ActiveOption = ActiveOption - 1;
  817. end
  818. AutoRespondFrame:Show();
  819. else
  820. DEFAULT_CHAT_FRAME:AddMessage(AUTO_RESPOND_EMPTY_LIST_TEXT);
  821. end
  822. end
  823.  
  824.  
  825. --[[-----------------------------------------------
  826. function to check status for previous-button
  827. --]]-----------------------------------------------
  828. function AutoRespond_ButtonPreviousOnShow()
  829. if ActiveOption <= 1 then
  830. AutoRespondFrame_ButtonPrevious:Disable();
  831. else
  832. AutoRespondFrame_ButtonPrevious:Enable();
  833. end
  834. end
  835.  
  836.  
  837. --[[-----------------------------------------------
  838. function to go to previous response
  839. --]]-----------------------------------------------
  840. function AutoRespond_ButtonPreviousOnClick()
  841. AutoRespondFrame:Hide();
  842. ActiveOption = ActiveOption - 1;
  843. AutoRespondFrame:Show();
  844. end
  845.  
  846.  
  847. --[[-----------------------------------------------
  848. function to check status for next-button
  849. --]]-----------------------------------------------
  850. function AutoRespond_ButtonNextOnShow()
  851. if ActiveOption == (getn(AutoRespondOptions[Realm][Player])) then
  852. AutoRespondFrame_ButtonNext:Disable();
  853. else
  854. AutoRespondFrame_ButtonNext:Enable();
  855. end
  856. end
  857.  
  858.  
  859. --[[-----------------------------------------------
  860. function to go to next response
  861. --]]-----------------------------------------------
  862. function AutoRespond_ButtonNextOnClick()
  863. AutoRespondFrame:Hide();
  864. ActiveOption = ActiveOption + 1;
  865. AutoRespondFrame:Show();
  866. end
  867.  
  868.  
  869. --[[--------------------------------------------------------------------------------------------
  870. functions for the main-options
  871. --]]--------------------------------------------------------------------------------------------
  872.  
  873.  
  874. --[[-----------------------------------------------
  875. function to show the actual status of the ActiveMod option
  876. --]]-----------------------------------------------
  877. function AutoRespondOptions_InitActiveMod()
  878. AutoRespondOptionsFrame_ActiveMod:SetChecked(AutoRespondMainOptions[Realm][Player]["ActiveMod"]);
  879. end
  880.  
  881.  
  882. --[[-----------------------------------------------
  883. function to save the status of the ActiveMod option
  884. --]]-----------------------------------------------
  885. function AutoRespondOptions_ToggleActiveMod()
  886. local active = AutoRespondOptionsFrame_ActiveMod:GetChecked();
  887. if active then
  888. AutoRespondFrame:RegisterEvent("CHAT_MSG_WHISPER");
  889. else
  890. AutoRespondFrame:UnregisterEvent("CHAT_MSG_WHISPER");
  891. end
  892. AutoRespondMainOptions[Realm][Player]["ActiveMod"] = AutoRespondOptionsFrame_ActiveMod:GetChecked();
  893. end
  894.  
  895.  
  896. --[[-----------------------------------------------
  897. function to show the status of the actual InFight option
  898. --]]-----------------------------------------------
  899. function AutoRespondOptions_InitInFight()
  900. AutoRespondOptionsFrame_InFight:SetChecked(AutoRespondMainOptions[Realm][Player]["InFight"]);
  901. end
  902.  
  903.  
  904. --[[-----------------------------------------------
  905. function to save the status of the InFight option
  906. --]]-----------------------------------------------
  907. function AutoRespondOptions_ToggleInFight()
  908. AutoRespondMainOptions[Realm][Player]["InFight"] = AutoRespondOptionsFrame_InFight:GetChecked();
  909. end
  910.  
  911.  
  912. --[[-----------------------------------------------
  913. function to show the actual scaling and texts for the scale-widget
  914. --]]-----------------------------------------------
  915. function AutoRespondOptions_Scaling_OnShow()
  916. local scaling = AutoRespondMainOptions[Realm][Player]["Scaling"];
  917.  
  918. getglobal(AutoRespondOptionsFrame_Scaling_Slider:GetName() .. "High"):SetText("150%");
  919. getglobal(AutoRespondOptionsFrame_Scaling_Slider:GetName() .. "Low"):SetText("50%");
  920. getglobal(AutoRespondOptionsFrame_Scaling_Slider:GetName() .. "Text"):SetText("Scaling - " .. (scaling*100));
  921.  
  922. AutoRespondOptionsFrame_Scaling_Slider:SetMinMaxValues(0.5, 1.5);
  923. AutoRespondOptionsFrame_Scaling_Slider:SetValueStep(0.01);
  924. AutoRespondOptionsFrame_Scaling_Slider:SetValue(scaling);
  925. end
  926.  
  927.  
  928. --[[-----------------------------------------------
  929. function to save the scaling when changed
  930. --]]-----------------------------------------------
  931. function AutoRespondOptions_Scaling_OnValueChanged()
  932. scaling = floor(AutoRespondOptionsFrame_Scaling_Slider:GetValue()*100+0.5)/100;
  933. getglobal(AutoRespondOptionsFrame_Scaling_Slider:GetName() .. "Text"):SetText("Scaling - " .. (scaling*100) .. "%");
  934. AutoRespondMainOptions[Realm][Player]["Scaling"] = scaling;
  935. AutoRespondOptions_ScaleFrame(scaling);
  936. end
  937.  
  938.  
  939. --[[-----------------------------------------------
  940. function to set the scale of the mainframe
  941. --]]-----------------------------------------------
  942. function AutoRespondOptions_ScaleFrame(scaling)
  943. AutoRespondFrame:SetScale(scaling);
  944. end
  945.  
  946.  
  947. --[[-----------------------------------------------
  948. function to init the spam check option
  949. --]]-----------------------------------------------
  950. function AutoRespondOptions_InitSpamCheck()
  951. AutoRespondOptionsFrame_SpamCheck:SetChecked(AutoRespondMainOptions[Realm][Player]["SpamCheck"]);
  952. end
  953.  
  954. --[[-----------------------------------------------
  955. function to save the spam check option when changed
  956. --]]-----------------------------------------------
  957. function AutoRespondOptions_ToggleSpamCheck()
  958. AutoRespondMainOptions[Realm][Player]["SpamCheck"] = AutoRespondOptionsFrame_SpamCheck:GetChecked();
  959. end
  960.  
  961.  
  962. --[[-----------------------------------------------
  963. function to save the spam timer when changed
  964. --]]-----------------------------------------------
  965. function AutoRespondOptions_SpamTimer_OnValueChanged()
  966. timer = AutoRespondOptionsFrame_SpamTimer_Slider:GetValue();
  967. getglobal(AutoRespondOptionsFrame_SpamTimer_Slider:GetName() .. "Text"):SetText("Spam timer - " .. (timer));
  968. AutoRespondMainOptions[Realm][Player]["SpamTimer"] = timer;
  969. end
  970.  
  971. --[[-----------------------------------------------
  972. function to init the spam timer option
  973. --]]-----------------------------------------------
  974. function AutoRespondOptions_SpamTimer_OnShow()
  975. local timer = AutoRespondMainOptions[Realm][Player]["SpamTimer"];
  976. if not timer then
  977. timer = 60.0;
  978. end
  979. getglobal(AutoRespondOptionsFrame_SpamTimer_Slider:GetName().."High"):SetText("60s");
  980. getglobal(AutoRespondOptionsFrame_SpamTimer_Slider:GetName().."Low"):SetText("1s");
  981. getglobal(AutoRespondOptionsFrame_SpamTimer_Slider:GetName() .. "Text"):SetText("Spam timer - " .. (timer));
  982.  
  983. AutoRespondOptionsFrame_SpamTimer_Slider:SetMinMaxValues(1.0, 60.0);
  984. AutoRespondOptionsFrame_SpamTimer_Slider:SetValueStep(1.0);
  985. AutoRespondOptionsFrame_SpamTimer_Slider:SetValue(timer);
  986. end
  987.  
  988.  
  989. --[[--------------------------------------------------------------------------------------------
  990. special functions for macros or scripts
  991. --]]--------------------------------------------------------------------------------------------
  992.  
  993. --[[-----------------------------------------------
  994. function to promote a response to a channel
  995. Parameter:
  996. index - the index of the response to promote
  997. channel - the identifier of the channel to promote to
  998. number - only with channel "CHANNEL" where number is the numeric id of the channel to promote to
  999. --]]-----------------------------------------------
  1000. function AutoRespond_PromoteResponse(index,channel,number)
  1001. if channel and index and (index <= getn(AutoRespondOptions[Realm][Player])) then
  1002. for i,v in AutoRespondOptions[Realm][Player][index]["Response"] do
  1003. if channel == "CHANNEL" then
  1004. if number then
  1005. SendChatMessage(v,channel,GetDefaultLanguage("player"),number);
  1006. else
  1007. DEFAULT_CHAT_FRAME:AddMessage(AUTO_RESPOND_PROMOTE_CHANNEL_ERROR);
  1008. end
  1009. else
  1010. SendChatMessage(v,channel,GetDefaultLanguage("player"));
  1011. end
  1012. end
  1013. end
  1014. end
  1015.  
  1016.  
  1017. --[[-----------------------------------------------
  1018. function to promote all keywords of response(s) to a channel
  1019. Parameter:
  1020. index - the index of the response, if nil all active responses will be used
  1021. channel - the identifier of the channel to promote to
  1022. number - only with channel "CHANNEL" where number is the numeric id of the channel to promote to
  1023. --]]-----------------------------------------------
  1024. function AutoRespond_PromoteKeywords(index,channel, number)
  1025. local s,e = 1,getn(AutoRespondOptions[Realm][Player]);
  1026. if index then
  1027. s = index;
  1028. e = index;
  1029. end
  1030. for i=s,e do
  1031. if AutoRespondOptions[Realm][Player][i] and AutoRespondOptions[Realm][Player][i]["Active"] then
  1032. if AutoRespondOptions[Realm][Player][i]["Keywords"] then
  1033. local text,max = "", getn(AutoRespondOptions[Realm][Player][i]["Keywords"]);
  1034. for j,v in ipairs(AutoRespondOptions[Realm][Player][i]["Keywords"]) do
  1035. text = text..v;
  1036. if j < max then
  1037. text = text..", ";
  1038. end
  1039. end
  1040. if channel == "CHANNEL" then
  1041. if number then
  1042. SendChatMessage(text,channel,GetDefaultLanguage("player"),number);
  1043. else
  1044. DEFAULT_CHAT_FRAME:AddMessage(AUTO_RESPOND_PROMOTE_CHANNEL_ERROR);
  1045. end
  1046. else
  1047. SendChatMessage(text,channel,GetDefaultLanguage("player"));
  1048. end
  1049. end
  1050. end
  1051. end
  1052. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement