def parseResponse(self): cantAffordItemPattern = PatternManager.getOrCompilePattern( 'cantAffordItem') if cantAffordItemPattern.search(self.responseText): raise NotEnoughMeatError("You can not afford to buy this item.") noItemAtThatPricePattern = PatternManager.getOrCompilePattern( 'mallNoItemAtThatPrice') if noItemAtThatPricePattern.search(self.responseText): raise NotSoldHereError("That item is not sold here at that price.") ignoreListPattern = PatternManager.getOrCompilePattern( 'cantBuyItemIgnoreList') if ignoreListPattern.search(self.responseText): raise UserIsIgnoringError( "The owner of that store has balleeted you.") mallHitLimitPattern = PatternManager.getOrCompilePattern( 'mallHitLimit') if mallHitLimitPattern.search(self.responseText): raise MallLimitError( "You have hit the limit for this item at this store.") items = ParseResponseUtils.parseItemsReceived(self.responseText, self.session) if len(items) == 0: raise RequestError("Unknown error: %s" % self.responseText) self.responseData["items"] = items spentMeatPattern = PatternManager.getOrCompilePattern('meatSpent') match = spentMeatPattern.search(self.responseText) self.responseData['meatSpent'] = int(match.group(1).replace(',', ''))
def parseResponse(self): # Check for errors. notEnoughMeatPattern = PatternManager.getOrCompilePattern( 'noMeatForStore') invalidStorePattern = PatternManager.getOrCompilePattern( 'invalidStore') notSoldPattern = PatternManager.getOrCompilePattern('notSoldHere') if len(self.responseText) == 0: raise UserShouldNotBeHereError("You cannot visit that store yet.") if invalidStorePattern.search(self.responseText): raise NotAStoreError("The store you tried to visit doesn't exist.") if notSoldPattern.search(self.responseText): raise NotSoldHereError("This store doesn't carry that item.") if notEnoughMeatPattern.search(self.responseText): raise NotEnoughMeatError( "You do not have enough meat to purchase the item(s).") items = ParseResponseUtils.parseItemsReceived(self.responseText, self.session) if len(items) == 0: raise RequestError("Unknown error. No items received.") self.responseData["items"] = items meatSpentPattern = PatternManager.getOrCompilePattern('meatSpent') match = spentMeatPattern.search(self.responseText) self.responseData['meatSpent'] = int(match.group(1).replace(',', ''))
def parseResponse(self): clanIDPattern = PatternManager.getOrCompilePattern('clanID') match = clanIDPattern.search(self.responseText) if match: self.responseData["clanID"] = int(match.group(1)) else: raise RequestError("Wasn't able to read a clanID for that player")
def __init__(self, session, box="Inbox", pageNumber=None, messagesPerPage=None, oldestFirst=None): """ Initializes the GetMessagesRequest object. Due to a bug in KoL, it is highly recommended that you do not specify more than one of pageNumber, messagesPerPage, and oldestFirst in the same request. Doing so can cause the server to take up to 5 minutes to respond to your request. For now, if you want to specify two or three of these parameters, you should specify one at a time and make multiple requests. KoL is nice enough to remember the values you last used for both messagesPerPage and oldestFirst. """ super(GetMessagesRequest, self).__init__(session) self.url = session.serverURL + "messages.php?box=%s" % box if pageNumber and pageNumber > 1: self.url += "&begin=%s" % pageNumber if messagesPerPage: if messagesPerPage not in [10, 20, 50, 100]: raise RequestError( "%s is not a valid number of messages to request per page. Please specify 10, 20, 50, or 100." % messagesPerPage) self.url += "&per_page=%s" % (messagesPerPage / 10) if oldestFirst == True: self.url += "&order=1" elif oldestFirst == False: self.url += "&order=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 DontHaveEffectError( "Unable to remove effect. The user does not have that effect.") youDontHaveSGEEAPattern = PatternManager.getOrCompilePattern( 'youDontHaveSGEEA') if youDontHaveSGEEAPattern.search(self.responseText): raise NotEnoughItemsError( "Unable to remove effect. You do not have a soft green echo eyedrop antidote." ) Report.error("request", "Unknown error occurred when trying to remove an effect") Report.error("request", self.responseText) raise RequestError( "Unknown error occurred when trying to remove an effect.")
def parseResponse(self): notEnoughCloversPattern = PatternManager.getOrCompilePattern( 'notEnoughClovers') noTrinketsPattern = PatternManager.getOrCompilePattern('noTrinkets') noHermitPermitPattern = PatternManager.getOrCompilePattern( 'noHermitPermits') notHermitItemPattern = PatternManager.getOrCompilePattern( 'notHermitItem') # Check for errors. if notEnoughCloversPattern.search(self.responseText): raise RequestError( "The Hermit doesn't have enough clovers for that") if noTrinketsPattern.search(self.responseText): raise NotEnoughItemsError( "You don't have enough worthless items for that") if noHermitPermitPattern.search(self.responseText): raise NotEnoughHermitPermitsError( "You don't have enough hermit permits for that") if notHermitItemPattern.search(self.responseText): raise NotSoldHereError("The Hermit doesn't have any of those") response = {} items = ParseResponseUtils.parseItemsReceived(self.responseText, self.session) if len(items) > 0: response["items"] = items self.responseData = response
def __init__(self, session, itemId, slot=0): super(EquipRequest, self).__init__(session) self.url = session.serverURL + "inv_equip.php?pwd=" + str( session.pwd) + "&which=2&action=equip&whichitem=" + str(itemId) if slot >= 4 or slot < 0: raise RequestError("Invalid slot number passed") elif slot != 0: self.url += "&slot=" + str(slot)
def parseResponse(self): if len(self.responseText) == 0: raise UserShouldNotBeHereError("You cannot use the Mind Control Device yet.") NoAdventuresPattern = PatternManager.getOrCompilePattern('noAdvInstitue') InvalidTurnsPattern = PatternManager.getOrCompilePattern('invalidAdvInstitute') if NoAdventuresPattern.search(self.responseText): raise NotEnoughAdventuresLeftError("You don't have enough adventures to study at the institute.") if InvalidTurnsPattern.search(self.responseText): raise RequestError("That is an invalid number of turns for studying") self.responseData["substats"] = ParseResponseUtils.parseSubstatsGainedLost(self.responseText, checkMuscle=False, checkMoxie=False) self.responseData["stats"] = ParseResponseUtils.ParseResponseUtils.parseStatsGainedLost(self.responseText, checkMuscle=False, checkMoxie=False) self.responseData["level"] = ParseResponseUtils.parseLevelsGained(self.responseText)
def parseResponse(self): # Check for errors. noMeatForPastePattern = PatternManager.getOrCompilePattern( 'noMeatForMeatpasting') if noMeatForPastePattern.search(self.responseText): raise NotEnoughMeatError( "Unable to make the requested item. You don't have enough meat" ) # Get the item(s) we received. items = ParseResponseUtils.parseItemsReceived(self.responseText, self.session) if len(items) > 0: self.responseData["items"] = item else: raise RequestError("Unknown error. No items received.")
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 InvalidRecipeError( "Unable to make cocktail. The submitted ingredients do not mix together." ) elif dontHaveSkillPattern.search(self.responseText): raise SkillMissingError( "Unable to make cocktail. We are not skilled enough.") elif dontHaveItemsPattern.search(self.responseText): raise NotEnoughItemsError( "Unable to make cocktail. You don't have all of the items you are trying to mix." ) elif dontHaveAdventuresPattern.search(self.responseText): raise NotEnoughAdventuresLeftError( "Unable to mix drink(s). We don't have 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.getItemFromDescId(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.getItemFromDescId(descId, self.session) quantity = int(match.group(2).replace(',', '')) item["quantity"] = quantity else: raise RequestError("Unknown error.") self.responseData["booze"] = item
def parseResponse(self): # Check for errors. dontHaveMeatpastePattern = PatternManager.getOrCompilePattern('noMeatpaste') itemsDontMeatpastePattern = PatternManager.getOrCompilePattern('itemsDontMeatpaste') dontHaveItemsPattern = PatternManager.getOrCompilePattern('dontHaveItemsMeatpaste') if dontHaveMeatpastePattern.search(self.responseText): raise NotEnoughItemsError("Unable to combine items. You don't have any meatpaste.") elif itemsDontMeatpastePattern.search(self.responseText): raise InvalidRecipeError("Unable to combine items. The submitted ingredients do not meatpaste together.") elif dontHaveItemsPattern.search(self.responseText): raise NotEnoughItemsError("Unable to combine items. You don't have all of the items you are trying to meatpaste.") # Find the items attached to the message. items = ParseResponseUtils.parseItemsReceived(self.responseText, self.session) if len(items) > 0: self.responseData["items"] = item else: raise RequestError("Unknown error.")
def __init__(self, session, itemList, howMany, amount=1): super(AutoSellRequest, self).__init__(session) self.url = session.serverURL + "sellstuff_ugly.php" self.requestData["pwd"] = session.pwd self.requestData["action"] = "sell" if howMany == self.ALL: self.requestData["mode"] = self.ALL elif howMany == self.ALL_BUT_ONE: self.requestData["mode"] = self.ALL_BUT_ONE elif howMany == self.QUANTITY: self.requestData["mode"] = self.QUANTITY self.requestData["quantity"] = amount else: raise RequestError("Invalid AutoSell Mode Selected.") for item in itemList: self.requestData[("item"+str(item["id"]))] = str(item["id"])
def parseResponse(self): menuItemPattern = PatternManager.getOrCompilePattern('menuItem') cannotGoPattern = PatternManager.getOrCompilePattern('userShouldNotBeHere') if cannotGoPattern.search(self.responseText): raise UserShouldNotBeHereError("You cannot reach that cafe") items = [] for match in menuItemPattern.finditer(self.responseText): descId = match.group(2) if descId.isdigit(): descId = int(descId) item = ItemDatabase.getItemFromDescId(descId, session=self.session) items.append(item) if len(items) == 0: raise RequestError("Retrieved an Empty Menu") self.responseData["menu"] = items
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 InvalidActionError("You aren't a high enough level to train that skill") if badSkillPattern.search(self.responseText): raise SkillMissingError("You cannot train that skill at the Guild Hall") if poorSkillPattern.search(self.responseText): raise NotEnoughMeatError("You cannot afford to train that skill") if haveSkillPattern.search(self.responseText): raise RequestError("You already know that skill") skillLearnedPattern = PatternManager.getOrCompilePattern('skillLearned') match = skillLearnedPattern.search(self.responseText) if match: try: skill = SkillDatabase.getSkillFromName(match.group(1)) self.responseData["skill"] = skill except SkillNotFoundError, inst: Report.error("bot", inst.message, inst)
def parseResponse(self): hardcoreRoninPattern = PatternManager.getOrCompilePattern( 'userInHardcoreRonin') ignoringPattern = PatternManager.getOrCompilePattern('userIgnoringUs') notEnoughItemsPattern = PatternManager.getOrCompilePattern( 'notEnoughItemsToSend') sentMessagePattern = PatternManager.getOrCompilePattern('messageSent') if hardcoreRoninPattern.search(self.responseText): raise UserInHardcoreRoninError( "Unable to send items or meat. User is in hardcore or ronin.") elif ignoringPattern.search(self.responseText): raise UserIsIgnoringError( "Unable to send message. User is ignoring us.") elif notEnoughItemsPattern.search(self.responseText): raise NotEnoughItemsError( "You don't have enough of one of the items you're trying to send." ) elif sentMessagePattern.search(self.responseText) == None: Report.alert( "system", "Received unknown response when attempting to send a message.") Report.alert("system", self.responseText) raise RequestError("Unknown error")