-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
50 lines (37 loc) · 1.34 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import logging
import asyncio
import timeit
from pyrogram import Client, filters
from utils import load_messages
from dotenv import load_dotenv
from utils import list_builder
load_dotenv()
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
level=logging.INFO)
logger = logging.getLogger(__name__)
api_id = os.getenv("API_ID")
api_hash = os.getenv("API_HASH")
bot_token = os.getenv("BOT_TOKEN")
app = Client("user", api_id=api_id, api_hash=api_hash, bot_token=bot_token)
messages = load_messages()
@app.on_message(filters.command(["start", "help"]))
def start(client, message):
message.reply('Hello, send me a query to search in @rememberbox!')
@app.on_message(filters.text)
def echo(client, message):
indices = set()
text = message.text
try:
start_time = timeit.default_timer()
indices = {messages[i]['id'] for i in range(len(messages)) if text in str(messages[i]['text'])}
string = list_builder(list(indices))
time_elapsed = (timeit.default_timer() - start_time) * 1000
text = f"💡 Remember Box\n{string}\n{len(indices)} results in {time_elapsed:.2f} ms"
message.reply(text)
except Exception as e:
message.reply("Query not found.")
logger.info("Ready to rock..!")
app.run()