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-27 17:54:01 -04:00
|
|
|
function core:OnInitialize()
|
2011-05-25 18:58:22 -04:00
|
|
|
self:RegisterChatCommand('cs','SlashCommand');
|
|
|
|
|
2011-05-27 17:54:01 -04:00
|
|
|
if(ChatSaverDB == nil) then
|
|
|
|
core.firstrun = true;
|
|
|
|
ChatSaverDB = {};
|
|
|
|
else
|
|
|
|
core.firstrun = false;
|
|
|
|
end
|
2011-05-25 05:05:57 -04:00
|
|
|
end
|
|
|
|
|
2011-05-25 18:58:22 -04:00
|
|
|
function core:OnEnable()
|
2011-05-29 06:36:07 -04:00
|
|
|
self:RawHook(SlashCmdList,'JOIN','JoinChannel',true);
|
|
|
|
self:RawHook(SlashCmdList,'LEAVE','LeaveChannel',true);
|
|
|
|
self:Hook('ToggleChatChannel','ToggleChatChannel',true);
|
|
|
|
|
2011-05-27 18:53:50 -04:00
|
|
|
self:RegisterEvent('CHANNEL_UI_UPDATE','RejoinChannels');
|
2011-05-27 17:54:01 -04:00
|
|
|
if(core.firstrun) then
|
2011-05-27 18:53:50 -04:00
|
|
|
self:RegisterEvent('CHAT_MSG_CHANNEL_NOTICE','SetupChatSaver');
|
2011-05-27 17:54:01 -04:00
|
|
|
end
|
2011-05-25 18:58:22 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
function core:SlashCommand()
|
|
|
|
core:RejoinChannels();
|
|
|
|
end
|
|
|
|
|
2011-05-27 18:53:50 -04:00
|
|
|
function core:RejoinChannels(...)
|
2011-05-27 19:30:56 -04:00
|
|
|
local currentChannels = {};
|
2011-05-29 06:36:07 -04:00
|
|
|
for i = 1,select('#',GetChannelList()) do
|
2011-05-27 19:30:56 -04:00
|
|
|
currentChannels[select(i,GetChannelList())] = true
|
|
|
|
end
|
2011-05-25 05:36:29 -04:00
|
|
|
|
2011-06-02 04:53:40 -04:00
|
|
|
local sortedChannels = {};
|
2011-05-27 21:49:47 -04:00
|
|
|
for channel,_ in pairs(ChatSaverDB) do
|
2011-06-02 04:53:40 -04:00
|
|
|
table.insert(sortedChannels,channel);
|
|
|
|
end
|
|
|
|
|
|
|
|
table.sort(sortedChannels,function(a,b) return ChatSaverDB[a].index < ChatSaverDB[b].index end);
|
|
|
|
|
|
|
|
for _,channel in pairs(sortedChannels) do
|
2011-05-27 15:08:27 -04:00
|
|
|
if(currentChannels[channel] == nil) then
|
2011-05-29 06:36:07 -04:00
|
|
|
JoinPermanentChannel(channel); -- does not place in chat frame properly
|
2011-05-27 21:49:47 -04:00
|
|
|
for index,_ in pairs(ChatSaverDB[channel].frames) do
|
|
|
|
ChatFrame_AddChannel(_G['ChatFrame'..index],channel);
|
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
|
|
|
|
2011-05-27 18:53:50 -04:00
|
|
|
self:UnregisterEvent('CHANNEL_UI_UPDATE');
|
|
|
|
end
|
|
|
|
|
2011-05-29 06:36:07 -04:00
|
|
|
function core:SetupChatSaver(...)
|
|
|
|
for frame = 1,NUM_CHAT_WINDOWS do
|
2011-05-29 11:26:59 -04:00
|
|
|
local chatWindowChannels = { GetChatWindowChannels(frame) };
|
2011-05-29 06:36:07 -04:00
|
|
|
for i = 1,#chatWindowChannels,2 do
|
2011-06-02 16:12:14 -04:00
|
|
|
local name,zone = chatWindowChannels[i],chatWindowChannels[i + 1];
|
2011-05-27 18:53:50 -04:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2011-05-27 17:54:01 -04:00
|
|
|
self:UnregisterEvent('CHAT_MSG_CHANNEL_NOTICE');
|
2011-05-25 05:05:57 -04:00
|
|
|
end
|
|
|
|
|
2011-06-03 04:56:12 -04:00
|
|
|
function core:GetChannelInfo(id)
|
|
|
|
--addon.lua:373
|
|
|
|
--channelapi.lua:65
|
|
|
|
--channelapi.lua:55
|
|
|
|
local channelTable = core:GetChanneltable();
|
|
|
|
end
|
|
|
|
|
|
|
|
function core:GetChannelTable()
|
|
|
|
local channelList = { GetChannelList() };
|
|
|
|
local channelTable = {};
|
|
|
|
for i = 1,#channelList,2 do
|
|
|
|
channelTable[channelList[i]] = channelList[i + 1];
|
|
|
|
channelTable[channelList[i + 1]] = channelList[i];
|
|
|
|
if(type(channelList[i + 1]) == 'string') then
|
|
|
|
channelTable[channelList[i + 1]:lower()] = channelList[i];
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return channelTable;
|
|
|
|
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-06-02 16:12:14 -04:00
|
|
|
|
|
|
|
if(strlen(name) == 0 or not string.match(name,"%a+")) then
|
|
|
|
return;
|
|
|
|
end
|
|
|
|
|
|
|
|
local index = GetChannelName(name); -- in game function does not handle "General" or "Trade"
|
|
|
|
|
|
|
|
local _,_,_,_,_,_,category,_,_ = GetChannelDisplayInfo(index);
|
|
|
|
print(category);
|
2011-05-25 22:02:41 -04:00
|
|
|
|
2011-06-02 16:12:14 -04:00
|
|
|
if(category == CHANNEL_CATEGORY_CUSTOM) then
|
2011-05-26 00:01:58 -04:00
|
|
|
ChatSaverDB[name] = {};
|
|
|
|
ChatSaverDB[name]['frames'] = {};
|
2011-06-02 16:12:14 -04:00
|
|
|
ChatSaverDB[name]['index'] = index;
|
2011-05-26 00:01:58 -04:00
|
|
|
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-06-02 09:51:18 -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
|
2011-05-27 21:49:47 -04:00
|
|
|
ChatSaverDB[channel]['frames'][FCF_GetCurrentChatFrameID()] = nil;
|
2011-05-25 22:41:33 -04:00
|
|
|
end
|
2011-05-25 18:58:22 -04:00
|
|
|
end
|