コード例 #1
0
ファイル: bot.py プロジェクト: MAkzent/Betminion1.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)
コード例 #2
0
ファイル: bot.py プロジェクト: MAkzent/Betminion1.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)
コード例 #3
0
ファイル: bot.py プロジェクト: singlerider/command_center
    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():
            print "Yes, it is in commands"

        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(" ")

        # 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

        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)

        def join_channels_after_runtime(self):
            pass
コード例 #4
0
ファイル: bot.py プロジェクト: singlerider/docbot
 def handle_command(self, command, channel, username, message):
     User.get_or_create(username=username)
     moderator = get_moderator(channel, username)
     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) and not moderator:
         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) and not moderator:
         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)
     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
     if commands.check_has_user_level(username, command):
         if not moderator and username != SUPERUSER:
             if commands.commands[command].get("optional") is not None and len(
                     message.split(" ")) < 2:
                 pass
             else:
                 resp = '(%s) : %s' % (
                     username, "This is a moderator-only command!")
                 pbot(resp, channel)
                 self.IRC.send_whisper(username, resp)
                 return
     approved_channels = [
         PRIMARY_CHANNEL, BOT_USER, SUPERUSER, TEST_USER, EXTRA_CHANNEL]
     if channel.lstrip("#") not in approved_channels:
         prevented_list = []
         if command.lstrip("!") in prevented_list:
             return
     result = commands.pass_to_function(
         command, args, username=username, channel=channel.lstrip("#"),
         irc=self.IRC)
     commands.update_last_used(command, channel)
     if result:
         resp = '(%s) : %s' % (username, result)
         pbot(resp, channel)
         # self.save_message(BOT_USER, channel, resp)  # pragma: no cover
         return resp[:350]
コード例 #5
0
ファイル: bot.py プロジェクト: singlerider/command_center
    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():
            print "Yes, it is in commands"

        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(" ")

        # 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

        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)

        def join_channels_after_runtime(self):
            pass
コード例 #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 = []

        ######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)
コード例 #7
0
 def handle_command(self, command, channel, username, message):
     User.get_or_create(username=username)
     moderator = get_moderator(channel, username)
     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) and not moderator:
         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) and not moderator:
         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)
     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
     if commands.check_has_user_level(username, command):
         if not moderator and username != SUPERUSER:
             if commands.commands[command].get(
                     "optional") is not None and len(
                         message.split(" ")) < 2:
                 pass
             else:
                 resp = '(%s) : %s' % (username,
                                       "This is a moderator-only command!")
                 pbot(resp, channel)
                 self.IRC.send_whisper(username, resp)
                 return
     approved_channels = [
         PRIMARY_CHANNEL, BOT_USER, SUPERUSER, TEST_USER, EXTRA_CHANNEL
     ]
     if channel.lstrip("#") not in approved_channels:
         prevented_list = []
         if command.lstrip("!") in prevented_list:
             return
     result = commands.pass_to_function(command,
                                        args,
                                        username=username,
                                        channel=channel.lstrip("#"),
                                        irc=self.IRC)
     commands.update_last_used(command, channel)
     if result:
         resp = '(%s) : %s' % (username, result)
         pbot(resp, channel)
         # self.save_message(BOT_USER, channel, resp)  # pragma: no cover
         return resp[:350]
コード例 #8
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)
コード例 #9
0
ファイル: bot.py プロジェクト: deadrime/twitch-bot
    def run(self):
        irc = self.irc
        sock = self.socket
        config = self.config

        while True:

            data = sock.recv(config['socket_buffer_size']).rstrip()

            if len(data) == 0:
                pp('Connection was lost, reconnecting.')
                sock = self.irc.get_irc_socket_object()

            if config['debug']:
                print data

            # check for ping, reply with pong
            irc.check_for_ping(data)

            if irc.check_for_message(data):
                message_dict = irc.get_message(data)

                channel = message_dict['channel']
                message = message_dict['message']
                username = message_dict['username']

                ppi(channel, message, username)

                # check if message is a command with no arguments
                if commands.is_valid_command(
                        message) or commands.is_valid_command(
                            message.split(' ')[0]):
                    command = message

                    if commands.check_returns_function(command.split(' ')[0]):
                        if commands.check_has_correct_args(
                                command,
                                command.split(' ')[0]):
                            args = command.split(' ')
                            del args[0]

                            command = command.split(' ')[0]

                            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)
                            else:
                                pbot(
                                    'Command is valid an not on cooldown. (%s) (%s)'
                                    % (command, username), channel)

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

                                if result:
                                    resp = '@%s - %s' % (username, result)
                                    pbot(resp, channel)
                                    irc.send_message(channel, resp)

                    else:
                        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)
                        elif commands.check_has_return(command):
                            pbot(
                                'Command is valid and not on cooldown. (%s) (%s)'
                                % (command, username), channel)
                            commands.update_last_used(command, channel)

                            resp = '@%s - %s' % (username,
                                                 commands.get_return(command))
                            commands.update_last_used(command, channel)

                            pbot(resp, channel)
                            irc.send_message(channel, resp)
