async def welcome_security_passed(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 db.greetings.find_one({'chat_id': chat_id}) if 'message' in message: message = message.message # Welcome if 'note' in db_item: 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']))
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
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) return return await db.connections.update_one({'user_id': user_id}, { "$set": { 'user_id': user_id, 'chat_id': chat_id }, "$addToSet": { 'history': { '$each': [chat_id] } } }, upsert=True)
@register(cmds='start', only_pm=True) @get_strings_dec('connections') 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 chat_id = int(cached['chat_id']) 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
async def connected_start_state(message, strings, chat): key = 'sophie_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)