diff --git a/cogs.csv b/cogs.csv index 2667afb09..7332a07b4 100644 --- a/cogs.csv +++ b/cogs.csv @@ -8,6 +8,7 @@ EmbedCreator,"Create embeds using buttons, modals and dropdowns!",Tools,Kreusada Flags,Get the flag for a country,Tools,Kreusada MessageDeleter,"Delete messages from users and bots, inclusively or exclusively, in text channels.",Tools,Kreusada Minifier,Minify your code with python minifier,Tools,Kreusada +MorseCode,Encode and decode morse code.,Tools,Kreusada OnThisDay,"Find out what happened today, in multiple different years in history.",Fun,Kreusada PyPi,Get information about a package available on PyPi.,Tools,"Kreusada, OofChair" QR,Create QR codes.,Tools,Kreusada @@ -21,4 +22,3 @@ TextFont,Change the font of text through unicode alternatives.,"Fun, Tools",Kreu TongueTwisters,Generate tongue twisters,Fun,Kreusada TimeStamps,Produce Discord timestamps.,Tools,Kreusada UnicodeLookup,Search the unicode library for characters and names. Supports fuzzy searching.,Tools,Kreusada - diff --git a/docs/cog_morsecode.rst b/docs/cog_morsecode.rst new file mode 100644 index 000000000..b3a74b91c --- /dev/null +++ b/docs/cog_morsecode.rst @@ -0,0 +1,75 @@ +.. _morsecode: + +========= +MorseCode +========= + +This is the cog guide for the 'MorseCode' cog. This guide +contains the collection of commands which you can use in the cog. + +Through this guide, ``[p]`` will always represent your prefix. Replace +``[p]`` with your own prefix when you use these commands in Discord. + +.. note:: + + This guide was last updated for version 1.0.0. Ensure + that you are up to date by running ``[p]cog update morsecode``. + + If there is something missing, or something that needs improving + in this documentation, feel free to create an issue `here `_. + + This documentation is auto-generated everytime this cog receives an update. + +-------------- +About this cog +-------------- + +Encode and decode morse code. + +-------- +Commands +-------- + +Here are all the commands included in this cog (3): + ++---------------------+-------------------------------+ +| Command | Help | ++=====================+===============================+ +| ``[p]morse`` | Encode and decode morse code. | ++---------------------+-------------------------------+ +| ``[p]morse decode`` | Decode morse code. | ++---------------------+-------------------------------+ +| ``[p]morse encode`` | Encode morse code. | ++---------------------+-------------------------------+ + +------------ +Installation +------------ + +If you haven't added my repo before, lets add it first. We'll call it +"kreusada-cogs" here. + +.. code-block:: ini + + [p]repo add kreusada-cogs https://github.com/Kreusada/Kreusada-Cogs + +Now, we can install MorseCode. + +.. code-block:: ini + + [p]cog install kreusada-cogs morsecode + +Once it's installed, it is not loaded by default. Load it by running the following +command: + +.. code-block:: ini + + [p]load morsecode + +--------------- +Further Support +--------------- + +For more support, head over to the `cog support server `_, +I have my own channel over there at #support_kreusada-cogs. Feel free to join my +`personal server `_ whilst you're here. diff --git a/docs/index.rst b/docs/index.rst index 49200cc68..caf46fb9c 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -34,6 +34,7 @@ Useful Links cog_flags cog_messagedeleter cog_minifier + cog_morsecode cog_onthisday cog_pypi cog_qr diff --git a/morsecode/README.rst b/morsecode/README.rst new file mode 100644 index 000000000..b3a74b91c --- /dev/null +++ b/morsecode/README.rst @@ -0,0 +1,75 @@ +.. _morsecode: + +========= +MorseCode +========= + +This is the cog guide for the 'MorseCode' cog. This guide +contains the collection of commands which you can use in the cog. + +Through this guide, ``[p]`` will always represent your prefix. Replace +``[p]`` with your own prefix when you use these commands in Discord. + +.. note:: + + This guide was last updated for version 1.0.0. Ensure + that you are up to date by running ``[p]cog update morsecode``. + + If there is something missing, or something that needs improving + in this documentation, feel free to create an issue `here `_. + + This documentation is auto-generated everytime this cog receives an update. + +-------------- +About this cog +-------------- + +Encode and decode morse code. + +-------- +Commands +-------- + +Here are all the commands included in this cog (3): + ++---------------------+-------------------------------+ +| Command | Help | ++=====================+===============================+ +| ``[p]morse`` | Encode and decode morse code. | ++---------------------+-------------------------------+ +| ``[p]morse decode`` | Decode morse code. | ++---------------------+-------------------------------+ +| ``[p]morse encode`` | Encode morse code. | ++---------------------+-------------------------------+ + +------------ +Installation +------------ + +If you haven't added my repo before, lets add it first. We'll call it +"kreusada-cogs" here. + +.. code-block:: ini + + [p]repo add kreusada-cogs https://github.com/Kreusada/Kreusada-Cogs + +Now, we can install MorseCode. + +.. code-block:: ini + + [p]cog install kreusada-cogs morsecode + +Once it's installed, it is not loaded by default. Load it by running the following +command: + +.. code-block:: ini + + [p]load morsecode + +--------------- +Further Support +--------------- + +For more support, head over to the `cog support server `_, +I have my own channel over there at #support_kreusada-cogs. Feel free to join my +`personal server `_ whilst you're here. diff --git a/morsecode/__init__.py b/morsecode/__init__.py new file mode 100644 index 000000000..9f7efc9ea --- /dev/null +++ b/morsecode/__init__.py @@ -0,0 +1,56 @@ +from morse3 import Morse + +from redbot.core import commands +from redbot.core.utils import get_end_user_data_statement +from redbot.core.utils.chat_formatting import box, pagify + + +__red_end_user_data_statement__ = get_end_user_data_statement(__file__) + + +class MorseCode(commands.Cog): + """Encode and decode morse code.""" + + __author__ = "Kreusada" + __version__ = "1.0.0" + + def format_help_for_context(self, ctx: commands.Context) -> str: + context = super().format_help_for_context(ctx) + return f"{context}\n\nAuthor: {self.__author__}\nVersion: {self.__version__}" + + async def red_delete_data_for_user(self, **kwargs): + return + + @staticmethod + def safe_morse_encode(text: str): + try: + return Morse(text).stringToMorse() + except Exception as e: + return str(e) + + @staticmethod + def safe_morse_decode(morse_code: str): + try: + return Morse(morse_code).morseToString() + except Exception as e: + return str(e) + + @commands.group() + async def morse(self, ctx: commands.Context): + """Encode and decode morse code.""" + + @morse.command() + async def encode(self, ctx: commands.Context, *, text: str): + """Encode morse code.""" + for page in pagify(self.safe_morse_encode(text), page_length=1990): + await ctx.send(box(page)) + + @morse.command() + async def decode(self, ctx: commands.Context, *, morse_code: str): + """Decode morse code.""" + for page in pagify(self.safe_morse_decode(morse_code), page_length=1990): + await ctx.send(box(page)) + + +async def setup(bot): + await bot.add_cog(MorseCode()) diff --git a/morsecode/info.json b/morsecode/info.json new file mode 100644 index 000000000..60a75cee7 --- /dev/null +++ b/morsecode/info.json @@ -0,0 +1,23 @@ +{ + "author": [ + "Kreusada" + ], + "description": "Encode and decode morse code.", + "disabled": false, + "end_user_data_statement": "This cog does not persistently store data or metadata about users.", + "hidden": false, + "install_msg": "Thanks for installing, have fun. Please refer to my docs if you need any help: https://kreusadacogs.readthedocs.io/en/latest/cog_morsecode.html", + "name": "MorseCode", + "required_cogs": {}, + "requirements": [ + "morse3" + ], + "short": "Encode and decode morse code.", + "tags": [ + "Morse", + "Code", + "Encode", + "Decode" + ], + "type": "COG" +} \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 31160420e..be54a1c1f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -33,6 +33,7 @@ 'flags', 'messagedeleter', 'minifier', + 'morsecode', 'onthisday', 'pypi', 'qr',