Esempio n. 1
0
def test_strip_prefix_cases():
    test1 = "!mustikkabot a"
    test2 = "!MustikkaBot a"
    test3 = "!Mustikkabot a"
    test4 = "!mustikkaBot a"

    assert tools.strip_name(test1) == "!a"
    assert tools.strip_name(test2) == "!a"
    assert tools.strip_name(test3) == "!a"
    assert tools.strip_name(test4) == "!a"
Esempio n. 2
0
    def handle_message(self, data, user, msg):
        msg = tools.strip_name(msg)

        result = re.search(r'^!say (.*)', msg)
        if result is not None:
            if self.bot.accessmanager.is_in_acl(user, self.acl):
                self.bot.send_message(' '.join(result.groups(1)))
Esempio n. 3
0
    def handle_message(self, data, user, msg):
        msg = tools.strip_name(msg)
        args = msg.split()

        if args[0] == "!time":
            if len(args) > 1:
                self.time_set(args)
            else:
                self.time_print()
        else:
            pass
Esempio n. 4
0
    def handle_message(self, data, user, msg):
        msg = tools.strip_name(msg)
        args = msg.split()

        if args[0] == "!uptime":
            if self.state == self.STATE_ONLINE:
                uptime = tools.tz_now() - self.started
                msg = "Up for: "
            else:
                uptime = self.state_last_changed - self.started
                msg = "Was up for: "

            total_seconds = uptime.total_seconds()
            total_minutes = floor(total_seconds / 60)
            hours = floor(total_minutes / 60)
            minutes = total_minutes - 60*hours

            self.bot.send_message(msg  + str(hours) + " h, " + str(minutes) + " min")
Esempio n. 5
0
    def handle_message(self, data, user, msg):
        """
        :param data: Full IRC command
        :type data: str
        :param user: name of the user that sent the message
        :type user: str
        :param msg: the message itself
        :type msg: str

        Handle incoming chat-messages. Check if it contains either !about or !bot commmands
        """
        msg = tools.strip_name(msg)
        args = msg.split()

        if args[0] == "!about" or args[0] == "!bot":
            self.log.info("Printing \"about\"")
            self.bot.send_message("MustikkaBot is a IRC/Twitch chatbot created in python " +
                                  "for the awesome youtuber/streamer HerraMustikka. Author: Esa Varemo")
Esempio n. 6
0
    def handle_message(self, data, user, msg):
        """
        Callback that handles all incoming chat messages for this modules

        :param data: Raw message (unused)
        :type data: str
        :param user: User sending the message
        :type user: str
        :param msg: Actual message content
        :type msg: str
        :rtype: None
        """
        msg = tools.strip_name(msg)
        args = msg.split()

        if args[0] == "!commands" or args[0] == "!comm":
            self.setup_commands(user, args)
        else:
            self.run_commands(user, args)

        self.lines_received += 1
Esempio n. 7
0
    def handle_message(self, data, user, msg):
        """
        :param data: full IRC command
        :param user: user that sent the message
        :param msg: the chat-message the user sent

        Look for any commands that the command-module should handle and handle any found commands.
        Called by the eventmanager/dispatcher when a message is received
        """
        msg = tools.strip_name(msg)
        args = msg.split()

        if len(args) < 1:
            return

        if not args[0].lower() == "!modules":
            return

        if not self.bot.accessmanager.is_in_acl(user, self.acl):
            self.log.warning("User " + user + " tried to issue an module management command without permissions")
            return

        if len(args) == 1:
            self.bot.send_message("Available commands for !modules are: list, enable, disable, reload")
            return

        if args[1].lower() == "enable":
            if len(args) < 3:
                self.bot.send_message("Name of the module is missing. Correct format: !modules enable <name>")
                return
            if self.bot.modulemanager.is_module_enabled(args[2]):
                self.bot.send_message("Module " + args[2] + " is already enabled")
                return
            if args[2] not in self.bot.modulemanager.get_available_modules():
                self.bot.send_message("Module does not exist")
                return
            self.bot.modulemanager.enable_module(args[2])
            self.bot.send_message("Module " + args[2] + " enabled")

        elif args[1].lower() == "disable":
            if len(args) < 3:
                self.bot.send_message("Name of the module is missing. Correct format: !modules disable <name>")
                return
            if not self.bot.modulemanager.is_module_enabled(args[2]):
                self.bot.send_message("Module " + args[2] + " is not enabled")
                return
            if args[2] not in self.bot.modulemanager.get_available_modules():
                self.bot.send_message("Module does not exist")
                return
            self.bot.modulemanager.disable_module(args[2])
            self.bot.send_message("Module " + args[2] + " disabled")

        elif args[1].lower() == "list":
            enabled = list()
            disabled = list()
            for module in self.bot.modulemanager.get_available_modules():
                if self.bot.modulemanager.is_module_enabled(module):
                    enabled.append(module)
                else:
                    disabled.append(module)
            if len(enabled) == 0:
                enabled.append("None")
            if len(disabled) == 0:
                disabled.append("None")
            self.bot.send_message("Currently enabled modules: " + ", ".join(enabled))
            self.bot.send_message("Currently disabled modules: " + ", ".join(disabled))

        elif args[1].lower() == "reload":
            if len(args) < 3:
                self.bot.send_message("Name of the module is missing. Correct format: !modules reload <name>")
                return
            if not self.bot.modulemanager.is_module_enabled(args[2]):
                self.bot.send_message("Module " + args[2] + " does not exists or is not enabled")
                return
            self.bot.modulemanager.reload_module(args[2])
            self.bot.send_message("Module " + args[2] + " reloaded")
Esempio n. 8
0
def test_strip_prefix_nomatch():
    test1 = "!mustikkaot a"
    test2 = "MustikkaBot a"

    assert tools.strip_name(test1) == test1
    assert tools.strip_name(test2) == test2