Spaces:
Running
Running
File size: 4,701 Bytes
d32bbaf fb5dadd 73c328a a03f7d7 5abede8 a03f7d7 5abede8 a03f7d7 73c328a d32bbaf fb5dadd 3e96bbe fb5dadd 3e96bbe 73c328a 4a4cb82 73c328a 7945680 a03f7d7 d32bbaf fb5dadd d32bbaf 14d5911 7945680 14d5911 d32bbaf 10fb16c 22f6372 10fb16c f1c32f6 df4f66c 84d8632 af2a77a f1c32f6 d32bbaf 10fb16c 73c328a f1c32f6 82701a5 84d8632 3b26f29 f1c32f6 10fb16c 14d5911 d32bbaf 14d5911 82701a5 f1c4e52 10fb16c 2f9fabc |
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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
import gradio as gr
from telethon.sync import TelegramClient, events
import datetime
import socks
import time
import os
import requests
import random
def download_file(url, filename):
response = requests.get(url)
with open(filename, 'wb') as file:
file.write(response.content)
RndMssgs = [
"I've received your message. I'll get back to you as soon as possible.",
"I appreciate your patience and understanding.",
"Your message has been received. I'll respond shortly.",
"I'm currently unavailable, but I'll reply as soon as I can.",
"Your message has been received and it's important to us.",
"I'm away at the moment. Rest assured, I'll respond to your message soon.",
"Your message is received. Thank you for your understanding.",
"I've received your message and will respond at my earliest convenience.",
"I've received your message. I'll make sure to reply as soon as possible.",
"I'm currently out offline, but I'll get back to you shortly.",
"I've received your message. I'll get back to you soon.",
"I'm not available right now, but I've received your message.",
"Thank you for contacting me. I'll respond as soon as I can.",
"I'm currently busy, but I'll make sure to reply to your message as soon as possible.",
"Your message has been received. I'll get back to you shortly.",
"Thank you for your patience. I'll respond as soon as I can.",
"I've received your message and will get back to you shortly.",
"Your message has been received. Thank you for waiting.",
"I'm currently on a break, but I've received your message and will respond soon."
]
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=os.environ['apiID']
api_hash=os.environ['apiHash']
phone=os.environ['phone']
username=os.environ['username']
serssionFile=os.environ['sessionUrlFile']
download_file(serssionFile, 'anon.session')
# 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
# Personal message
if chat_id == sender_id and not sender.bot:
# 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*60*6: # reply only if not replied in the last minute
response = f'Hello <a href="tg://user?id={sender_id}">{sender_name}</a> ๐๐ป ,\n {random.choice(RndMssgs)} ๐'
#response = f'ุฃููุง <a href="tg://user?id={sender_id}">{sender_name}</a> ๐๐ป ,\nุงูุญุณุงุจ ู
ุบูู ุญุงููุงู. \n ุงูุฑุณุงุฆู ุงููุงู
ุฉ ุนุจุฑ <a href="https://www.facebook.com/MohammedAlakras/">Messenger</a> \n \n ุดูุฑุงู ูุชููู
ู '
await client.send_message(chat_id, response, parse_mode='HTML',link_preview=False)
reply_times[str(sender_id)] = time.time() # update the last reply time
# Group message
elif username 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*5:
response = f'Hello <a href="tg://user?id={sender_id}">{sender_name}</a> @ <a href="https://t.me/c/{chat_id}">{chat.title}</a> ๐๐ป,\n {random.choice(RndMssgs)} ๐'
#response = f'ุฃููุง <a href="tg://user?id={sender_id}">{sender_name}</a> ๐๐ป ,\nุงูุญุณุงุจ ู
ุบูู ุญุงููุงู. \n ุงูุฑุณุงุฆู ุงููุงู
ุฉ ุนุจุฑ <a href="https://www.facebook.com/MohammedAlakras/">Messenger</a> \n \n ุดูุฑุงู ูุชููู
ู '
await client.send_message(chat_id, response, parse_mode='HTML',link_preview=False)
reply_times[str(str(chat_id)+str(sender_id))] = time.time()
await client.run_until_disconnected()
# Gradio Inteface
inputs = []
output = "text"
gr.Interface(fn=main, inputs=inputs, outputs=output).launch()
# client.loop.run_until_complete(main()) |