Skip to content

Commit

Permalink
[MorseCode] Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Kreusada committed Nov 28, 2024
1 parent aa2ff22 commit 1dc6bc0
Show file tree
Hide file tree
Showing 7 changed files with 232 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cogs.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

75 changes: 75 additions & 0 deletions docs/cog_morsecode.rst
Original file line number Diff line number Diff line change
@@ -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 <https://github.com/Kreusada/Kreusada-Cogs/issues>`_.

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 <https://discord.gg/GET4DVk>`_,
I have my own channel over there at #support_kreusada-cogs. Feel free to join my
`personal server <https://discord.gg/JmCFyq7>`_ whilst you're here.
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Useful Links
cog_flags
cog_messagedeleter
cog_minifier
cog_morsecode
cog_onthisday
cog_pypi
cog_qr
Expand Down
75 changes: 75 additions & 0 deletions morsecode/README.rst
Original file line number Diff line number Diff line change
@@ -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 <https://github.com/Kreusada/Kreusada-Cogs/issues>`_.

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 <https://discord.gg/GET4DVk>`_,
I have my own channel over there at #support_kreusada-cogs. Feel free to join my
`personal server <https://discord.gg/JmCFyq7>`_ whilst you're here.
56 changes: 56 additions & 0 deletions morsecode/__init__.py
Original file line number Diff line number Diff line change
@@ -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())
23 changes: 23 additions & 0 deletions morsecode/info.json
Original file line number Diff line number Diff line change
@@ -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"
}
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
'flags',
'messagedeleter',
'minifier',
'morsecode',
'onthisday',
'pypi',
'qr',
Expand Down

0 comments on commit 1dc6bc0

Please sign in to comment.