예제 #1
0
async def get_connected_chat(message,
                             admin=False,
                             only_groups=False,
                             from_id=None):
    # admin - Require admin rights in connected chat
    # only_in_groups - disable command when bot's pm not connected to any chat
    real_chat_id = message.chat.id
    user_id = from_id or message.from_user.id
    key = 'connection_cache_' + str(user_id)

    if not message.chat.type == 'private':
        chat_title = (await
                      db.chat_list.find_one({'chat_id':
                                             real_chat_id}))['chat_title']
        return {
            'status': 'chat',
            'chat_id': real_chat_id,
            'chat_title': chat_title
        }

    # Cached
    if cached := redis.hgetall(key):
        cached['status'] = True
        cached['chat_id'] = int(cached['chat_id'])
        return cached
예제 #2
0
파일: connections.py 프로젝트: pokurt/Mashu
async def get_connected_chat(message, admin=False, only_groups=False, from_id=None):

    # admin - Require admin rights in connected chat
    # only_in_groups - disable command when bot's pm not connected to any chat
    real_chat_id = message.chat.id
    user_id = from_id or message.from_user.id
    key = 'connection_cache_' + str(user_id)

    if not message.chat.type == 'private':
        _chat = await db.chat_list.find_one({'chat_id': real_chat_id})
        chat_title = _chat['chat_title'] if _chat is not None else message.chat.title
        # On some strange cases such as Database is fresh or new ; it doesn't contain chat data
        # Only to "handle" the error, we do the above workaround - getting chat title from the update
        return {'status': 'chat', 'chat_id': real_chat_id, 'chat_title': chat_title}

    # Cached
    if cached := redis.hgetall(key):
        cached['status'] = True
        cached['chat_id'] = int(cached['chat_id'])
예제 #3
0
async def btn_note_start_state(message, strings):
    key = 'btn_note_start_state:' + str(message.from_user.id)
    if not (cached := redis.hgetall(key)):
        return