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

rewrite function module of init args #533

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
23 changes: 9 additions & 14 deletions mmpy_bot/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import re
import shlex
from abc import ABC, abstractmethod
from itertools import islice
from typing import TYPE_CHECKING, Callable, Optional, Sequence, Union

import click
Expand Down Expand Up @@ -85,15 +86,11 @@ def __init__(
self.needs_mention = needs_mention
self.silence_fail_msg = silence_fail_msg

if allowed_users is None:
self.allowed_users = []
else:
self.allowed_users = [user.lower() for user in allowed_users]
self.allowed_users = [user.lower() for user in (allowed_users or [])]

if allowed_channels is None:
self.allowed_channels = []
else:
self.allowed_channels = [channel.lower() for channel in allowed_channels]
self.allowed_channels = [
channel.lower() for channel in (allowed_channels or [])
]

# Default for non-click functions
_function: Union[Callable, click.Command] = self.function
Expand All @@ -115,8 +112,8 @@ def __init__(
if _function is not None:
self.name = _function.__qualname__

argspec = list(inspect.signature(_function).parameters.keys())
if not argspec[:2] == ["self", "message"]:
argspec = list(inspect.signature(_function).parameters)[:2]
if argspec != ["self", "message"]:
raise TypeError(
"Any message listener function should at least have the positional"
f" arguments `self` and `message`, but function {self.name} has"
Expand Down Expand Up @@ -187,11 +184,9 @@ def listen_to(
"""Wrap the given function in a MessageFunction class so we can register some
properties."""

if allowed_users is None:
allowed_users = []
allowed_users = allowed_users or []

if allowed_channels is None:
allowed_channels = []
allowed_channels = allowed_users or []

def wrapped_func(func):
reg = regexp
Expand Down
2 changes: 1 addition & 1 deletion tests/integration_tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def expect_reply(driver: Driver, post: Dict, wait=RESPONSE_TIMEOUT, retries=1):
reply = thread_info["posts"][reply_id]
break

if not reply:
if reply is None:
raise ValueError("Expected a response, but didn't get any!")

return reply
Expand Down
Loading