From 4b871609190ce5ecb9eb47c5e1f7e3a42effd989 Mon Sep 17 00:00:00 2001 From: PureFunctor Date: Sat, 13 Jun 2020 23:06:37 +0800 Subject: Add initial caesarcipher command --- bot/exts/evergreen/fun.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'bot/exts/evergreen/fun.py') diff --git a/bot/exts/evergreen/fun.py b/bot/exts/evergreen/fun.py index 67a4bae5..5f4c5b3e 100644 --- a/bot/exts/evergreen/fun.py +++ b/bot/exts/evergreen/fun.py @@ -87,6 +87,40 @@ class Fun(Cog): converted_text = f">>> {converted_text.lstrip('> ')}" await ctx.send(content=converted_text, embed=embed) + @commands.command(name="caesarcipher", aliases=("caesar",)) + async def caesarcipher_command(self, ctx: Context, offset: int, *, text: str) -> None: + """ + Given an integer `offset`, encrypt the given `text`. + + A positive `offset` will cause the letters to shift right, + while a negative `offset` will cause the letters to shift left. + + Also accepts a valid discord Message ID or link. + """ + + def cipher_func(text: str) -> str: + """Implements a lazy Caesar cipher algorithm.""" + for char in text: + if not char.isascii() or not char.isalpha() or char.isspace(): + yield char + continue + case_start = 65 if char.isupper() else 97 + yield chr((ord(char) - case_start + offset) % 26 + case_start) + + def conversion_func(text: str) -> str: + """Encrypts the given string using the Caesar cipher.""" + return "".join(cipher_func(text)) + + text, embed = await Fun._get_text_and_embed(ctx, text) + # Convert embed if it exists + if embed is not None: + embed = Fun._convert_embed(conversion_func, embed) + converted_text = conversion_func(text) + # Don't put >>> if only embed present + if converted_text: + converted_text = f">>> {converted_text.lstrip('> ')}" + await ctx.send(content=converted_text, embed=embed) + @staticmethod async def _get_text_and_embed(ctx: Context, text: str) -> Tuple[str, Union[Embed, None]]: """ -- cgit v1.2.3 From 3e58b35174ea4aa686f1347c41ecd056df74f6ee Mon Sep 17 00:00:00 2001 From: PureFunctor Date: Sun, 14 Jun 2020 11:20:59 +0800 Subject: Make caesarcipher a command group --- bot/exts/evergreen/fun.py | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'bot/exts/evergreen/fun.py') diff --git a/bot/exts/evergreen/fun.py b/bot/exts/evergreen/fun.py index 5f4c5b3e..2b1abaa4 100644 --- a/bot/exts/evergreen/fun.py +++ b/bot/exts/evergreen/fun.py @@ -87,19 +87,32 @@ class Fun(Cog): converted_text = f">>> {converted_text.lstrip('> ')}" await ctx.send(content=converted_text, embed=embed) - @commands.command(name="caesarcipher", aliases=("caesar",)) - async def caesarcipher_command(self, ctx: Context, offset: int, *, text: str) -> None: + @commands.group(name="caesarcipher", aliases=("caesar",)) + async def caesarcipher_group(self, ctx: Context) -> None: """ - Given an integer `offset`, encrypt the given `text`. + Translates a message using the Caesar Cipher. + + See `info` and `translate` subcommands. + """ + if ctx.invoked_subcommand is None: + await self.bot.get_cog("Help").new_help(ctx, "caesarcipher") + + @caesarcipher_group.command(name="info") + async def caesarcipher_info(self, ctx: Context) -> None: + """Information about the Caesar Cipher.""" + + @caesarcipher_group.command(name="translate") + async def caesarcipher_translate(self, ctx: Context, offset: int, *, text: str) -> None: + """ + Given an integer `offset`, translate the given `text`. A positive `offset` will cause the letters to shift right, while a negative `offset` will cause the letters to shift left. Also accepts a valid discord Message ID or link. """ - def cipher_func(text: str) -> str: - """Implements a lazy Caesar cipher algorithm.""" + """Implements a lazy Caesar Cipher algorithm.""" for char in text: if not char.isascii() or not char.isalpha() or char.isspace(): yield char @@ -108,7 +121,7 @@ class Fun(Cog): yield chr((ord(char) - case_start + offset) % 26 + case_start) def conversion_func(text: str) -> str: - """Encrypts the given string using the Caesar cipher.""" + """Encrypts the given string using the Caesar Cipher.""" return "".join(cipher_func(text)) text, embed = await Fun._get_text_and_embed(ctx, text) -- cgit v1.2.3 From baa20503e716a9ed9ab8be5f82c3456c7b4cfbb5 Mon Sep 17 00:00:00 2001 From: PureFunctor Date: Sun, 14 Jun 2020 14:20:09 +0800 Subject: Add basic caesar cipher information embed --- bot/exts/evergreen/fun.py | 13 ++++++++++++- bot/resources/evergreen/caesar_info.json | 4 ++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 bot/resources/evergreen/caesar_info.json (limited to 'bot/exts/evergreen/fun.py') diff --git a/bot/exts/evergreen/fun.py b/bot/exts/evergreen/fun.py index 2b1abaa4..f3e3bfcc 100644 --- a/bot/exts/evergreen/fun.py +++ b/bot/exts/evergreen/fun.py @@ -1,4 +1,5 @@ import functools +import json import logging import random from typing import Callable, Tuple, Union @@ -8,7 +9,7 @@ from discord.ext import commands from discord.ext.commands import Bot, Cog, Context, MessageConverter from bot import utils -from bot.constants import Emojis +from bot.constants import Colours, Emojis log = logging.getLogger(__name__) @@ -100,6 +101,16 @@ class Fun(Cog): @caesarcipher_group.command(name="info") async def caesarcipher_info(self, ctx: Context) -> None: """Information about the Caesar Cipher.""" + with open("bot\\resources\\evergreen\\caesar_info.json", "r") as f: + data = json.load(f) + + embed = Embed( + title=data["title"], + description="".join(data["description"]), + colour=Colours.dark_green, + ) + + await ctx.send(embed=embed) @caesarcipher_group.command(name="translate") async def caesarcipher_translate(self, ctx: Context, offset: int, *, text: str) -> None: diff --git a/bot/resources/evergreen/caesar_info.json b/bot/resources/evergreen/caesar_info.json new file mode 100644 index 00000000..ae3a4656 --- /dev/null +++ b/bot/resources/evergreen/caesar_info.json @@ -0,0 +1,4 @@ +{ + "title": "Caesar Cipher", + "description": "**Information**\nThe Caesar Cipher, named after hte Roman General Julius Caesar is one of the simplest and most widely known encryption techniques. It is a type of substitution cipher in which each letter in the plaintext is replaced by a letter given a specific position offset in the alphabet, with the letters wrapping around both sides.\n\n**Examples**\n1) `Hello World` <=> `Khoor Zruog` where letters are shifted forwards by `3.`\n2) `Julius Caesar` <=> `Yjaxjh Rpthpg` where letters are shifted backwards by `11.`" +} -- cgit v1.2.3 From 3260a16d78351fec2bab9ba6124e4a655fbd2e26 Mon Sep 17 00:00:00 2001 From: PureFunctor Date: Thu, 25 Jun 2020 23:29:06 +0800 Subject: Refactor translate subcommand to encrypt and decrypt --- bot/exts/evergreen/fun.py | 40 +++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) (limited to 'bot/exts/evergreen/fun.py') diff --git a/bot/exts/evergreen/fun.py b/bot/exts/evergreen/fun.py index f3e3bfcc..75b0e2b0 100644 --- a/bot/exts/evergreen/fun.py +++ b/bot/exts/evergreen/fun.py @@ -93,7 +93,7 @@ class Fun(Cog): """ Translates a message using the Caesar Cipher. - See `info` and `translate` subcommands. + See `decrpyt`, `encrypt`, and `info` subcommands. """ if ctx.invoked_subcommand is None: await self.bot.get_cog("Help").new_help(ctx, "caesarcipher") @@ -112,17 +112,17 @@ class Fun(Cog): await ctx.send(embed=embed) - @caesarcipher_group.command(name="translate") - async def caesarcipher_translate(self, ctx: Context, offset: int, *, text: str) -> None: + @staticmethod + async def _caesar_cipher(ctx: Context, offset: int, text: str) -> None: """ - Given an integer `offset`, translate the given `text`. + Given an integer `offset`, translates and sends the given `text`. - A positive `offset` will cause the letters to shift right, - while a negative `offset` will cause the letters to shift left. + A positive `offset` will cause the letters to shift right, while + a negative `offset` will cause the letters to shift left. - Also accepts a valid discord Message ID or link. + Also accepts a valid Discord Message ID or link. """ - def cipher_func(text: str) -> str: + def caesar_func(text: str) -> str: """Implements a lazy Caesar Cipher algorithm.""" for char in text: if not char.isascii() or not char.isalpha() or char.isspace(): @@ -133,7 +133,7 @@ class Fun(Cog): def conversion_func(text: str) -> str: """Encrypts the given string using the Caesar Cipher.""" - return "".join(cipher_func(text)) + return "".join(caesar_func(text)) text, embed = await Fun._get_text_and_embed(ctx, text) # Convert embed if it exists @@ -145,6 +145,28 @@ class Fun(Cog): converted_text = f">>> {converted_text.lstrip('> ')}" await ctx.send(content=converted_text, embed=embed) + @caesarcipher_group.command(name="encrypt", aliases=("rightshift", "rshift")) + async def caesarcipher_encrypt(self, ctx: Context, offset: int, *, text: str) -> None: + """ + Given a positive integer `offset`, encrypt the given `text`. + + Performs a right shift of the letters in the message. + + Also accepts a valid Discord Message ID or link. + """ + await self._caesar_cipher(ctx, offset, text) + + @caesarcipher_group.command(name="decrypt", aliases=("leftshift", "lshift")) + async def caesarcipher_decrypt(self, ctx: Context, offset: int, *, text: str) -> None: + """ + Given a positive integer `offset`, decrypt the given `text`. + + Performs a left shift of the letters in the message. + + Also accepts a valid Discord Message ID or link. + """ + await self._caesar_cipher(ctx, -offset, text) + @staticmethod async def _get_text_and_embed(ctx: Context, text: str) -> Tuple[str, Union[Embed, None]]: """ -- cgit v1.2.3 From f1a79fb65a98c4c483b3e77dfb1c910c8702165b Mon Sep 17 00:00:00 2001 From: PureFunctor Date: Thu, 25 Jun 2020 23:47:30 +0800 Subject: Add offset validation --- bot/exts/evergreen/fun.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'bot/exts/evergreen/fun.py') diff --git a/bot/exts/evergreen/fun.py b/bot/exts/evergreen/fun.py index 75b0e2b0..364ce74b 100644 --- a/bot/exts/evergreen/fun.py +++ b/bot/exts/evergreen/fun.py @@ -154,7 +154,10 @@ class Fun(Cog): Also accepts a valid Discord Message ID or link. """ - await self._caesar_cipher(ctx, offset, text) + if offset < 0: + await ctx.send(":no_entry: Cannot use a negative offset.") + else: + await self._caesar_cipher(ctx, offset, text) @caesarcipher_group.command(name="decrypt", aliases=("leftshift", "lshift")) async def caesarcipher_decrypt(self, ctx: Context, offset: int, *, text: str) -> None: @@ -165,7 +168,10 @@ class Fun(Cog): Also accepts a valid Discord Message ID or link. """ - await self._caesar_cipher(ctx, -offset, text) + if offset < 0: + await ctx.send(":no_entry: Cannot use a negative offset.") + else: + await self._caesar_cipher(ctx, -offset, text) @staticmethod async def _get_text_and_embed(ctx: Context, text: str) -> Tuple[str, Union[Embed, None]]: -- cgit v1.2.3 From d6539562aef0ae4be88ddb023f5ff49206a90cf0 Mon Sep 17 00:00:00 2001 From: PureFunctor Date: Fri, 26 Jun 2020 12:11:00 +0800 Subject: Load embed data in __init__ and use Embed.from_dict --- bot/exts/evergreen/fun.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'bot/exts/evergreen/fun.py') diff --git a/bot/exts/evergreen/fun.py b/bot/exts/evergreen/fun.py index 364ce74b..4fc06b49 100644 --- a/bot/exts/evergreen/fun.py +++ b/bot/exts/evergreen/fun.py @@ -33,6 +33,9 @@ class Fun(Cog): def __init__(self, bot: Bot) -> None: self.bot = bot + with open("bot\\resources\\evergreen\\caesar_info.json", "r") as f: + self._caesar_cipher_embed = json.load(f) + @commands.command() async def roll(self, ctx: Context, num_rolls: int = 1) -> None: """Outputs a number of random dice emotes (up to 6).""" @@ -101,14 +104,8 @@ class Fun(Cog): @caesarcipher_group.command(name="info") async def caesarcipher_info(self, ctx: Context) -> None: """Information about the Caesar Cipher.""" - with open("bot\\resources\\evergreen\\caesar_info.json", "r") as f: - data = json.load(f) - - embed = Embed( - title=data["title"], - description="".join(data["description"]), - colour=Colours.dark_green, - ) + embed = Embed.from_dict(self._caesar_cipher_embed) + embed.colour = Colours.dark_green await ctx.send(embed=embed) -- cgit v1.2.3 From 3fe9a22fc9cf57d284d17949563596e05ea5d033 Mon Sep 17 00:00:00 2001 From: PureFunctor Date: Fri, 26 Jun 2020 12:21:46 +0800 Subject: Use Context.invoke instead of invoking the Help cog --- bot/exts/evergreen/fun.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bot/exts/evergreen/fun.py') diff --git a/bot/exts/evergreen/fun.py b/bot/exts/evergreen/fun.py index 4fc06b49..090714aa 100644 --- a/bot/exts/evergreen/fun.py +++ b/bot/exts/evergreen/fun.py @@ -99,7 +99,7 @@ class Fun(Cog): See `decrpyt`, `encrypt`, and `info` subcommands. """ if ctx.invoked_subcommand is None: - await self.bot.get_cog("Help").new_help(ctx, "caesarcipher") + await ctx.invoke(self.bot.get_command("help"), "caesarcipher") @caesarcipher_group.command(name="info") async def caesarcipher_info(self, ctx: Context) -> None: -- cgit v1.2.3 From 3b27b96374488f2c2c34f51e718fc42fa5b7c1a6 Mon Sep 17 00:00:00 2001 From: PureFunctor Date: Fri, 26 Jun 2020 14:50:44 +0800 Subject: Utilize Union[Message, str] for converting messages --- bot/exts/evergreen/fun.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'bot/exts/evergreen/fun.py') diff --git a/bot/exts/evergreen/fun.py b/bot/exts/evergreen/fun.py index 090714aa..d1f87b6a 100644 --- a/bot/exts/evergreen/fun.py +++ b/bot/exts/evergreen/fun.py @@ -110,7 +110,7 @@ class Fun(Cog): await ctx.send(embed=embed) @staticmethod - async def _caesar_cipher(ctx: Context, offset: int, text: str) -> None: + async def _caesar_cipher(ctx: Context, offset: int, msg: Union[Message, str]) -> None: """ Given an integer `offset`, translates and sends the given `text`. @@ -132,18 +132,23 @@ class Fun(Cog): """Encrypts the given string using the Caesar Cipher.""" return "".join(caesar_func(text)) - text, embed = await Fun._get_text_and_embed(ctx, text) - # Convert embed if it exists + is_message = isinstance(msg, Message) + + text = msg.content if is_message else msg + embed = msg.embeds[0] if is_message and msg.embeds else None + if embed is not None: embed = Fun._convert_embed(conversion_func, embed) + converted_text = conversion_func(text) - # Don't put >>> if only embed present + if converted_text: converted_text = f">>> {converted_text.lstrip('> ')}" + await ctx.send(content=converted_text, embed=embed) @caesarcipher_group.command(name="encrypt", aliases=("rightshift", "rshift")) - async def caesarcipher_encrypt(self, ctx: Context, offset: int, *, text: str) -> None: + async def caesarcipher_encrypt(self, ctx: Context, offset: int, *, msg: Union[Message, str]) -> None: """ Given a positive integer `offset`, encrypt the given `text`. @@ -154,10 +159,10 @@ class Fun(Cog): if offset < 0: await ctx.send(":no_entry: Cannot use a negative offset.") else: - await self._caesar_cipher(ctx, offset, text) + await self._caesar_cipher(ctx, offset, msg) @caesarcipher_group.command(name="decrypt", aliases=("leftshift", "lshift")) - async def caesarcipher_decrypt(self, ctx: Context, offset: int, *, text: str) -> None: + async def caesarcipher_decrypt(self, ctx: Context, offset: int, *, msg: Union[Message, str]) -> None: """ Given a positive integer `offset`, decrypt the given `text`. @@ -168,7 +173,7 @@ class Fun(Cog): if offset < 0: await ctx.send(":no_entry: Cannot use a negative offset.") else: - await self._caesar_cipher(ctx, -offset, text) + await self._caesar_cipher(ctx, -offset, msg) @staticmethod async def _get_text_and_embed(ctx: Context, text: str) -> Tuple[str, Union[Embed, None]]: -- cgit v1.2.3 From 093a54c9acd546435c517497af409d55e0512412 Mon Sep 17 00:00:00 2001 From: PureFunctor Date: Sat, 27 Jun 2020 15:17:18 +0800 Subject: Use pathlib and fix grammar in the information embed --- bot/exts/evergreen/fun.py | 3 ++- bot/resources/evergreen/caesar_info.json | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'bot/exts/evergreen/fun.py') diff --git a/bot/exts/evergreen/fun.py b/bot/exts/evergreen/fun.py index d1f87b6a..601ae45b 100644 --- a/bot/exts/evergreen/fun.py +++ b/bot/exts/evergreen/fun.py @@ -2,6 +2,7 @@ import functools import json import logging import random +from pathlib import Path from typing import Callable, Tuple, Union from discord import Embed, Message @@ -33,7 +34,7 @@ class Fun(Cog): def __init__(self, bot: Bot) -> None: self.bot = bot - with open("bot\\resources\\evergreen\\caesar_info.json", "r") as f: + with Path("bot/resources/evergreen/caesar_info.json").open("r") as f: self._caesar_cipher_embed = json.load(f) @commands.command() diff --git a/bot/resources/evergreen/caesar_info.json b/bot/resources/evergreen/caesar_info.json index ae3a4656..8229c4f3 100644 --- a/bot/resources/evergreen/caesar_info.json +++ b/bot/resources/evergreen/caesar_info.json @@ -1,4 +1,4 @@ { "title": "Caesar Cipher", - "description": "**Information**\nThe Caesar Cipher, named after hte Roman General Julius Caesar is one of the simplest and most widely known encryption techniques. It is a type of substitution cipher in which each letter in the plaintext is replaced by a letter given a specific position offset in the alphabet, with the letters wrapping around both sides.\n\n**Examples**\n1) `Hello World` <=> `Khoor Zruog` where letters are shifted forwards by `3.`\n2) `Julius Caesar` <=> `Yjaxjh Rpthpg` where letters are shifted backwards by `11.`" + "description": "**Information**\nThe Caesar Cipher, named after the Roman General Julius Caesar, is one of the simplest and most widely known encryption techniques. It is a type of substitution cipher in which each letter in the plaintext is replaced by a letter given a specific position offset in the alphabet, with the letters wrapping around both sides.\n\n**Examples**\n1) `Hello World` <=> `Khoor Zruog` where letters are shifted forwards by `3`.\n2) `Julius Caesar` <=> `Yjaxjh Rpthpg` where letters are shifted backwards by `11`." } -- cgit v1.2.3 From c59a1630817503ed8507a0b364e037077645af35 Mon Sep 17 00:00:00 2001 From: PureFunctor Date: Sat, 27 Jun 2020 15:29:03 +0800 Subject: Add UTF-8 encoding when loading embed information --- bot/exts/evergreen/fun.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bot/exts/evergreen/fun.py') diff --git a/bot/exts/evergreen/fun.py b/bot/exts/evergreen/fun.py index 601ae45b..f9bd8812 100644 --- a/bot/exts/evergreen/fun.py +++ b/bot/exts/evergreen/fun.py @@ -34,7 +34,7 @@ class Fun(Cog): def __init__(self, bot: Bot) -> None: self.bot = bot - with Path("bot/resources/evergreen/caesar_info.json").open("r") as f: + with Path("bot/resources/evergreen/caesar_info.json").open("r", encoding="UTF-8") as f: self._caesar_cipher_embed = json.load(f) @commands.command() -- cgit v1.2.3 From e8a94313f93f12b52c76cebf4f425206475b89c1 Mon Sep 17 00:00:00 2001 From: PureFunctor Date: Sun, 28 Jun 2020 13:51:01 +0800 Subject: Add 'cc' alias for caesarcipher --- bot/exts/evergreen/fun.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bot/exts/evergreen/fun.py') diff --git a/bot/exts/evergreen/fun.py b/bot/exts/evergreen/fun.py index f9bd8812..0abc0138 100644 --- a/bot/exts/evergreen/fun.py +++ b/bot/exts/evergreen/fun.py @@ -92,7 +92,7 @@ class Fun(Cog): converted_text = f">>> {converted_text.lstrip('> ')}" await ctx.send(content=converted_text, embed=embed) - @commands.group(name="caesarcipher", aliases=("caesar",)) + @commands.group(name="caesarcipher", aliases=("caesar", "cc",)) async def caesarcipher_group(self, ctx: Context) -> None: """ Translates a message using the Caesar Cipher. -- cgit v1.2.3 From 1d9ee64755736b715896e90c9b359b490f08e547 Mon Sep 17 00:00:00 2001 From: PureFunctor Date: Sun, 28 Jun 2020 13:53:54 +0800 Subject: Fix return type annotation --- bot/exts/evergreen/fun.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'bot/exts/evergreen/fun.py') diff --git a/bot/exts/evergreen/fun.py b/bot/exts/evergreen/fun.py index 0abc0138..d376c44e 100644 --- a/bot/exts/evergreen/fun.py +++ b/bot/exts/evergreen/fun.py @@ -3,7 +3,7 @@ import json import logging import random from pathlib import Path -from typing import Callable, Tuple, Union +from typing import Callable, Iterable, Tuple, Union from discord import Embed, Message from discord.ext import commands @@ -120,7 +120,7 @@ class Fun(Cog): Also accepts a valid Discord Message ID or link. """ - def caesar_func(text: str) -> str: + def caesar_func(text: str) -> Iterable[str]: """Implements a lazy Caesar Cipher algorithm.""" for char in text: if not char.isascii() or not char.isalpha() or char.isspace(): -- cgit v1.2.3 From b02b4e84caddb595d39b87571de6181f7446c528 Mon Sep 17 00:00:00 2001 From: PureFunctor Date: Tue, 30 Jun 2020 20:21:50 +0800 Subject: Change text to msg in command docstrings --- bot/exts/evergreen/fun.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'bot/exts/evergreen/fun.py') diff --git a/bot/exts/evergreen/fun.py b/bot/exts/evergreen/fun.py index d376c44e..220881d4 100644 --- a/bot/exts/evergreen/fun.py +++ b/bot/exts/evergreen/fun.py @@ -113,7 +113,7 @@ class Fun(Cog): @staticmethod async def _caesar_cipher(ctx: Context, offset: int, msg: Union[Message, str]) -> None: """ - Given an integer `offset`, translates and sends the given `text`. + Given an integer `offset`, translates and sends the given `msg`. A positive `offset` will cause the letters to shift right, while a negative `offset` will cause the letters to shift left. @@ -151,7 +151,7 @@ class Fun(Cog): @caesarcipher_group.command(name="encrypt", aliases=("rightshift", "rshift")) async def caesarcipher_encrypt(self, ctx: Context, offset: int, *, msg: Union[Message, str]) -> None: """ - Given a positive integer `offset`, encrypt the given `text`. + Given a positive integer `offset`, encrypt the given `msg`. Performs a right shift of the letters in the message. @@ -165,7 +165,7 @@ class Fun(Cog): @caesarcipher_group.command(name="decrypt", aliases=("leftshift", "lshift")) async def caesarcipher_decrypt(self, ctx: Context, offset: int, *, msg: Union[Message, str]) -> None: """ - Given a positive integer `offset`, decrypt the given `text`. + Given a positive integer `offset`, decrypt the given `msg`. Performs a left shift of the letters in the message. -- cgit v1.2.3 From 52f99c69f882fdc253de594002d404a5b454a971 Mon Sep 17 00:00:00 2001 From: PureFunctor Date: Thu, 2 Jul 2020 19:21:56 +0800 Subject: Separate the formula for the actual offset --- bot/exts/evergreen/fun.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'bot/exts/evergreen/fun.py') diff --git a/bot/exts/evergreen/fun.py b/bot/exts/evergreen/fun.py index 220881d4..5f5c3718 100644 --- a/bot/exts/evergreen/fun.py +++ b/bot/exts/evergreen/fun.py @@ -126,8 +126,11 @@ class Fun(Cog): if not char.isascii() or not char.isalpha() or char.isspace(): yield char continue + case_start = 65 if char.isupper() else 97 - yield chr((ord(char) - case_start + offset) % 26 + case_start) + true_offset = (ord(char) - case_start + offset) % 26 + + yield chr(case_start + true_offset) def conversion_func(text: str) -> str: """Encrypts the given string using the Caesar Cipher.""" -- cgit v1.2.3 From c7f6489453ccad4ec10bd316a641461ee8ca4c94 Mon Sep 17 00:00:00 2001 From: PureFunctor Date: Thu, 2 Jul 2020 19:31:44 +0800 Subject: Add 'enc'/'dec' aliases for encrypt/decrypt --- bot/exts/evergreen/fun.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'bot/exts/evergreen/fun.py') diff --git a/bot/exts/evergreen/fun.py b/bot/exts/evergreen/fun.py index 5f5c3718..31dba936 100644 --- a/bot/exts/evergreen/fun.py +++ b/bot/exts/evergreen/fun.py @@ -151,7 +151,7 @@ class Fun(Cog): await ctx.send(content=converted_text, embed=embed) - @caesarcipher_group.command(name="encrypt", aliases=("rightshift", "rshift")) + @caesarcipher_group.command(name="encrypt", aliases=("rightshift", "rshift", "enc",)) async def caesarcipher_encrypt(self, ctx: Context, offset: int, *, msg: Union[Message, str]) -> None: """ Given a positive integer `offset`, encrypt the given `msg`. @@ -165,7 +165,7 @@ class Fun(Cog): else: await self._caesar_cipher(ctx, offset, msg) - @caesarcipher_group.command(name="decrypt", aliases=("leftshift", "lshift")) + @caesarcipher_group.command(name="decrypt", aliases=("leftshift", "lshift", "dec",)) async def caesarcipher_decrypt(self, ctx: Context, offset: int, *, msg: Union[Message, str]) -> None: """ Given a positive integer `offset`, decrypt the given `msg`. -- cgit v1.2.3 From 411db10969387fbb8e89f87c78a39dc580cc6498 Mon Sep 17 00:00:00 2001 From: PureFunctor Date: Wed, 15 Jul 2020 15:03:13 +0800 Subject: Refactor translation methods to avoid repetition --- bot/exts/evergreen/fun.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'bot/exts/evergreen/fun.py') diff --git a/bot/exts/evergreen/fun.py b/bot/exts/evergreen/fun.py index 31dba936..759a9e2a 100644 --- a/bot/exts/evergreen/fun.py +++ b/bot/exts/evergreen/fun.py @@ -111,15 +111,21 @@ class Fun(Cog): await ctx.send(embed=embed) @staticmethod - async def _caesar_cipher(ctx: Context, offset: int, msg: Union[Message, str]) -> None: + async def _caesar_cipher(ctx: Context, offset: int, msg: Union[Message, str], left_shift: bool = False) -> None: """ - Given an integer `offset`, translates and sends the given `msg`. + Given a positive integer `offset`, translates and sends the given `msg`. - A positive `offset` will cause the letters to shift right, while - a negative `offset` will cause the letters to shift left. + Performs a right shift by default unless `left_shift` is specified as `True`. Also accepts a valid Discord Message ID or link. """ + if offset < 0: + await ctx.send(":no_entry: Cannot use a negative offset.") + return + + if left_shift: + offset = -offset + def caesar_func(text: str) -> Iterable[str]: """Implements a lazy Caesar Cipher algorithm.""" for char in text: @@ -160,10 +166,7 @@ class Fun(Cog): Also accepts a valid Discord Message ID or link. """ - if offset < 0: - await ctx.send(":no_entry: Cannot use a negative offset.") - else: - await self._caesar_cipher(ctx, offset, msg) + await self._caesar_cipher(ctx, offset, msg, False) @caesarcipher_group.command(name="decrypt", aliases=("leftshift", "lshift", "dec",)) async def caesarcipher_decrypt(self, ctx: Context, offset: int, *, msg: Union[Message, str]) -> None: @@ -174,10 +177,7 @@ class Fun(Cog): Also accepts a valid Discord Message ID or link. """ - if offset < 0: - await ctx.send(":no_entry: Cannot use a negative offset.") - else: - await self._caesar_cipher(ctx, -offset, msg) + await self._caesar_cipher(ctx, offset, msg, True) @staticmethod async def _get_text_and_embed(ctx: Context, text: str) -> Tuple[str, Union[Embed, None]]: -- cgit v1.2.3 From 86387796ca671a47d7f7a7740b63980e6d0346b6 Mon Sep 17 00:00:00 2001 From: PureFunctor Date: Wed, 29 Jul 2020 12:37:16 +0800 Subject: Explicitly pass left_shift as a keyword argument --- bot/exts/evergreen/fun.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'bot/exts/evergreen/fun.py') diff --git a/bot/exts/evergreen/fun.py b/bot/exts/evergreen/fun.py index 759a9e2a..5a499270 100644 --- a/bot/exts/evergreen/fun.py +++ b/bot/exts/evergreen/fun.py @@ -166,7 +166,7 @@ class Fun(Cog): Also accepts a valid Discord Message ID or link. """ - await self._caesar_cipher(ctx, offset, msg, False) + await self._caesar_cipher(ctx, offset, msg, left_shift=False) @caesarcipher_group.command(name="decrypt", aliases=("leftshift", "lshift", "dec",)) async def caesarcipher_decrypt(self, ctx: Context, offset: int, *, msg: Union[Message, str]) -> None: @@ -177,7 +177,7 @@ class Fun(Cog): Also accepts a valid Discord Message ID or link. """ - await self._caesar_cipher(ctx, offset, msg, True) + await self._caesar_cipher(ctx, offset, msg, left_shift=True) @staticmethod async def _get_text_and_embed(ctx: Context, text: str) -> Tuple[str, Union[Embed, None]]: -- cgit v1.2.3 From 2cde858674fa6b4828f1a91028a62fb986c874f0 Mon Sep 17 00:00:00 2001 From: Joe Banks Date: Thu, 20 Aug 2020 22:38:34 +0100 Subject: Temporarily remove message functionality from Fun Remove message link functionality from uwu and randomcase due to a security vulnerability --- bot/exts/evergreen/fun.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'bot/exts/evergreen/fun.py') diff --git a/bot/exts/evergreen/fun.py b/bot/exts/evergreen/fun.py index 67a4bae5..b2c0aad9 100644 --- a/bot/exts/evergreen/fun.py +++ b/bot/exts/evergreen/fun.py @@ -49,8 +49,6 @@ class Fun(Cog): async def uwu_command(self, ctx: Context, *, text: str) -> None: """ Converts a given `text` into it's uwu equivalent. - - Also accepts a valid discord Message ID or link. """ conversion_func = functools.partial( utils.replace_many, replacements=UWU_WORDS, ignore_case=True, match_case=True @@ -69,8 +67,6 @@ class Fun(Cog): async def randomcase_command(self, ctx: Context, *, text: str) -> None: """ Randomly converts the casing of a given `text`. - - Also accepts a valid discord Message ID or link. """ def conversion_func(text: str) -> str: """Randomly converts the casing of a given string.""" @@ -97,12 +93,14 @@ class Fun(Cog): Union[Embed, None]: The embed if found in the valid Message, else None """ embed = None - message = await Fun._get_discord_message(ctx, text) - if isinstance(message, Message): - text = message.content - # Take first embed because we can't send multiple embeds - if message.embeds: - embed = message.embeds[0] + + # message = await Fun._get_discord_message(ctx, text) + # if isinstance(message, Message): + # text = message.content + # # Take first embed because we can't send multiple embeds + # if message.embeds: + # embed = message.embeds[0] + return (text, embed) @staticmethod -- cgit v1.2.3 From 09553df414dc225d2857c100a8cf02eaeeca4d47 Mon Sep 17 00:00:00 2001 From: Joe Banks Date: Thu, 20 Aug 2020 22:45:56 +0100 Subject: Update fun.py to satisfy the linter --- bot/exts/evergreen/fun.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'bot/exts/evergreen/fun.py') diff --git a/bot/exts/evergreen/fun.py b/bot/exts/evergreen/fun.py index b2c0aad9..0a5d22f9 100644 --- a/bot/exts/evergreen/fun.py +++ b/bot/exts/evergreen/fun.py @@ -47,9 +47,7 @@ class Fun(Cog): @commands.command(name="uwu", aliases=("uwuwize", "uwuify",)) async def uwu_command(self, ctx: Context, *, text: str) -> None: - """ - Converts a given `text` into it's uwu equivalent. - """ + """Converts a given `text` into it's uwu equivalent.""" conversion_func = functools.partial( utils.replace_many, replacements=UWU_WORDS, ignore_case=True, match_case=True ) @@ -65,9 +63,7 @@ class Fun(Cog): @commands.command(name="randomcase", aliases=("rcase", "randomcaps", "rcaps",)) async def randomcase_command(self, ctx: Context, *, text: str) -> None: - """ - Randomly converts the casing of a given `text`. - """ + """Randomly converts the casing of a given `text`.""" def conversion_func(text: str) -> str: """Randomly converts the casing of a given string.""" return "".join( -- cgit v1.2.3 From e0caf6787d862ba605a734fdf9b9363cdf100b85 Mon Sep 17 00:00:00 2001 From: Joe Banks Date: Thu, 20 Aug 2020 22:49:36 +0100 Subject: Remove whitespace from fun.py --- bot/exts/evergreen/fun.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bot/exts/evergreen/fun.py') diff --git a/bot/exts/evergreen/fun.py b/bot/exts/evergreen/fun.py index 0a5d22f9..36a13ac0 100644 --- a/bot/exts/evergreen/fun.py +++ b/bot/exts/evergreen/fun.py @@ -89,7 +89,7 @@ class Fun(Cog): Union[Embed, None]: The embed if found in the valid Message, else None """ embed = None - + # message = await Fun._get_discord_message(ctx, text) # if isinstance(message, Message): # text = message.content -- cgit v1.2.3 From c8ba498d34fbbc9cd8ac49092d19fafe1f97cefa Mon Sep 17 00:00:00 2001 From: Gustav Odinger Date: Wed, 16 Sep 2020 23:50:10 +0200 Subject: Update .roll to use new dice emojis - Resolves #440 --- bot/constants.py | 12 ++++++------ bot/exts/evergreen/fun.py | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'bot/exts/evergreen/fun.py') diff --git a/bot/constants.py b/bot/constants.py index 295bb90b..6605882d 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -108,12 +108,12 @@ class Emojis: trashcan = "<:trashcan:637136429717389331>" ok_hand = ":ok_hand:" - terning1 = "<:terning1:431249668983488527>" - terning2 = "<:terning2:462339216987127808>" - terning3 = "<:terning3:431249694467948544>" - terning4 = "<:terning4:579980271475228682>" - terning5 = "<:terning5:431249716328792064>" - terning6 = "<:terning6:431249726705369098>" + dice_1 = "<:dice_1:755891608859443290>" + dice_2 = "<:dice_2:755891608741740635>" + dice_3 = "<:dice_3:755891608251138158>" + dice_4 = "<:dice_4:755891607882039327>" + dice_5 = "<:dice_5:755891608091885627>" + dice_6 = "<:dice_6:755891607680843838>" issue = "<:IssueOpen:629695470327037963>" issue_closed = "<:IssueClosed:629695470570307614>" diff --git a/bot/exts/evergreen/fun.py b/bot/exts/evergreen/fun.py index 36a13ac0..1a7ebb90 100644 --- a/bot/exts/evergreen/fun.py +++ b/bot/exts/evergreen/fun.py @@ -41,7 +41,7 @@ class Fun(Cog): elif num_rolls < 1: output = ":no_entry: You must roll at least once." for _ in range(num_rolls): - terning = f"terning{random.randint(1, 6)}" + terning = f"dice_{random.randint(1, 6)}" output += getattr(Emojis, terning, '') await ctx.send(output) -- cgit v1.2.3 From f1ac62822d070d5df3a2cc9d13dc018149c55898 Mon Sep 17 00:00:00 2001 From: Gustav Odinger Date: Thu, 17 Sep 2020 00:32:55 +0200 Subject: Update variable name from terning to dice --- bot/exts/evergreen/fun.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'bot/exts/evergreen/fun.py') diff --git a/bot/exts/evergreen/fun.py b/bot/exts/evergreen/fun.py index 1a7ebb90..b0240c45 100644 --- a/bot/exts/evergreen/fun.py +++ b/bot/exts/evergreen/fun.py @@ -41,8 +41,8 @@ class Fun(Cog): elif num_rolls < 1: output = ":no_entry: You must roll at least once." for _ in range(num_rolls): - terning = f"dice_{random.randint(1, 6)}" - output += getattr(Emojis, terning, '') + dice = f"dice_{random.randint(1, 6)}" + output += getattr(Emojis, dice, '') await ctx.send(output) @commands.command(name="uwu", aliases=("uwuwize", "uwuify",)) -- cgit v1.2.3 From 98718712ab38ecb98970ade58fd1afd6796f8718 Mon Sep 17 00:00:00 2001 From: PureFunctor Date: Fri, 18 Sep 2020 20:30:56 +0800 Subject: Make the encryption function top-level This makes caesar_func a top-level function and renames it to caesar_cipher. --- bot/exts/evergreen/fun.py | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) (limited to 'bot/exts/evergreen/fun.py') diff --git a/bot/exts/evergreen/fun.py b/bot/exts/evergreen/fun.py index 5a499270..3fd0f275 100644 --- a/bot/exts/evergreen/fun.py +++ b/bot/exts/evergreen/fun.py @@ -28,6 +28,26 @@ UWU_WORDS = { } +def caesar_cipher(text: str, offset: int) -> Iterable[str]: + """ + Implements a lazy Caesar Cipher algorithm. + + Encrypts a `text` given a specific integer `offset`. The sign + of the `offset` dictates the direction in which it shifts to, + with a negative value shifting to the left, and a positive + value shifting to the right. + """ + for char in text: + if not char.isascii() or not char.isalpha() or char.isspace(): + yield char + continue + + case_start = 65 if char.isupper() else 97 + true_offset = (ord(char) - case_start + offset) % 26 + + yield chr(case_start + true_offset) + + class Fun(Cog): """A collection of general commands for fun.""" @@ -126,21 +146,9 @@ class Fun(Cog): if left_shift: offset = -offset - def caesar_func(text: str) -> Iterable[str]: - """Implements a lazy Caesar Cipher algorithm.""" - for char in text: - if not char.isascii() or not char.isalpha() or char.isspace(): - yield char - continue - - case_start = 65 if char.isupper() else 97 - true_offset = (ord(char) - case_start + offset) % 26 - - yield chr(case_start + true_offset) - def conversion_func(text: str) -> str: """Encrypts the given string using the Caesar Cipher.""" - return "".join(caesar_func(text)) + return "".join(caesar_cipher(text, offset)) is_message = isinstance(msg, Message) -- cgit v1.2.3 From d6b331080d57fb122eb63644382717f2fc4860c7 Mon Sep 17 00:00:00 2001 From: PureFunctor Date: Fri, 18 Sep 2020 20:39:38 +0800 Subject: Refactor methods to use _get_text_and_embed This changes the converters used by caesarcipher_encrypt and caesarcipher_decrypt in order to accomodate for the manual conversion that _get_text_and_embed does, which allows for this feature to be easily disabled. --- bot/exts/evergreen/fun.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'bot/exts/evergreen/fun.py') diff --git a/bot/exts/evergreen/fun.py b/bot/exts/evergreen/fun.py index 3fd0f275..8235d072 100644 --- a/bot/exts/evergreen/fun.py +++ b/bot/exts/evergreen/fun.py @@ -131,7 +131,7 @@ class Fun(Cog): await ctx.send(embed=embed) @staticmethod - async def _caesar_cipher(ctx: Context, offset: int, msg: Union[Message, str], left_shift: bool = False) -> None: + async def _caesar_cipher(ctx: Context, offset: int, msg: str, left_shift: bool = False) -> None: """ Given a positive integer `offset`, translates and sends the given `msg`. @@ -150,10 +150,7 @@ class Fun(Cog): """Encrypts the given string using the Caesar Cipher.""" return "".join(caesar_cipher(text, offset)) - is_message = isinstance(msg, Message) - - text = msg.content if is_message else msg - embed = msg.embeds[0] if is_message and msg.embeds else None + text, embed = await Fun._get_text_and_embed(ctx, msg) if embed is not None: embed = Fun._convert_embed(conversion_func, embed) @@ -166,7 +163,7 @@ class Fun(Cog): await ctx.send(content=converted_text, embed=embed) @caesarcipher_group.command(name="encrypt", aliases=("rightshift", "rshift", "enc",)) - async def caesarcipher_encrypt(self, ctx: Context, offset: int, *, msg: Union[Message, str]) -> None: + async def caesarcipher_encrypt(self, ctx: Context, offset: int, *, msg: str) -> None: """ Given a positive integer `offset`, encrypt the given `msg`. @@ -177,7 +174,7 @@ class Fun(Cog): await self._caesar_cipher(ctx, offset, msg, left_shift=False) @caesarcipher_group.command(name="decrypt", aliases=("leftshift", "lshift", "dec",)) - async def caesarcipher_decrypt(self, ctx: Context, offset: int, *, msg: Union[Message, str]) -> None: + async def caesarcipher_decrypt(self, ctx: Context, offset: int, *, msg: str) -> None: """ Given a positive integer `offset`, decrypt the given `msg`. -- cgit v1.2.3 From 0567a6fe099465b2a36df7818113fadc8ff1c7d7 Mon Sep 17 00:00:00 2001 From: Kieran Siek Date: Fri, 18 Sep 2020 23:00:23 +0800 Subject: Fix typo in casercipher help. --- bot/exts/evergreen/fun.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bot/exts/evergreen/fun.py') diff --git a/bot/exts/evergreen/fun.py b/bot/exts/evergreen/fun.py index 8235d072..c5f8f9c8 100644 --- a/bot/exts/evergreen/fun.py +++ b/bot/exts/evergreen/fun.py @@ -117,7 +117,7 @@ class Fun(Cog): """ Translates a message using the Caesar Cipher. - See `decrpyt`, `encrypt`, and `info` subcommands. + See `decrypt`, `encrypt`, and `info` subcommands. """ if ctx.invoked_subcommand is None: await ctx.invoke(self.bot.get_command("help"), "caesarcipher") -- cgit v1.2.3 From dc63f50d2445c628806e9ac4f08d5ece6c72b18a Mon Sep 17 00:00:00 2001 From: kosayoda Date: Fri, 18 Sep 2020 23:33:56 +0800 Subject: Stop users from viewing messages they shouldn't. Using a user token, a user could fetch the message ID of a message in any channel, which may leak information when potential Message objects are automatically converted and parsed. Now, the bot will only retrive text from a valid Message object if the user has read permissions for the message the channel is in. --- bot/exts/evergreen/fun.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'bot/exts/evergreen/fun.py') diff --git a/bot/exts/evergreen/fun.py b/bot/exts/evergreen/fun.py index 2f575c1c..e6cdf716 100644 --- a/bot/exts/evergreen/fun.py +++ b/bot/exts/evergreen/fun.py @@ -181,18 +181,22 @@ class Fun(Cog): """ Attempts to extract the text and embed from a possible link to a discord Message. + Does not retrieve the text and embed from the Message if it is in a channel the user does + not have read permissions in. + Returns a tuple of: str: If `text` is a valid discord Message, the contents of the message, else `text`. Union[Embed, None]: The embed if found in the valid Message, else None """ embed = None - # message = await Fun._get_discord_message(ctx, text) - # if isinstance(message, Message): - # text = message.content - # # Take first embed because we can't send multiple embeds - # if message.embeds: - # embed = message.embeds[0] + msg = await Fun._get_discord_message(ctx, text) + # Ensure the user has read permissions for the channel the message is in + if isinstance(msg, Message) and ctx.author.permissions_in(msg.channel).read_messages: + text = msg.content + # Take first embed because we can't send multiple embeds + if msg.embeds: + embed = msg.embeds[0] return (text, embed) -- cgit v1.2.3 From 27d29c0981b5e846d6b5b130d2b07a4927950dab Mon Sep 17 00:00:00 2001 From: scragly <29337040+scragly@users.noreply.github.com> Date: Mon, 21 Sep 2020 18:31:13 +1000 Subject: Prevent uwu output from pinging globally allowed roles. --- bot/exts/evergreen/fun.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'bot/exts/evergreen/fun.py') diff --git a/bot/exts/evergreen/fun.py b/bot/exts/evergreen/fun.py index b0240c45..5d4743e4 100644 --- a/bot/exts/evergreen/fun.py +++ b/bot/exts/evergreen/fun.py @@ -5,7 +5,7 @@ from typing import Callable, Tuple, Union from discord import Embed, Message from discord.ext import commands -from discord.ext.commands import Bot, Cog, Context, MessageConverter +from discord.ext.commands import Bot, Cog, Context, MessageConverter, clean_content from bot import utils from bot.constants import Emojis @@ -46,7 +46,7 @@ class Fun(Cog): await ctx.send(output) @commands.command(name="uwu", aliases=("uwuwize", "uwuify",)) - async def uwu_command(self, ctx: Context, *, text: str) -> None: + async def uwu_command(self, ctx: Context, *, text: clean_content(fix_channel_mentions=True)) -> None: """Converts a given `text` into it's uwu equivalent.""" conversion_func = functools.partial( utils.replace_many, replacements=UWU_WORDS, ignore_case=True, match_case=True -- cgit v1.2.3 From 1c0afb81dbd690c4051ee90f59d63bb171d1656f Mon Sep 17 00:00:00 2001 From: scragly <29337040+scragly@users.noreply.github.com> Date: Mon, 21 Sep 2020 20:12:58 +1000 Subject: Use clean_content when fetching linked msgs for fun commands. --- bot/exts/evergreen/fun.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'bot/exts/evergreen/fun.py') diff --git a/bot/exts/evergreen/fun.py b/bot/exts/evergreen/fun.py index 1668982b..de6a92c6 100644 --- a/bot/exts/evergreen/fun.py +++ b/bot/exts/evergreen/fun.py @@ -87,7 +87,7 @@ class Fun(Cog): await ctx.send(content=converted_text, embed=embed) @commands.command(name="randomcase", aliases=("rcase", "randomcaps", "rcaps",)) - async def randomcase_command(self, ctx: Context, *, text: str) -> None: + async def randomcase_command(self, ctx: Context, *, text: clean_content(fix_channel_mentions=True)) -> None: """Randomly converts the casing of a given `text`.""" def conversion_func(text: str) -> str: """Randomly converts the casing of a given string.""" @@ -193,7 +193,7 @@ class Fun(Cog): msg = await Fun._get_discord_message(ctx, text) # Ensure the user has read permissions for the channel the message is in if isinstance(msg, Message) and ctx.author.permissions_in(msg.channel).read_messages: - text = msg.content + text = msg.clean_content # Take first embed because we can't send multiple embeds if msg.embeds: embed = msg.embeds[0] -- cgit v1.2.3