Beispiel #1
0
    def __list_generic(self, generic_args=None):
        generic_list = self.bountydb.list_generic()

        if len(generic_list) > 0:
            if generic_args:
                # list only the specified IDs
                generic_args_int = [int(gen_id) for gen_id in generic_args if BbCommon.represents_int(gen_id)]
                message = ""
                found = False
                for wh_gen in generic_list:
                    if wh_gen.idx in generic_args_int:
                        message += ">" + str(wh_gen) + "\n"
                        found = True
                if not found:
                    message += "No generic orders found with the given id(s)!"
            else:
                # list all generics
                message = "Generic orders:\n"
                for wh_gen in generic_list:
                    message += ">" + str(wh_gen) + "\n"

        else:
            message = "Generic wormhole list is empty"

        return message
Beispiel #2
0
    def __list_generic(self, generic_args=None):
        generic_list = self.bountydb.list_generic()

        if len(generic_list) > 0:
            if generic_args:
                # list only the specified IDs
                generic_args_int = [
                    int(gen_id) for gen_id in generic_args
                    if BbCommon.represents_int(gen_id)
                ]
                message = ""
                found = False
                for wh_gen in generic_list:
                    if wh_gen.idx in generic_args_int:
                        message += ">" + str(wh_gen) + "\n"
                        found = True
                if not found:
                    message += "No generic orders found with the given id(s)!"
            else:
                # list all generics
                message = "Generic orders:\n"
                for wh_gen in generic_list:
                    message += ">" + str(wh_gen) + "\n"

        else:
            message = "Generic wormhole list is empty"

        return message
Beispiel #3
0
 def cbk_generic(self, channel, cmd_args):
     if len(cmd_args) >= 1:
         idx = cmd_args[0]
         
         if BbCommon.represents_int(idx):
             # -----------------------------------------------------------------------------
             idx = int(idx)
             jcodes = self.bountydb.generic_jcodes(idx)
             if jcodes is not None:
                 if jcodes:
                     message = "Matches: {}.".format(len(jcodes))
                     
                     if len(jcodes) > BountyConfig.SEARCH_RESULTS:
                         message += " Results limited to {}.".format(BountyConfig.SEARCH_RESULTS)
                     
                     message += "```"
                     message += " ".join(jcodes[:BountyConfig.SEARCH_RESULTS])
                     message += "```"
                 
                 else:
                     message = "Generic #{} has no associated J-codes".format(idx)
             else:
                 message = "Generic #{} is not in list".format(idx)
             # -----------------------------------------------------------------------------
         else:
             message = BountyBot.cmd_error("generic", "'{}' is not a number".format(idx))
             
         # display result of operation
         self.talk(channel, message)
     else:
         self.talk(channel, BountyBot.invalid_arg("generic", 1))
Beispiel #4
0
    def cbk_remove(self, channel, cmd_args):
        if len(cmd_args) >= 1:
            # remove a generic wormhole
            if cmd_args[0].lower() == "generic":
                if len(cmd_args) >= 2:
                    idx = cmd_args[1]
                    if BbCommon.represents_int(idx):
                        idx = int(idx)
                        message = self.bountydb.remove_generic(idx)
                    else:
                        message = BountyBot.cmd_error(
                            "remove", "'{}' is not a number".format(idx))
                else:
                    message = BountyBot.cmd_error(
                        "remove",
                        "generic removal must have another argument <id>")

            # remove a specific J-code
            else:
                name = cmd_args[0]
                message = self.bountydb.remove_jcode(name)

            # display result of operation
            self.talk(channel, message)
            print "[Op] Remove:", message
        else:
            self.talk(channel, BountyBot.invalid_arg("remove", 1))
Beispiel #5
0
    def cbk_generic(self, channel, cmd_args):
        if len(cmd_args) >= 1:
            idx = cmd_args[0]

            if BbCommon.represents_int(idx):
                # -----------------------------------------------------------------------------
                idx = int(idx)
                jcodes = self.bountydb.generic_jcodes(idx)
                if jcodes is not None:
                    if jcodes:
                        message = "Matches: {}.".format(len(jcodes))

                        if len(jcodes) > BountyConfig.SEARCH_RESULTS:
                            message += " Results limited to {}.".format(
                                BountyConfig.SEARCH_RESULTS)

                        message += "```"
                        message += " ".join(
                            jcodes[:BountyConfig.SEARCH_RESULTS])
                        message += "```"

                    else:
                        message = "Generic #{} has no associated J-codes".format(
                            idx)
                else:
                    message = "Generic #{} is not in list".format(idx)
                # -----------------------------------------------------------------------------
            else:
                message = BountyBot.cmd_error(
                    "generic", "'{}' is not a number".format(idx))

            # display result of operation
            self.talk(channel, message)
        else:
            self.talk(channel, BountyBot.invalid_arg("generic", 1))
Beispiel #6
0
    def __computeFloatRange(self, text):
        min_nr = 0
        max_nr = 0
        
        matchObj = re.search("([.0-9]+)-([.0-9]+)", text, re.I)
        if matchObj:
            min_str = matchObj.group(1)
            max_str = matchObj.group(2)

            if BbCommon.represents_float(min_str) and BbCommon.represents_float(max_str):
                min_nr = float(min_str)
                max_nr = float(max_str)
        
        # maximum radius should be greater than zero and min should be smaller than max
        if matchObj and max_nr != 0 and min_nr <= max_nr:
            return [min_nr, max_nr]
        else:
            return []
Beispiel #7
0
    def __computeIntRange(self, text):
        min_nr = 0
        max_nr = 0
        
        matchObj = re.search("([0-9]+)-([0-9]+)", text, re.I)
        if matchObj:
            min_str = matchObj.group(1)
            max_str = matchObj.group(2)

            if BbCommon.represents_int(min_str) and BbCommon.represents_int(max_str):
                min_nr = int(min_str)
                max_nr = int(max_str)
        
        # min should be smaller than max
        if matchObj and min_nr <= max_nr:
            return [min_nr, max_nr]
        else:
            return []
Beispiel #8
0
    def __computeFloatRange(self, text):
        min_nr = 0
        max_nr = 0

        matchObj = re.search("([.0-9]+)-([.0-9]+)", text, re.I)
        if matchObj:
            min_str = matchObj.group(1)
            max_str = matchObj.group(2)

            if BbCommon.represents_float(
                    min_str) and BbCommon.represents_float(max_str):
                min_nr = float(min_str)
                max_nr = float(max_str)

        # maximum radius should be greater than zero and min should be smaller than max
        if matchObj and max_nr != 0 and min_nr <= max_nr:
            return [min_nr, max_nr]
        else:
            return []
Beispiel #9
0
    def __computeIntRange(self, text):
        min_nr = 0
        max_nr = 0

        matchObj = re.search("([0-9]+)-([0-9]+)", text, re.I)
        if matchObj:
            min_str = matchObj.group(1)
            max_str = matchObj.group(2)

            if BbCommon.represents_int(min_str) and BbCommon.represents_int(
                    max_str):
                min_nr = int(min_str)
                max_nr = int(max_str)

        # min should be smaller than max
        if matchObj and min_nr <= max_nr:
            return [min_nr, max_nr]
        else:
            return []
Beispiel #10
0
    def cbk_edit(self, channel, cmd_args):
        if len(cmd_args) >= 2:

            # edit a generic wormhole
            if cmd_args[0].lower() == "generic":
                if len(cmd_args) >= 3:
                    idx = cmd_args[1]
                    if BbCommon.represents_int(idx):
                        idx = int(idx)
                        description = " ".join(cmd_args[2:])
                        [message, result_info
                         ] = self.bountydb.edit_generic(idx, description)
                        if result_info != "":
                            self.talk(channel, result_info)
                    else:
                        message = BountyBot.cmd_error(
                            "edit", "'{}' is not a number".format(idx))
                else:
                    message = BountyBot.cmd_error(
                        "edit",
                        "generic editing must have an <id> and a <new_description>"
                    )

            # edit a specific wormhole
            else:
                name = cmd_args[0]

                if cmd_args[1].lower() == "true":
                    watchlist = True
                elif cmd_args[1].lower() == "false":
                    watchlist = False
                else:
                    watchlist = None

                comments = " ".join(cmd_args[2:])

                if watchlist is not None:
                    message = self.bountydb.edit_jcode(name, watchlist,
                                                       comments)
                else:
                    message = BountyBot.cmd_error(
                        "edit",
                        "2nd argument 'watchlist' must be either true or false"
                    )

            # display result of operation
            self.talk(channel, message)
            print "[Op] Edit:", message
        else:
            self.talk(channel, BountyBot.invalid_arg("edit", 2))
Beispiel #11
0
 def cbk_edit(self, channel, cmd_args):
     if len(cmd_args) >= 2:
 
         # edit a generic wormhole
         if cmd_args[0].lower() == "generic":
             if len(cmd_args) >= 3:
                 idx = cmd_args[1]
                 if BbCommon.represents_int(idx):
                     idx = int(idx)
                     description = " ".join(cmd_args[2:])
                     [message, result_info] = self.bountydb.edit_generic(idx, description)
                     if result_info != "":
                         self.talk(channel, result_info)
                 else:
                     message = BountyBot.cmd_error("edit", "'{}' is not a number".format(idx))
             else:
                 message = BountyBot.cmd_error("edit", "generic editing must have an <id> and a <new_description>")
 
         # edit a specific wormhole
         else:
             name = cmd_args[0]
             
             if cmd_args[1].lower() == "true":
                 watchlist = True
             elif cmd_args[1].lower() == "false":
                 watchlist = False
             else:
                 watchlist = None
             
             comments = " ".join(cmd_args[2:])
             
             if watchlist is not None:
                 message = self.bountydb.edit_jcode(name, watchlist, comments)
             else:
                 message = BountyBot.cmd_error("edit", "2nd argument 'watchlist' must be either true or false")
 
         # display result of operation
         self.talk(channel, message)
         print "[Op] Edit:", message
     else:
         self.talk(channel, BountyBot.invalid_arg("edit", 2))
Beispiel #12
0
 def cbk_remove(self, channel, cmd_args):
     if len(cmd_args) >= 1:
         # remove a generic wormhole
         if cmd_args[0].lower() == "generic":
             if len(cmd_args) >= 2:
                 idx = cmd_args[1]
                 if BbCommon.represents_int(idx):
                     idx = int(idx)
                     message = self.bountydb.remove_generic(idx)
                 else:
                     message = BountyBot.cmd_error("remove", "'{}' is not a number".format(idx))
             else:
                 message = BountyBot.cmd_error("remove", "generic removal must have another argument <id>")
         
         # remove a specific J-code
         else:
             name = cmd_args[0]
             message = self.bountydb.remove_jcode(name)
         
         # display result of operation
         self.talk(channel, message)
         print "[Op] Remove:", message
     else:
         self.talk(channel, BountyBot.invalid_arg("remove", 1))