Source code for slackminion.plugins.test

from ..plugin import cmd, webhook

try:
    from slackminion.plugins.core import commit
except ImportError:
    commit = "HEAD"
from slackminion.plugin.base import BasePlugin


[docs]class TestPlugin(BasePlugin):
[docs] @cmd() def echo(self, msg, args): """Simply repeats whatever is said.""" self.log.debug("Received args: %s", args) return " ".join(args)
[docs] @cmd() def xyzzy(self, msg, args): """Nothing happens.""" return "Nothing happens for %s" % msg.user
[docs] @cmd() async def alert(self, msg, args): """Alert everyone.""" await self.send_message( self.config["channel"], "<!here>: something important is going to happen!" ) return None
[docs] @webhook("/echo", form_params="foo") async def web_echo(self, foo): await self.send_message(self.config["channel"], foo)
[docs] @cmd() def shortsleep(self, msg, args): """Sleep for a bit, then print a message.""" self.start_timer(5, self._sleep_func)
[docs] @cmd() def shortsleep2(self, msg, args): """Sleep for a bit, then echo the message back""" self.start_timer(5, self._sleep_func2, msg.channel, " ".join(args))
[docs] @cmd() def lookup(self, msg, args): if args[0] == "channel": return "Found %s" % self.get_channel(args[1]) elif args[0] == "user": return "Found %s" % self.get_user(args[1])
[docs] @cmd() def topic(self, msg, args): channel = msg.channel self.log.debug("Current channel topic: %s", channel.topic) if len(args) > 0: channel.topic = " ".join(args)
async def _sleep_func(self): await self.send_message(self.config["channel"], "Slept for a bit") async def _sleep_func2(self, channel, text): await self.send_message(channel, text)
[docs]class TestAclPlugin(BasePlugin):
[docs] @cmd(admin_only=True) def admincmd(self, msg, args): """A command only admins should be able to run.""" return ":boom:"
[docs] @cmd(acl="test") def acltest(self, msg, args): """A command only members of 'test' should be able to run.""" return ":sushi:"
[docs] @cmd(admin_only=True, acl="test") def adminacl(self, msg, args): """Only admins who are in 'test' should be able to run this.""" return ":godmode:"