ChatSaver/ChatSaver.lua

90 lines
2.3 KiB
Lua
Raw Permalink Normal View History

ChatSaver = LibStub('AceAddon-3.0'):NewAddon('ChatSaver','AceConsole-3.0','AceHook-3.0','AceEvent-3.0');
2011-05-25 05:05:57 -04:00
local core = ChatSaver;
core.verified = false;
2011-05-25 05:36:29 -04:00
function core:OnInitialize()
self:RawHook(SlashCmdList,'JOIN','JoinChannel',true);
self:RawHook(SlashCmdList,'LEAVE','LeaveChannel',true);
self:Hook('ToggleChatChannel','ToggleChatChannel',true);
self:RegisterChatCommand('cs','SlashCommand');
if(ChatSaverDB == nil) then ChatSaverDB = {}; end
2011-05-25 05:05:57 -04:00
end
function core:OnEnable()
self:RegisterEvent('CHAT_MSG_CHANNEL_NOTICE','RejoinChannels');
end
function core:SlashCommand()
core.verified = false
core:RejoinChannels();
end
function core:RejoinChannels(event,message,...)
if(message == 'YOU_LEFT' or core.verified == true) then
return;
end
local channelList = {};
2011-05-25 05:36:29 -04:00
for i = 1, select("#",GetChannelList()), 2 do
local index,channel = select(i,GetChannelList());
channelList[index] = channel;
end
for channel,information in pairs(ChatSaverDB) do
local found = false;
for jIndex,jChannel in pairs(channelList) do
if(jChannel == channel) then
found = true;
2011-05-25 07:21:59 -04:00
end
end
if(found == false) then
JoinPermanentChannel(channel);
for index,shown in pairs(ChatSaverDB[channel].frames) do
if(shown) then
_G['ChatFrame'..index].channelList[table.getn(_G['ChatFrame'..index].channelList) + 1] = channel;
end
end
2011-05-25 05:36:29 -04:00
end
end
core.verified = true;
2011-05-25 05:05:57 -04:00
end
function core:JoinChannel(msg)
self.hooks[SlashCmdList].JOIN(msg);
local name = gsub(msg, "%s*([^%s]+).*", "%1");
2011-05-26 00:01:58 -04:00
if(strlen(name) > 0 and string.match(name,"%a+")) then
ChatSaverDB[name] = {};
ChatSaverDB[name]['frames'] = {};
ChatSaverDB[name]['index'] = GetChannelName(name);
ChatSaverDB[name]['frames'][DEFAULT_CHAT_FRAME:GetID()] = true;
end
end
function core:LeaveChannel(msg)
self.hooks[SlashCmdList].LEAVE(msg);
local number = gsub(msg, "%s*([^%s]+).*", "%1");
local _,name = GetChannelName(number);
ChatSaverDB[name] = nil;
end
function core:ToggleChatChannel(checked,channel)
2011-05-25 23:18:21 -04:00
if(ChatSaverDB[channel] == nil) then
return;
end
if(checked) then
ChatSaverDB[channel]['frames'][FCF_GetCurrentChatFrameID()] = true;
else
ChatSaverDB[channel]['frames'][FCF_GetCurrentChatFrameID()] = false;
end
end