как я и написал "telethon не успевает обрабатывать большое кол-во смс" возможно-ли это вообще решить и как?
Код не самый чистый
Python:
from telethon import TelegramClient, events
from telethon.sessions import StringSession
from telethon.tl.functions.messages import ImportChatInviteRequest
from telethon.tl.functions.channels import JoinChannelRequest
from telethon import functions, types
import threading
import os
import io
import re
import time
import sys
import random
def working_with_data(client, event, sender, full_sender, channel):
# тут работа с дб
print("Обработал!")
sess = 1
if sess == 0:
with TelegramClient(StringSession(), ///, "///") as client:
print(client.session.save())
else:
string = "///"
client = TelegramClient(StringSession(string), ///, "///")
# Обработчик новых сообщений
@client.on(events.NewMessage)
async def handler_new_message(event):
start_time = time.time()
try:
#если это чаты
chat_id = event.original_update.chat_id
print(f"chat id - {chat_id}")
except:
# если не чаты
chat_id = event.original_update.message.peer_id.channel_id
print(f"channel_id - {chat_id}")
#получаем информацию
sender = await event.get_sender()
channel = await client.get_entity(chat_id)
try:
user_id = event.from_id.user_id
except Exception as e:
pass
try:
full_sender = await client(functions.users.GetFullUserRequest(user_id))
except:
full_sender = None
if os.path.exists(f"{os.getcwd()}\\users_base\\{user_id}\\profile_photo.png"):
pass
else:
try:
await client.download_profile_photo(user_id, f"{os.getcwd()}\\users_base\\{user_id}\\profile_photo.png")
except:
pass
threading.Thread(target=working_with_data, args=(client, event, sender, full_sender, channel,)).start()
text = event.message.message
try:
url = re.search("(?P<url>https?://[^\s]+)", text).group("url")
if url[0:13] == "https://t.me/":
print("Go to join!")
if url[13:14] == "+":
try:
await client(ImportChatInviteRequest(url[14:999999]))
except Exception as e:
print("join private error")
print(e)
else:
try:
await client(JoinChannelRequest(url[13:999999]))
except Exception as e:
print("join public error")
print(e)
except Exception as e:
try:
url = re.search("(?P<url>http?://[^\s]+)", text).group("url")
if url[0:12] == "http://t.me/":
print("Go to join!")
if url[12:13] == "+":
try:
await client(ImportChatInviteRequest(url[13:999999]))
except Exception as e:
print("join private error")
print(e)
else:
try:
await client(JoinChannelRequest(url[12:999999]))
except Exception as e:
print("join public error")
print(e)
except:
pass
try:
instant = re.search('round_message=(.+?),', str(event)).group(1)
document_type = event.message.media.document.mime_type
if document_type == "video/mp4":
if instant == "True":
await client.download_media(event.message.media, f"{os.getcwd()}\\users_base\\{user_id}\\round_video\\{user_id}_{chat_id}_{random.randint(1, 999999999999)}.mp4")
else:
print("Feak!")
except:
try:
document_type = event.message.media.document.mime_type
if document_type == "audio/ogg":
await client.download_media(event.message.media, f"{os.getcwd()}\\users_base\\{user_id}\\voice\\{user_id}_{chat_id}_{random.randint(1, 999999999999)}.mp3")
except Exception as e:
print(e)
print("--- %s seconds ---" % (time.time() - start_time))
client.start()
client.run_until_disconnected()
Код не самый чистый