MohammedAlakhras commited on
Commit
f1c4e52
·
1 Parent(s): 7d0b23a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -32
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
- 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
- inputs = []
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
- # client.loop.run_until_complete(main())
 
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())