File size: 2,614 Bytes
d32bbaf
 
 
fb5dadd
 
d32bbaf
fb5dadd
 
 
 
3e96bbe
fb5dadd
 
 
 
 
 
 
 
3e96bbe
fb5dadd
 
 
d32bbaf
fb5dadd
 
d32bbaf
14d5911
 
 
 
 
 
 
 
 
 
d32bbaf
10fb16c
14d5911
 
3e96bbe
10fb16c
14d5911
10fb16c
f1c32f6
14d5911
 
 
f1c32f6
d32bbaf
10fb16c
14d5911
f1c32f6
14d5911
 
 
f1c32f6
10fb16c
14d5911
 
 
d32bbaf
 
14d5911
d32bbaf
f1c4e52
 
 
10fb16c
 
14d5911
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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
61
62
63
64
65
66
67
68
69
70
71
72
import gradio as gr
from telethon.sync import TelegramClient, events
import datetime
import socks
import time

proxy_server = '142.93.68.63'
proxy_port = 2434
proxy_secret = 'ee32b920dffb51643028e2f6b878d4eac1666172616b61762e636f6d'
proxy_dc_id = 2  # This is usually 2 for MTProto proxies

proxy = (
    socks.SOCKS5,
    proxy_server,
    proxy_port,
    True,
    'vpn',
    'unlimited'
)

api_id = '10086982'
api_hash = '3ed461889a88b31fcbc323d13e43cf7e'
phone = '+963994935356'

# Dictionary to track the times when senders were last replied to
reply_times = {}

async def main():
    async with TelegramClient('anon', api_id, api_hash) as client:
        @client.on(events.NewMessage())
        async def my_event_handler(event):
            sender = await event.get_sender()
            sender_id = sender.id
            sender_name = sender.first_name
            chat = await event.get_chat()
            chat_id = chat.id
            text = event.raw_text

            # Timekeeping
            checkpoint = datetime.datetime.now()
            print(f'Checkpoint: {checkpoint}')

            # Personal message
            if chat_id == sender_id:
                # Check the last reply to this sender
                last_reply_time = reply_times.get(str(sender_id), None)
                if last_reply_time is None or time.time() - last_reply_time > 60:  # reply only if not replied in the last minute
                    response = f'Hello {sender_name}, I received your message and will reply as soon as possible. Thank you for your understanding.'
                    await client.send_message(chat_id, response)
                    reply_times[str(sender_id)] = time.time()  # update the last reply time

            # Group message
            elif '@Mohammed_Alakhras' in text:
                last_reply_time = reply_times.get(str(str(chat_id)+str(sender_id)), None)
                if last_reply_time is None or time.time() - last_reply_time > 60:
                    response = f'Hello {sender_name}, I received your message and will reply as soon as possible. Thank you for your understanding.'
                    await client.send_message(chat_id, response)
                    reply_times[str(str(chat_id)+str(sender_id))] = time.time()

   
        await client.run_until_disconnected()
     #   client.loop.run_until_complete(main())

# تعريف حقول النص في Gradio

# تعريف الواجهة
inputs = []
output = "text"
gr.Interface(fn=main, inputs=inputs, outputs=output).launch()

# Run the main function in the event loop
    #    client.loop.run_until_complete(main())