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-25 07:21:59 -04:00
|
|
|
local db;
|
|
|
|
|
2011-05-25 05:36:29 -04:00
|
|
|
function core:OnInitialize()
|
2011-05-25 07:21:59 -04:00
|
|
|
self:Hook(SlashCmdList,'JOIN','JoinChannel',true);
|
2011-05-25 18:58:22 -04:00
|
|
|
self:Hook(SlashCmdList,'LEAVE','LeaveChannel',true);
|
|
|
|
|
|
|
|
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()
|
|
|
|
core:RejoinChannels();
|
|
|
|
end
|
|
|
|
|
|
|
|
function core:RejoinChannels(event,message,...)
|
|
|
|
if(message == 'YOU_LEFT') 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
|
|
|
|
|
2011-05-25 18:58:22 -04:00
|
|
|
for index,channel 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
|
2011-05-25 18:58:22 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
if(found == false) then
|
|
|
|
JoinPermanentChannel(channel);
|
|
|
|
DEFAULT_CHAT_FRAME.channelList[table.getn(DEFAULT_CHAT_FRAME.channelList) + 1] = channel;
|
2011-05-25 05:36:29 -04:00
|
|
|
end
|
|
|
|
end
|
2011-05-25 05:05:57 -04:00
|
|
|
end
|
|
|
|
|
2011-05-25 18:58:22 -04:00
|
|
|
function core:InChannels()
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
function core:JoinChannel(msg)
|
|
|
|
local name = gsub(msg, "%s*([^%s]+).*", "%1");
|
2011-05-25 07:21:59 -04:00
|
|
|
--need to store channel in db
|
2011-05-25 18:58:22 -04:00
|
|
|
local channelCount = table.getn(ChatSaverDB);
|
|
|
|
ChatSaverDB[channelCount + 1] = name;
|
|
|
|
end
|
|
|
|
|
|
|
|
function core:LeaveChannel(msg)
|
|
|
|
local number = gsub(msg, "%s*([^%s]+).*", "%1");
|
|
|
|
local _,name = GetChannelName(number);
|
|
|
|
|
|
|
|
pos = 9;
|
|
|
|
for index,channel in pairs(ChatSaverDB) do
|
|
|
|
if(channel == name) then
|
|
|
|
pos = index;
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
table.remove(ChatSaverDB,pos);
|
|
|
|
end
|