Ejemplo n.º 1
0
    def parseResponse(self):
        # Check for errors.
        notEnoughMeatPattern = PatternManager.getOrCompilePattern(
            'noMeatForStore')
        invalidStorePattern = PatternManager.getOrCompilePattern(
            'invalidStore')
        notSoldPattern = PatternManager.getOrCompilePattern('notSoldHere')
        if len(self.responseText) == 0:
            raise Error.Error("You cannot visit that store yet.",
                              Error.INVALID_LOCATION)
        if invalidStorePattern.search(self.responseText):
            raise Error.Error("The store you tried to visit doesn't exist.",
                              Error.INVALID_LOCATION)
        if notSoldPattern.search(self.responseText):
            raise Error.Error("This store doesn't carry that item.",
                              Error.ITEM_NOT_FOUND)
        if notEnoughMeatPattern.search(self.responseText):
            raise Error.Error(
                "You do not have enough meat to purchase the item(s).",
                Error.NOT_ENOUGH_MEAT)

        items = ParseResponseUtils.parseItemsReceived(self.responseText,
                                                      self.session)
        if len(items) == 0:
            raise Error.Error("Unknown error. No items received.",
                              Error.REQUEST_FATAL)
        self.responseData["items"] = items

        meatSpentPattern = PatternManager.getOrCompilePattern('meatSpent')
        match = meatSpentPattern.search(self.responseText)
        self.responseData['meatSpent'] = int(match.group(1).replace(',', ''))
Ejemplo n.º 2
0
    def parseResponse(self):
        # Check for errors.
        dontHaveMeatpastePattern = PatternManager.getOrCompilePattern(
            'noMeatpaste')
        itemsDontMeatpastePattern = PatternManager.getOrCompilePattern(
            'itemsDontMeatpaste')
        dontHaveItemsPattern = PatternManager.getOrCompilePattern(
            'dontHaveItemsMeatpaste')
        if dontHaveMeatpastePattern.search(self.responseText):
            e = Error.Error(
                "Unable to combine items. You don't have any meatpaste.",
                Error.ITEM_NOT_FOUND)
            e.itemId = 25
            raise e
        elif itemsDontMeatpastePattern.search(self.responseText):
            raise Error.Error(
                "Unable to combine items. The submitted ingredients do not meatpaste together.",
                Error.RECIPE_NOT_FOUND)
        elif dontHaveItemsPattern.search(self.responseText):
            raise Error.Error(
                "Unable to combine items. You don't have all of the items you are trying to meatpaste.",
                Error.ITEM_NOT_FOUND)

        # Find the items attached to the message.
        items = ParseResponseUtils.parseItemsReceived(self.responseText,
                                                      self.session)
        if len(items) > 0:
            self.responseData["items"] = items
        else:
            raise Error.Error(
                "Unknown error meatpasting items: %s" % self.responseText,
                Error.REQUEST_FATAL)
Ejemplo n.º 3
0
    def parseResponse(self):
        noWokAccess = PatternManager.getOrCompilePattern('noWokAccess')
        itemsDontMakeFoodPattern = PatternManager.getOrCompilePattern('dontHaveItemsForWok')
        dontHaveSkillPattern = PatternManager.getOrCompilePattern('dontHaveSkillForWok')
        dontHaveAdventuresPattern = PatternManager.getOrCompilePattern('dontHaveAdventuresForWok')
        # Check for errors.
        if noWokAccess.search(self.responseText):
            raise Error.Error("Unable to use the Wok of Ages. I can't get to the Wok!", Error.RECIPE_NOT_FOUND)
        elif dontHaveSkillPattern.search(self.responseText):
            raise Error.Error("Unable to use the Wok of Ages. I am not skilled enough.", Error.SKILL_NOT_FOUND)
        elif itemsDontMakeFoodPattern.search(self.responseText):
            raise Error.Error("Unable to use the Wok of Ages. Invalid ingredients.", Error.ITEM_NOT_FOUND)
        elif dontHaveAdventuresPattern.search(self.responseText):
            raise Error.Error("Unable to use the Wok of Agles. I don't have enough adventures.", Error.NOT_ENOUGH_ADVENTURES)

        # Find the items attached to the message.
        singleItemPattern = PatternManager.getOrCompilePattern('acquireSingleItem')
        match = singleItemPattern.search(self.responseText)
        if match:
            descId = int(match.group(1))
            item = ItemDatabase.getOrDiscoverItemFromDescId(descId, self.session)
            item["quantity"] = 1
        else:
            multiItemPattern = PatternManager.getOrCompilePattern('acquireMultipleItems')
            match = multiItemPattern.search(self.responseText)
            if match:
                descId = int(match.group(1))
                item = ItemDatabase.getOrDiscoverItemFromDescId(descId, self.session)
                quantity = int(match.group(2).replace(',', ''))
                item["quantity"] = quantity
            else:
                raise Error.Error("Unknown error.", Error.REQUEST_GENERIC)

        self.responseData["wok"] = item
