package com.jukebot.jukebot.message

import com.jukebot.jukebot.Constant
import com.jukebot.jukebot.pojo.Command
import com.jukebot.jukebot.storage.VolatileStorage
import com.jukebot.jukebot.util.Util
import com.pengrad.telegrambot.model.Message
import com.pengrad.telegrambot.model.MessageEntity
import com.pengrad.telegrambot.model.Update

/**
 * Created by Ting.
 */

class AuthFilter : UpdateHandler() {
    override fun responsible(update: Update): Any? {
        var pass: Boolean = false

        val verifiedChatId: Long? = VolatileStorage.get(Constant.KEY_VERIFIED_CHAT_ID) as Long?
        if (update.message()?.chat()?.id() == verifiedChatId)
            pass = true

        // if is verify command
        if (update.message()?.entities()?.get(0)?.type() == MessageEntity.Type.bot_command) {
            val cmd: Command = Util.parseCmd(update.message().text())

            if (cmd.cmd != null && cmd.cmd.equals("/bind"))
                pass = true
        }

        return pass
    }

    override fun handle(pair: Pair<Message, Any>) {
        // do nothing...
    }
}

