Load player's channels if first login after ChatSaver install

This commit is contained in:
Andrew Tomaka 2011-05-27 17:54:01 -04:00
parent 827818c6d4
commit d5c30070b8

View file

@ -1,50 +1,64 @@
ChatSaver = LibStub('AceAddon-3.0'):NewAddon('ChatSaver','AceConsole-3.0','AceHook-3.0','AceEvent-3.0'); ChatSaver = LibStub('AceAddon-3.0'):NewAddon('ChatSaver','AceConsole-3.0','AceHook-3.0','AceEvent-3.0');
local core = ChatSaver; local core = ChatSaver;
core.verified = false; function core:OnInitialize()
function core:OnInitialize()
self:RawHook(SlashCmdList,'JOIN','JoinChannel',true); self:RawHook(SlashCmdList,'JOIN','JoinChannel',true);
self:RawHook(SlashCmdList,'LEAVE','LeaveChannel',true); self:RawHook(SlashCmdList,'LEAVE','LeaveChannel',true);
self:Hook('ToggleChatChannel','ToggleChatChannel',true); self:Hook('ToggleChatChannel','ToggleChatChannel',true);
self:RegisterChatCommand('cs','SlashCommand'); self:RegisterChatCommand('cs','SlashCommand');
if(ChatSaverDB == nil) then ChatSaverDB = {}; end if(ChatSaverDB == nil) then
core.firstrun = true;
ChatSaverDB = {};
else
core.firstrun = false;
end
end end
function core:OnEnable() function core:OnEnable()
self:RegisterEvent('CHAT_MSG_CHANNEL_NOTICE','RejoinChannels'); self:RegisterEvent('CHAT_MSG_CHANNEL_NOTICE','RejoinChannels');
--store curret channels if this is our first run
if(core.firstrun) then
for frame = 1,10 do
local frameChannels = { GetChatWindowChannels(frame) };
for i = 1,#frameChannels,2 do
local name,zone = frameChannels[i], frameChannels[i+1]
if(zone == 0) then
if(ChatSaverDB[name] == nil) then
ChatSaverDB[name] = {};
ChatSaverDB[name]['frames'] = {};
ChatSaverDB[name]['index'] = GetChannelName(name);
end
ChatSaverDB[name]['frames'][frame] = true;
end
end
end
end
end end
function core:SlashCommand() function core:SlashCommand()
core.verified = false
core:RejoinChannels(); core:RejoinChannels();
end end
function core:RejoinChannels(event,message,...) function core:RejoinChannels(event,message,...)
if(core.verified == true) then local currentChannels = { GetChannelList() };
return;
end
local currentChannels = {};
for i = 1,select("#",GetChannelList()),2 do
local index,channel = select(i,GetChannelList());
currentChannels[channel] = true;
end
for channel,information in pairs(ChatSaverDB) do for channel,information in pairs(ChatSaverDB) do
if(currentChannels[channel] == nil) then if(currentChannels[channel] == nil) then
JoinPermanentChannel(channel); JoinPermanentChannel(channel);
for index,shown in pairs(ChatSaverDB[channel].frames) do for index,shown in pairs(ChatSaverDB[channel].frames) do
if(shown) then if(shown) then
_G['ChatFrame'..index].channelList[table.getn(_G['ChatFrame'..index].channelList) + 1] = channel; ChatFrame_AddChannel(_G['ChatFrame'..index],channel);
end end
end end
end end
end end
core.verified = true; self:UnregisterEvent('CHAT_MSG_CHANNEL_NOTICE');
end end
function core:JoinChannel(msg) function core:JoinChannel(msg)