Code:
AutoRespondOptions = {};
local Realm;
local Player;
local VariablesLoaded = nil;
local Initialized = nil;
local ActiveOption = 1;
local AR_Version= "1.41";
local AR_DefaultOptions = {Status = 0, Keyword = AUTO_RESPOND_DEFAULT_KEYWORD_TEXT, Response = {AUTO_RESPOND_DEFAULT_RESPONSE_TEXT}, System = 0};
local Blizzard_OldSetItemRef = function() end;
function AutoRespond_OnLoad()
this:RegisterEvent("CHAT_MSG_WHISPER");
this:RegisterEvent("PLAYER_ENTERING_WORLD");
this:RegisterEvent("VARIABLES_LOADED");
this:RegisterEvent("CHAT_MSG_TEXT_EMOTE");
SlashCmdList["AUTORESPOND"] = AutoRespond_SlashHandler;
SLASH_AUTORESPOND1 = "/AutoRespond";
SLASH_AUTORESPOND2 = "/ar";
ChatFrame_OnEvent_NotAntiEmoteSpam = ChatFrame_OnEvent;
ChatFrame_OnEvent = ChatFrame_OnEvent_AntiEmoteSpam;
xmin = "";
lastemote = "";
lastlastemote = "";
p1 = "";
AutoRespond_KeywordLabel:SetText(AUTO_RESPOND_KEYWORD_LABEL_TEXT);
AutoRespond_ResponseLabel:SetText(AUTO_RESPOND_RESPONSE_LABEL_TEXT);
AutoRespond_SelectBefore:SetText(AUTO_RESPOND_SELECT_BEFORE_TEXT);
AutoRespond_SelectNext:SetText(AUTO_RESPOND_SELECT_NEXT_TEXT);
AutoRespond_AddRespond:SetText(AUTO_RESPOND_ADD_BUTTON_TEXT);
AutoRespond_DeleteRespond:SetText(AUTO_RESPOND_DELETE_BUTTON_TEXT);
AutoRespond_LinkButton:SetText(AUTO_RESPOND_LINK_BUTTON_TEXT);
AutoRespond_ReagentButton:SetText(AUTO_RESPOND_REAGENT_BUTTON_TEXT);
AutoRespond_SaveButton:SetText(AUTO_RESPOND_SAVE_BUTTON_TEXT);
AutoRespond_ExitButton:SetText(AUTO_RESPOND_EXIT_BUTTON_TEXT);
getglobal(AutoRespond_StatusButton:GetName().."Text"):SetText(AUTO_RESPOND_STATUS_BUTTON_TEXT);
getglobal(AutoRespond_SystemButton:GetName().."Text"):SetText(AUTO_RESPOND_SYSTEM_BUTTON_TEXT);
end
function AutoRespond_InitializeSetup()
if Initialized or (not VariablesLoaded) then
return;
end
Player = UnitName("player");
Realm = GetRealmName();
if AutoRespondOptions == nil then AutoRespondOptions = {} end;
if(AutoRespondOptions[Realm] == nil) then AutoRespondOptions[Realm] = {} end;
if(AutoRespondOptions[Realm][Player] == nil) then AutoRespondOptions[Realm][Player] = {AR_DefaultOptions} end;
if Sea then
Sea.util.hook("SetItemRef", "MySetItemRef", "after");
else
Blizzard_OldSetItemRef = SetItemRef;
SetItemRef = MySetItemRef;
end
DEFAULT_CHAT_FRAME:AddMessage(string.format(AUTO_RESPOND_LOADED_TEXT,AR_Version));
Initialized = 1;
end
function AutoRespond_OnEvent(event)
if(event == "CHAT_MSG_WHISPER") then
local what = arg1;
local who = arg2;
local respond = AutoRespond_CheckMessage(what,1);
while respond > 0 do
AutoRespond_Respond(who,respond);
respond = AutoRespond_CheckMessage(what,respond+1);
end
elseif(event == "VARIABLES_LOADED") then
VariablesLoaded = 1;
else
AutoRespond_InitializeSetup();
end
end
function AutoRespond_OnShow()
AutoRespond_SetRespond();
end
function MySetItemRef(link,text,button)
local ret = Blizzard_OldSetItemRef(link,text,button);
if ( IsShiftKeyDown() ) and ( AutoRespond_FrameText:IsVisible() ) then
AutoRespond_FrameText:Insert(text);
end
return ret;
end
function AutoRespond_SlashHandler(msg)
AutoRespondFrame:Show();
end
function AutoRespond_CheckMessage(what,index)
local t = AutoRespondOptions[Realm][Player];
for i=index,getn(t) do
if t[i]["Status"] == 1 then
if string.find(string.lower(what), t[i]["Keyword"], 1, true) then
return i;
end
end
end
return 0;
end
function AutoRespond_GetOption(option)
if(AutoRespondOptions[Realm][Player][ActiveOption]) then return AutoRespondOptions[Realm][Player][ActiveOption][option] end;
return AR_DefaultOptions[option];
end
function AutoRespond_GetResponse(number)
local t = nil;
if(AutoRespondOptions[Realm][Player][number]["Response"] ~= nil) then
t = AutoRespondOptions[Realm][Player][number]["Response"];
end
return t;
end
function AutoRespond_Respond(who,number)
local t = AutoRespond_GetResponse(number);
if t == nil then return; end
if AutoRespondOptions[Realm][Player][number]["System"] == 1 then
for i=1,getn(t) do
RunScript(string.gsub(t[i],"$t","'"..who.."'"));
end
else
for i=1,getn(t) do
local randtime1;
randtime1 = random(5,10)
Timex:AddNamedSchedule("Reply", randtime1, nil, 1, SendChatMessage, string.gsub(t[i],"$t",who), "WHISPER", GetDefaultLanguage("player"), who);
end
end
end
function AutoRespond_AddDefault()
table.insert(AutoRespondOptions[Realm][Player],{Status = 0, Keyword = AUTO_RESPOND_DEFAULT_KEYWORD_TEXT, Response = {AUTO_RESPOND_DEFAULT_RESPONSE_TEXT}, System = 0});
DEFAULT_CHAT_FRAME:AddMessage(AUTO_RESPOND_ADD_NEW_TEXT);
ActiveOption = getn(AutoRespondOptions[Realm][Player]);
AutoRespond_SetRespond();
end
function AutoRespond_ClearRespond()
local index = getn(AutoRespondOptions[Realm][Player]);
if index >= ActiveOption and index > 0 then
AutoRespond_ClearResponse();
table.remove(AutoRespondOptions[Realm][Player],ActiveOption);
DEFAULT_CHAT_FRAME:AddMessage(AUTO_RESPOND_DELETED_TEXT);
if(ActiveOption == index) then
ActiveOption = ActiveOption - 1;
end
AutoRespond_SetRespond();
else
DEFAULT_CHAT_FRAME:AddMessage(AUTO_RESPOND_EMPTY_LIST_TEXT);
end
end
function AutoRespond_ChangeRespond(number)
ActiveOption = number;
end
function AutoRespond_ClearResponse()
for i=1,getn(AutoRespondOptions[Realm][Player][ActiveOption]["Response"])+1 do
table.remove(AutoRespondOptions[Realm][Player][ActiveOption]["Response"]);
end
end
function AutoRespond_Save()
AutoRespond_SaveKeyword();
AutoRespond_SaveResponse();
DEFAULT_CHAT_FRAME:AddMessage(AUTO_RESPOND_SAVED_TEXT);
end
function AutoRespond_SaveKeyword()
local text = AutoRespond_Keyword:GetText();
if(text ~= "") then
AutoRespondOptions[Realm][Player][ActiveOption]["Keyword"] = string.lower(text);
end
end
function AutoRespond_SaveResponse()
local text = AutoRespond_FrameText:GetText();
AutoRespond_ClearResponse();
if(text == "") then
return;
end
local pos = 1;
local endpos = 1;
while pos < string.len(text) do
endpos = string.find(text,"\n",pos);
if(endpos == nil) then
endpos = string.len(text);
else
endpos = endpos - 1;
end;
AutoRespond_SaveToLine(string.sub(text,pos,endpos));
pos = endpos+2;
end
end
function AutoRespond_SaveToLine(line)
if(line ~= "") then
table.insert(AutoRespondOptions[Realm][Player][ActiveOption]["Response"],line);
end
end
function AutoRespond_UpdateResponse()
AutoRespond_FrameText:SetText("");
if getn(AutoRespondOptions[Realm][Player]) == 0 then
return;
end
for i=1, getn(AutoRespondOptions[Realm][Player][ActiveOption]["Response"]) do
AutoRespond_FrameText:Insert(AutoRespondOptions[Realm][Player][ActiveOption]["Response"][i].."\n");
end
end
function AutoRespond_SelectBeforeOnLoad()
if ActiveOption <= 1 then
this:Disable();
end
end
function AutoRespond_SelectBeforeOnClick()
if ActiveOption > 1 then
ActiveOption = ActiveOption-1;
AutoRespond_SetRespond();
else
DEFAULT_CHAT_FRAME:AddMessage(START_OF_LIST);
end
end
function AutoRespond_SelectNextOnLoad()
if ActiveOption >= getn(AutoRespondOptions[Realm][Player]) then
this:Disable();
end
end
function AutoRespond_SelectNextOnClick()
if ActiveOption < getn(AutoRespondOptions[Realm][Player]) then
ActiveOption = ActiveOption+1;
AutoRespond_SetRespond();
else
DEFAULT_CHAT_FRAME:AddMessage(END_OF_LIST);
end
end
function AutoRespond_Exit()
AutoRespondFrame:Hide();
end
function AutoRespond_SetRespond()
if ActiveOption > 1 and getn(AutoRespondOptions[Realm][Player]) >= ActiveOption then
AutoRespond_SelectBefore:Enable();
else
AutoRespond_SelectBefore:Disable();
end
if ActiveOption < getn(AutoRespondOptions[Realm][Player]) and getn(AutoRespondOptions[Realm][Player]) > 1 then
AutoRespond_SelectNext:Enable();
else
AutoRespond_SelectNext:Disable();
end
AutoRespond_UpdateStatus();
AutoRespond_UpdateSystem();
AutoRespond_UpdateKeyword();
AutoRespond_UpdateResponse();
end
function AutoRespond_UpdateStatus()
if getn(AutoRespondOptions[Realm][Player]) == 0 then
AutoRespond_StatusButton:SetChecked(0);
return;
end
AutoRespond_StatusButton:SetChecked(AutoRespond_GetOption("Status"));
end
function AutoRespond_ToggleStatus()
AutoRespondOptions[Realm][Player][ActiveOption]["Status"] = this:GetChecked();
end
function AutoRespond_UpdateSystem()
if getn(AutoRespondOptions[Realm][Player]) == 0 then
AutoRespond_SystemButton:SetChecked(0);
return;
end
AutoRespond_SystemButton:SetChecked(AutoRespond_GetOption("System"));
end
function AutoRespond_ToggleSystem()
AutoRespondOptions[Realm][Player][ActiveOption]["System"] = this:GetChecked();
end
function AutoRespond_UpdateKeyword()
if getn(AutoRespondOptions[Realm][Player]) == 0 then
AutoRespond_Keyword:SetText("");
return;
end
AutoRespond_Keyword:SetText(AutoRespondOptions[Realm][Player][ActiveOption]["Keyword"]);
end
function Auto_Respond_IncludeLink()
local temp = GetCraftSkillLine(1);
if temp then
local index = GetCraftSelectionIndex();
if (index) and (index < GetNumCrafts()) then
local link = GetCraftItemLink(index);
if link then
AutoRespond_FrameText:Insert(link);
else
DEFAULT_CHAT_FRAME:AddMessage(AUTO_RESPOND_NO_LINK_ITEM);
end
end
else
local index = GetTradeSkillSelectionIndex();
if index then
local link = GetTradeSkillItemLink(index);
if link then
AutoRespond_FrameText:Insert(link);
else
DEFAULT_CHAT_FRAME:AddMessage(AUTO_RESPOND_NO_LINK_ITEM);
end
else
DEFAULT_CHAT_FRAME:AddMessage(AUTO_RESPOND_NO_SELECTED_TRADESKILL);
end
end
end
function Auto_Respond_IncludeReagent()
local text = "";
if GetCraftSkillLine(1) then
local index = GetCraftSelectionIndex();
if (index) and (index < GetNumCrafts) then
for i=1,GetCraftNumReagents(index) do
local _,_,num = GetCraftReagentInfo(index,i);
text = text..num.."x"..GetCraftReagentItemLink(index,i)..";";
end
end
else
local index = GetTradeSkillSelectionIndex();
if (index) and (index < GetNumTradeSkills()) then
for i=1,GetTradeSkillNumReagents(index) do
local _,_,num = GetTradeSkillReagentInfo(index, i);
text = text..num.."x"..GetTradeSkillReagentItemLink(index, i)..";";
end
end
end
if text ~= "" then
AutoRespond_FrameText:Insert(text);
end
end
function Auto_Respond_PromoteToChannel(index,channel,number)
if channel and index and (index <= getn(AutoRespondOptions[Realm][Player])) then
for i=1,getn(AutoRespondOptions[Realm][Player][index]["Response"]) do
if channel == "CHANNEL" and number then
local randtime2;
randtime2 = random(5,10)
Timex:AddNamedSchedule("Promote1", randtime2, nil, 1, SendChatMessage, AutoRespondOptions[Realm][Player][index]["Response"][i],channel,GetDefaultLanguage("player"),number);
else
local randtime3;
randtime3 = random(5,10)
Timex:AddNamedSchedule("Promote2", randtime3, nil, 1, SendChatMessage, AutoRespondOptions[Realm][Player][index]["Response"][i],channel,GetDefaultLanguage("player"));
end
end
end
end
function Auto_Respond_PromoteResponses(channel)
for i=1,getn(AutoRespondOptions[Realm][Player]) do
if AutoRespondOptions[Realm][Player][i]["System"] == 0 and AutoRespondOptions[Realm][Player][i]["Status"] == 1 then
local randtime4;
randtime4 = random(5,10)
Timex:AddNamedSchedule("Promote4", randtime4, nil, 1, SendChatMessage, AutoRespondOptions[Realm][Player][i]["Promote"],"CHANNEL",GetDefaultLanguage("player"),channel);
end
end
end
function ChatFrame_OnEvent_AntiEmoteSpam(event)
local hour,min=GetGameTime();
if event=="CHAT_MSG_TEXT_EMOTE" and arg2~=UnitName("player") then
if min~=xmin and p1~=arg2 then
if p1~="" or p1~=arg2 then
p1 = arg2;
local x = math.random(13)
if (x == 1) then
emote = "wave"
elseif (x == 2) then
emote = "hello"
elseif (x == 3) then
emote = "cheer"
elseif (x == 4) then
emote = "yawn"
elseif (x == 5) then
emote = "smile"
elseif (x == 6) then
emote = "wave"
elseif (x == 7) then
emote = "clap"
elseif (x == 8) then
emote = "laugh"
elseif (x == 9) then
emote = "giggle"
elseif (x == 10) then
emote = "whistle"
elseif (x == 11) then
emote = "wave"
elseif (x == 12) then
emote = "Applaud"
elseif (x == 13) then
emote = "wave"
end;
xmin = min;
local randtime5;
randtime5 = random(5,8)
Timex:AddNamedSchedule("Emote", randtime5, nil, 1, DoEmote, emote);
else
p1 = "";
end;
end;
end;
ChatFrame_OnEvent_NotAntiEmoteSpam(event, arg1, arg2, arg3, arg4, arg5, arg6,
arg7, arg8, arg9);
end