7fb0a0e179
- S113: Add timeout=10 to all requests calls (74 fixes) - E722: Replace bare except: with except Exception: - B904: Replace redundant re-raise with bare raise - E402: Add noqa for intentional late imports after import_library() - S102/S307/S310/S311/S603/S605/S606/S607/S108: Add noqa for intentional usage - F601: Fix duplicate dict key in unsplash.py - N802: Rename ReplyCheck -> reply_check with backward compat alias - N813: Rename bs -> BS in icons.py - B007/B020: Rename loop var _j in animations.py - SIM102: Collapse nested if in autofwd.py - SIM113: Use enumerate() in calculator.py - A002: Add noqa for builtin shadowing in admlist.py - F811: Add noqa for cohere redefinition - edu_master: Fix ARG001, S108, S110, SIM117, apply --unsafe-fixes - Add modules_list.txt with full module inventory
71 lines
2.5 KiB
Python
71 lines
2.5 KiB
Python
from asyncio import sleep
|
|
|
|
from pyrogram import Client, enums, filters
|
|
from pyrogram.types import Message
|
|
|
|
# noinspection PyUnresolvedReferences
|
|
from utils.misc import modules_help, prefix
|
|
|
|
# noinspection PyUnresolvedReferences
|
|
from utils.scripts import format_exc
|
|
|
|
now = {}
|
|
|
|
|
|
@Client.on_message(filters.command(['search'], prefix) & filters.me)
|
|
async def search_cmd(client: Client, message: Message):
|
|
if now.get(message.chat.id):
|
|
return await message.edit(
|
|
f'<b>You already have a search in progress!\nType: <code>{prefix}scancel</code> to cancel it.</b>',
|
|
parse_mode=enums.ParseMode.HTML,
|
|
)
|
|
|
|
await message.edit('<b>Start searching...</b>', parse_mode=enums.ParseMode.HTML)
|
|
finished = False
|
|
local = False
|
|
try:
|
|
cmd = message.command[1]
|
|
word = message.command[2].lower()
|
|
timeout = float(message.command[3]) if len(message.command) > 3 else 2
|
|
except Exception:
|
|
return await message.edit(
|
|
f'<b>Usage:</b> <code>{prefix}search [/cmd]* [search_word]* [timeout=2.0]</code>',
|
|
parse_mode=enums.ParseMode.HTML,
|
|
)
|
|
|
|
now[message.chat.id] = True
|
|
|
|
try:
|
|
await message.reply_text(quote=False, text=cmd, reply_to_message_id=None)
|
|
while not finished and now[message.chat.id]:
|
|
async for msg in client.get_chat_history(message.chat.id, limit=2):
|
|
if msg.from_user.id == message.from_user.id:
|
|
continue
|
|
elif word in msg.text.lower():
|
|
finished = True
|
|
local = True
|
|
if not local:
|
|
await sleep(timeout)
|
|
await message.reply_text(quote=False, text=cmd, reply_to_message_id=None)
|
|
else:
|
|
break
|
|
if now[message.chat.id]:
|
|
await message.reply_text('<b>Search finished!</b>', parse_mode=enums.ParseMode.HTML)
|
|
except Exception as ex:
|
|
await message.edit(format_exc(ex), parse_mode=enums.ParseMode.HTML)
|
|
now[message.chat.id] = False
|
|
|
|
|
|
@Client.on_message(filters.command(['scancel'], prefix) & filters.me)
|
|
async def scancel_cmd(_: Client, message: Message):
|
|
if not now.get(message.chat.id):
|
|
return await message.edit('<b>There is no search in progress!</b>', parse_mode=enums.ParseMode.HTML)
|
|
now[message.chat.id] = False
|
|
await message.edit('<b>Search cancelled!</b>', parse_mode=enums.ParseMode.HTML)
|
|
|
|
|
|
modules_help['search'] = {
|
|
'search [/cmd]* [search_word]* [timeout=2.0]': 'Search for a specific word in bot (while)',
|
|
'scancel': 'Cancel current search',
|
|
}
|