示例#1
0
    def load(self):
        for name, callback in inspect.getmembers(self, inspect.ismethod):
            tags = getattr(callback, 'tags', [])

            for tag in tags:
                name = tag['name']
                properties = tag['properties']

                if name == "pre_command":
                    self.pre_command_hooks.append(callback)

                elif name == "command":
                    command = Command(properties['pattern'],
                                      callback,
                                      trigger=properties['trigger'],
                                      access=properties['access'])

                    self.commands.append(command)

                elif name == "regex_command":
                    command = RegexCommand(properties['pattern'],
                                           callback,
                                           trigger=properties['trigger'],
                                           access=properties['access'])

                    self.commands.append(command)

                elif name == "parse_command":
                    command = ParseCommand(properties['pattern'],
                                           callback,
                                           trigger=properties['trigger'],
                                           access=properties['access'])

                    self.commands.append(command)

                elif name == "webhook":
                    self.bot.webhooks.add_route(properties['route'], callback,
                                                properties['methods'])

                elif name == "interval":
                    self.bot.scheduler.run_interval(callback,
                                                    properties['seconds'])

                elif name == "subscriber":
                    self.bot.events.subscribe(properties['event'], callback)
示例#2
0
 def test_change_trigger(self):
     command = ParseCommand("test command",
                            self.dummycallback,
                            trigger="?!")
     self.assertTrue(command.matches("?!test command"))
示例#3
0
 def test_command_args_kwargs(self):
     command = ParseCommand("test command {:d} {fake_thing}",
                            self.dummycallback)
     args, kwargs = command.parse("test command 1234 mortimer")
     self.assertListEqual(args, [1234])
     self.assertDictEqual(kwargs, {"fake_thing": "mortimer"})
示例#4
0
 def test_command_args(self):
     command = ParseCommand("test command {:d}", self.dummycallback)
     args, kwargs = command.parse("test command 1234")
     self.assertListEqual(args, [1234])
     self.assertDictEqual(kwargs, {})
示例#5
0
 def test_command_kwargs(self):
     command = ParseCommand("test command {fake_id:d}", self.dummycallback)
     args, kwargs = command.parse("test command 1234")
     self.assertListEqual(args, [])
     self.assertDictEqual(kwargs, {"fake_id": 1234})
示例#6
0
    def test_command_not_matches(self):
        command = ParseCommand("test command", self.dummycallback)

        self.assertFalse(command.matches(" test commanding"))
        self.assertFalse(command.matches("test commanding"))
示例#7
0
 def test_command_matches(self):
     command = ParseCommand("test command", self.dummycallback)
     self.assertTrue(command.matches("test command"))