コード例 #10
0
ファイル: bot.py プロジェクト: MAkzent/betminionbot0.1
 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)
コード例 #11
0
ファイル: bot.py プロジェクト: qwertyuiop1234/lorenzotherobot
    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]
コード例 #12
0
ファイル: bot.py プロジェクト: ShrikeGames/twitch-bot
    def run(self):
        irc = self.irc
        sock = self.socket
        config = self.config
        ALWAYS_LEARN = False
        while True:
            data = sock.recv(config['socket_buffer_size']).rstrip()

            if len(data) == 0:
                pp('Connection was lost, reconnecting.')
                sock = self.irc.get_irc_socket_object()

            if config['debug']:
                print(data)

            # check for ping, reply with pong
            irc.check_for_ping(data)

            if irc.check_for_message(data):
                message_dict = irc.get_message(data)

                channel = message_dict['channel']
                message = message_dict['message']
                username = message_dict['username']
                botCommand = ('@ShrikeChanBot' in message) or ('!learn'
                                                               in message)
                if username is 'shrikechanbot':
                    print('skip bot messages')
                else:

                    if ALWAYS_LEARN and not botCommand and self.last_message != '':
                        clean_message = message.replace('@ShrikeChanBot',
                                                        '').replace(
                                                            '!learn',
                                                            '').strip()
                        chatbot.learn_response(
                            Statement(text=clean_message),
                            Statement(text=self.last_message))
                        print('LEARNING', clean_message, '>',
                              self.last_message, '=',
                              chatbot.get_response(clean_message))
                        self.last_message = clean_message
                    ppi(channel, message, username)
                    # check if message is a command with no arguments
                    if commands.is_valid_command(
                            message) or commands.is_valid_command(
                                message.split(' ')[0]):
                        command = message

                        if commands.check_returns_function(
                                command.split(' ')[0]):
                            if commands.check_has_correct_args(
                                    command,
                                    command.split(' ')[0]):
                                args = command.split(' ')
                                del args[0]

                                command = command.split(' ')[0]

                                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)
                                else:
                                    pbot(
                                        'Command is valid and not on cooldown. (%s) (%s)'
                                        % (command, username), channel)
                                    if botCommand:
                                        args = message
                                    result = commands.pass_to_function(
                                        command, args, chatbot,
                                        self.last_message)
                                    commands.update_last_used(command, channel)

                                    if result:
                                        resp = '%s @%s' % (result, username)
                                        pbot(resp, channel)
                                        irc.send_message(channel, resp)

                        else:
                            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)
                            elif commands.check_has_return(command):
                                pbot(
                                    'Command is valid and not on cooldown. (%s) (%s)'
                                    % (command, username), channel)
                                commands.update_last_used(command, channel)

                                resp = '%s @%s' % (
                                    commands.get_return(command), username)
                                commands.update_last_used(command, channel)

                                pbot(resp, channel)
                                irc.send_message(channel, resp)
                    if ALWAYS_LEARN or botCommand:
                        self.last_message = message.replace(
                            '@ShrikeChanBot', '').replace('!learn',
                                                          '').strip()
