fix later too tired
This commit is contained in:
parent
8021d17d27
commit
d300a3c812
8 changed files with 170 additions and 457 deletions
60
main.py
60
main.py
|
@ -179,12 +179,11 @@ async def talk(ctx: commands.Context, sentence_size: int = 5) -> None:
|
|||
await send_message(ctx, f"{(_('command_talk_insufficent_text'))}")
|
||||
return
|
||||
|
||||
response: Optional[str] = None
|
||||
response = None
|
||||
for _ in range(20):
|
||||
if sentence_size == 1:
|
||||
response = markov_model.make_short_sentence(max_chars=100, tries=100)
|
||||
if response:
|
||||
response = response.split()[0]
|
||||
sentence = markov_model.make_short_sentence(max_chars=100, tries=100)
|
||||
response = sentence.split()[0] if sentence else None
|
||||
else:
|
||||
response = markov_model.make_sentence(tries=100, max_words=sentence_size)
|
||||
|
||||
|
@ -193,20 +192,23 @@ async def talk(ctx: commands.Context, sentence_size: int = 5) -> None:
|
|||
response = improve_sentence_coherence(response)
|
||||
generated_sentences.add(response)
|
||||
break
|
||||
|
||||
if response:
|
||||
cleaned_response: str = re.sub(r'[^\w\s]', '', response).lower()
|
||||
coherent_response: str = rephrase_for_coherence(cleaned_response)
|
||||
if random.random() < 0.9 and is_positive(coherent_response):
|
||||
gif_url: str = random.choice(positive_gifs)
|
||||
combined_message: str = f"{coherent_response}\n[jif]({gif_url})"
|
||||
else:
|
||||
combined_message: str = coherent_response
|
||||
logger.info(combined_message)
|
||||
os.environ['gooberlatestgen'] = combined_message
|
||||
await send_message(ctx, combined_message)
|
||||
else:
|
||||
await send_message(ctx, f"{(_('command_talk_generation_fail'))}")
|
||||
return
|
||||
|
||||
cleaned = re.sub(r'[^\w\s]', '', response).lower()
|
||||
coherent = rephrase_for_coherence(cleaned)
|
||||
|
||||
if random.random() < 0.9 and is_positive(coherent):
|
||||
gif_url = random.choice(positive_gifs)
|
||||
message = f"{coherent}\n[jif]({gif_url})"
|
||||
else:
|
||||
message = coherent
|
||||
|
||||
logger.info(message)
|
||||
os.environ['gooberlatestgen'] = message
|
||||
await send_message(ctx, message)
|
||||
|
||||
|
||||
@bot.hybrid_command(description=f"RAM")
|
||||
async def ramusage(ctx):
|
||||
|
@ -216,24 +218,27 @@ async def ramusage(ctx):
|
|||
|
||||
@bot.hybrid_command(description=f"{(_('command_desc_help'))}")
|
||||
async def impact(ctx: commands.Context, text: Optional[str] = None) -> None:
|
||||
assets_folder: str = "assets/images"
|
||||
temp_input: Optional[str] = None
|
||||
assets_folder = "assets/images"
|
||||
|
||||
def get_random_asset_image() -> Optional[str]:
|
||||
files: List[str] = [f for f in os.listdir(assets_folder) if f.lower().endswith(('.png', '.jpg', '.jpeg', '.webp'))]
|
||||
if not files:
|
||||
images = [f for f in os.listdir(assets_folder) if f.lower().endswith(('.png', '.jpg', '.jpeg', '.webp'))]
|
||||
if not images:
|
||||
return None
|
||||
return os.path.join(assets_folder, random.choice(files))
|
||||
return os.path.join(assets_folder, random.choice(images))
|
||||
|
||||
temp_input = None
|
||||
input_path = None
|
||||
|
||||
# Determine input image path
|
||||
if ctx.message.attachments:
|
||||
attachment: discord.Attachment = ctx.message.attachments[0]
|
||||
attachment = ctx.message.attachments[0]
|
||||
if attachment.content_type and attachment.content_type.startswith("image/"):
|
||||
ext: str = os.path.splitext(attachment.filename)[1]
|
||||
ext = os.path.splitext(attachment.filename)[1]
|
||||
temp_input = f"tempy{ext}"
|
||||
await attachment.save(temp_input)
|
||||
input_path: str = temp_input
|
||||
input_path = temp_input
|
||||
else:
|
||||
fallback_image: Optional[str] = get_random_asset_image()
|
||||
fallback_image = get_random_asset_image()
|
||||
if fallback_image is None:
|
||||
await ctx.reply(_('no_image_available'))
|
||||
return
|
||||
|
@ -249,8 +254,8 @@ async def impact(ctx: commands.Context, text: Optional[str] = None) -> None:
|
|||
shutil.copy(fallback_image, temp_input)
|
||||
input_path = temp_input
|
||||
|
||||
output_path: Optional[str] = await gen_meme(input_path, custom_text=text)
|
||||
|
||||
# Generate meme image with one-shot text generation
|
||||
output_path = 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):
|
||||
|
@ -263,6 +268,7 @@ async def impact(ctx: commands.Context, text: Optional[str] = None) -> None:
|
|||
if temp_input and os.path.exists(temp_input):
|
||||
os.remove(temp_input)
|
||||
|
||||
|
||||
bot.remove_command('help')
|
||||
# Command: Show help information
|
||||
@bot.hybrid_command(description=f"{(_('command_desc_help'))}")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue