def decorate(self, func): wrapper = super().decorate(func) wrapper.__doc__ = encode_docstring( add_header( add_header(parse_docstring(wrapper.__doc__), "Throttled", str(self.period)), "Throttle-Count", str(self.count))) return wrapper
def public_only(func): """Prevent an event-handler function from being called via private message Usage: @public_only def on_event(self, conn, event, ...): ... """ @functools.wraps(func) async def wrapper(self, conn, event, *args, **kwargs): if event.type == "pubmsg" or self.is_mod(event): return await func(self, conn, event, *args, **kwargs) else: source = irc.client.NickMask(event.source) conn.privmsg(source.nick, "That command cannot be used via private message.") wrapper.__doc__ = encode_docstring( add_header(parse_docstring(wrapper.__doc__), "Public-Only", "true")) return wrapper
def sub_only(func): """Prevent an event-handler function from being called by non-subscribers Usage: @sub_only def on_event(self, conn, event, ...): ... """ @functools.wraps(func) async def wrapper(self, conn, event, *args, **kwargs): if self.is_sub(event) or self.is_mod(event): return await func(self, conn, event, *args, **kwargs) else: log.info("Refusing %s due to not-a-sub" % func.__name__) source = irc.client.NickMask(event.source) conn.privmsg(source.nick, "That is a sub-only command.") return None wrapper.__doc__ = encode_docstring( add_header(parse_docstring(wrapper.__doc__), "Sub-Only", "true")) return wrapper
def mod_only(func): """Prevent an event-handler function from being called by non-moderators Usage: @mod_only def on_event(self, conn, event, ...): ... """ @functools.wraps(func) @asyncio.coroutine def wrapper(self, conn, event, *args, **kwargs): if self.is_mod(event): return (yield from func(self, conn, event, *args, **kwargs)) else: log.info("Refusing %s due to not-a-mod" % func.__name__) source = irc.client.NickMask(event.source) conn.privmsg(source.nick, "That is a mod-only command.") return None wrapper.__doc__ = encode_docstring( add_header(parse_docstring(wrapper.__doc__), "Mod-Only", "true")) return wrapper