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