Ejemplo n.º 4
0
    def parseResponse(self):
        cantPulverizePattern = PatternManager.getOrCompilePattern('cantPulverizeItem')
        if cantPulverizePattern.search(self.responseText) != None:
            item = ItemDatabase.getOrDiscoverItemFromId(self.itemId, self.session)
            raise Error.Error("'%s' is not an item that can be pulverized." % item["name"], Error.WRONG_KIND_OF_ITEM)

        notEnoughItemsPattern = PatternManager.getOrCompilePattern('notEnoughItems')
        if notEnoughItemsPattern.search(self.responseText) != None:
            item = ItemDatabase.getOrDiscoverItemFromId(self.itemId, self.session)
            if self.quantity == 1:
                itemStr = item["name"]
            else:
                itemStr = item["plural"]
            raise Error.Error("You do not have %s (%s)." % (itemStr, self.quantity), Error.ITEM_NOT_FOUND)

        items = []

        singleItemPattern = PatternManager.getOrCompilePattern('acquireSingleItem')
        for match in singleItemPattern.finditer(self.responseText):
            descId = int(match.group(1))
            item = ItemDatabase.getOrDiscoverItemFromDescId(descId, self.session)
            item["quantity"] = 1
            items.append(item)

        multiItemPattern = PatternManager.getOrCompilePattern('acquireMultipleItems')
        for match in multiItemPattern.finditer(self.responseText):
            descId = int(match.group(1))
            quantity = int(match.group(2).replace(',', ''))
            item = ItemDatabase.getOrDiscoverItemFromDescId(descId, self.session)
            item["quantity"] = quantity
            items.append(item)

        self.responseData["results"] = items
Ejemplo n.º 5
0
    def parseResponse(self):
        weakSkillPattern = PatternManager.getOrCompilePattern('skillTooWeak')
        badSkillPattern = PatternManager.getOrCompilePattern(
            'skillNotTrainable')
        poorSkillPattern = PatternManager.getOrCompilePattern('skillTooPoor')
        haveSkillPattern = PatternManager.getOrCompilePattern(
            'skillHaveAlready')

        if weakSkillPattern.search(self.responseText):
            raise Error.Error(
                "You aren't a high enough level to train that skill.",
                Error.USER_IS_LOW_LEVEL)
        if badSkillPattern.search(self.responseText):
            raise Error.Error("You cannot train that skill at the Guild Hall.",
                              Error.SKILL_NOT_FOUND)
        if poorSkillPattern.search(self.responseText):
            raise Error.Error("You cannot afford to train that skill",
                              Error.NOT_ENOUGH_MEAT)
        if haveSkillPattern.search(self.responseText):
            raise Error.Error("You already know that skill.",
                              Error.ALREADY_COMPLETED)

        skillLearnedPattern = PatternManager.getOrCompilePattern(
            'skillLearned')
        match = skillLearnedPattern.search(self.responseText)
        skill = SkillDatabase.getSkillFromName(match.group(1))
        self.responseData["skill"] = skill
Ejemplo n.º 6
0
    def parseResponse(self):
        resultsPattern = PatternManager.getOrCompilePattern('results')

        if self._hc_ronin.search(self.responseText) is not None:
            raise Error.Error(
                "Unable to cast spell. "
                "User is in Hardcore/Ronin.", Error.USER_IN_HARDCORE_RONIN)
        if self._noskill.search(self.responseText) is not None:
            raise Error.Error("Unable to cast spell. I don't know it.",
                              Error.INVALID_ITEM)
        if self._nouser.search(self.responseText) is not None:
            raise Error.Error("Unable to cast spell. No such user.",
                              Error.INVALID_USER)
        if self._ignoring.search(self.responseText) is not None:
            raise Error.Error("Unable to cast spell. User is ignoring us.",
                              Error.USER_IS_IGNORING)
        if self._tooManyATBuffs.search(self.responseText) is not None:
            raise Error.Error(
                "Unable to cast spell. User has too many "
                "songs in his/her head.", Error.LIMIT_REACHED)

        match = resultsPattern.search(self.responseText)
        if match:
            results = match.group(1)
            self.responseData["results"] = results
