---------------------------------------------------------------------------------
--
-- Prat - A framework for World of Warcraft chat mods
--
-- Copyright (C) 2006-2007  Prat Development Team
--
-- This program is free software; you can redistribute it and/or
-- modify it under the terms of the GNU General Public License
-- as published by the Free Software Foundation; either version 2
-- of the License, or (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program; if not, write to:
--
-- Free Software Foundation, Inc., 
-- 51 Franklin Street, Fifth Floor, 
-- Boston, MA  02110-1301, USA.
--
--
-------------------------------------------------------------------------------



--[[
Name: PratFiltering
Revision: $Revision: 30740 $
Author(s): Sylvanaar
Website: http://www.wowace.com/files/index.php?path=Prat/
Documentation: http://www.wowace.com/wiki/Prat/Integrated_Modules#Filtering
Subversion: http://svn.wowace.com/wowace/trunk/Prat/
Discussions: http://groups.google.com/group/wow-prat
Issues and feature requests: http://code.google.com/p/prat/issues/list
Description: A module to provide basic chat filtering. (default=off).
Dependencies: Prat
]]

-- set prat module name
local PRAT_MODULE = Prat:RequestModuleName("PratFiltering")

-- define localized strings
local L = AceLibrary("AceLocale-2.2"):new(PRAT_MODULE)

L:RegisterTranslations("enUS", function() return {
	["Filtering"] = true,
	["A module to provide basic chat filtering."] = true,
    ["leavejoin_name"] = "Filter Channel Leave/Join",
    ["leavejoin_desc"] = "Filter out channel leave/join spam",
    ["notices_name"] = "Filter Channel Notices",
    ["notices_desc"] = "Filter out other custom channel notification messages, e.g. moderator changes.",
} end)

L:RegisterTranslations("koKR", function() return {
	["Filtering"] = "필터링",
	["A module to provide basic chat filtering."] = "기본 대화 필터링을 제공하는 모듈입니다.",
	["leavejoin_name"] = "채널 참가/떠남 필터",
	["leavejoin_desc"] = "채널 참가/떠남 스팸을 제거합니다.",
	["notices_name"] = "채널 알림 필터링",
	["notices_desc"] = "다른 사용자 지정 채널 알림 메세지를 필터링합니다, 예. moderator changes.",
} end)

L:RegisterTranslations("deDE", function() return {
	["Filtering"] = "Filterrung",
	["A module to provide basic chat filtering."] = "Ein Modul das einen grundlegenden Chatfilter bietet.",
    ["leavejoin_name"] = "Filtere Kanal Verlassen/Betreten",
    ["leavejoin_desc"] = "Rausfiltern von Kanal verlassen/betreten Spam.",
} end)

L:RegisterTranslations("zhTW", function() return {
    ["Filtering"] = "訊息過濾",
    ["A module to provide basic chat filtering."] = "提供基本過濾功能的模組",
    ["leavejoin_name"] = "過濾 離開/加入",
    ["leavejoin_desc"] = "過濾 離開/加入 的頻道訊息",
    ["notices_name"] = "過濾頻道通知",
    ["notices_desc"] = "過濾其他頻道通知訊息，例如頻道主席變更。",
} end)


-- get prat module categories
local cat = Prat.Categories

-- create prat module
Prat_Filtering = Prat:NewModule(PRAT_MODULE)
Prat_Filtering.revision = tonumber(string.sub("$Revision: 30740 $", 12, -3))

-- define key module values
Prat_Filtering.moduleName = L["Filtering"] 	
Prat_Filtering.moduleDesc = L["A module to provide basic chat filtering."] 	

Prat_Filtering.consoleName = string.lower(Prat_Filtering.moduleName)
Prat_Filtering.guiName = Prat_Filtering.moduleName

Prat_Filtering.Categories	= { cat.FILTER }	
				-- list here: http://groups-beta.google.com/group/wow-prat/web/prat-categories

-- init moduleOoptions (which gets populated by the other
-- various options tables below
Prat_Filtering.moduleOptions = {}

-- default values for any settings that need them
Prat_Filtering.defaultDB = {
	on	= false,
    leavejoin = true,
    notices = true,
}

-- any boolean options
Prat_Filtering.toggleOptions = {
    leavejoin = 100,
    notices = 110,
}



--ERR_BG_PLAYER_JOINED_SS = "|Hplayer:%s|h[%s]|h has joined the battle";
--ERR_BG_PLAYER_LEFT_S = "%s has left the battle"-;


--[[------------------------------------------------
    Module Event Functions
------------------------------------------------]]--

-- things to do when the module is enabled
function Prat_Filtering:OnModuleEnable()
	-- register events
	self:RegisterEvent("Prat_FrameMessage")
end

-- things to do when the module is disabled
function Prat_Filtering:OnModuleDisable()
	-- unregister events
	self:UnregisterAllEvents()
end

--[[------------------------------------------------
    Core Functions
------------------------------------------------]]--

--
-- Prat Event Implementation
--

function Prat_Filtering:Prat_FrameMessage(message, frame)
    if self.db.profile.leavejoin then 
    	if  event == "CHAT_MSG_CHANNEL_JOIN" or event == "CHAT_MSG_CHANNEL_LEAVE"  then
    		message.DONOTPROCESS = true
    	end
    end
    
        	
    if self.db.profile.notices then 
    	if  event == "CHAT_MSG_CHANNEL_NOTICE_USER" or event == "CHAT_MSG_CHANNEL_NOTICE"  then
    		message.DONOTPROCESS = true
    	end
    end
end