diff --git a/assets/cogs/webserver.py.disabled b/assets/cogs/webserver.py similarity index 100% rename from assets/cogs/webserver.py.disabled rename to assets/cogs/webserver.py diff --git a/bot.py b/bot.py index 74cf0b7..0c40592 100644 --- a/bot.py +++ b/bot.py @@ -225,7 +225,7 @@ async def talk(ctx: commands.Context, sentence_size: int = 5) -> None: # Command: Generate an image @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" temp_input: Optional[str] = None @@ -259,7 +259,8 @@ async def impact(ctx: commands.Context) -> None: shutil.copy(fallback_image, 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 temp_input and os.path.exists(temp_input): diff --git a/modules/image.py b/modules/image.py index 58180d5..d3807df 100644 --- a/modules/image.py +++ b/modules/image.py @@ -37,7 +37,7 @@ def split_text_to_fit(text, font, max_width, draw): midpoint = len(words) // 2 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() if not markov_model or not os.path.isfile(input_image_path): return None @@ -52,19 +52,22 @@ async def gen_meme(input_image_path, sentence_size=5, max_attempts=10): font = load_font(font_size) response = None - for _ in range(20): - if sentence_size == 1: - candidate = markov_model.make_short_sentence(max_chars=100, tries=100) - if candidate: - candidate = candidate.split()[0] - else: - candidate = markov_model.make_sentence(tries=100, max_words=sentence_size) + if custom_text: + response = custom_text + else: + for _ in range(20): + if sentence_size == 1: + candidate = markov_model.make_short_sentence(max_chars=100, tries=100) + 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 sentence_size > 1: - candidate = improve_sentence_coherence(candidate) - generated_sentences.add(candidate) - response = candidate + if candidate and candidate not in generated_sentences: + if sentence_size > 1: + candidate = improve_sentence_coherence(candidate) + generated_sentences.add(candidate) + response = candidate break if not response: