def on_regexp(self, regexp):
"""
Creates a decorator that registers a regexp command handler.
The regexp command handler takes as arguments:
1. The bot instance
2. The command sender
3. The command recipient, usually a channel
4. The match object, for any groups you might wanna extract.
The regexp is searched, not just matched.
Your handler might get called multiple times per message,
depending on the amount of matches.
"""
regexp = re.compile(regexp)
def _inner(func):
if not inspect.iscoroutinefunction(func):
raise ValueError("You can only register coroutines!")
self._regexp_callbacks.setdefault(regexp, [])\
.append(func)
return func
return _inner
评论列表
文章目录