Skip to content
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

feat: add .yoda command #1656

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

marcuserlandsson
Copy link

Relevant Issues

Closes #494

Description

Implemented the .yoda command, which converts input text to Yoda-like speech according to the description in issue #494. Also includes unit tests to verify the functionality of the file.

Did you:

willeStjerna and others added 13 commits March 6, 2025 21:14
Details: added a new file yadaify.py which implements the yoda speech commands. When the command is called with ".yoda <text>" it will transform the text into Yoda-like speech.
A basic tutorial in how to run tests
Add a file for putting uml diagrams of the repo for easier understanding
Makes the pull request eiser to handle.
Copy link
Contributor

@wookie184 wookie184 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is super cool, nice work!

I have added a few comments. There are definitely extensions that could be made to the functionality here, such as better preservation/handling of punctuation, but since language is sort of complex it's sort of an endless task so I wouldn't expect anything more for this PR.

One other thing, CI is currently failing because of trailing whitespace in the file, take a look at, make sure you run poetry run task precommit to install checks when you commit to fix this. (you can also run poetry run task lint to fix it).

Comment on lines +18 to +19
if len(words) < 3:
return sentence + "."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason this doesn't return None, as because it doesn't sentences with less than 3 words don't get the "Yodafication this doesn't need, wookie!" message even though they weren't changed.

I think you could also just remove the check, it doesn't seem like it would break anything lower down.

Comment on lines +45 to +46
if not text:
return # Help message handled by Discord.py's help system
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you just type .yoda, currently nothing is output. The command's help or some sort of message should be sent.

Comment on lines +1 to +78
import pytest
from unittest.mock import AsyncMock, MagicMock, patch
from bot.exts.fun.yodaify import Yodaify


@pytest.mark.asyncio
@patch("bot.exts.fun.yodaify.Yodaify.yodaify", new_callable=AsyncMock)
async def test_yodaify_command_is_called(mock_yodaify):
"""
Requirement 1 Bot-command: When a user writes .yoda <text> it runs the function.
"""
ctx = AsyncMock()

# Simulate a user writing ".yodaify I am driving a car."
await mock_yodaify(ctx, text="I am driving a car.")

# Verify that the command was indeed called with the expected arguments
mock_yodaify.assert_awaited_once_with(ctx, text="I am driving a car.")


async def yodaify_conversion_helper(text, converted_text):
"""
Requirement 5 Format: The returned text should have the format object-subject-verb.
Requirement 7 Consistency: No words should be lost during the conversion.
Requirement 8 Capitalization: The sentence should be capitalized correctly.
"""

cog = Yodaify()

mock_ctx = MagicMock()
mock_ctx.author.display_name = "TestUser"
mock_ctx.send = AsyncMock()
mock_ctx.author.edit = AsyncMock()

await cog.yodaify.callback(cog, mock_ctx, text=text)

# Ensure a message was sent
mock_ctx.send.assert_called_once()
args, kwargs = mock_ctx.send.call_args
sent_message = args[0]
assert sent_message == converted_text, f"Unexpected sent message: {sent_message}"


@pytest.mark.asyncio
async def test_yodaify_conversion_1():
await yodaify_conversion_helper("I like trains.", ">>> " + "Trains, I like.")


@pytest.mark.asyncio
async def test_yodaify_conversion_2():
await yodaify_conversion_helper("I am driving a car.", ">>> " + "Driving a car, I am.")


@pytest.mark.asyncio
async def test_yodaify_conversion_3():
await yodaify_conversion_helper("She likes my new van.", ">>> " + "My new van, she likes.")


@pytest.mark.asyncio
async def test_yodaify_conversion_4():
await yodaify_conversion_helper("We should get out of here.", ">>> " + "Get out of here, we should.")


@pytest.mark.asyncio
async def test_yodaify_invalid_sentecne():
"""
Requirement 6 Invalid sentence: If no changes to the format can be made, it should return: “Yodafication this doesn't need {username}!” + the original text.
"""
await yodaify_conversion_helper("sghafuj fhaslkhglf ajshflka.", "Yodafication this doesn't need, TestUser!" + "\n>>> " + "sghafuj fhaslkhglf ajshflka.")


@pytest.mark.asyncio
async def test_yodaify_multiple_sentances():
"""
Requirement 9 Multiple sentences: If there are multiple sentences in the input, they should be converted separately.
"""
await yodaify_conversion_helper("I like trains. I am driving a car. She likes my new van.", ">>> " + "Trains, I like. Driving a car, I am. My new van, she likes.")

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I appreciate the effort put in to write tests, though I'm not sure about these since we don't currently have tests on this project.

If we did want to keep them we would want to ensure they are run in CI, documented in the contributing guide, and dependencies are added, However, we have previously decided against this to keep this project as friendly as possible to new contributors.

@wookie184 wookie184 added type: feature Relating to the functionality of the application. status: waiting for author Waiting for author to address a review or respond to a comment category: fun Related to fun and games labels Apr 8, 2025
@wookie184 wookie184 mentioned this pull request Apr 8, 2025
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: fun Related to fun and games status: waiting for author Waiting for author to address a review or respond to a comment type: feature Relating to the functionality of the application.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Yoda Text Command
4 participants