Example #1
0
 def handleCommand(self, command, channel, username, message):
     # parse arguments
     # if command is space case then
     #   !foo bar baz
     # turns into
     #   command = "!foo", args=["bar baz"]
     # otherwise it turns into
     #   command = "!foo", args=["bar", "baz"]
     # print("Inputs:", command, channel, username, message)
     if command == message:
         args = []
     else:
         # default to args = ["bar baz"]
         args = [message[len(command) + 1:]]
     if not commands.check_is_space_case(command) and args:
         # if it's not space case, break the arg apart
         args = args[0].split(" ")
     if commands.is_on_cooldown(command, channel):
         pbot(
             'Command is on cooldown. (%s) (%s) (%ss remaining)' %
             (command, username,
              commands.get_cooldown_remaining(command, channel)), channel)
         return
     if commands.check_has_user_cooldown(command):
         if commands.is_on_user_cooldown(command, channel, username):
             resp = "/w " + username + " Sorry! You've got " + str(
                 commands.get_user_cooldown_remaining(
                     command, channel, username)) + \
                 " seconds before you can do that again!"
             self.irc.send_message(channel, resp)
             return
         commands.update_user_last_used(command, channel, username)
     pbot(
         'Command is valid and not on cooldown. (%s) (%s)' %
         (command, username), channel)
     # Check for and handle the simple non-command case.
     cmd_return = commands.get_return(command)
     if cmd_return != "command":
         # it's a return = "some message here" kind of function
         resp = '/w %s %s' % (username, cmd_return)
         commands.update_last_used(command, channel)
         self.irc.send_message(channel, resp)
         return
     # if there's a required userlevel, validate it.
     if commands.check_has_ul(username, command):
         if username.lower() not in self.config["mods"]:
             resp = '/w %s %s' % (username,
                                  "This is a moderator-only command!")
             pbot(resp, channel)
             self.irc.send_message(channel, resp)
             return
     result = commands.pass_to_function(command, args)
     commands.update_last_used(command, channel)
     if result:
         resp = '/w %s %s' % (username, result)
         pbot(resp, channel)
         self.irc.send_message(channel, resp)
Example #2
0
 def handleCommand(self, command, channel, username, message):
     # parse arguments
     # if command is space case then
     #   !foo bar baz
     # turns into
     #   command = "!foo", args=["bar baz"]
     # otherwise it turns into
     #   command = "!foo", args=["bar", "baz"]
     # print("Inputs:", command, channel, username, message)
     if command == message:
         args = []
     else:
         # default to args = ["bar baz"]
         args = [message[len(command) + 1:]]
     if not commands.check_is_space_case(command) and args:
         # if it's not space case, break the arg apart
         args = args[0].split(" ")
     if commands.is_on_cooldown(command, channel):
         pbot('Command is on cooldown. (%s) (%s) (%ss remaining)' % (
             command, username, commands.get_cooldown_remaining(
                 command, channel)), channel)
         return
     if commands.check_has_user_cooldown(command):
         if commands.is_on_user_cooldown(command, channel, username):
             resp = "/w " + username + " Sorry! You've got " + str(
                 commands.get_user_cooldown_remaining(
                     command, channel, username)) + \
                 " seconds before you can do that again!"
             self.irc.send_message(channel, resp)
             return
         commands.update_user_last_used(command, channel, username)
     pbot('Command is valid and not on cooldown. (%s) (%s)' %
          (command, username), channel)
     # Check for and handle the simple non-command case.
     cmd_return = commands.get_return(command)
     if cmd_return != "command":
         # it's a return = "some message here" kind of function
         resp = '/w %s %s' % (username, cmd_return)
         commands.update_last_used(command, channel)
         self.irc.send_message(channel, resp)
         return
     # if there's a required userlevel, validate it.
     if commands.check_has_ul(username, command):
         if username.lower() not in self.config["mods"]:
             resp = '/w %s %s' % (
                 username, "This is a moderator-only command!")
             pbot(resp, channel)
             self.irc.send_message(channel, resp)
             return
     result = commands.pass_to_function(command, args)
     commands.update_last_used(command, channel)
     if result:
         resp = '/w %s %s' % (username, result)
         pbot(resp, channel)
         self.irc.send_message(channel, resp)
Example #3
0
 def handleCommand(self, command, channel, username, message):
     # parse arguments
     # if command is space case then
     #   !foo bar baz
     # turns into
     #   command = "!foo", args=["bar baz"]
     # otherwise it turns into
     #   command = "!foo", args=["bar", "baz:]
     # print("Inputs:", command, channel, username, message)
     if command == message:
         args = []
     elif command == message and command in commands.keys():
         pass
     else:
         # default to args = ["bar baz"]
         args = [message[len(command) + 1:]]
     if not commands.check_is_space_case(command) and args:
         # if it's not space case, break the arg apart
         args = args[0].split(" ")
     if commands.is_on_cooldown(command, channel):
         pbot('Command is on cooldown. (%s) (%s) (%ss remaining)' % (
             command, username, commands.get_cooldown_remaining(
                 command, channel)), channel)
         return
     if commands.check_has_user_cooldown(command):
         if commands.is_on_user_cooldown(command, channel, username):
             return
         commands.update_user_last_used(command, channel, username)
     pbot('Command is valid and not on cooldown. (%s) (%s)' %
          (command, username), channel)
     # Check for and handle the simple non-command case.
     cmd_return = commands.get_return(command)
     if cmd_return != "command":
         # it's a return = "some message here" kind of function
         resp = '(%s) : %s' % (username, cmd_return)
         commands.update_last_used(command, channel)
         self.irc.send_message(channel, resp)
         return
     # if there's a required userlevel, validate it.
     if commands.check_has_ul(username, command):
         user_data, __ = twitch.get_dict_for_users(channel)
         try:
             if username not in user_data["chatters"]["moderators"]:
                 if username != SUPERUSER:
                     resp = '(%s) : %s' % (
                         username, "This is a moderator-only command!")
                     pbot(resp, channel)
                     self.irc.send_message(channel, resp)
                     return
         except Exception as error:
             with open("errors.txt", "a") as f:
                 error_message = "{0} | {1} : {2}\n{3}\n{4}".format(
                     username, channel, command, user_data, error)
                 f.write(error_message)
     approved_channels = [PRIMARY_CHANNEL, BOT_USER, SUPERUSER, TEST_USER]
     if globals.CURRENT_CHANNEL not in approved_channels:
         print globals.CURRENT_CHANNEL
         prevented_list = ['songrequest', 'request', 'shots', 'donation',
                           'welcome', 'rules', 'poll', 'vote', 'gt',
                           'llama', 'loyalty', 'uptime', 'highlight',
                           'weather', 'poll', 'treats', 'vote']
         if command.lstrip("!") in prevented_list:
             return
     result = commands.pass_to_function(command, args)
     commands.update_last_used(command, channel)
     if result:
         resp = '(%s) : %s' % (username, result)
         pbot(resp, channel)
         self.irc.send_message(channel, resp)
         if channel == "#" + PRIMARY_CHANNEL:
             write_to_log(channel, "[BOT]", resp)
         save_message(BOT_USER, channel, resp)
Example #4
0
    def handleCommand(self, command, channel, username, message):
        # parse arguments
        # if command is space case then
        #   !foo bar baz
        # turns into
        #   command = "!foo", args=["bar baz"]
        # otherwise it turns into
        #   command = "!foo", args=["bar", "baz:]
        # print("Inputs:", command, channel, username, message)
        if command == message:
            args = []

        ######TEMPORARY COMMAND IGNORES FOR shedeviil_09

        elif command == message and command in commands.keys():
            print "Yes, it is in commands"

        else:
            args = [message[len(command) + 1:]
                    ]  # default to args = ["bar baz"]

        if not commands.check_is_space_case(command) and args:
            # if it's not space case, break the arg apart
            args = args[0].split(" ")

        # print("Command:", command, "args", args)

        # check cooldown.
        if commands.is_on_cooldown(command, channel):
            pbot(
                'Command is on cooldown. (%s) (%s) (%ss remaining)' %
                (command, username,
                 commands.get_cooldown_remaining(command, channel)), channel)
            return
        pbot(
            'Command is valid and not on cooldown. (%s) (%s)' %
            (command, username), channel)

        # Check for and handle the simple non-command case.
        cmd_return = commands.get_return(command)
        if cmd_return != "command":
            # it's a return = "some message here" kind of function
            resp = '(%s) : %s' % (username, cmd_return)
            commands.update_last_used(command, channel)
            self.irc.send_message(channel, resp)
            return

        # if there's a required userleve, validate it.
        if commands.check_has_ul(username, command):
            user_dict, all_users = twitch.get_dict_for_users()
            if username not in user_dict["chatters"]["moderators"]:
                resp = '(%s) : %s' % (username,
                                      "This is a moderator-only command!")
                pbot(resp, channel)
                self.irc.send_message(channel, resp)
                return

        result = commands.pass_to_function(command, args)
        commands.update_last_used(command, channel)

        pbot("Command %s(%s) had a result of %s" % (command, args, result),
             channel)
        if result:
            resp = '(%s) : %s' % (username, result)
            pbot(resp, channel)
            self.irc.send_message(channel, resp)
Example #5
0
    def handleCommand(self, command, channel, username, message):
        # parse arguments
        # if command is space case then
        #   !foo bar baz
        # turns into
        #   command = "!foo", args=["bar baz"]
        # otherwise it turns into
        #   command = "!foo", args=["bar", "baz:]
        # print("Inputs:", command, channel, username, message)
        if command == message:
            args = []
            
            
        ######TEMPORARY COMMAND IGNORES FOR shedeviil_09
        
        elif command == message and command in commands.keys():
            print "Yes, it is in commands"
            
            
            
            
        else:
            args = [message[len(command)+1:]] # default to args = ["bar baz"]

        if not commands.check_is_space_case(command) and args:
            # if it's not space case, break the arg apart
            args = args[0].split(" ")

        # print("Command:", command, "args", args)

        # check cooldown.
        if commands.is_on_cooldown(command, channel):
            pbot('Command is on cooldown. (%s) (%s) (%ss remaining)' % (
                command, username, commands.get_cooldown_remaining(command, channel)),
                channel
            )
            return
        pbot('Command is valid and not on cooldown. (%s) (%s)' %
                (command, username) ,channel)


        # Check for and handle the simple non-command case.
        cmd_return = commands.get_return(command)
        if cmd_return != "command":
            # it's a return = "some message here" kind of function
            resp = '(%s) : %s' % (username, cmd_return)
            commands.update_last_used(command, channel)
            self.irc.send_message(channel, resp)
            return


        # if there's a required userleve, validate it.
        if commands.check_has_ul(username, command):
            user_dict, all_users = twitch.get_dict_for_users()
            if username not in user_dict["chatters"]["moderators"]:
                resp = '(%s) : %s' % (
                    username, "This is a moderator-only command!")
                pbot(resp, channel)
                self.irc.send_message(channel, resp)
                return

       

        result = commands.pass_to_function(command, args)
        commands.update_last_used(command, channel)

        pbot("Command %s(%s) had a result of %s" % (command, args, result), channel)
        if result:
            resp = '(%s) : %s' % (username, result)
            pbot(resp, channel)
            self.irc.send_message(channel, resp)