コード例 #13
0
ファイル: bot.py プロジェクト: hlku/TwitchChatRankingBot
    def run(self):
        irc = self.irc
        sock = self.socket
        config = self.config
        for rank in self.ranks:
            self.ranks[rank].start()
            resp = u'! 98bot進入聊天室,計算聊天等級開始。'
            irc.send_message(rank, resp)

        while True:
            data = sock.recv(config['socket_buffer_size']).rstrip()

            if len(data) == 0:
                pp('Connection was lost, reconnecting.')
                sock = self.irc.get_irc_socket_object()

            if config['debug']:
                print data

            # check for ping, reply with pong
            irc.check_for_ping(data)

            if irc.check_for_message(data):
                message_dict = irc.get_message(data)

                channel = message_dict['channel']
                message = message_dict['message']
                username = message_dict['username']

                if username.lower() in self.config['ignore']: continue

                # give XP to this user
                rks = self.ranks.get(channel, None)
                if rks is not None and rks.live == True: rks.newchat(username)
                if rks.quiet: continue

                #I'm lazy to write a module
                msg = message.strip().split(' ')
                target = username
                if len(msg) > 1: target = msg[1].lower()
                if msg[0].lower() == '!rank':
                    if username == channel[1:] and len(
                            msg) == 1:  #broadcaster don't have level
                        u = rks.top()
                        if u is not None:
                            if u[4].lower() == u[1].lower():
                                resp = u'! 報告台主,目前講話最多的是 %s,%s級,經驗值%s/%s。' % (
                                    u[4], str(u[3]), str(
                                        u[2]), str(threshold[u[3]]))
                            else:
                                resp = u'! 報告台主,目前講話最多的是%s (%s),%s級,經驗值%s/%s。' % (
                                    u[4], u[1], str(u[3]), str(
                                        u[2]), str(threshold[u[3]]))
                        else:
                            resp = u'! 報告台主,你到現在都沒有半個觀眾講過話,幫QQ'
                    else:
                        u = rks.find(target)
                        if u is not None:
                            if u[4].lower() == u[1].lower():
                                resp = u'! %s 目前%s級,排第%s名,經驗值%s/%s。' % (
                                    u[4], str(u[3]), str(u[0]), str(
                                        u[2]), str(threshold[u[3]]))
                            else:
                                resp = u'! %s (%s) 目前%s級,排第%s名,經驗值%s/%s。' % (
                                    u[4], u[1], str(u[3]), str(u[0]), str(
                                        u[2]), str(threshold[u[3]]))
                        else:
                            resp = u'! 找不到 %s 的等級,大概還沒講過話吧。' % target
                    irc.send_message(channel, resp)
                    continue

                # for checking the bot is online
                if message.strip().lower() == '!98bot' or message.strip(
                ).split(' ')[0].lower() == '!98bot':
                    if rks.live:
                        resp = u'! 正在努力記錄大家的經驗值。'
                    else:
                        resp = u'! 目前沒開台沒經驗值,但我不會阻止你講話~'
                    irc.send_message(channel, resp)
                    continue

                # check if message is a command with no arguments
                if commands.is_valid_command(
                        message) or commands.is_valid_command(
                            message.split(' ')[0]):
                    command = message

                    if commands.check_returns_function(command.split(' ')[0]):
                        if commands.check_has_correct_args(
                                command,
                                command.split(' ')[0]):
                            args = command.split(' ')
                            del args[0]

                            command = command.split(' ')[0]

                            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)
                            else:
                                pbot(
                                    'Command is valid an not on cooldown. (%s) (%s)'
                                    % (command, username), channel)

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

                                if result:
                                    resp = '%s' % result
                                    pbot(resp, channel)
                                    irc.send_message(channel, resp)

                    else:
                        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)
                        elif commands.check_has_return(command):
                            pbot(
                                'Command is valid and not on cooldown. (%s) (%s)'
                                % (command, username), channel)
                            commands.update_last_used(command, channel)

                            resp = '%s' % commands.get_return(command)
                            commands.update_last_used(command, channel)

                            pbot(resp, channel)
                            irc.send_message(channel, resp)
コード例 #14
0
ファイル: bot.py プロジェクト: singlerider/nano_machina
    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
コード例 #15
0
ファイル: bot.py プロジェクト: nelsonam/lorenzotherobot
 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)
