asd
This commit is contained in:
parent
21ba23d8bc
commit
1eb1f66a7c
@ -4,25 +4,23 @@ from discord import app_commands
|
||||
import re
|
||||
import random
|
||||
|
||||
def _owoify_text(text: str) -> str:
|
||||
"""Helper function to owoify text."""
|
||||
text = re.sub(r'[rl]', 'w', text)
|
||||
text = re.sub(r'[RL]', 'W', text)
|
||||
text = re.sub(r'n([aeiou])', r'ny\1', text)
|
||||
text = re.sub(r'N([aeiou])', r'Ny\1', text)
|
||||
text = re.sub(r'N([AEIOU])', r'NY\1', text)
|
||||
text = re.sub(r'ove', 'uv', text)
|
||||
text = re.sub(r'OVE', 'UV', text)
|
||||
suffixes = [" owo", " uwu", " >w<", " ^w^", " OwO", " UwU", " >.<"]
|
||||
text += random.choice(suffixes)
|
||||
return text
|
||||
|
||||
class OwoifyCog(commands.Cog):
|
||||
def __init__(self, bot: commands.Bot):
|
||||
self.bot = bot
|
||||
|
||||
def _owoify_text(self, text: str) -> str:
|
||||
"""Helper function to owoify text."""
|
||||
text = re.sub(r'[rl]', 'w', text)
|
||||
text = re.sub(r'[RL]', 'W', text)
|
||||
text = re.sub(r'n([aeiou])', r'ny\1', text)
|
||||
text = re.sub(r'N([aeiou])', r'Ny\1', text)
|
||||
text = re.sub(r'N([AEIOU])', r'NY\1', text)
|
||||
text = re.sub(r'ove', 'uv', text)
|
||||
text = re.sub(r'OVE', 'UV', text)
|
||||
|
||||
# Add some cute faces/suffixes
|
||||
suffixes = [" owo", " uwu", " >w<", " ^w^", " OwO", " UwU", " >.<"] # Escaped > and < for XML
|
||||
text += random.choice(suffixes)
|
||||
return text
|
||||
|
||||
@app_commands.command(name="owoify", description="Owoifies your message!")
|
||||
@app_commands.describe(message_to_owoify="The message to owoify")
|
||||
async def owoify_slash_command(self, interaction: discord.Interaction, message_to_owoify: str):
|
||||
@ -30,36 +28,33 @@ class OwoifyCog(commands.Cog):
|
||||
if not message_to_owoify.strip():
|
||||
await interaction.response.send_message("You nyeed to pwovide some text to owoify! >w<", ephemeral=True)
|
||||
return
|
||||
|
||||
owo_text = self._owoify_text(message_to_owoify)
|
||||
owo_text = _owoify_text(message_to_owoify)
|
||||
await interaction.response.send_message(owo_text)
|
||||
|
||||
@app_commands.context_menu(name="Owoify Message")
|
||||
async def owoify_context_menu(self, interaction: discord.Interaction, message: discord.Message):
|
||||
"""Owoifies the content of the selected message and replies."""
|
||||
if not message.content:
|
||||
await interaction.response.send_message("The sewected message has no text content to owoify! >.<", ephemeral=True)
|
||||
return
|
||||
|
||||
original_content = message.content
|
||||
owo_text = self._owoify_text(original_content)
|
||||
|
||||
try:
|
||||
# Attempt to reply to the message
|
||||
await message.reply(owo_text)
|
||||
# Send a silent confirmation to the user who invoked the command
|
||||
await interaction.response.send_message("Message owoified and wepwied! uwu", ephemeral=True)
|
||||
except discord.Forbidden:
|
||||
# If replying is forbidden, send the owoified text as an ephemeral message to the user
|
||||
await interaction.response.send_message(
|
||||
f"I couwdn't wepwy to the message (nyi Pwermissions? owo).\n"
|
||||
f"But hewe's the owoified text fow you: {owo_text}",
|
||||
ephemeral=True
|
||||
)
|
||||
except discord.HTTPException as e:
|
||||
# Handle other potential HTTP errors during reply
|
||||
await interaction.response.send_message(f"Oopsie! A tiny ewwow occuwwed: {e} >w<", ephemeral=True)
|
||||
# Context menu command must be defined at module level
|
||||
@app_commands.context_menu(name="Owoify Message")
|
||||
async def owoify_context_menu(interaction: discord.Interaction, message: discord.Message):
|
||||
"""Owoifies the content of the selected message and replies."""
|
||||
if not message.content:
|
||||
await interaction.response.send_message("The sewected message has no text content to owoify! >.<", ephemeral=True)
|
||||
return
|
||||
original_content = message.content
|
||||
owo_text = _owoify_text(original_content)
|
||||
try:
|
||||
await message.reply(owo_text)
|
||||
await interaction.response.send_message("Message owoified and wepwied! uwu", ephemeral=True)
|
||||
except discord.Forbidden:
|
||||
await interaction.response.send_message(
|
||||
f"I couwdn't wepwy to the message (nyi Pwermissions? owo).\n"
|
||||
f"But hewe's the owoified text fow you: {owo_text}",
|
||||
ephemeral=True
|
||||
)
|
||||
except discord.HTTPException as e:
|
||||
await interaction.response.send_message(f"Oopsie! A tiny ewwow occuwwed: {e} >w<", ephemeral=True)
|
||||
|
||||
async def setup(bot: commands.Bot):
|
||||
await bot.add_cog(OwoifyCog(bot))
|
||||
cog = OwoifyCog(bot)
|
||||
await bot.add_cog(cog)
|
||||
# Add the context menu command to the tree
|
||||
bot.tree.add_command(owoify_context_menu)
|
||||
print("OwoifyCog woaded! uwu")
|
||||
|
Loading…
x
Reference in New Issue
Block a user