2011-05-25 18:58:22 -04:00
|
|
|
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;
|
|
|
|
|
2011-05-26 02:09:37 -04:00
|
|
|
core.verified = false;
|
|
|
|
|
2011-05-25 05:36:29 -04:00
|
|
|
function core:OnInitialize()
|
2011-05-25 22:02:41 -04:00
|
|
|
self:RawHook(SlashCmdList,'JOIN','JoinChannel',true);
|
2011-05-25 22:41:33 -04:00
|
|
|
self:RawHook(SlashCmdList,'LEAVE','LeaveChannel',true);
|
|
|
|
self:Hook('ToggleChatChannel','ToggleChatChannel',true);
|
2011-05-25 18:58:22 -04:00
|
|
|
|
|
|
|
self:RegisterChatCommand('cs','SlashCommand');
|
|
|
|
|
|
|
|
if(ChatSaverDB == nil) then ChatSaverDB = {}; end
|
2011-05-25 05:05:57 -04:00
|
|
|
end
|
|
|
|
|
2011-05-25 18:58:22 -04:00
|
|
|
function core:OnEnable()
|
|
|
|
self:RegisterEvent('CHAT_MSG_CHANNEL_NOTICE','RejoinChannels');
|
|
|
|
end
|
|
|
|
|
|
|
|
function core:SlashCommand()
|
2011-05-26 02:09:37 -04:00
|
|
|
core.verified = false
|
2011-05-25 18:58:22 -04:00
|
|
|
core:RejoinChannels();
|
|
|
|
end
|
|
|
|
|
|
|
|
function core:RejoinChannels(event,message,...)
|
2011-05-27 15:09:58 -04:00
|
|
|
if(core.verified == true) then
|
2011-05-25 18:58:22 -04:00
|
|
|
return;
|
|
|
|
end
|
2011-05-26 02:09:37 -04:00
|
|
|
|
2011-05-27 15:08:27 -04:00
|
|
|
local currentChannels = {};
|
|
|
|
for i = 1,select("#",GetChannelList()),2 do
|
2011-05-25 05:36:29 -04:00
|
|
|
local index,channel = select(i,GetChannelList());
|
2011-05-27 15:08:27 -04:00
|
|
|
currentChannels[channel] = true;
|
2011-05-25 05:36:29 -04:00
|
|
|
end
|
|
|
|
|
2011-05-25 22:02:41 -04:00
|
|
|
for channel,information in pairs(ChatSaverDB) do
|
2011-05-27 15:08:27 -04:00
|
|
|
if(currentChannels[channel] == nil) then
|
2011-05-25 18:58:22 -04:00
|
|
|
JoinPermanentChannel(channel);
|
2011-05-25 22:41:33 -04:00
|
|
|
for index,shown in pairs(ChatSaverDB[channel].frames) do
|
2011-05-25 23:04:12 -04:00
|
|
|
if(shown) then
|
|
|
|
_G['ChatFrame'..index].channelList[table.getn(_G['ChatFrame'..index].channelList) + 1] = channel;
|
|
|
|
end
|
2011-05-25 22:41:33 -04:00
|
|
|
end
|
2011-05-25 05:36:29 -04:00
|
|
|
end
|
|
|
|
end
|
2011-05-26 02:09:37 -04:00
|
|
|
|
|
|
|
core.verified = true;
|
2011-05-25 05:05:57 -04:00
|
|
|
end
|
|
|
|
|
2011-05-25 18:58:22 -04:00
|
|
|
function core:JoinChannel(msg)
|
2011-05-25 22:02:41 -04:00
|
|
|
self.hooks[SlashCmdList].JOIN(msg);
|
|
|
|
|
2011-05-25 18:58:22 -04:00
|
|
|
local name = gsub(msg, "%s*([^%s]+).*", "%1");
|
2011-05-25 22:02:41 -04:00
|
|
|
|
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
|
2011-05-25 18:58:22 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
function core:LeaveChannel(msg)
|
2011-05-25 22:02:41 -04:00
|
|
|
self.hooks[SlashCmdList].LEAVE(msg);
|
|
|
|
|
2011-05-25 18:58:22 -04:00
|
|
|
local number = gsub(msg, "%s*([^%s]+).*", "%1");
|
|
|
|
local _,name = GetChannelName(number);
|
|
|
|
|
2011-05-27 15:09:58 -04:00
|
|
|
--ChatSaverDB[name] = nil;
|
2011-05-25 22:41:33 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
function core:ToggleChatChannel(checked,channel)
|
2011-05-25 23:18:21 -04:00
|
|
|
if(ChatSaverDB[channel] == nil) then
|
|
|
|
return;
|
|
|
|
end
|
|
|
|
|
2011-05-25 22:41:33 -04:00
|
|
|
if(checked) then
|
|
|
|
ChatSaverDB[channel]['frames'][FCF_GetCurrentChatFrameID()] = true;
|
|
|
|
else
|
|
|
|
ChatSaverDB[channel]['frames'][FCF_GetCurrentChatFrameID()] = false;
|
|
|
|
end
|
2011-05-25 18:58:22 -04:00
|
|
|
end
|