コード例 #16
0
ファイル: bot.py プロジェクト: willychenchen/twitch-bot
    def run(self):
        irc = self.irc
        sock = self.socket
        config = self.config
        
        while True:
            data = sock.recv(config['socket_buffer_size']).rstrip()
            
            if len(data) == 0:
                pp('Connection was lost, reconnecting.')
                sock = self.irc.get_irc_socket_object()

            if config['debug']:
                print data

            # check for ping, reply with pong
            irc.check_for_ping(data)
            
            if irc.check_for_message(data):
                message_dict = irc.get_message(data)

                channel = message_dict['channel']
                message = message_dict['message']
                username = message_dict['username']
                
                ppi(channel, message, username)
                
                #custom triggers
                stop = re.match('stop ([0-9]+)', message)
                if stop:
                    time.sleep(int(stop.group(1)))
                    continue
                    
                #pause for some time to prevent hitting request limit
                time.sleep(randint(2,4))
                print "sending rando"
                irc.random_chat(config['channels'][0])
                
                # check if message is a command with no arguments
                if commands.is_valid_command(message) or commands.is_valid_command(message.split(' ')[0]):
                    command = message

                    if commands.check_returns_function(command.split(' ')[0]):
                        if commands.check_has_correct_args(command, command.split(' ')[0]):
                            args = command.split(' ')
                            del args[0]

                            command = command.split(' ')[0]

                            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
                                )
                            else:
                                pbot('Command is valid an not on cooldown. (%s) (%s)' % (
                                    command, username), 
                                    channel
                                )
                                
                                result = commands.pass_to_function(command, args)
                                commands.update_last_used(command, channel)

                                if result:
                                    resp = '(%s) > %s' % (username, result)
                                    pbot(resp, channel)
                                    irc.send_message(channel, resp)

                    else:
                        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
                            )
                        elif commands.check_has_return(command):
                            pbot('Command is valid and not on cooldown. (%s) (%s)' % (
                                command, username), 
                                channel
                            )
                            commands.update_last_used(command, channel)

                            resp = '(%s) > %s' % (username, commands.get_return(command))
                            commands.update_last_used(command, channel)

                            pbot(resp, channel)
                            irc.send_message(channel, resp)
コード例 #17
0
ファイル: bot.py プロジェクト: alexbip15/MarcoBot
    def run(self):
        irc = self.irc
        sock = self.socket
        config = self.config

        while True:
            data = sock.recv(config['socket_buffer_size']).rstrip()

            if len(data) == 0:
                pp('Connection was lost, reconnecting.')
                sock = self.irc.get_irc_socket_object()

            if config['debug']:
                print data

            # check for ping, reply with pong
            irc.check_for_ping(data)

            for channel in config['channels'] :
                channel_runtime.of(channel)

            if irc.check_for_message(data):
                message_dict = irc.get_message(data)

                channel = message_dict['channel']
                message = message_dict['message']
                username = message_dict['username']

                ppi(channel, message, username)

                # check if message is a command with no arguments
                if commands.is_valid_command(message) or commands.is_valid_command(message.split(' ')[0]):
                    command = message

                    if commands.is_protected(message.split(' ')[0]) \
                                    and not username in channel_runtime.of(channel).moderators:
                                continue

                    if commands.check_returns_function(command.split(' ')[0]):
                        if commands.check_has_correct_args(command, command.split(' ')[0]):
                            args = command.split(' ')
                            del args[0]

                            command = command.split(' ')[0]

                            """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
                                )
                            else:
                                pbot('Command is valid an not on cooldown. (%s) (%s)' % (
                                    command, username),
                                    channel
                                )"""

                            #args.append(username)
                            result = commands.pass_to_function(command, args, username, channel_runtime.of(channel))
                            commands.update_last_used(command, channel)

                            if result:
                                resp = '%s' % result
                                pbot(resp, channel)
                                irc.send_message(channel, resp)

                    else:
                        """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
                            )
                        elif commands.check_has_return(command):
                            pbot('Command is valid and not on cooldown. (%s) (%s)' % (
                                command, username),
                                channel
                            )"""
                        commands.update_last_used(command, channel)

                        resp = '%s' % commands.get_return(command)
                        commands.update_last_used(command, channel)
                        if resp != "nothing":
                            pbot(resp, channel)
                            irc.send_message(channel, resp)
