Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @bot.on.chat_message(lower=True, text=["g", "d", "gen", "г", "/ген", "dem", "/g", "ген", "/gen", "д", "дем"])
- async def gen(message: Message):
- text_length = len(message.text)
- chat_path = f"{dir_to_txt}{message.peer_id}.txt"
- picture_path = f"{dir_to_pic}{message.peer_id}.txt"
- with open(picture_path, encoding="utf8") as f:
- pic_count = len(f.readlines())
- with open(chat_path, encoding="utf8") as f:
- text_lines = len(f.readlines())
- if text_lines >= 10 and pic_count >= 1:
- print("ГЕНЕРИРУЕМ ПО КОМАНДЕ")
- with open(chat_path, encoding="utf8") as file:
- texts = file.read().splitlines()
- random_text = random.choice(texts)
- random_bottom_text = random.choice(texts) + " " + random.choice(texts)
- with open(picture_path, encoding="utf8") as file:
- pictures = file.read().splitlines()
- random_picture = random.choice(pictures)
- response = requests.get(random_picture)
- random_filename = f"randomimg_{random.randint(0, 10000000000000000000000000)}.jpg"
- with open(random_filename, "wb") as f:
- f.write(response.content)
- random_text_len = len(random_text)
- dem_filename = f"result_{random.randint(0, 10000000000000000000000000)}.jpg"
- if random_text_len <= 50:
- dem = arrangedem(random_text, random_bottom_text)
- dem.makeImage(random_filename.rstrip(".jpg"))
- add_watermark_and_rename(result_filename=dem_filename)
- photo = await photo_uploader.upload_message_photo(dem_filename)
- await message(attachment=photo)
- os.remove(dem_filename)
- os.remove(random_filename)
- return
- else:
- random_bottom_text_short = random_text[:50]
- dem = arrangedem(random_text, random_bottom_text_short)
- dem.makeImage("randomimg")
- add_watermark_and_rename(result_filename=dem_filename)
- photo = await photo_uploader.upload_message_photo(dem_filename)
- await message(attachment=photo)
- os.remove(dem_filename)
- os.remove(random_filename)
- return
- else:
- await message(
- "Недостаточно сообщений для генерации.\nНужное количество: 10 сообщений и 1 фотография"
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement