Skip to content

Commit

Permalink
[TextEditor] v3.4.1 Implement typoglycemia
Browse files Browse the repository at this point in the history
  • Loading branch information
Kreusada committed Apr 15, 2024
1 parent 2e54490 commit cb23a2a
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 51 deletions.
56 changes: 31 additions & 25 deletions docs/cog_texteditor.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Through this guide, ``[p]`` will always represent your prefix. Replace

.. note::

This guide was last updated for version 3.4.0. Ensure
This guide was last updated for version 3.4.1. Ensure
that you are up to date by running ``[p]cog update texteditor``.

If there is something missing, or something that needs improving
Expand All @@ -30,54 +30,60 @@ Edit and manipulate with text.
Commands
--------

Here are all the commands included in this cog (23):
Here are all the commands included in this cog (24):

* ``[p]editor``
Base command for editing text.
Base command for editing text.
* ``[p]editor alternating <text>``
Convert the text to alternating case.
Convert the text to alternating case.
* ``[p]editor bullet <bullet> [items...]``
Bullet point a selection of items.
Bullet point a selection of items.
* ``[p]editor camu <text>``
Jumble text in Cambridge University style.
Jumble text in Cambridge University style.

https://www.mrc-cbu.cam.ac.uk/people/matt.davis/cmabridge/
* ``[p]editor charcount <text>``
Count the number of characters appearing in the text.
Count the number of characters appearing in the text.
* ``[p]editor formatnumber <number>``
Format a number with commas.
Format a number with commas.
* ``[p]editor lower <text>``
Convert the text to lowercase.
Convert the text to lowercase.
* ``[p]editor multiply <multiplier> <text>``
Multiply the text.
Multiply the text.
* ``[p]editor occurance <check> <text>``
Count how many times something appears in the text.
Count how many times something appears in the text.
* ``[p]editor permutate <text>``
Generate permutations for given combinations of words/digits.
Generate permutations for given combinations of words/digits.
* ``[p]editor remove <remove> <text>``
Remove something from the text.
Remove something from the text.
* ``[p]editor replace <text_to_replace> <replacement> <text>``
Replace certain parts of the text.
Replace certain parts of the text.
* ``[p]editor reverse <text>``
Reverse the text.
Reverse the text.
* ``[p]editor shlex <text>``
Shlex split a given string.
Shlex split a given string.
* ``[p]editor shuffle <text>``
Shuffle the word order in the text.
Shuffle the word order in the text.
* ``[p]editor snake <text>``
Convert all spaces to underscores.
Convert all spaces to underscores.
* ``[p]editor squash <text>``
Squash all the words into one.
Squash all the words into one.
* ``[p]editor swapcase <text>``
Swap the casing for text.
Swap the casing for text.
* ``[p]editor title <text>``
Convert the text to titlecase.
Convert the text to titlecase.
* ``[p]editor trim [trimmer= ] <text>``
Trim the outskirts of the text.
Trim the outskirts of the text.
* ``[p]editor typoglycemia <text>``
Scrambles all letters except the first and last letters in a word.

Aoccdrnig to a rscheearch at Cmabrigde Uinervtisy, it deosn't mttaer in waht oredr the ltteers in a wrod are, the olny iprmoetnt tihng is taht the frist and lsat ltteer be at the rghit pclae. The rset can be a toatl mses and you can sitll raed it wouthit porbelm. Tihs is bcuseae the huamn mnid deos not raed ervey lteter by istlef, but the wrod as a wlohe.
* ``[p]editor upper <text>``
Convert the text to uppercase.
Convert the text to uppercase.
* ``[p]editor wordcount <text>``
Count the number of words appearing in the text.
Count the number of words appearing in the text.
* ``[p]editor wrap <cut_length> [cut_words=True] <text>``
Wrap the text.
Wrap the text.

------------
Installation
Expand Down
56 changes: 31 additions & 25 deletions texteditor/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Through this guide, ``[p]`` will always represent your prefix. Replace

.. note::

This guide was last updated for version 3.4.0. Ensure
This guide was last updated for version 3.4.1. Ensure
that you are up to date by running ``[p]cog update texteditor``.

If there is something missing, or something that needs improving
Expand All @@ -30,54 +30,60 @@ Edit and manipulate with text.
Commands
--------

Here are all the commands included in this cog (23):
Here are all the commands included in this cog (24):

