Esempio n. 1
0
    async def test_irc_catch_all(self) -> None:
        bot = MockBot()
        conn = MockConn(nick="bot")
        event = Event(
            irc_command="PRIVMSG",
            event_type=EventType.message,
            channel="#foo",
            nick="bar",
            conn=conn,
            content=".foo bar",
        )
        event.notice = MagicMock()
        plugin = MagicMock()

        run_hooks = []

        @hook.irc_raw("*")
        async def coro(hook):
            run_hooks.append(hook)

        full_hook = RawHook(plugin, hook._get_hook(coro, "irc_raw"))
        bot.plugin_manager.catch_all_triggers.append(full_hook)

        await CloudBot.process(bot, event)
        assert sorted(run_hooks, key=id) == sorted(
            [
                full_hook,
            ],
            key=id,
        )
Esempio n. 2
0
    async def test_event(self) -> None:
        bot = MockBot()
        conn = MockConn(nick="bot")
        event = Event(
            irc_command="PRIVMSG",
            event_type=EventType.message,
            channel="#foo",
            nick="bar",
            conn=conn,
            content=".foo bar",
        )
        event.notice = MagicMock()
        plugin = MagicMock()

        run_hooks = []

        @hook.event(EventType.message)
        async def coro(hook):
            run_hooks.append(hook)

        full_event_hook = EventHook(plugin, hook._get_hook(coro, "event"))
        for event_type in full_event_hook.types:
            bot.plugin_manager.event_type_hooks[event_type].append(
                full_event_hook)

        await CloudBot.process(bot, event)
        assert sorted(run_hooks, key=id) == sorted(
            [
                full_event_hook,
            ],
            key=id,
        )
Esempio n. 3
0
    async def test_command_partial(self) -> None:
        bot = MockBot()
        conn = MockConn(nick="bot")
        event = Event(
            irc_command="PRIVMSG",
            event_type=EventType.message,
            channel="#foo",
            nick="bar",
            conn=conn,
            content=".foo bar",
        )
        event.notice = MagicMock()
        plugin = MagicMock()

        run_hooks = []

        @hook.command("foob", "fooc")
        async def coro(hook):  # pragma: no cover
            run_hooks.append(hook)

        full_hook = CommandHook(plugin, hook._get_hook(coro, "command"))

        for cmd in full_hook.aliases:
            bot.plugin_manager.commands[cmd] = full_hook

        await CloudBot.process(bot, event)
        assert sorted(run_hooks, key=id) == sorted(
            [],
            key=id,
        )

        event.notice.assert_called_once_with("Possible matches: foob or fooc")
Esempio n. 4
0
    async def test_command(self) -> None:
        bot = MockBot()
        conn = MockConn(nick="bot")
        event = Event(
            irc_command="PRIVMSG",
            event_type=EventType.message,
            channel="#foo",
            nick="bar",
            conn=conn,
            content=".foo bar",
        )
        event.notice = MagicMock()
        plugin = MagicMock()

        run_hooks = []

        @hook.command("foo")
        async def coro(hook):
            run_hooks.append(hook)

        full_hook = CommandHook(plugin, hook._get_hook(coro, "command"))

        for cmd in full_hook.aliases:
            bot.plugin_manager.commands[cmd] = full_hook

        await CloudBot.process(bot, event)
        assert sorted(run_hooks, key=id) == sorted(
            [
                full_hook,
            ],
            key=id,
        )
Esempio n. 5
0
    async def test_irc_raw_block(self):
        bot = MockBot()
        conn = MockConn(nick="bot")
        event = Event(
            irc_command="PRIVMSG",
            event_type=EventType.message,
            channel="#foo",
            nick="bar",
            conn=conn,
            content=".foo bar",
        )
        event.notice = MagicMock()
        plugin = MagicMock()

        run_hooks = []

        @hook.irc_raw("PRIVMSG",
                      priority=Priority.HIGH,
                      action=Action.HALTTYPE)
        async def coro(hook):
            run_hooks.append(hook)

        @hook.irc_raw("PRIVMSG", priority=Priority.NORMAL)
        async def coro1(hook):  # pragma: no cover
            run_hooks.append(hook)

        full_hook = RawHook(plugin, hook._get_hook(coro, "irc_raw"))
        full_hook1 = RawHook(plugin, hook._get_hook(coro1, "irc_raw"))
        bot.plugin_manager.raw_triggers["PRIVMSG"].append(full_hook)
        bot.plugin_manager.raw_triggers["PRIVMSG"].append(full_hook1)

        await CloudBot.process(bot, event)
        assert sorted(run_hooks, key=id) == sorted(
            [
                full_hook,
            ],
            key=id,
        )
Esempio n. 6
0
async def test_reload_config():
    bot = MockBot()
    conn = MockConn()
    bot.connections = {"foo": conn}
    bot.config.load_config = MagicMock()
    runs = []

    @hook.config()
    @hook.config()
    async def coro(hook):
        runs.append(hook)

    plugin = MagicMock()
    config_hook = ConfigHook(plugin, hook._get_hook(coro, "config"))

    bot.plugin_manager.config_hooks.append(config_hook)

    bot.config.load_config.assert_not_called()
    await CloudBot.reload_config(bot)
    conn.reload.assert_called()
    bot.config.load_config.assert_called()
    assert runs == [config_hook]