示例#1
0
async def update_handlers_cache(chat_id):
    redis.delete(f'filters_cache_{chat_id}')
    filters = db.filters.find({'chat_id': chat_id})
    handlers = []
    async for filter in filters:
        handler = filter['handler']
        if handler in handlers:
            continue

        handlers.append(handler)
        redis.lpush(f'filters_cache_{chat_id}', handler)

    return handlers
示例#2
0
async def set_connected_chat(user_id, chat_id):
    key = f'connection_cache_{user_id}'
    redis.delete(key)
    if not chat_id:
        await db.connections.update_one({'user_id': user_id}, {"$unset": {'chat_id': 1, 'command': 1}}, upsert=True)
        await get_connection_data.reset_cache(user_id)
        return

    await db.connections.update_one(
        {'user_id': user_id},
        {
            "$set": {'user_id': user_id, 'chat_id': chat_id},
            "$unset": {'command': 1},
            "$addToSet": {'history': {'$each': [chat_id]}}
        },
        upsert=True
    )
    return await get_connection_data.reset_cache(user_id)
示例#3
0
async def connected_start_state(message, strings, chat):
    key = 'texas_connected_start_state:' + str(message.from_user.id)
    if redis.get(key):
        await message.reply(
            strings['pm_connected'].format(chat_name=chat['chat_title']))
        redis.delete(key)
示例#4
0
async def welcome_security_passed(message: Union[CallbackQuery, Message],
                                  state, strings):
    user_id = message.from_user.id
    async with state.proxy() as data:
        chat_id = data['chat_id']
        msg_id = data['msg_id']
        verify_msg_id = data['verify_msg_id']
        to_delete = data['to_delete']

    with suppress(ChatAdminRequired):
        await unmute_user(chat_id, user_id)

    with suppress(MessageToDeleteNotFound, MessageCantBeDeleted):
        if to_delete:
            await bot.delete_message(chat_id, msg_id)
        await bot.delete_message(user_id, verify_msg_id)
    await state.finish()

    with suppress(MessageToDeleteNotFound, MessageCantBeDeleted):
        message_id = redis.get(f"welcome_security_users:{user_id}:{chat_id}")
        # Delete the person's real security button if exists!
        if message_id:
            await bot.delete_message(chat_id, message_id)

    redis.delete(f"welcome_security_users:{user_id}:{chat_id}")

    with suppress(JobLookupError):
        scheduler.remove_job(f"wc_expire:{chat_id}:{user_id}")

    title = (await db.chat_list.find_one({'chat_id': chat_id}))['chat_title']

    if 'data' in message:
        await message.answer(strings['passed_no_frm'] % title, show_alert=True)
    else:
        await message.reply(strings['passed'] % title)

    db_item = await get_greetings_data(chat_id)

    if 'message' in message:
        message = message.message

    # Welcome
    if 'note' in db_item and not db_item.get("welcome_disabled", False):
        text, kwargs = await t_unparse_note_item(
            message.reply_to_message if message.reply_to_message is not None
            else message, db_item['note'], chat_id)
        await send_note(user_id, text, **kwargs)

    # Welcome mute
    if 'welcome_mute' in db_item and db_item['welcome_mute'][
            'enabled'] is not False:
        user = await bot.get_chat_member(chat_id, user_id)
        if 'can_send_messages' not in user or user['can_send_messages'] is True:
            await restrict_user(chat_id,
                                user_id,
                                until_date=convert_time(
                                    db_item['welcome_mute']['time']))

    chat = await db.chat_list.find_one({'chat_id': chat_id})

    buttons = None
    if chat_nick := chat['chat_nick'] if chat.get('chat_nick', None) else None:
        buttons = InlineKeyboardMarkup().add(
            InlineKeyboardButton(text=strings['click_here'],
                                 url=f"t.me/{chat_nick}"))
示例#5
0
    user_id = message.from_user.id
    note_name = cached['notename']

    note = await db.notes.find_one({
        'chat_id': chat_id,
        'names': {
            '$in': [note_name]
        }
    })
    await get_note(message,
                   db_item=note,
                   chat_id=chat_id,
                   send_id=user_id,
                   rpl_id=None)

    redis.delete(key)


@register(cmds='privatenotes', is_admin=True)
@chat_connection(admin=True)
@get_strings_dec('notes')
async def private_notes_cmd(message, chat, strings):
    chat_id = chat['chat_id']
    chat_name = chat['chat_title']
    text = str

    try:
        (text := ''.join(message.text.split()[1]).lower())
    except IndexError:
        pass