コード例 #18
0
ファイル: bot.py プロジェクト: Escheria/EschBot
	def run(self):
		irc = self.irc
		sock = self.socket
		config = self.config

		tasks.run_tasks()

		while True:
			data = sock.recv(config['socket_buffer_size']).rstrip()

			if len(data) == 0:
				pp('Connection was lost, reconnecting.')
				sock = self.irc.get_irc_socket_object()

			if config['debug']:
				print(data)

			# check for ping, reply with pong
			irc.check_for_ping(data)

			if irc.check_for_message(data):
				message_dict = irc.get_message(data)

				channel = message_dict['channel']
				message = message_dict['message']
				username = message_dict['username']

				ppi(channel, message, username)

				# check if message is a command with no arguments
				if commands.is_valid_command(message) or commands.is_valid_command(message.split(' ')[0]):
					command = message

					if commands.check_returns_function(command.split(' ')[0]):
						if commands.check_has_correct_args(command, command.split(' ')[0]):
							args = command.split(' ')
							del args[0]

							command = command.split(' ')[0]

							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
								)
							else:
								pbot('Command is valid an not on cooldown. (%s) (%s)' % (
									command, username), 
									channel
								)
								
								result = commands.pass_to_function(command, args)
								commands.update_last_used(command, channel)

								if result:
									# resp = '(%s) > %s' % (username, result)
									resp = '%s' % (result)
									pbot(resp, channel)
									irc.send_message(channel, resp)

					else:
						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
							)
						elif commands.check_has_return(command):
							pbot('Command is valid and not on cooldown. (%s) (%s)' % (
								command, username), 
								channel
							)
							commands.update_last_used(command, channel)

							resp = '(%s) > %s' % (username, commands.get_return(command))
							commands.update_last_used(command, channel)

							pbot(resp, channel)
							irc.send_message(channel, resp)
コード例 #19
0
    def run(self):
        irc = self.irc
        sock = self.socket
        config = self.config

        while True:
            data_raw = sock.recv(config['socket_buffer_size']).rstrip()

            for data in data_raw.split('\r'):
                data = data.strip()
                if len(data) == 0:
                    pp('Connection was lost, reconnecting.')
                    sock = self.irc.get_irc_socket_object()

                if config['debug']:
                    print data

                # check for ping, reply with pong
                if irc.check_for_ping(data):
                    continue

                if irc.check_for_join(data):
                    user, channel = irc.get_join(data)
                    self.users[channel].add(user.lower())
                    pp("User {0} joined {1}".format(user, channel))
                    continue

                if irc.check_for_part(data):
                    user, channel = irc.get_part(data)
                    try:
                        self.users[channel].remove(user.lower())
                    except KeyError:
                        pass
                    pp("User {0} left {1}".format(user, channel))
                    continue

                if irc.check_for_message(data):
                    message_dict = irc.get_message(data)

                    channel = message_dict['channel']
                    message = message_dict['message']
                    username = message_dict['username']

                    ppi(channel, message, username)

                    # check if message is a command with no arguments
                    if commands.is_valid_command(
                            message) or commands.is_valid_command(
                                message.split(' ')[0]):
                        command = message

                        if commands.check_returns_function(
                                command.split(' ')[0]):
                            if commands.check_has_correct_args(
                                    command,
                                    command.split(' ')[0]):
                                command_name = command.split(' ')[0]
                                args = command.split(' ')[1:]

                                if commands.is_on_cooldown(
                                        command_name, channel):
                                    pbot(
                                        'Command is on cooldown. (%s) (%s) (%ss remaining)'
                                        % (command, username,
                                           commands.get_cooldown_remaining(
                                               command_name, channel)),
                                        channel)
                                else:
                                    pbot(
                                        'Command is valid an not on cooldown. (%s) (%s)'
                                        % (command, username), channel)

                                    result = commands.pass_to_function(
                                        command_name[1:], args, username,
                                        self.users[channel])
                                    commands.update_last_used(
                                        command_name, channel)

                                    if result:
                                        for r in result:
                                            resp = '(%s) > %s' % (username, r)
                                            pbot(resp, channel)
                                            irc.send_message(channel, resp)

                        else:
                            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)
                            elif commands.check_has_return(command):
                                pbot(
                                    'Command is valid and not on cooldown. (%s) (%s)'
                                    % (command, username), channel)
                                commands.update_last_used(command, channel)

                                resp = '(%s) > %s' % (
                                    username, commands.get_return(command))
                                commands.update_last_used(command, channel)

                                pbot(resp, channel)
                                irc.send_message(channel, resp)