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
Changes from 1 commit
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
21 changes: 8 additions & 13 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,7 +112,7 @@ def __init__(
if _function is not None:
self.name = _function.__qualname__

argspec = list(inspect.signature(_function).parameters.keys())
argspec = list(islice(inspect.signature(_function).parameters.keys(), 2))
if not argspec[:2] == ["self", "message"]:
ArtemIsmagilov marked this conversation as resolved.
Show resolved Hide resolved
raise TypeError(
"Any message listener function should at least have the positional"
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
Loading