Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create ROT13 Command #170

Merged
merged 3 commits into from
Jan 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 60 additions & 9 deletions uqcsbot/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,30 @@ async def encoding_autocomplete(
class Text(commands.Cog):
def __init__(self, bot: commands.Bot):
self.bot = bot
self.zalgo_menu = app_commands.ContextMenu(
name="Zalgo",
callback=self.zalgo_context,
)
self.bot.tree.add_command(self.zalgo_menu)

self.mock_menu = app_commands.ContextMenu(
name="Mock",
callback=self.mock_context,
## self.zalgo_menu = app_commands.ContextMenu(
andrewj-brown marked this conversation as resolved.
Show resolved Hide resolved
## name="Zalgo",
## callback=self.zalgo_context,
## )
## self.bot.tree.add_command(self.zalgo_menu)
##
## self.mock_menu = app_commands.ContextMenu(
## name="Mock",
## callback=self.mock_context,
## )
## self.bot.tree.add_command(self.mock_menu)
##
## self.rot_13_menu = app_commands.ContextMenu(
## name="ROT13",
## callback=self.rot_13_context,
## )
## self.bot.tree.add_command(self.rot_13_menu)

self.rot_13_secret_menu = app_commands.ContextMenu(
name="ROT13 (Secret)",
callback=self.rot_13_secret_context,
)
self.bot.tree.add_command(self.mock_menu)
self.bot.tree.add_command(self.rot_13_secret_menu)

# casualty of the starboard's blacklist/whitelist commands, kept for posterity
# self.scare_menu = app_commands.ContextMenu(
Expand Down Expand Up @@ -273,6 +286,44 @@ async def zalgo_command(self, interaction: discord.Interaction, text: str):

await interaction.response.send_message(self.zalgo_common(text))

def rot_13_cipher(self, text: str) -> str:
andrewj-brown marked this conversation as resolved.
Show resolved Hide resolved
result = ""
for c in text:
if "a" <= c <= "m" or "A" <= c <= "M":
result += chr(ord(c) + 13)
elif "n" <= c <= "z" or "N" <= c <= "Z":
result += chr(ord(c) - 13)
else:
result += c
return result

@app_commands.command(name="rot_13")
@app_commands.describe(text="Input text")
@yelling_exemptor()
async def rot_13_command(self, interaction: discord.Interaction, text: str):
"""
Encodes the given text with the cunning ROT13 Cipher
"""
await interaction.response.send_message(self.rot_13_cipher(text))

## async def rot_13_context(
andrewj-brown marked this conversation as resolved.
Show resolved Hide resolved
## self, interaction: discord.Interaction, message: discord.Message
## ):
## """
## Encodes this message with the cunning ROT13 Cipher
## """
## await interaction.response.send_message(self.rot_13_cipher(message.content))

async def rot_13_secret_context(
self, interaction: discord.Interaction, message: discord.Message
):
"""
Encodes this message with the cunning ROT13 Cipher, and shows it secretly to the caller
"""
await interaction.response.send_message(
self.rot_13_cipher(message.content), ephemeral=True
)


async def setup(bot: commands.Bot):
await bot.add_cog(Text(bot))