Commit
·
14d5911
1
Parent(s):
f1c4e52
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,7 +9,6 @@ proxy_port = 2434
|
|
| 9 |
proxy_secret = 'ee32b920dffb51643028e2f6b878d4eac1666172616b61762e636f6d'
|
| 10 |
proxy_dc_id = 2 # This is usually 2 for MTProto proxies
|
| 11 |
|
| 12 |
-
#('hostname', port, 'secret')
|
| 13 |
proxy = (
|
| 14 |
socks.SOCKS5,
|
| 15 |
proxy_server,
|
|
@@ -26,47 +25,48 @@ phone = '+963994935356'
|
|
| 26 |
# Dictionary to track the times when senders were last replied to
|
| 27 |
reply_times = {}
|
| 28 |
|
| 29 |
-
|
| 30 |
-
async with TelegramClient('anon', api_id, api_hash
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
|
| 40 |
# Timekeeping
|
| 41 |
-
|
| 42 |
-
|
| 43 |
|
| 44 |
# Personal message
|
| 45 |
-
|
| 46 |
# Check the last reply to this sender
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
|
| 53 |
# Group message
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
|
| 61 |
-
|
|
|
|
|
|
|
| 62 |
|
| 63 |
# تعريف حقول النص في Gradio
|
| 64 |
-
|
| 65 |
-
pass
|
| 66 |
# تعريف الواجهة
|
| 67 |
inputs = []
|
| 68 |
output = "text"
|
| 69 |
gr.Interface(fn=main, inputs=inputs, outputs=output).launch()
|
| 70 |
|
| 71 |
# Run the main function in the event loop
|
| 72 |
-
#client.loop.run_until_complete(main())
|
|
|
|
| 9 |
proxy_secret = 'ee32b920dffb51643028e2f6b878d4eac1666172616b61762e636f6d'
|
| 10 |
proxy_dc_id = 2 # This is usually 2 for MTProto proxies
|
| 11 |
|
|
|
|
| 12 |
proxy = (
|
| 13 |
socks.SOCKS5,
|
| 14 |
proxy_server,
|
|
|
|
| 25 |
# Dictionary to track the times when senders were last replied to
|
| 26 |
reply_times = {}
|
| 27 |
|
| 28 |
+
async def main():
|
| 29 |
+
async with TelegramClient('anon', api_id, api_hash) as client:
|
| 30 |
+
@client.on(events.NewMessage())
|
| 31 |
+
async def my_event_handler(event):
|
| 32 |
+
sender = await event.get_sender()
|
| 33 |
+
sender_id = sender.id
|
| 34 |
+
sender_name = sender.first_name
|
| 35 |
+
chat = await event.get_chat()
|
| 36 |
+
chat_id = chat.id
|
| 37 |
+
text = event.raw_text
|
| 38 |
|
| 39 |
# Timekeeping
|
| 40 |
+
checkpoint = datetime.datetime.now()
|
| 41 |
+
print(f'Checkpoint: {checkpoint}')
|
| 42 |
|
| 43 |
# Personal message
|
| 44 |
+
if chat_id == sender_id:
|
| 45 |
# Check the last reply to this sender
|
| 46 |
+
last_reply_time = reply_times.get(sender_id, None)
|
| 47 |
+
if last_reply_time is None or time.time() - last_reply_time > 60: # reply only if not replied in the last minute
|
| 48 |
+
response = f'Hello {sender_name}, I received your message and will reply as soon as possible. Thank you for your understanding.'
|
| 49 |
+
await client.send_message(chat_id, response)
|
| 50 |
+
reply_times[sender_id] = time.time() # update the last reply time
|
| 51 |
|
| 52 |
# Group message
|
| 53 |
+
elif '@Mohammed_Alakhras' in text:
|
| 54 |
+
last_reply_time = reply_times.get(sender_id, None)
|
| 55 |
+
if last_reply_time is None or time.time() - last_reply_time > 60:
|
| 56 |
+
response = f'Hello {sender_name}, I received your message and will reply as soon as possible. Thank you for your understanding.'
|
| 57 |
+
await client.send_message(chat_id, response)
|
| 58 |
+
reply_times[sender_id] = time.time()
|
| 59 |
|
| 60 |
+
|
| 61 |
+
await client.run_until_disconnected()
|
| 62 |
+
# client.loop.run_until_complete(main())
|
| 63 |
|
| 64 |
# تعريف حقول النص في Gradio
|
| 65 |
+
|
|
|
|
| 66 |
# تعريف الواجهة
|
| 67 |
inputs = []
|
| 68 |
output = "text"
|
| 69 |
gr.Interface(fn=main, inputs=inputs, outputs=output).launch()
|
| 70 |
|
| 71 |
# Run the main function in the event loop
|
| 72 |
+
# client.loop.run_until_complete(main())
|