Ejemplo n.º 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)
Ejemplo n.º 2
0
 def test_change_trigger(self):
     command = ParseCommand("test command",
                            self.dummycallback,
                            trigger="?!")
     self.assertTrue(command.matches("?!test command"))
Ejemplo n.º 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"})
Ejemplo n.º 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, {})
Ejemplo n.º 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})
Ejemplo n.º 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"))
Ejemplo n.º 7
0
 def test_command_matches(self):
     command = ParseCommand("test command", self.dummycallback)
     self.assertTrue(command.matches("test command"))