* ``[p]editor``
Base command for editing text.
Base command for editing text.
* ``[p]editor alternating <text>``
Convert the text to alternating case.
Convert the text to alternating case.
* ``[p]editor bullet <bullet> [items...]``
Bullet point a selection of items.
Bullet point a selection of items.
* ``[p]editor camu <text>``
Jumble text in Cambridge University style.
Jumble text in Cambridge University style.

https://www.mrc-cbu.cam.ac.uk/people/matt.davis/cmabridge/
* ``[p]editor charcount <text>``
Count the number of characters appearing in the text.
Count the number of characters appearing in the text.
* ``[p]editor formatnumber <number>``
Format a number with commas.
Format a number with commas.
* ``[p]editor lower <text>``
Convert the text to lowercase.
Convert the text to lowercase.
* ``[p]editor multiply <multiplier> <text>``
Multiply the text.
Multiply the text.
* ``[p]editor occurance <check> <text>``
Count how many times something appears in the text.
Count how many times something appears in the text.
* ``[p]editor permutate <text>``
Generate permutations for given combinations of words/digits.
Generate permutations for given combinations of words/digits.
* ``[p]editor remove <remove> <text>``
Remove something from the text.
Remove something from the text.
* ``[p]editor replace <text_to_replace> <replacement> <text>``
Replace certain parts of the text.
Replace certain parts of the text.
* ``[p]editor reverse <text>``
Reverse the text.
Reverse the text.
* ``[p]editor shlex <text>``
Shlex split a given string.
Shlex split a given string.
* ``[p]editor shuffle <text>``
Shuffle the word order in the text.
Shuffle the word order in the text.
* ``[p]editor snake <text>``
Convert all spaces to underscores.
Convert all spaces to underscores.
* ``[p]editor squash <text>``
Squash all the words into one.
Squash all the words into one.
* ``[p]editor swapcase <text>``
Swap the casing for text.
Swap the casing for text.
* ``[p]editor title <text>``
Convert the text to titlecase.
Convert the text to titlecase.
* ``[p]editor trim [trimmer= ] <text>``
Trim the outskirts of the text.
Trim the outskirts of the text.
* ``[p]editor typoglycemia <text>``
Scrambles all letters except the first and last letters in a word.

Aoccdrnig to a rscheearch at Cmabrigde Uinervtisy, it deosn't mttaer in waht oredr the ltteers in a wrod are, the olny iprmoetnt tihng is taht the frist and lsat ltteer be at the rghit pclae. The rset can be a toatl mses and you can sitll raed it wouthit porbelm. Tihs is bcuseae the huamn mnid deos not raed ervey lteter by istlef, but the wrod as a wlohe.
* ``[p]editor upper <text>``
Convert the text to uppercase.
Convert the text to uppercase.
* ``[p]editor wordcount <text>``
Count the number of words appearing in the text.
Count the number of words appearing in the text.
* ``[p]editor wrap <cut_length> [cut_words=True] <text>``
Wrap the text.
Wrap the text.

------------
Installation
Expand Down
21 changes: 20 additions & 1 deletion texteditor/texteditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class TextEditor(commands.Cog):
"""

__author__ = "Kreusada"
__version__ = "3.4.0"
__version__ = "3.4.1"

def __init__(self, bot):
self.bot = bot
Expand Down Expand Up @@ -218,3 +218,22 @@ async def editor_formatnumber(self, ctx: commands.Context, number: int):
async def editor_bullet(self, ctx: commands.Context, bullet: str, *items: str):
"""Bullet point a selection of items."""
await send_safe(ctx, "\n".join(f"{bullet} {item}" for item in items))

@editor.command(name="typoglycemia")
async def editor_typoglycemia(self, ctx: commands.Context, *, text: str):
"""Scrambles all letters except the first and last letters in a word.
Aoccdrnig to a rscheearch at Cmabrigde Uinervtisy, it deosn't mttaer in waht oredr the ltteers in a wrod are, the olny iprmoetnt tihng is taht the frist and lsat ltteer be at the rghit pclae. The rset can be a toatl mses and you can sitll raed it wouthit porbelm. Tihs is bcuseae the huamn mnid deos not raed ervey lteter by istlef, but the wrod as a wlohe."""
ret = []
for word in text.split():
if len(word) < 4:
ret.append(word)
continue
while True:
middle = list(word[1:-1])
random.shuffle(middle)
middle = "".join(middle)
if middle != word:
break
ret.append(word[0] + middle + word[-1])
await send_safe(ctx, " ".join(ret))

0 comments on commit cb23a2a

Please sign in to comment.