MohammedAlakhras commited on
Commit
10fb16c
·
1 Parent(s): fb5dadd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -29
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 with TelegramClient('anon', api_id, api_hash, proxy=proxy) 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*15: # 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
- 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())