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

Minor updates to PR #48 #50

Merged
merged 2 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Changelog
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Version 0.6.15 unreleased
* Add .python-version in preferred order to support pyenv.
* Use conftest.py to explicitly set the time zone for all unit tests.
* Add Sphinx configuration path to .readthedocs.yml.
* Ignore commands containing numbers or starting with channel (by @achow101).

Version 0.6.14 08 Jan 2025

Expand Down
4 changes: 2 additions & 2 deletions src/hcoopmeetbotlogic/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,15 +273,15 @@ def list_commands() -> List[str]:

def dispatch(meeting: Meeting, context: Context, message: TrackedMessage) -> None:
"""Dispatch any command contained in the message to the dispatcher method with the matching name."""
if message.payload.lower().strip().startswith(meeting.channel.lower()):
return
operation_match = _OPERATION_REGEX.match(message.payload)
url_match = _URL_REGEX.match(message.payload)
if operation_match:
operation = operation_match.group(_OPERATION_GROUP).lower().strip()
operand = operation_match.group(_OPERAND_GROUP).strip()
if hasattr(_DISPATCHER, "%s%s" % (_METHOD_PREFIX, operation)):
getattr(_DISPATCHER, "%s%s" % (_METHOD_PREFIX, operation))(meeting, context, operation, operand, message)
elif message.payload.lower().strip().startswith(meeting.channel.lower()):
return
else:
context.send_reply("Unknown command: #%s" % operation)
elif url_match:
Expand Down
10 changes: 4 additions & 6 deletions tests/test_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


def run_dispatch(payload, operation, operand, method):
meeting = MagicMock()
meeting = MagicMock(channel="#channel")
context = MagicMock()
message = MagicMock(payload=payload)
method.reset_mock() # so we can test same method with different scenarios
Expand Down Expand Up @@ -88,7 +88,7 @@ def test_dispatch_valid_link(self, dispatcher, protocol):
@patch("hcoopmeetbotlogic.command._DISPATCHER")
def test_dispatch_invalid_link(self, dispatcher, protocol):
url = "%s://whatever" % protocol
meeting = MagicMock()
meeting = MagicMock(channel="#channel")
context = MagicMock()
message = MagicMock(payload=url)
dispatch(meeting, context, message)
Expand Down Expand Up @@ -127,7 +127,7 @@ def test_dispatch_valid_command(self, dispatcher):
@patch("hcoopmeetbotlogic.command.hasattr")
@patch("hcoopmeetbotlogic.command.getattr")
def test_dispatch_invalid_command(self, _getattr, _hasattr): # pylint: disable=redefined-builtin:
meeting = MagicMock(channel="chan")
meeting = MagicMock(channel="#channel")
context = MagicMock()
message = MagicMock(payload="#bogus")
_hasattr.return_value = False
Expand All @@ -139,9 +139,7 @@ def test_dispatch_invalid_command(self, _getattr, _hasattr): # pylint: disable=
@patch("hcoopmeetbotlogic.command.getattr")
def test_dispatch_non_commands(self, _getattr, _hasattr): # pylint: disable=redefined-builtin:
def run_ignored_dispatch(payload, channel=None):
if channel is None:
channel = "#channel"
meeting = MagicMock(channel=channel)
meeting = MagicMock(channel=channel if channel else "#channel")
context = MagicMock()
message = MagicMock(payload=payload)
_hasattr.return_value = False
Expand Down
Loading