Commit
ยท
3e96bbe
1
Parent(s):
d32bbaf
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,40 +3,45 @@ from telethon.sync import TelegramClient, events
|
|
| 3 |
import asyncio
|
| 4 |
import datetime
|
| 5 |
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 = [
|
| 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()
|