forked from gooberinc/goober
sigh
This commit is contained in:
parent
4ff0630d66
commit
c565f962c5
3 changed files with 19 additions and 15 deletions
5
bot.py
5
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):
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue