| import gradio as gr |
| from telethon.sync import TelegramClient, events |
| import datetime |
| import socks |
| import time |
|
|
| proxy_server = '142.93.68.63' |
| proxy_port = 2434 |
| proxy_secret = 'ee32b920dffb51643028e2f6b878d4eac1666172616b61762e636f6d' |
| proxy_dc_id = 2 |
|
|
| |
| proxy = ( |
| socks.SOCKS5, |
| proxy_server, |
| proxy_port, |
| True, |
| 'vpn', |
| 'unlimited' |
| ) |
|
|
| api_id = '10086982' |
| api_hash = '3ed461889a88b31fcbc323d13e43cf7e' |
| phone = '+963994935356' |
|
|
| |
| reply_times = {} |
|
|
|
|
| async with TelegramClient('anon', api_id, api_hash, proxy=proxy) as client: |
| @client.on(events.NewMessage()) |
| async def my_event_handler(event): |
| sender = await event.get_sender() |
| sender_id = sender.id |
| sender_name = sender.first_name |
| chat = await event.get_chat() |
| chat_id = chat.id |
| text = event.raw_text |
|
|
| |
| checkpoint = datetime.datetime.now() |
| print(f'Checkpoint: {checkpoint}') |
|
|
| |
| if chat_id == sender_id: |
| |
| last_reply_time = reply_times.get(sender_id, None) |
| if last_reply_time is None or time.time() - last_reply_time > 60*15: |
| response = f'Hello {sender_name}, I received your message and will reply as soon as possible. Thank you for your understanding.' |
| await client.send_message(chat_id, response) |
| reply_times[sender_id] = time.time() |
|
|
| |
| elif '@Mohammed_Alakhras' in text: |
| last_reply_time = reply_times.get(sender_id, None) |
| if last_reply_time is None or time.time() - last_reply_time > 60: |
| response = f'Hello {sender_name}, I received your message and will reply as soon as possible. Thank you for your understanding.' |
| await client.send_message(chat_id, response) |
| reply_times[sender_id] = time.time() |
|
|
| await client.run_until_disconnected() |
|
|
| |
| def main(): |
| pass |
| |
| inputs = [] |
| output = "text" |
| gr.Interface(fn=main, inputs=inputs, outputs=output).launch() |
|
|
| |
| |