Ejemplo n.º 7
0
    def parseResponse(self):
        noMeatPattern = PatternManager.getOrCompilePattern(
            'traderHasNotEnoughMeat')
        if noMeatPattern.search(self.responseText):
            raise Error.Error(
                "You don't have as much meat as you're promising.",
                Error.NOT_ENOUGH_MEAT)

        noItemsPattern = PatternManager.getOrCompilePattern(
            'traderHasNotEnoughItems')
        if noItemsPattern.search(self.responseText):
            raise Error.Error(
                "You don't have as many items as you're promising.",
                Error.NOT_ENOUGH_ITEMS)

        #Not testing for an offer being cancelled due to a bug in KoL - space reserved

        successPattern = PatternManager.getOrCompilePattern(
            'tradeResponseSentSuccessfully')
        if successPattern.search(self.responseText):
            Report.trace(
                "request", "Response to trade " +
                str(self.requestData['whichoffer']) + ' sent successfully.')
        else:
            raise Error.Error(
                "Unknown error sending response to trade " +
                str(self.requestData['whichoffer']), Error.REQUEST_GENERIC)
Ejemplo n.º 8
0
 def parseResponse(self):
     if self.requestTooHigh.search(self.responseText):
         raise Error.Error("You don't require that much healing.",
                           Error.REQUEST_GENERIC)
     if self.notEnoughMeat.search(self.responseText):
         raise Error.Error("You don't have enough meat.",
                           Error.NOT_ENOUGH_MEAT)
     self.responseData = {}
Ejemplo n.º 9
0
    def parseResponse(self):
        itemsDontMakeFoodPattern = PatternManager.getOrCompilePattern(
            'itemsDontCook')
        dontHaveSkillPattern = PatternManager.getOrCompilePattern(
            'dontHaveSkillToCook')
        dontHaveItemsPattern = PatternManager.getOrCompilePattern(
            'dontHaveItemsForCook')
        dontHaveAdventuresPattern = PatternManager.getOrCompilePattern(
            'dontHaveAdventuresToCook')
        chefExplosionPattern = PatternManager.getOrCompilePattern(
            'chefExplosion')
        # Check for errors.
        if itemsDontMakeFoodPattern.search(self.responseText):
            raise Error.Error(
                "Unable to make food. The submitted ingredients do not cook together.",
                Error.RECIPE_NOT_FOUND)
        elif dontHaveSkillPattern.search(self.responseText):
            raise Error.Error(
                "Unable to make food. We are not skilled enough.",
                Error.SKILL_NOT_FOUND)
        elif dontHaveItemsPattern.search(self.responseText):
            raise Error.Error(
                "Unable to make food. You don't have all of the items you are trying to cook.",
                Error.ITEM_NOT_FOUND)
        elif dontHaveAdventuresPattern.search(self.responseText):
            raise Error.Error(
                "Unable to cook food(s). We don't have enough adventures.",
                Error.NOT_ENOUGH_ADVENTURES)

        # Find the items attached to the message.
        singleItemPattern = PatternManager.getOrCompilePattern(
            'acquireSingleItem')
        match = singleItemPattern.search(self.responseText)
        if match:
            descId = int(match.group(1))
            item = ItemDatabase.getOrDiscoverItemFromDescId(
                descId, self.session)
            item["quantity"] = 1
        else:
            multiItemPattern = PatternManager.getOrCompilePattern(
                'acquireMultipleItems')
            match = multiItemPattern.search(self.responseText)
            if match:
                descId = int(match.group(1))
                item = ItemDatabase.getOrDiscoverItemFromDescId(
                    descId, self.session)
                quantity = int(match.group(2).replace(',', ''))
                item["quantity"] = quantity
            else:
                raise Error.Error("Unknown error.", Error.REQUEST_GENERIC)

        # Check for an explosion
        if chefExplosionPattern.search(self.responseText):
            self.responseData["explosion"] = 1
            #TODO: Remove the items that came from the explosion

        self.responseData["food"] = item
Ejemplo n.º 10
0
    def parseResponse(self):
        notEnoughMeatPattern = PatternManager.getOrCompilePattern(
            'noMeatForStore')
        cannotGoPattern = PatternManager.getOrCompilePattern(
            'userShouldNotBeHere')
        notSoldPattern = PatternManager.getOrCompilePattern('notSoldHere')

        if cannotGoPattern.search(self.responseText):
            raise Error.Error("You cannot reach that cafe.",
                              Error.INVALID_LOCATION)
        if notSoldPattern.search(self.responseText):
            raise Error.Error("This cafe doesn't carry that item.",
                              Error.ITEM_NOT_FOUND)
        if notEnoughMeatPattern.search(self.responseText):
            raise Error.Error(
                "You do not have enough meat to purchase the item(s).",
                Error.NOT_ENOUGH_MEAT)

        response = {}

        advResponse = ParseResponseUtils.parseAdventuresGained(
            self.responseText)
        if advResponse > 0:
            response["adventures"] = advResponse

        drunkResponse = ParseResponseUtils.parseDrunkGained(self.responseText)
        if drunkResponse > 0:
            response["drunkeness"] = drunkResponse

        subResponse = ParseResponseUtils.parseSubstatsGainedLost(
            self.responseText)
        if len(subResponse) > 0:
            response["substats"] = subResponse

        statResponse = ParseResponseUtils.parseStatsGainedLost(
            self.responseText)
        if len(statResponse) > 0:
            response["statPoints"] = statResponse

        levelResponse = ParseResponseUtils.parseLevelsGained(self.responseText)
        if levelResponse > 0:
            response["level"] = levelResponse

        effectResponse = ParseResponseUtils.parseEffectsGained(
            self.responseText)
        if len(effectResponse) > 0:
            response["effects"] = effectResponse

        hpResponse = ParseResponseUtils.parseHPGainedLost(self.responseText)
        if hpResponse != 0:
            response["hp"] = hpResponse

        mpResponse = ParseResponseUtils.parseMPGainedLost(self.responseText)
        if mpResponse != 0:
            response["mp"] = mpResponse

        self.responseData = response
Ejemplo n.º 11
0
 def parseResponse(self):
     if self.notEnough.search(self.responseText):
         raise Error.Error("Not enough items", Error.ITEM_NOT_FOUND)
     if self.badId.search(self.responseText):
         raise Error.Error("Bad hotdog ID", Error.INVALID_ACTION)
     if self.success.search(self.responseText):
         self.responseData["success"] = True
         return
     
     raise Error.Error("Unknown error. (Is that hotdog unlocked?)", Error.REQUEST_FATAL)
 def parseResponse(self):
     invalidGiftPattern = PatternManager.getOrCompilePattern('crimboInvalidGift')
     if invalidGiftPattern.search(self.responseText):
         raise Error.Error("Invalid gift selected.", Error.WRONG_KIND_OF_ITEM)
     
     invalidPlayerPattern = PatternManager.getOrCompilePattern('crimboInvalidPlayer')
     if invalidPlayerPattern.search(self.responseText):
         raise Error.Error("Invalid player.", Error.USER_NOT_FOUND)
     
     giftAlreadyReceivedPattern = PatternManager.getOrCompilePattern('crimboUserAlreadyReceivedGift')
     if giftAlreadyReceivedPattern.search(self.responseText):
         raise Error.Error("That player has already received that gift.", Error.ALREADY_COMPLETED)
Ejemplo n.º 13
0
    def parseResponse(self):
        # Check for errors.
        noMeatForPastePattern = PatternManager.getOrCompilePattern('noMeatForMeatpasting')
        if noMeatForPastePattern.search(self.responseText):
            raise Error.Error("Unable to make the requested item. You don't have enough meat.", Error.NOT_ENOUGH_MEAT)

        # Get the item(s) we received.
        items = ParseResponseUtils.parseItemsReceived(self.responseText, self.session)
        if len(items) > 0:
            self.responseData["items"] = items
        else:
            raise Error.Error("Unknown error. No items received.", Error.REQUEST_GENERIC)
Ejemplo n.º 14
0
 def parseResponse(self):
     # First parse for errors
     notEnoughPattern = PatternManager.getOrCompilePattern("dontHaveThatManyInStore")
     if notEnoughPattern.search(self.responseText):
         raise Error.Error("You either don't have that item, or not enough", Error.ITEM_NOT_FOUND)
         
     # Check if responseText matches the success pattern. If not, raise error.
     itemTakenSuccessfully = PatternManager.getOrCompilePattern("itemTakenSuccessfully")
     if itemTakenSuccessfully.search(self.responseText):
          Report.trace('request', 'Item appears to have been taken')
     else:
         raise Error.Error("Something went wrong with the taking of the item.", Error.ITEM_NOT_FOUND)
Ejemplo n.º 15
0
    def parseResponse(self):
        itemsDontMakeCocktailPattern = PatternManager.getOrCompilePattern(
            'itemsDontMakeCocktail')
        dontHaveSkillPattern = PatternManager.getOrCompilePattern(
            'dontHaveSkillToMixCocktail')
        dontHaveItemsPattern = PatternManager.getOrCompilePattern(
            'dontHaveItemsForThatCocktail')
        dontHaveAdventuresPattern = PatternManager.getOrCompilePattern(
            'dontHaveAdventuresToMixCocktail')

        # Check for errors.
        if itemsDontMakeCocktailPattern.search(self.responseText):
            raise Error.Error(
                "Unable to make cocktail. The submitted ingredients do not mix together.",
                Error.RECIPE_NOT_FOUND)
        elif dontHaveSkillPattern.search(self.responseText):
            raise Error.Error(
                "Unable to make cocktail. We are not skilled enough.",
                Error.SKILL_NOT_FOUND)
        elif dontHaveItemsPattern.search(self.responseText):
            raise Error.Error(
                "Unable to make cocktail. You don't have all of the items you are trying to mix.",
                Error.ITEM_NOT_FOUND)
        elif dontHaveAdventuresPattern.search(self.responseText):
            raise Error.Error(
                "Unable to mix drink(s). We don't have enough adventures.",
                Error.NOT_ENOUGH_ADVENTURES)

        # Find the items attached to the message.
        singleItemPattern = PatternManager.getOrCompilePattern(
            'acquireSingleItem')
        match = singleItemPattern.search(self.responseText)
        if match:
            descId = int(match.group(1))
            item = ItemDatabase.getOrDiscoverItemFromDescId(
                descId, self.session)
            item["quantity"] = 1
        else:
            multiItemPattern = PatternManager.getOrCompilePattern(
                'acquireMultipleItems')
            match = multiItemPattern.search(self.responseText)
            if match:
                descId = int(match.group(1))
                item = ItemDatabase.getOrDiscoverItemFromDescId(
                    descId, self.session)
                quantity = int(match.group(2).replace(',', ''))
                item["quantity"] = quantity
            else:
                raise Error.Error("Unknown error.", Error.REQUEST_GENERIC)

        self.responseData["booze"] = item
Ejemplo n.º 16
0
    def doRequest(self):
        """
        Performs the request. This method will ensure that nightly maintenance is not occuring.
        In addition, this method will throw a NOT_LOGGED_IN error if the session thinks it is
        logged in when it actually isn't.
        """

        Report.debug("request", "Requesting %s" % self.url)

        self.response = self.session.opener.opener.post(self.url, self.requestData, stream=True)
        responseStr = StringIO()
        try:
            for chunk in self.response.iter_content(self.chunkSize):
                responseStr.write(chunk)
                s = responseStr.getvalue()
                
                matched = True
                for regex in self.regexList:
                    if not regex.search(s):
                        matched = False
                        break

                if matched:                    
                    break

            self.responseText = responseStr.getvalue()
            responseStr.close()
        finally:
            self.response.close()

        Report.debug("request", "Received response: %s" % self.url)
        Report.debug("request", "Response Text: %s" % self.responseText)

        if self.response.url.find("/maint.php") >= 0:
            self.session.isConnected = False
            raise Error.Error("Nightly maintenance in progress.", Error.NIGHTLY_MAINTENANCE)

        if self.response.url.find("/login.php") >= 0:
            if self.session.isConnected:
                self.session.isConnected = False
                raise Error.Error("You are no longer connected to the server.", Error.NOT_LOGGED_IN)

        # Allow for classes that extend GenericRequest to parse all of the data someone
        # would need from the response and then to place this data in self.responseData.
        self.responseData = {}
        if self.skipParseResponse == False and hasattr(self, "parseResponse"):
            self.parseResponse()
            if len(self.responseData) > 0:
                Report.debug("request", "Parsed response data: %s" % self.responseData)

        return self.responseData
Ejemplo n.º 17
0
    def parseResponse(self):
        "Checks for errors due to equipping items you don't have, or equipping items that aren't equippable."

        noItemPattern = PatternManager.getOrCompilePattern("notEnoughItems")
        match = noItemPattern.search(self.responseText)
        if match:
            raise Error.Error("That item is not in your inventory.",
                              Error.ITEM_NOT_FOUND)

        notEquipmentPattern = PatternManager.getOrCompilePattern("notEquip")
        match = notEquipmentPattern.search(self.responseText)
        if match:
            raise Error.Error("That is not an equippable item.",
                              Error.WRONG_KIND_OF_ITEM)
Ejemplo n.º 18
0
def botProcessKmail(context, **kwargs):
    returnCode = FilterManager.CONTINUE
    message = kwargs["kmail"]
    bot = kwargs["bot"]
    cmd = BotUtils.getKmailCommand(message)

    if cmd == "uneffect":
        arr = message["text"].split()
        items = message["items"]

        # Get the effect ID.
        if len(arr) < 2:
            raise Error.Error(
                "You must specify the ID of the effect to remove.",
                Error.BOT_REQUEST)
        try:
            effectId = int(arr[1])
        except ValueError:
            raise Error.Error("Unable to remove effect. Invalid effect ID.",
                              Error.BOT_REQUEST)

        # Ensure the user sent a SGEEA.
        if len(items) != 1:
            raise Error.Error("Please include just a SGEEA in your kmail.",
                              Error.BOT_REQUEST)
        sgeea = ItemDatabase.getItemFromName(
            "soft green echo eyedrop antidote")
        if items[0]["id"] != sgeea["id"] or items[0]["quantity"] != 1:
            raise Error.Error(
                "Please include just a single SGEEA in your kmail.",
                Error.BOT_REQUEST)

        # Perform the request.
        m = {}
        m["userId"] = message["userId"]
        Report.info("bot", "Attempting to remove effect %s..." % effectId)
        r = UneffectRequest(bot.session, effectId)
        try:
            r.doRequest()
            m["text"] = "Effect successfully removed!"
        except Error.Error, inst:
            if inst.code == Error.EFFECT_NOT_FOUND:
                m["text"] = "I do not currently have that effect."
                m["items"] = items
            else:
                m["text"] = "Unable to remove effect for unknown reason."
                m["items"] = items

        bot.sendKmail(m)
        returnCode = FilterManager.FINISHED
Ejemplo n.º 19
0
    def parseResponse(self):
        if self.notSold.search(self.responseText):
            raise Error.Error("This store doesn't carry that item.", Error.ITEM_NOT_FOUND)
        if self.notEnoughMeat.search(self.responseText):
            raise Error.Error("You do not have enough meat to purchase the item(s).", Error.NOT_ENOUGH_MEAT)

        items = ParseResponseUtils.parseItemsReceived(self.responseText, self.session)
        if len(items) == 0:
            raise Error.Error("Unknown error. No items received.", Error.REQUEST_FATAL)
        self.responseData["items"] = items

        meatSpentPattern = PatternManager.getOrCompilePattern('meatSpent')
        match = meatSpentPattern.search(self.responseText)
        self.responseData['meatSpent'] = int(match.group(1).replace(',', ''))
Ejemplo n.º 20
0
    def parseResponse(self):
        notBarrelPattern = PatternManager.getOrCompilePattern('usedBarrel')
        noAdventuresPattern = PatternManager.getOrCompilePattern(
            'noAdventures')
        if notBarrelPattern.match(self.responseText):
            raise Error.Error(
                "Barrel already opened or doesn't exist. (#%s)" %
                self.requestData['smash'], Error.INVALID_ACTION)
        if noAdventuresPattern.match(self.responseText):
            raise Error.Error("You don't have enough adventures to smash that",
                              Error.NOT_ENOUGH_ADVENTURES)

        url = self.response.geturl()
        if url.find("/fight.php") >= 0:
            # Get the monster's name.
            self.responseData["adventureType"] = "combat"
            monsterNamePattern = PatternManager.getOrCompilePattern(
                'monsterName')
            monsterNameMatch = monsterNamePattern.search(self.responseText)
            self.responseData["monsterName"] = monsterNameMatch.group(1)

            # Check to see if the fight was won or lost.
            fightWonPattern = PatternManager.getOrCompilePattern('fightWon')
            if fightWonPattern.search(self.responseText):
                self.responseData["fightWon"] = True
            else:
                fightLostPattern = PatternManager.getOrCompilePattern(
                    'fightLost')
                if fightLostPattern.search(self.responseText):
                    self.responseData["fightLost"] = True

            # Get items, meat, and substats gained. We always need to check these since they can
            # happen at any point during the fight.
            self.responseData["items"] = ParseResponseUtils.parseItemsReceived(
                self.responseText, self.session)
            self.responseData["meat"] = ParseResponseUtils.parseMeatGainedLost(
                self.responseText)
            self.responseData[
                "substats"] = ParseResponseUtils.parseSubstatsGainedLost(
                    self.responseText)

        item = ParseResponseUtils.parseItemsReceived(self.responseText,
                                                     self.session)
        if len(item) > 0:
            self.responseData["items"] = item

        hp = ParseResponseUtils.parseHPGainedLost(self.responseText)
        if hp != 0:
            self.responseData["hp"] = hp
Ejemplo n.º 21
0
    def parseResponse(self):
        # Get the URL of the server that we were told to use.
        loginUrlPattern = PatternManager.getOrCompilePattern('loginURL')
        serverMatch = loginUrlPattern.match(self.response.geturl())
        if serverMatch:
            self.responseData["serverURL"] = serverMatch.group(1)
        else:
            raise Error.Error("Unable to determine server URL from: " + self.response.geturl(), Error.LOGIN_FAILED_GENERIC)

        # Get the user's challenge string which is used to provide a more secure login mechanism.
        loginChallengePattern = PatternManager.getOrCompilePattern('loginChallenge')
        challengeMatch = loginChallengePattern.search(self.responseText)
        if challengeMatch:
            self.responseData["loginChallenge"] = challengeMatch.group(1)
        else:
            raise Error.Error("Unable to find login challenge:\n" + self.responseText, Error.LOGIN_FAILED_GENERIC)
Ejemplo n.º 22
0
def getItemFromDescId(descId, session=None):
    "Returns information about an item given its description ID."
    if not __isInitialized:
        init()

    try:
        return __itemsByDescId[descId].copy()
    except KeyError:
        myError = Error.Error(
            "Item with description ID %s is unknown." % descId,
            Error.ITEM_NOT_FOUND)
        try:
            if session is None:
                raise KeyError()
            r = ItemDescriptionRequest(session, descId)
            result = r.doRequest()
            if not result or result['id'] is None:
                raise myError
            id_ = int(result['id'])
            if id_ in __itemsById:
                return __itemsById[id_].copy()
            else:
                try:
                    return getItemFromId(id_, session)
                except Error.Error:
                    return result
        except (KeyError, Error.Error):
            raise myError
Ejemplo n.º 23
0
def getItemFromId(itemId, session=None):
    "Returns information about an item given its ID."
    global __dbChanged

    if not __isInitialized:
        init()

    try:
        return __itemsById[itemId].copy()
    except KeyError:
        try:
            if session is None:
                raise KeyError()
            from kol.request.ItemInformationRequest import ItemInformationRequest
            r = ItemInformationRequest(session, itemId)
            result = r.doRequest()
            item = result["item"]
            addItem(item)
            Report.trace("itemdatabase",
                         "Discovered new item: %s" % item["name"])
            context = {"item": item}
            FilterManager.executeFiltersForEvent("discoveredNewItem",
                                                 context,
                                                 session=session,
                                                 item=item)
            __dbChanged = True
            return item
        except (KeyError, Error.Error):
            raise Error.Error("Item ID %s is unknown." % itemId,
                              Error.ITEM_NOT_FOUND)
Ejemplo n.º 24
0
    def parseResponse(self):
        # Check for errors.
        effectRemovedPattern = PatternManager.getOrCompilePattern('effectRemoved')
        if effectRemovedPattern.search(self.responseText):
            return

        youDontHaveThatEffectPattern = PatternManager.getOrCompilePattern('youDontHaveThatEffect')
        if youDontHaveThatEffectPattern.search(self.responseText):
            raise Error.Error("Unable to remove effect. The user does not have that effect.", Error.EFFECT_NOT_FOUND)

        youDontHaveSGEEAPattern = PatternManager.getOrCompilePattern('youDontHaveSGEEA')
        if youDontHaveSGEEAPattern.search(self.responseText):
            raise Error.Error("Unable to remove effect. You do not have a soft green echo eyedrop antidote.", Error.ITEM_NOT_FOUND)

        Report.error("request", "Unknown error occurred when trying to remove an effect")
        Report.error("request", self.responseText)
        raise Error.Error("Unknown error occurred when trying to remove an effect.", Error.REQUEST_FATAL)
Ejemplo n.º 25
0
    def parseResponse(self):
        mainFramesetPattern = PatternManager.getOrCompilePattern(
            'mainFrameset')
        if mainFramesetPattern.search(self.responseText):
            self.session.isConnected = True
            return

        waitFifteenMinutesPattern = PatternManager.getOrCompilePattern(
            'waitFifteenMinutesLoginError')
        if waitFifteenMinutesPattern.search(self.responseText):
            e = Error.Error(
                "Too many login attempts in too short a span of time. Please wait fifteen minutes and try again.",
                Error.LOGIN_FAILED_GENERIC)
            e.timeToWait = 900
            raise e

        waitFiveMinutesPattern = PatternManager.getOrCompilePattern(
            'waitFiveMinutesLoginError')
        if waitFiveMinutesPattern.search(self.responseText):
            e = Error.Error(
                "Too many login attempts in too short a span of time. Please wait five minutes and try again.",
                Error.LOGIN_FAILED_GENERIC)
            e.timeToWait = 300
            raise e

        waitOneMinutePattern = PatternManager.getOrCompilePattern(
            'waitOneMinuteLoginError')
        if waitOneMinutePattern.search(self.responseText):
            e = Error.Error(
                "Too many login attempts in too short a span of time. Please wait a minute and try again.",
                Error.LOGIN_FAILED_GENERIC)
            e.timeToWait = 60
            raise e

        waitTwoMinutesPattern = PatternManager.getOrCompilePattern(
            'waitTwoMinutesLoginError')
        if waitTwoMinutesPattern.search(self.responseText):
            e = Error.Error(
                "Your previous session did not close correctly. Please wait a couple of minutes and try again.",
                Error.LOGIN_FAILED_GENERIC)
            e.timeToWait = 120
            raise e

        badPasswordPattern = PatternManager.getOrCompilePattern('badPassword')
        if badPasswordPattern.search(self.responseText):
            raise Error.Error("Login failed. Bad password.",
                              Error.LOGIN_FAILED_BAD_PASSWORD)

        tooManyFailuresFromIPPattern = PatternManager.getOrCompilePattern(
            'tooManyLoginsFailuresFromThisIP')
        if tooManyFailuresFromIPPattern.search(self.responseText):
            e = Error.Error(
                "Too many login failures from this IP. Please wait 15 minutes and try again.",
                Error.LOGIN_FAILED_GENERIC)
            e.timeToWait = 900
            raise e

        e = Error.Error("Unknown login error.", Error.LOGIN_FAILED_GENERIC)
        e.timeToWait = 900
        raise e
Ejemplo n.º 26
0
def getItemFromName(itemName):
    "Returns information about an item given its name."
    if not __isInitialized:
        init()

    try:
        return __itemsByName[itemName].copy()
    except KeyError:
        raise Error.Error("The item '%s' is unknown." % itemName, Error.ITEM_NOT_FOUND)
Ejemplo n.º 27
0
def getItemFromDescId(descId):
    "Returns information about an item given its description ID."
    if not __isInitialized:
        init()

    try:
        return __itemsByDescId[descId].copy()
    except KeyError:
        raise Error.Error("Item with description ID %s is unknown." % descId, Error.ITEM_NOT_FOUND)
Ejemplo n.º 28
0
def getItemFromId(itemId):
    "Returns information about an item given its ID."
    if not __isInitialized:
        init()

    try:
        return __itemsById[itemId].copy()
    except KeyError:
        raise Error.Error("Item ID %s is unknown." % itemId, Error.ITEM_NOT_FOUND)
Ejemplo n.º 29
0
 def parseResponse(self):
     # Look for known errors. We override the NOT_ENOUGH_MEAT error here because it basically matches the error condition
     # of not having enough currency to buy the particular product. It is not worth creating a one-off error for this
     # particular situation, especially since the trader doesn't deal in meat.
     p = PatternManager.getOrCompilePattern('traderNotTradingForThatItem')
     if p.search(self.responseText):
         raise Error.Error("The trader isn't trading for that item.", Error.ITEM_NOT_FOUND)
     p = PatternManager.getOrCompilePattern('traderCantTradeForThatMany')
     if p.search(self.responseText):
         raise Error.Error("You are unable to trade for that many items.", Error.NOT_ENOUGH_MEAT)
     p = PatternManager.getOrCompilePattern('traderNotEnoughWads')
     if p.search(self.responseText):
         raise Error.Error("You are unable to trade for that many items.", Error.NOT_ENOUGH_MEAT)
     
     items = ParseResponseUtils.parseItemsReceived(self.responseText, self.session)
     if len(items) == 0:
         raise Error.Error("Unknown error. No items received.", Error.REQUEST_FATAL)
     self.responseData["items"] = items
Ejemplo n.º 30
0
 def parseResponse(self):
     # Get the URL of the server that we were told to use.
     loginUrlPattern = PatternManager.getOrCompilePattern('loginURL')
     serverMatch = loginUrlPattern.match(self.response.url)
     if serverMatch:
         self.responseData["serverURL"] = serverMatch.group(1)
     else:
         raise Error.Error(
             "Unable to determine server URL from: " + self.response.url,
             Error.LOGIN_FAILED_GENERIC)