Example #6
0
 def handleCommand(self, command, channel, username, message):
     # parse arguments
     # if command is space case then
     #   !foo bar baz
     # turns into
     #   command = "!foo", args=["bar baz"]
     # otherwise it turns into
     #   command = "!foo", args=["bar", "baz"]
     # print("Inputs:", command, channel, username, message)
     if command == message:
         args = []
     else:
         # default to args = ["bar baz"]
         args = [message[len(command) + 1:]]
     if not commands.check_is_space_case(command) and args:
         # if it's not space case, break the arg apart
         args = args[0].split(" ")
     if commands.is_on_cooldown(command, channel):
         pbot('Command is on cooldown. (%s) (%s) (%ss remaining)' % (
             command, username, commands.get_cooldown_remaining(
                 command, channel)), channel)
         return
     if commands.check_has_user_cooldown(command):
         if commands.is_on_user_cooldown(command, channel, username):
             resp = "Sorry! You've got " + str(
                 commands.get_user_cooldown_remaining(
                     command, channel, username)) + \
                 " seconds before you can do that again, " + username + "!"
             self.irc.send_message(channel, resp)
             return
         commands.update_user_last_used(command, channel, username)
     pbot('Command is valid and not on cooldown. (%s) (%s)' %
          (command, username), channel)
     # Check for and handle the simple non-command case.
     cmd_return = commands.get_return(command)
     if cmd_return != "command":
         # it's a return = "some message here" kind of function
         resp = '(%s) : %s' % (username, cmd_return)
         commands.update_last_used(command, channel)
         self.irc.send_message(channel, resp)
         return
     # if there's a required userlevel, validate it.
     if commands.check_has_ul(username, command):
         user_data, __ = twitch.get_dict_for_users(channel)
         try:
             if username not in user_data["chatters"]["moderators"]:
                 if username != TEST_USER:
                     resp = '(%s) : %s' % (
                         username, "This is a moderator-only command!")
                     pbot(resp, channel)
                     self.irc.send_message(channel, resp)
                     return
         except Exception as error:
             with open("errors.txt", "a") as f:
                 error_message = "{0} | {1} : {2}\n{3}\n{4}".format(
                     username, channel, command, user_data, error)
                 f.write(error_message)
     approved_channels = [STREAM_USER, BOT_USER, TEST_USER]
     if globals.CURRENT_CHANNEL not in approved_channels:
         prevented_list = []
         if command.lstrip("!") in prevented_list:
             return
     result = commands.pass_to_function(command, args)
     commands.update_last_used(command, channel)
     if result:
         resp = '/w %s %s' % (username, result)
         pbot(resp, channel)
         self.irc.send_message(channel, resp)
Example #7
0
    def handle_command(self, command, channel, username, message):
        if command == message:
            args = []
        elif command == message and command in commands.keys(
        ):  # pragma: no cover
            pass
        else:
            args = [message[len(command) + 1:]]
        if not commands.check_is_space_case(command) and args:
            args = args[0].split(" ")
        if (command == "!join"
                or command == "!leave") and channel == "#" + BOT_USER:
            self.join_part(command.lstrip("!"), "#" + username)
        if commands.is_on_cooldown(command, channel):
            pbot(
                'Command is on cooldown. (%s) (%s) (%ss remaining)' %
                (command, username,
                 commands.get_cooldown_remaining(command, channel)), channel)
            self.IRC.send_whisper(
                username, "Sorry! " + command + " is on cooldown for " +
                str(commands.get_cooldown_remaining(command, channel)) +
                " more seconds in " + channel.lstrip("#") +
                ". Can I help you?")
            return
        if commands.check_has_user_cooldown(command):
            if commands.is_on_user_cooldown(command, channel, username):
                self.IRC.send_whisper(
                    username, "Slow down! Try " + command + " in " +
                    channel.lstrip("#") + " in another " + str(
                        commands.get_user_cooldown_remaining(
                            command, channel, username)) + " seconds or just \
ask me directly?")
                return
            commands.update_user_last_used(command, channel, username)
        if check_for_blacklist(username):
            return
        pbot(
            'Command is valid and not on cooldown. (%s) (%s)' %
            (command, username), channel)
        cmd_return = commands.get_return(command)
        if cmd_return != "command":
            resp = '(%s) : %s' % (username, cmd_return)
            commands.update_last_used(command, channel)
            self.IRC.send_message(channel, resp)
            return
        command_has_ul = commands.check_has_ul(username, command)
        if command_has_ul:
            user_data, __ = twitch.get_dict_for_users(channel)
            if command_has_ul == "superuser":
                if username == SUPERUSER:
                    return commands.pass_to_function(
                        command,
                        args,
                        username=username,
                        channel=channel.lstrip("#"))
                else:
                    return
            try:
                moderator = get_moderator(username, channel.lstrip("#"))
                if not moderator and username != SUPERUSER:
                    resp = '(%s) : %s' % (username,
                                          "This is a moderator-only command!")
                    pbot(resp, channel)
                    self.IRC.send_whisper(username, resp)
                    return
            except Exception as error:  # pragma: no cover
                with open("errors.txt", "a") as f:
                    error_message = "{0} | {1} : {2}\n{3}\n{4}".format(
                        username, channel, command, user_data, error)
                    f.write(error_message)
        approved_channels = [
            PRIMARY_CHANNEL, BOT_USER, SUPERUSER, TEST_USER, EXTRA_CHANNEL
        ]
        if channel.lstrip("#") not in approved_channels:
            prevented_list = [
                'songrequest', 'request', 'shots', 'donation', 'welcome',
                'rules', 'gt', 'llama', 'loyalty', 'uptime', 'highlight',
                'weather', 'treats', 'wins', 'subcount'
            ]
            if command.lstrip("!") in prevented_list:
                return
        result = commands.pass_to_function(command,
                                           args,
                                           username=username,
                                           channel=channel.lstrip("#"))
        commands.update_last_used(command, channel)
        if result:
            resp = '(%s) : %s' % (username, result)
            pbot(resp, channel)
            save_message(BOT_USER, channel, resp)  # pragma: no cover
            return resp[:350]
