from bot.commands import BaseCommand

import mongo


class DisconnectCommand(BaseCommand):

    _COMMAND = 'disconnect'
    _DESCRIPTION = 'Close currently active chat.'
    _SUCCESS_MESSAGE = 'Disconnected from chat'

    def _callback(self, user, _bot, update, **kwargs):
        return self._call(user, _bot, update, **kwargs)

    def _call(self, user, _bot, update, **kwargs):
        chat = mongo.chats.get_active_chat_by_telegram_id(user.id)
        if chat:
            mongo.chats.disable_chat(chat['_id'])
            return True

        _bot.send_message(
            user.id,
            'You are not connected to any vk user',
        )
        return False

[((16, 15, 16, 66), 'mongo.chats.get_active_chat_by_telegram_id', 'mongo.chats.get_active_chat_by_telegram_id', ({(16, 58, 16, 65): 'user.id'}, {}), '(user.id)', False, 'import mongo\n'), ((18, 12, 18, 49), 'mongo.chats.disable_chat', 'mongo.chats.disable_chat', ({(18, 37, 18, 48): "chat['_id']"}, {}), "(chat['_id'])", False, 'import mongo\n')]