local Util = require("common.Util")
local ChatHandler = require("chat.Handler")
local Broadcast = require("broadcast.Broadcast")
local ChatLogic = require("chat.ChatLogic")
local Lang = require("common.Lang")

ectypeLink = nil
redBagLink = nil

-- 招募
function chatUnion(human, msgType, msg)
    if msgType ~= ChatHandler.CHAT_TYPE_UNION then
       return
    end

    if human.db.banSayTime and (os.time() < human.db.banSayTime or human.db.banSayTime == -1) then
        local leftMin = math.ceil((human.db.banSayTime - os.time())/60)
        local content = Util.format(human.db.banSayReason,leftMin)
        Broadcast.sendErr(human, content)	
        return 1
    end

    local content = {}
    content.msgType = ChatHandler.CHAT_TYPE_WORLD
    content.msg = msg
    return ChatLogic.chat(human, content, ChatHandler.CHAT_UNION_ZHAOMU)
end

-- 公会副本
function chatUnionEctype(human, str)
    if human.db.banSayTime and (os.time() < human.db.banSayTime or human.db.banSayTime == -1) then
        local leftMin = math.ceil((human.db.banSayTime - os.time())/60)
        local content = Util.format(human.db.banSayReason,leftMin)
        Broadcast.sendErr(human, content)	
        return 1
    end

    local content = {}
    content.msgType = ChatHandler.CHAT_TYPE_UNION
    content.msg = str

    ChatLogic.chat(human, content, ChatHandler.CHAT_UNION_ECTYPE)

    return 
end

-- 公会红包
function chatUnionRedBag(human)
    local content = {}
    local str = Util.format(Lang.UNION_RED_BAG_SEND_TXT,human.db.name)
    content.msgType = ChatHandler.CHAT_TYPE_UNION
    content.msg = str

    return ChatLogic.chat(human, content, ChatHandler.CHAT_UNION_RED_BAG)
end

-- 异界之战集结
function chatUnionGather(human, str)
    local content = {}
    content.msgType = ChatHandler.CHAT_TYPE_UNION
    content.msg = str

    return ChatLogic.chat(human, content, ChatHandler.CHAT_UNION_AB_HATHER)
end