no idea atp #1

Merged
WhatDidYouExpect merged 5 commits from dev into main 2025-07-17 23:41:22 +02:00
3 changed files with 19 additions and 15 deletions
Showing only changes of commit c565f962c5 - Show all commits

5
bot.py
View file

@ -225,7 +225,7 @@ async def talk(ctx: commands.Context, sentence_size: int = 5) -> None:
# Command: Generate an image # Command: Generate an image
@bot.hybrid_command(description=f"{(_('command_desc_help'))}") @bot.hybrid_command(description=f"{(_('command_desc_help'))}")
async def impact(ctx: commands.Context) -> None: async def impact(ctx: commands.Context, text: Optional[str] = None) -> None:
assets_folder: str = "assets/images" assets_folder: str = "assets/images"
temp_input: Optional[str] = None temp_input: Optional[str] = None
@ -259,7 +259,8 @@ async def impact(ctx: commands.Context) -> None:
shutil.copy(fallback_image, temp_input) shutil.copy(fallback_image, temp_input)
input_path = temp_input input_path = temp_input
output_path: Optional[str] = await gen_meme(input_path) output_path: Optional[str] = await gen_meme(input_path, custom_text=text)
if output_path is None or not os.path.isfile(output_path): if output_path is None or not os.path.isfile(output_path):
if temp_input and os.path.exists(temp_input): if temp_input and os.path.exists(temp_input):

View file

@ -37,7 +37,7 @@ def split_text_to_fit(text, font, max_width, draw):
midpoint = len(words) // 2 midpoint = len(words) // 2
return " ".join(words[:midpoint]), " ".join(words[midpoint:]) return " ".join(words[:midpoint]), " ".join(words[midpoint:])
async def gen_meme(input_image_path, sentence_size=5, max_attempts=10): async def gen_meme(input_image_path, sentence_size=5, max_attempts=10, custom_text=None):
markov_model = load_markov_model() markov_model = load_markov_model()
if not markov_model or not os.path.isfile(input_image_path): if not markov_model or not os.path.isfile(input_image_path):
return None return None
@ -52,19 +52,22 @@ async def gen_meme(input_image_path, sentence_size=5, max_attempts=10):
font = load_font(font_size) font = load_font(font_size)
response = None response = None
for _ in range(20): if custom_text:
if sentence_size == 1: response = custom_text
candidate = markov_model.make_short_sentence(max_chars=100, tries=100) else:
if candidate: for _ in range(20):
candidate = candidate.split()[0] if sentence_size == 1:
else: candidate = markov_model.make_short_sentence(max_chars=100, tries=100)
candidate = markov_model.make_sentence(tries=100, max_words=sentence_size) if candidate:
candidate = candidate.split()[0]
else:
candidate = markov_model.make_sentence(tries=100, max_words=sentence_size)
if candidate and candidate not in generated_sentences: if candidate and candidate not in generated_sentences:
if sentence_size > 1: if sentence_size > 1:
candidate = improve_sentence_coherence(candidate) candidate = improve_sentence_coherence(candidate)
generated_sentences.add(candidate) generated_sentences.add(candidate)
response = candidate response = candidate
break break
if not response: if not response: