MohammedAlakhras commited on
Commit
3e96bbe
ยท
1 Parent(s): d32bbaf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -7
app.py CHANGED
@@ -3,40 +3,45 @@ from telethon.sync import TelegramClient, events
3
  import asyncio
4
  import datetime
5
 
6
- def handle_messages(api_id, api_hash, sender_name, chat_id, text):
 
 
 
 
7
  async def process_messages():
8
  async with TelegramClient('anon', api_id, api_hash) as client:
9
  @client.on(events.NewMessage())
10
  async def my_event_handler(event):
11
  sender = await event.get_sender()
12
  sender_id = sender.id
 
13
  chat = await event.get_chat()
14
  chat_id = chat.id
15
  text = event.raw_text
16
 
17
- # ู…ู‚ูŠุงุณ ุงู„ุฒู…ู†
18
  checkpoint = datetime.datetime.now()
19
  print(f'Checkpoint: {checkpoint}')
20
 
21
- # ุฑุณุงู„ุฉ ุดุฎุตูŠุฉ
22
  if chat_id == sender_id:
23
  response = f'ุงู‡ู„ุง {sender_name} , ู„ู‚ุฏ ุชู„ู‚ูŠุช ุฑุณุงู„ุชูƒ ุณุฃู‚ูˆู… ุจุงู„ุฑุฏ ุนู„ูŠูƒ ุจุฃู‚ุฑุจ ูˆู‚ุช ู…ู…ูƒู† ูˆุดูƒุฑุงู‹ ู„ุชูู‡ู…ูƒ.'
24
  await client.send_message(chat_id, response)
25
-
26
- # ุฑุณุงู„ุฉ ู…ุฌู…ูˆุนุฉ
27
  elif '@Mohammed_Alakhras' in text:
28
  response = f'ุงู‡ู„ุง {sender_name} , ู„ู‚ุฏ ุชู„ู‚ูŠุช ุฑุณุงู„ุชูƒ ุณุฃู‚ูˆู… ุจุงู„ุฑุฏ ุนู„ูŠูƒ ุจุฃู‚ุฑุจ ูˆู‚ุช ู…ู…ูƒู† ูˆุดูƒุฑุงู‹ ู„ุชูู‡ู…ูƒ.'
29
  await client.send_message(chat_id, response)
30
 
 
31
  await client.run_until_disconnected()
32
 
33
  asyncio.run(process_messages())
34
 
35
  # ุชุนุฑูŠู ุญู‚ูˆู„ ุงู„ู†ุต ููŠ Gradio
36
- phone_number = gr.inputs.Textbox(label="ุฑู‚ู… ุงู„ู‡ุงุชู", type="str")
37
 
38
  # ุชุนุฑูŠู ุงู„ูˆุงุฌู‡ุฉ
39
- inputs = [phone_number]
40
  output = "text"
41
 
42
  gr.Interface(fn=handle_messages, inputs=inputs, outputs=output).launch()
 
3
  import asyncio
4
  import datetime
5
 
6
+ api_id = '10086982'
7
+ api_hash = '3ed461889a88b31fcbc323d13e43cf7e'
8
+
9
+
10
+ def handle_messages():
11
  async def process_messages():
12
  async with TelegramClient('anon', api_id, api_hash) as client:
13
  @client.on(events.NewMessage())
14
  async def my_event_handler(event):
15
  sender = await event.get_sender()
16
  sender_id = sender.id
17
+ sender_name = sender.first_name
18
  chat = await event.get_chat()
19
  chat_id = chat.id
20
  text = event.raw_text
21
 
22
+ # ู…ู‚ูŠุงุณ ุงู„ุฒู…ู†
23
  checkpoint = datetime.datetime.now()
24
  print(f'Checkpoint: {checkpoint}')
25
 
26
+ # ุฑุณุงู„ุฉ ุดุฎุตูŠุฉ
27
  if chat_id == sender_id:
28
  response = f'ุงู‡ู„ุง {sender_name} , ู„ู‚ุฏ ุชู„ู‚ูŠุช ุฑุณุงู„ุชูƒ ุณุฃู‚ูˆู… ุจุงู„ุฑุฏ ุนู„ูŠูƒ ุจุฃู‚ุฑุจ ูˆู‚ุช ู…ู…ูƒู† ูˆุดูƒุฑุงู‹ ู„ุชูู‡ู…ูƒ.'
29
  await client.send_message(chat_id, response)
30
+
31
+ # ุฑุณุงู„ุฉ ู…ุฌู…ูˆุนุฉ
32
  elif '@Mohammed_Alakhras' in text:
33
  response = f'ุงู‡ู„ุง {sender_name} , ู„ู‚ุฏ ุชู„ู‚ูŠุช ุฑุณุงู„ุชูƒ ุณุฃู‚ูˆู… ุจุงู„ุฑุฏ ุนู„ูŠูƒ ุจุฃู‚ุฑุจ ูˆู‚ุช ู…ู…ูƒู† ูˆุดูƒุฑุงู‹ ู„ุชูู‡ู…ูƒ.'
34
  await client.send_message(chat_id, response)
35
 
36
+
37
  await client.run_until_disconnected()
38
 
39
  asyncio.run(process_messages())
40
 
41
  # ุชุนุฑูŠู ุญู‚ูˆู„ ุงู„ู†ุต ููŠ Gradio
 
42
 
43
  # ุชุนุฑูŠู ุงู„ูˆุงุฌู‡ุฉ
44
+ inputs = []
45
  output = "text"
46
 
47
  gr.Interface(fn=handle_messages, inputs=inputs, outputs=output).launch()