-
-
Notifications
You must be signed in to change notification settings - Fork 255
Add cases output in fun cog. #1457
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
Closed
Closed
Changes from 13 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
90625a1
Add 4 different case commands + helper function
JelmerKorten 494f7c8
Updated neutralise string for slight optimization.
JelmerKorten 54a4622
Removed spaces
JelmerKorten a03b682
Fixed end of file.
JelmerKorten 7bb7be4
Fixed ruff feedback.
JelmerKorten d701255
Extracted duplicate code into function.
JelmerKorten 1a4bc6a
Added BadArgument error when no text provided.
JelmerKorten 731ab4d
Changed error message for snakecase commands. -JK
JelmerKorten ddaeb14
Adjusted error message for casecommands. -JK
JelmerKorten 7ea86c9
Removed raise error, replaced with early return in helper function. -JK
JelmerKorten 1891f44
Corrected comments. -JK
JelmerKorten 1432558
Swap pascal/camel case to be correct. -JK
JelmerKorten c599e70
Adjust variable name. -JK
JelmerKorten 3686fd3
Redo to have less .join and .split -JK
JelmerKorten 67863ee
Removed the no longer required .split(). -JK
JelmerKorten 03d73f0
Changed regex command. -JK
JelmerKorten 79a2afe
Move neutralise string into conversion func. -JK
JelmerKorten File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,6 +1,6 @@ | ||||||
import json | ||||||
import random | ||||||
from collections.abc import Iterable | ||||||
from collections.abc import Callable, Iterable | ||||||
from pathlib import Path | ||||||
from typing import Literal | ||||||
|
||||||
|
@@ -51,6 +51,21 @@ def _get_random_die() -> str: | |||||
die_name = f"dice_{random.randint(1, 6)}" | ||||||
return getattr(Emojis, die_name) | ||||||
|
||||||
@staticmethod | ||||||
async def _clean_text(ctx: Context, text: str, conversion_func: Callable[[str], str]) -> tuple[str, Embed]: | ||||||
"""This groups the clean and convert functions into one so we can reuse this without duplicated code.""" | ||||||
text = await clean_text_or_reply(ctx, text) | ||||||
text, embed = await messages.get_text_and_embed(ctx, text) | ||||||
# Convert embed if it exists | ||||||
if embed is not None: | ||||||
embed = messages.convert_embed(conversion_func, embed) | ||||||
converted_text = conversion_func(text) | ||||||
converted_text = helpers.suppress_links(converted_text) | ||||||
# Don't put >>> if only embed present | ||||||
if converted_text: | ||||||
converted_text = f">>> {converted_text.lstrip('> ')}" | ||||||
return converted_text, embed | ||||||
|
||||||
@commands.command() | ||||||
async def roll(self, ctx: Context, num_rolls: int = 1) -> None: | ||||||
"""Outputs a number of random dice emotes (up to 6).""" | ||||||
|
@@ -68,17 +83,56 @@ def conversion_func(text: str) -> str: | |||||
return "".join( | ||||||
char.upper() if round(random.random()) else char.lower() for char in text | ||||||
) | ||||||
text = await clean_text_or_reply(ctx, text) | ||||||
text, embed = await messages.get_text_and_embed(ctx, text) | ||||||
# Convert embed if it exists | ||||||
if embed is not None: | ||||||
embed = messages.convert_embed(conversion_func, embed) | ||||||
converted_text = conversion_func(text) | ||||||
converted_text = helpers.suppress_links(converted_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) | ||||||
cleaned_text, embed = await self._clean_text(ctx, text, conversion_func) | ||||||
await ctx.send(content=cleaned_text, embed=embed) | ||||||
|
||||||
@commands.command(name="snakecase", aliases=("scase",)) | ||||||
async def snakecase_command(self, ctx: Context, *, text: str | None) -> None: | ||||||
"""Attempts to convert the provided string to snake_case.""" | ||||||
text = helpers.neutralise_string(text) | ||||||
def conversion_func(text: str) -> str: | ||||||
"""Converts the provided string to snake_case.""" | ||||||
return "_".join( | ||||||
text.split() | ||||||
) | ||||||
cleaned_text, embed = await self._clean_text(ctx, text, conversion_func) | ||||||
await ctx.send(content=cleaned_text, embed=embed) | ||||||
|
||||||
@commands.command(name="pascalcase", aliases=("pcase", "pascal",)) | ||||||
async def pascalcase_command(self, ctx: Context, *, text: str | None) -> None: | ||||||
"""Attempts to convert the provided string to PascalCase.""" | ||||||
text = helpers.neutralise_string(text) | ||||||
def conversion_func(text: str) -> str: | ||||||
"""Converts the provided string to PascalCase.""" | ||||||
return "".join( | ||||||
word.capitalize() for word in text.split() | ||||||
) | ||||||
cleaned_text, embed = await self._clean_text(ctx, text, conversion_func) | ||||||
await ctx.send(content=cleaned_text, embed=embed) | ||||||
|
||||||
@commands.command(name="screamingsnakecase", aliases=("screamsnake", "ssnake", "screamingsnake",)) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
How about having a |
||||||
async def screamingsnakecase_command(self, ctx: Context, *, text: str | None) -> None: | ||||||
"""Attempts to convert the provided string to SCREAMING_SNAKE_CASE.""" | ||||||
text = helpers.neutralise_string(text) | ||||||
def conversion_func(text: str) -> str: | ||||||
"""Converts the provided string to SCREAMING_SNAKE_CASE.""" | ||||||
return "_".join( | ||||||
word.upper() for word in text.split() | ||||||
) | ||||||
cleaned_text, embed = await self._clean_text(ctx, text, conversion_func) | ||||||
await ctx.send(content=cleaned_text, embed=embed) | ||||||
|
||||||
@commands.command(name="camelcase", aliases=("ccase", "camel",)) | ||||||
async def camelcase_command(self, ctx: Context, *, text: str | None) -> None: | ||||||
"""Attempts to convert the provided string to camelCase.""" | ||||||
text = helpers.neutralise_string(text) | ||||||
def conversion_func(text: str) -> str: | ||||||
"""Converts the provided string to camelCase.""" | ||||||
return "".join( | ||||||
word.capitalize() if i != 0 else word for i, word in enumerate(text.split()) | ||||||
) | ||||||
cleaned_text, embed = await self._clean_text(ctx, text, conversion_func) | ||||||
await ctx.send(content=cleaned_text, embed=embed) | ||||||
|
||||||
@commands.group(name="caesarcipher", aliases=("caesar", "cc",)) | ||||||
async def caesarcipher_group(self, ctx: Context) -> None: | ||||||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.