Advertisement
l1von

вав

Jan 2nd, 2021
20
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.41 KB | None | 0 0
  1. @bot.on.chat_message(lower=True, text=["g", "d", "gen", "г", "/ген", "dem", "/g", "ген", "/gen", "д", "дем"])
  2. async def gen(message: Message):
  3. text_length = len(message.text)
  4. chat_path = f"{dir_to_txt}{message.peer_id}.txt"
  5. picture_path = f"{dir_to_pic}{message.peer_id}.txt"
  6.  
  7. with open(picture_path, encoding="utf8") as f:
  8. pic_count = len(f.readlines())
  9. with open(chat_path, encoding="utf8") as f:
  10. text_lines = len(f.readlines())
  11.  
  12. if text_lines >= 10 and pic_count >= 1:
  13. print("ГЕНЕРИРУЕМ ПО КОМАНДЕ")
  14. with open(chat_path, encoding="utf8") as file:
  15. texts = file.read().splitlines()
  16. random_text = random.choice(texts)
  17. random_bottom_text = random.choice(texts) + " " + random.choice(texts)
  18. with open(picture_path, encoding="utf8") as file:
  19. pictures = file.read().splitlines()
  20. random_picture = random.choice(pictures)
  21. response = requests.get(random_picture)
  22.  
  23. random_filename = f"randomimg_{random.randint(0, 10000000000000000000000000)}.jpg"
  24. with open(random_filename, "wb") as f:
  25. f.write(response.content)
  26.  
  27. random_text_len = len(random_text)
  28.  
  29. dem_filename = f"result_{random.randint(0, 10000000000000000000000000)}.jpg"
  30. if random_text_len <= 50:
  31. dem = arrangedem(random_text, random_bottom_text)
  32. dem.makeImage(random_filename.rstrip(".jpg"))
  33. add_watermark_and_rename(result_filename=dem_filename)
  34. photo = await photo_uploader.upload_message_photo(dem_filename)
  35. await message(attachment=photo)
  36. os.remove(dem_filename)
  37. os.remove(random_filename)
  38. return
  39. else:
  40. random_bottom_text_short = random_text[:50]
  41. dem = arrangedem(random_text, random_bottom_text_short)
  42. dem.makeImage("randomimg")
  43. add_watermark_and_rename(result_filename=dem_filename)
  44. photo = await photo_uploader.upload_message_photo(dem_filename)
  45. await message(attachment=photo)
  46. os.remove(dem_filename)
  47. os.remove(random_filename)
  48. return
  49. else:
  50. await message(
  51. "Недостаточно сообщений для генерации.\nНужное количество: 10 сообщений и 1 фотография"
  52. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement