assert( oRA, "oRA not found!")

------------------------------
--      Are you local?      --
------------------------------

local L = AceLibrary("AceLocale-2.0"):new("oRAPRaidWarn")

local blockregexs = {
        "%*+ .+ %*+$",
}

----------------------------
--      Localization      --
----------------------------

L:RegisterTranslations("enUS", function() return {
	["rw"] = true,
	["raidwarning"] = true,
	["Raidwarning"] = true,
	["Options for raid warning."] = true,
	["Participant/RaidWarn"] = true,
	["Bossblock"] = true,
	["Block messages from Bossmods."] = true,
} end )

----------------------------------
--      Module Declaration      --
----------------------------------

oRAPRaidWarn = oRA:NewModule(L["raidwarning"])
oRAPRaidWarn.defaults = {
	bossblock = true,
}
oRAPRaidWarn.participant = true
oRAPRaidWarn.name = L["Participant/RaidWarn"]

oRAPRaidWarn.consoleCmd = L"rw"
oRAPRaidWarn.consoleOptions = {
	type = "group",
	desc = L["Options for raid warning."],
	name = L["Raidwarning"],
	args = {
		[L["Bossblock"]] = {
			name = L["Bossblock"], type = "toggle",
			desc = L["Block messages from Bossmods."],
			get = function() return oRAPRaidWarn.db.profile.bossblock end,
			set = function(v)
				oRAPRaidWarn.db.profile.bossblock = v
			end,
		},
	}
}


------------------------------
--      Initialization      --
------------------------------

function oRAPRaidWarn:OnInitialize()
	self.debugFrame = ChatFrame5
end

function oRAPRaidWarn:OnEnable()
	self.core:RegisterCheck("MS", "oRA_RaidWarnMessage")

	self:RegisterEvent("oRA_RaidWarnMessage")
end

function oRAPRaidWarn:OnDisable()

	self:UnregisterAllEvents()

	self:UnregisterCheck("MS")
end


-------------------------------
--      Event Handlers       --
-------------------------------

function oRAPRaidWarn:oRA_RaidWarnMessage(msg, author)
	if not self.core:IsValidRequest(author) then return end
	msg = self.core:CleanMessage(msg)

	if not msg then return end

	_,_, msg = string.find(msg, "^MS (.+)$")
	
	if not msg then return end

	if self:IsSpam(msg) then return end

	local info = ChatTypeInfo["RAID_WARNING"]

	PlaySound("RaidWarning")

	RaidWarningFrame:AddMessage( author .. ": " .. msg, info.r, info.g, info.b, 1.0, UIERRORS_HOLD_TIME)
end

function oRAPRaidWarn:IsSpam(text)
	if not text then return end
	for _,regex in pairs(blockregexs) do if string.find(text, regex) then return true end end
end
