Advertisement
Guest User

Untitled

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