Spaces:
Running
Running
Commit
·
f1c4e52
1
Parent(s):
7d0b23a
Update app.py
Browse files
app.py
CHANGED
@@ -9,6 +9,7 @@ proxy_port = 2434
|
|
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,48 +26,47 @@ phone = '+963994935356'
|
|
25 |
# Dictionary to track the times when senders were last replied to
|
26 |
reply_times = {}
|
27 |
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
|
39 |
# Timekeeping
|
40 |
-
|
41 |
-
|
42 |
|
43 |
# Personal message
|
44 |
-
|
45 |
# Check the last reply to this sender
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
|
52 |
# Group message
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
|
60 |
-
|
61 |
-
output = "text"
|
62 |
-
gr.Interface(fn=main, inputs=inputs, outputs=output).launch()
|
63 |
-
await client.run_until_disconnected()
|
64 |
-
# client.loop.run_until_complete(main())
|
65 |
|
66 |
# تعريف حقول النص في Gradio
|
67 |
-
|
|
|
68 |
# تعريف الواجهة
|
69 |
-
|
|
|
|
|
70 |
|
71 |
# Run the main function in the event loop
|
72 |
-
#
|
|
|
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 |
# 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, 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 |
+
def main():
|
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())
|