Example #8
0
    def handle_command(self, command, channel, username, message):
        db = Database()
        is_active = db.get_active_command(
            channel=channel.lstrip("#"), command=command)[0]
        if is_active == 0:
            return
        if command == message:
            args = []
        elif command == message and command in commands.keys():  # pragma: no cover
            pass
        else:
            args = [message[len(command) + 1:]]
        if not commands.check_is_space_case(command) and args:
            args = args[0].split(" ")
        if commands.is_on_cooldown(command, channel):
            pbot('Command is on cooldown. ({0}) ({1}) ({2}s remaining)'.format(
                command, username, commands.get_cooldown_remaining(
                    command, channel)), channel)
            self.whisper(
                username, channel,  "Sorry! " + command +
                " is on cooldown for " + str(
                    commands.get_cooldown_remaining(
                        command, channel)
                ) + " more seconds in " + channel.lstrip("#") +
                ". Can I help you?")
            return
        if commands.check_has_user_cooldown(command):
            if commands.is_on_user_cooldown(command, channel, username):
                self.whisper(
                    username, channel, "Slow down! Try " + command +
                    " in " + channel.lstrip("#") + " in another " + str(
                        commands.get_user_cooldown_remaining(
                            command, channel, username)) + " seconds or just \
ask me directly?")
                return
            commands.update_user_last_used(command, channel, username)
        cmd_return = commands.get_return(command)
        if cmd_return != "command":
            resp = '(%s) : %s' % (username, cmd_return)
            commands.update_last_used(command, channel)
            self.msg(channel, resp)
            return
        if commands.check_has_ul(username, command):
            user_data, __ = twitch.get_dict_for_users(channel)
            try:
                moderator = Database().get_moderator(username, channel.lstrip("#"))
                if not moderator and username != SUPERUSER:
                    resp = '(%s) : %s' % (
                        username, "This is a moderator-only command!")
                    pbot(resp, channel)
                    self.msg(channel, resp)
                    return
            except Exception as error:  # pragma: no cover
                with open("errors.txt", "a") as f:
                    error_message = "{0} | {1} : {2}\n{3}\n{4}".format(
                        username, channel, command, user_data, error)
                    f.write(error_message)
        result = commands.pass_to_function(
            command, args, username=username, channel=channel.lstrip("#"))
        commands.update_last_used(command, channel)
        if result:
            resp = '(%s) : %s' % (username, result)[:350]
            pbot(resp, channel)
            return resp