Пример #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 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(',', ''))
Пример #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)
Пример #3
0
def parseDungeonChatMessage(context, **kwargs):
    chat = kwargs["chat"]
    bot = kwargs["bot"]
    state = bot.states["global"]

    trappedPattern = PatternManager.getOrCompilePattern('imprisonedByChums')
    rescuedPattern = PatternManager.getOrCompilePattern('freedFromChums')

    if chat["text"].find("has put a tire on the fire") > 0:
        numTires = 0
        if "hobo:tiresStacked" in state:
            numTires = state["hobo:tiresStacked"]
        numTires += 1
        state["hobo:tiresStacked"] = numTires
        bot.writeState("global")
    elif chat["text"].find("has started a tirevalanche") > 0:
        state["hobo:tiresStacked"] = 0
        bot.writeState("global")
    elif chat["text"].find(
            "escaped from the C. H. U. M.s by gnawing through their cage"
    ) > 0 or rescuedPattern.match(chat["text"]):
        if "hobo:sewerTrapped" in state:
            del state["hobo:sewerTrapped"]
            bot.writeState("global")
    elif chat["text"].find("flooded the sewers leading to Hobopolis") > 0:
        keysToClear = ["hobo:sewerTrapped", "hobo:tiresStacked"]
        for key in keysToClear:
            if key in state:
                del state[key]
        bot.writeState("global")
    else:
        match = trappedPattern.match(chat["text"])
        if match:
            state["hobo:sewerTrapped"] = match.group(1)
            bot.writeState("global")
Пример #4
0
    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):
            e = Error.Error("The Hermit doesn't have enough clovers for that.", Error.ITEM_NOT_FOUND)
            e.itemId = 24
            raise e
        if noTrinketsPattern.search(self.responseText):
            e = Error.Error("You don't have enough worthless items for that.", Error.ITEM_NOT_FOUND)
            e.itemId = 43
            raise e
        if noHermitPermitPattern.search(self.responseText):
            e = Error.Error("You don't have enough hermit permits for that.", Error.ITEM_NOT_FOUND)
            e.itemId = 42
            raise e
        if notHermitItemPattern.search(self.responseText):
            e = Error.Error("The Hermit doesn't have any of those.", Error.ITEM_NOT_FOUND)
            e.itemId = self.requestData['whichitem']
            raise e

        response = {}
        items = ParseResponseUtils.parseItemsReceived(self.responseText, self.session)
        if len(items) > 0:
            response["items"] = items
        self.responseData = response
Пример #5
0
	def parseResponse(self):
		noMeatForPastePattern = PatternManager.getOrCompilePattern('noMeatForMeatpasting')
		
		# Check for errors.
		if noMeatForPastePattern.search(self.responseText):
			raise NotEnoughMeatError("Unable to make the requested item. You don't have enough meat")

		# 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["items"] = item
Пример #6
0
    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
Пример #7
0
	def parseResponse(self):
		dontHaveMeatpastePattern = PatternManager.getOrCompilePattern('noMeatpaste')
		itemsDontMeatpastePattern = PatternManager.getOrCompilePattern('itemsDontMeatpaste')
		dontHaveItemsPattern = PatternManager.getOrCompilePattern('dontHaveItemsMeatpaste')
		
		# Check for errors.
		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.
		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["items"] = item
Пример #8
0
    def parseResponse(self):
        response = {}
        
        bountyAvailablePattern = PatternManager.getOrCompilePattern('bountyAvailable')
        if bountyAvailablePattern.search(self.responseText):
            bountyAvailable = True
        else:
            bountyAvailable = False

        bountyChosenPattern = PatternManager.getOrCompilePattern('bountyChosen')
        bountyActivePattern1 = PatternManager.getOrCompilePattern('bountyActive1')
        bountyActivePattern2 = PatternManager.getOrCompilePattern('bountyActive2')
        
        if bountyChosenPattern.search(self.responseText) or \
            bountyActivePattern1.search(self.responseText) or \
            bountyActivePattern2.search(self.responseText):
                bountyActive = True
        else:
            bountyActive = False

        dailyBounties = []
        if bountyAvailable:
            bountyPattern = PatternManager.getOrCompilePattern('dailyBountyItem')
            for match in bountyPattern.finditer(self.responseText):
                itemId = int(match.group('itemid'))
                item = ItemDatabase.getItemFromId(itemId)
                dailyBounties.append(item)
        
        response['bountyAvailable'] = bountyAvailable
        response['bountyActive'] = bountyActive
        response['dailyBounties'] = dailyBounties
        
        self.responseData = response
Пример #9
0
def parseDungeonChatMessage(context, **kwargs):
	chat = kwargs["chat"]
	bot = kwargs["bot"]
	state = bot.states["global"]
	
	trappedPattern = PatternManager.getOrCompilePattern('imprisonedByChums')
	rescuedPattern = PatternManager.getOrCompilePattern('freedFromChums')
	
	if chat["text"].find("has put a tire on the fire") > 0:
		numTires = 0
		if "hobo:tiresStacked" in state:
			numTires = state["hobo:tiresStacked"]
		numTires += 1
		state["hobo:tiresStacked"] = numTires
		bot.writeState("global")
	elif chat["text"].find("has started a tirevalanche") > 0:
		state["hobo:tiresStacked"] = 0
		bot.writeState("global")
	elif chat["text"].find("escaped from the C. H. U. M.s by gnawing through their cage") > 0 or rescuedPattern.match(chat["text"]):
		if "hobo:sewerTrapped" in state:
			del state["hobo:sewerTrapped"]
			bot.writeState("global")
	elif chat["text"].find("flooded the sewers leading to Hobopolis") > 0:
		keysToClear = ["hobo:sewerTrapped", "hobo:tiresStacked"]
		for key in keysToClear:
			if key in state:
				del state[key]
		bot.writeState("global")
	else:
		match = trappedPattern.match(chat["text"])
		if match:
			state["hobo:sewerTrapped"] = match.group(1)
			bot.writeState("global")
Пример #10
0
	def parseResponse(self):
		cantPulverizePattern = PatternManager.getOrCompilePattern('cantPulverizeItem')
		if cantPulverizePattern.search(self.responseText) != None:
			item = ItemDatabase.getItemFromId(self.itemId, self.session)
			raise UnableToPulverizeItemError("'%s' is not an item that can be pulverized." % item["name"])
		
		notEnoughItemsPattern = PatternManager.getOrCompilePattern('notEnoughItems')
		if notEnoughItemsPattern.search(self.responseText) != None:
			item = ItemDatabase.getItemFromId(self.itemId, self.session)
			if self.quantity == 1:
				itemStr = item["name"]
			else:
				itemStr = item["plural"]
			raise NotEnoughItemsError("You do not have %s %s" % (self.quantity % itemStr))
			
		items = []
		
		singleItemPattern = PatternManager.getOrCompilePattern('acquireSingleItem')
		for match in singleItemPattern.finditer(self.responseText):
			descId = int(match.group(1))
			item = ItemDatabase.getItemFromDescId(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.getItemFromDescId(descId, self.session)
			item["quantity"] = quantity
			items.append(item)
		
		self.responseData["results"] = items
Пример #11
0
	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(',', ''))
Пример #12
0
def parseStatPointsGained(text, checkMuscle=True, checkMysticality=True, checkMoxie=True):
	statPoints = {}
	
	if checkMuscle:
		muscPattern = PatternManager.getOrCompilePattern('musclePointGainLoss')
		muscMatch = muscPattern.search(text)
		if muscMatch:
			if muscMatch.group(1) == "gain":
				statPoints["muscle"] = '+'
			else:
				statPoints["muscle"] = '-'
				
	if checkMysticality:
		mystPattern = PatternManager.getOrCompilePattern('mystPointGainLoss')
		mystMatch = mystPattern.search(text)
		if mystMatch:
			if mystMatch.group(1) == "gain":
				statPoints["mysticality"] = '+'
			else:
				statPoints["mysticality"] = '-'
				
	if checkMoxie:
		moxPattern = PatternManager.getOrCompilePattern('moxiePointGainLoss')
		moxMatch = moxPattern.search(text)
		if moxMatch:
			if moxMatch.group(1) == "gain":
				statPoints["moxie"] = '+'
			else:
				statPoints["moxie"] = '-'
				
	return statPoints
Пример #13
0
 def __init__(self, session):
     super(ClanLogPartialRequest, self).__init__(
         session, 
         [PatternManager.getOrCompilePattern('clanLogFax'),
          PatternManager.getOrCompilePattern('clanLogEntry')],
         5*1024)
     self.url = session.serverURL + "clan_log.php"
Пример #14
0
 def parseResponse(self):
     items = []
     itemMatchPattern = PatternManager.getOrCompilePattern('mallItemSearchResult')
     itemDetailsPattern = PatternManager.getOrCompilePattern('mallItemSearchDetails')
     for itemMatch in itemMatchPattern.finditer(self.responseText):
         matchText = itemMatch.group(1)
         match = itemDetailsPattern.search(matchText)
         itemId = int(match.group('itemId'))
         try:
             item = ItemDatabase.getItemFromId(itemId)
             item["price"] = int(match.group('price').replace(',', ''))
             item["storeId"] = int(match.group('storeId'))
             item["storeName"] = match.group('storeName').replace('<br>', ' ')
             item["quantity"] = int(match.group('quantity').replace(',', ''))
             limit = match.group('limit').replace(',', '')
             if len(limit) > 0:
                 limit = int(limit)
             item["limit"] = limit
             if matchText.find('limited"') >= 0:
                 item["hitLimit"] = True
             items.append(item)
         except Error.Error, inst:
             if inst.code == Error.ITEM_NOT_FOUND:
                 Report.info("itemdatabase", "Unrecognized item found in mall search: %s" % itemId, inst)
             else:
                 raise inst
Пример #15
0
	def parseResponse(self):
		hardcoreRoninPattern = PatternManager.getOrCompilePattern('userInHardcoreRonin')
		ignoringPattern = PatternManager.getOrCompilePattern('userIgnoringUs')
		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.")
Пример #16
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(',', ''))
Пример #17
0
    def parseResponse(self):
        usernamePattern = PatternManager.getOrCompilePattern('profileUserName')
        match = usernamePattern.search(self.responseText)
        self.responseData["userName"] = match.group(1)

        playerClanPattern = PatternManager.getOrCompilePattern('profileClan')
        match = playerClanPattern.search(self.responseText)
        if match:
            self.responseData["clanId"] = int(match.group(1))
            self.responseData["clanName"] = match.group(2)

        numberAscensionsPattern = PatternManager.getOrCompilePattern('profileNumAscensions')
        match = numberAscensionsPattern.search(self.responseText)
        if match:
            self.responseData["numAscensions"] = int(match.group(1))
        else:
            self.responseData["numAscensions"] = 0

        numberTrophiesPattern = PatternManager.getOrCompilePattern('profileNumTrophies')
        match = numberTrophiesPattern.search(self.responseText)
        if match:
            self.responseData["numTrophies"] = int(match.group(1))
        else:
            self.responseData["numTrophies"] = 0

        numberTattoosPattern = PatternManager.getOrCompilePattern('profileNumTattoos')
        match = numberTattoosPattern.search(self.responseText)
        if match:
            self.responseData["numTattoos"] = int(match.group(1))
        else:
            self.responseData["numTattoos"] = 0
Пример #18
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
Пример #19
0
    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(',', ''))
Пример #20
0
    def parseResponse(self):
        cantAffordItemPattern = PatternManager.getOrCompilePattern('cantAffordItem')
        if cantAffordItemPattern.search(self.responseText):
            raise Error.Error("You can not afford to buy this item.", Error.NOT_ENOUGH_MEAT)

        noItemAtThatPricePattern = PatternManager.getOrCompilePattern('mallNoItemAtThatPrice')
        if noItemAtThatPricePattern.search(self.responseText):
            raise Error.Error("That item is not sold here at that price.", Error.ITEM_NOT_FOUND)

        ignoreListPattern = PatternManager.getOrCompilePattern('cantBuyItemIgnoreList')
        if ignoreListPattern.search(self.responseText):
            raise Error.Error("The owner of that store has balleeted you.", Error.USER_IS_IGNORING)

        mallHitLimitPattern = PatternManager.getOrCompilePattern('mallHitLimit')
        if mallHitLimitPattern.search(self.responseText):
            raise Error.Error("You have hit the limit for this item at this store.", Error.LIMIT_REACHED)

        items = ParseResponseUtils.parseItemsReceived(self.responseText, self.session)
        if len(items) == 0:
            raise Error.Error("Unknown error: %s" % self.responseText, Error.REQUEST_GENERIC)
        self.responseData["items"] = items

        spentMeatPattern = PatternManager.getOrCompilePattern('meatSpent')
        match = spentMeatPattern.search(self.responseText)
        self.responseData['meatSpent'] = int(match.group(1).replace(',', ''))
Пример #21
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
Пример #22
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.")
Пример #23
0
def parseDungeonChatMessage(context, **kwargs):
    chat = kwargs["chat"]
    bot = kwargs["bot"]
    state = bot.states["global"]

    trappedPattern = PatternManager.getOrCompilePattern("imprisonedByChums")
    rescuedPattern = PatternManager.getOrCompilePattern("freedFromChums")

    if chat["text"].find("has put a tire on the fire") > 0:
        numTires = 0
        if "hobo:tiresStacked" in state:
            numTires = state["hobo:tiresStacked"]
        numTires += 1
        state["hobo:tiresStacked"] = numTires
        bot.writeState("global")
    elif chat["text"].find("has started a tirevalanche") > 0:
        state["hobo:tiresStacked"] = 0
        bot.writeState("global")
    elif rescuedPattern.match(chat["text"]):
        if "hobo:sewerTrapped" in state:
            del state["hobo:sewerTrapped"]
            bot.writeState("global")
    else:
        match = trappedPattern.match(chat["text"])
        if match:
            state["hobo:sewerTrapped"] = match.group(1)
            bot.writeState("global")
Пример #24
0
def parseSubstatsGainedLost(text, checkMuscle=True, checkMysticality=True, checkMoxie=True):
    substats = {}

    if checkMuscle:
        muscPattern = PatternManager.getOrCompilePattern('muscleGainLoss')
        muscMatch = muscPattern.search(text)
        if muscMatch:
            muscle = int(muscMatch.group(2).replace(',', ''))
            if muscMatch.group(1) == "gain":
                substats["muscle"] = muscle
            else:
                substats["muscle"] = -1 * muscle

    if checkMysticality:
        mystPattern = PatternManager.getOrCompilePattern('mysticalityGainLoss')
        mystMatch = mystPattern.search(text)
        if mystMatch:
            myst = int(mystMatch.group(2).replace(',', ''))
            if mystMatch.group(1) == "gain":
                substats["mysticality"] = myst
            else:
                substats["mysticality"] = -1 * myst

    if checkMoxie:
        moxPattern = PatternManager.getOrCompilePattern('moxieGainLoss')
        moxMatch = moxPattern.search(text)
        if moxMatch:
            moxie = int(moxMatch.group(2).replace(',', ''))
            if moxMatch.group(1) == "gain":
                substats["moxie"] = moxie
            else:
                substats["moxie"] = -1 * moxie

    return substats
Пример #25
0
    def parseResponse(self):
        # Check for errors.
        effectRemovedPattern = PatternManager.getOrCompilePattern(
            'effectRemoved')
        if effectRemovedPattern.search(self.responseText):
            self.responseData['result'] = 'Effect removed.'
            return

        youDontHaveThatEffectPattern = PatternManager.getOrCompilePattern(
            'youDontHaveThatEffect')
        if youDontHaveThatEffectPattern.search(self.responseText):
            self.responseData[
                'result'] = "I don't seem to have effect number {}.".format(
                    self.requestData['whicheffect'])
            return

        youDontHaveSGEEAPattern = PatternManager.getOrCompilePattern(
            'youDontHaveSGEEA')
        if youDontHaveSGEEAPattern.search(self.responseText):
            self.responseData[
                'result'] = "I am out of SGEEAs. Please help and send me a few!"
            return

        self.responseData[
            'result'] = "An unknown error occurred while trying to remove an effect."
Пример #26
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)
Пример #27
0
 def parseResponse(self):
     items = []
     itemMatchPattern = PatternManager.getOrCompilePattern(
         'mallItemSearchResult')
     itemDetailsPattern = PatternManager.getOrCompilePattern(
         'mallItemSearchDetails')
     for itemMatch in itemMatchPattern.finditer(self.responseText):
         matchText = itemMatch.group(1)
         match = itemDetailsPattern.search(matchText)
         itemId = int(match.group('itemId'))
         try:
             item = ItemDatabase.getItemFromId(itemId, self.session)
             item["price"] = int(match.group('price').replace(',', ''))
             item["storeId"] = int(match.group('storeId'))
             item["storeName"] = match.group('storeName').replace(
                 '<br>', ' ')
             item["quantity"] = int(
                 match.group('quantity').replace(',', ''))
             limit = match.group('limit').replace(',', '')
             if len(limit) > 0:
                 limit = int(limit)
             item["limit"] = limit
             if matchText.find('limited"') >= 0:
                 item["hitLimit"] = True
             items.append(item)
         except ItemNotFoundError, inst:
             Report.info(
                 "itemdatabase",
                 "Unrecognized item found in mall search: %s" % itemId,
                 inst)
    def parseResponse(self):
        item = ItemDatabase.getOrDiscoverItemFromId(int(self.itemId), self.session)
        mallPricesUnlimitedPattern = PatternManager.getOrCompilePattern('mallPricesUnlimited')

        for match in mallPricesUnlimitedPattern.finditer(self.responseText):
            unlimited = []
            price = {"price" : match.group(1).replace(",", ""), "count" : match.group(2).replace(",", "")}
            unlimited.append(price)
            price = {"price" : match.group(3).replace(",", ""), "count" : match.group(4).replace(",", "")}
            unlimited.append(price)       
            price = {"price" : match.group(5).replace(",", ""), "count" : match.group(6).replace(",", "")}
            unlimited.append(price)        
            price = {"price" : match.group(7).replace(",", ""), "count" : match.group(8).replace(",", "")}
            unlimited.append(price)             
            
            item["unlimited"] = unlimited

        mallPricesLimitedPattern = PatternManager.getOrCompilePattern('mallPricesLimited')

        for match in mallPricesLimitedPattern.finditer(self.responseText):            
            limited = []
            print 
            price = {"price" : match.group(1).replace(",", ""), "limit" : match.group(2).replace(",", ""), "count" : match.group(3).replace(",", "")}
            limited.append(price)
            price = {"price" : match.group(4).replace(",", ""), "limit" : match.group(5).replace(",", ""), "count" : match.group(6).replace(",", "")}
            limited.append(price)
            price = {"price" : match.group(7).replace(",", ""), "limit" : match.group(8).replace(",", ""), "count" : match.group(9).replace(",", "")}
            limited.append(price)
            
            item["limited"] = limited

        self.responseData["item"] = item
Пример #29
0
    def parseResponse(self):
        salePattern = PatternManager.getOrCompilePattern("autosellResponse")

        saleMatch = salePattern.search(self.responseText)
        if saleMatch:
            multiItemPattern = PatternManager.getOrCompilePattern("autosellItems")
            finalTwoPattern = PatternManager.getOrCompilePattern("autosellLastTwo")
            finalOnePattern = PatternManager.getOrCompilePattern("autosellOne")

            salesTotal = int(saleMatch.group(2).replace(',',''))

            soldItems = []
            lastItemIndex = None
            for itemMatch in multiItemPattern.finditer(saleMatch.group(1)):
                # We cannot look up the item because the names are likely pluralized
                name = itemMatch.group(2)
                if itemMatch.group(1) == "":
                    quantity = 1
                else:
                    quantity = int(itemMatch.group(1).replace(',',''))

                soldItems.append({"quantity":quantity, "name":name})
                lastItemIndex = itemMatch.end(2)

            if lastItemIndex != None:
                finalMatch = finalTwoPattern.search(saleMatch.group(1)[lastItemIndex+1:])
            else:
                finalMatch = finalTwoPattern.search(saleMatch.group(1))

            if finalMatch:
                if finalMatch.group(2) != "":
                    name = finalMatch.group(2)
                    if finalMatch.group(1) == "":
                        quantity = 1
                    else:
                        quantity = int(finalMatch.group(1).replace(',',''))
                    soldItems.append({"quantity":quantity, "name":name})

                name = finalMatch.group(4)
                if finalMatch.group(3) == "":
                    quantity = 1
                else:
                    quantity = int(finalMatch.group(3).replace(',',''))
                soldItems.append({"quantity":quantity, "name":name})
            else:
                singleItem = finalOnePattern.search(saleMatch.group(1))
                name = singleItem.group(2)
                if singleItem.group(1) == "":
                    quantity = 1
                else:
                    quantity = int(singleItem.group(1).replace(',',''))
                soldItems.append({"quantity":quantity, "name":name})
        else:
            salesTotal = 0
            soldItems = []

        self.responseData["meatGained"] = salesTotal
        self.responseData["itemsSold"] = soldItems
Пример #30
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
Пример #31
0
 def parseResponse(self):
     hardcoreRoninPattern = PatternManager.getOrCompilePattern(
         'userInHardcoreRonin')
     ignoringPattern = PatternManager.getOrCompilePattern('userIgnoringUs')
     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.")
Пример #32
0
def parseMeatGainedLost(text):
    meatPattern = PatternManager.getOrCompilePattern('gainMeat')
    match = meatPattern.search(text)
    if match:
        return int(match.group(1).replace(',', ''))
    meatPattern = PatternManager.getOrCompilePattern('loseMeat')
    match = meatPattern.search(text)
    if match:
        return -1 * int(match.group(1).replace(',', ''))
    return 0
Пример #33
0
    def parseResponse(self):
        if self._astralSpiritPattern.search(self.responseText):
            self.responseData["astralSpirit"] = True
        else:
            self.responseData["astralSpirit"] = False
        
        match = self._datePattern.search(self.responseText)
        if match:
            s = match.group(1).split()
            # pull month from dict, since I don't want to deal with locales
            month = {'January': 1,
                     'February': 2,
                     'March': 3,
                     'April': 4,
                     'May': 5,
                     'June': 6,
                     'July': 7,
                     'August': 8,
                     'September': 9,
                     'October': 10,
                     'November': 11,
                     'December': 12}[s[0]]
            lastLoginDate = date(int(s[2]), month, int(s[1][:-1]))
            self.responseData["lastLogin"] = lastLoginDate
        
        usernamePattern = PatternManager.getOrCompilePattern('profileUserName')
        match = usernamePattern.search(self.responseText)
        self.responseData["userName"] = match.group(1)

        match = self._playerClanPattern.search(self.responseText)
        if match:
            self.responseData["clanId"] = int(match.group(1))
            self.responseData["clanName"] = match.group(2)
            self.responseData["clanTitle"] = match.group(3)

        numberAscensionsPattern = PatternManager.getOrCompilePattern('profileNumAscensions')
        match = numberAscensionsPattern.search(self.responseText)
        if match:
            self.responseData["numAscensions"] = int(match.group(1))
        else:
            self.responseData["numAscensions"] = 0

        numberTrophiesPattern = PatternManager.getOrCompilePattern('profileNumTrophies')
        match = numberTrophiesPattern.search(self.responseText)
        if match:
            self.responseData["numTrophies"] = int(match.group(1))
        else:
            self.responseData["numTrophies"] = 0

        numberTattoosPattern = PatternManager.getOrCompilePattern('profileNumTattoos')
        match = numberTattoosPattern.search(self.responseText)
        if match:
            self.responseData["numTattoos"] = int(match.group(1))
        else:
            self.responseData["numTattoos"] = 0
Пример #34
0
	def parseResponse(self):
		# Get the set of clan ranks.
		ranks = []
		ranksById = {}
		rankContainerPattern = PatternManager.getOrCompilePattern('clanRankContainer')
		match = rankContainerPattern.search(self.responseText)
		if match:
			rankText = match.group(1)
			rankPattern = PatternManager.getOrCompilePattern('clanRank')
			for rankMatch in rankPattern.finditer(rankText):
				rank = {
					"rankId": int(rankMatch.group(1)),
					"rankName": rankMatch.group(2),
					"rankNumber": int(rankMatch.group(3))
				}
				ranks.append(rank)
				ranksById[rank["rankId"]] = rank

		# Get the player's info
		memberPattern = PatternManager.getOrCompilePattern('clanWhitelistMember')
		for match in memberPattern.finditer(self.responseText):
			if match.group('userId') == self.userId:
				member = {
					"userId": match.group('userId'),
					"userName": match.group('userName'),
					"clanTitle": match.group('clanTitle')
				}
				rankId = match.group('clanRankId')
				rankName = match.group('clanRankName')
				if rankId is not None:
					rank = ranksById[int(rankId)]
					member["rankId"] = rank["rankId"]
					member["rankName"] = rank["rankName"]
					member["rankNumber"] = rank["rankNumber"]
				elif rankName is not None:
					member["rankName"] = rankName
					foundRank = False
					for rank in ranks:
						if rank["rankName"] == rankName:
							foundRank = True
							break
					if not foundRank:
						rank = {
							"rankId": -1,
							"rankName": rankName,
							"rankNumber": -1
						}
						ranks.append(rank)
				self.responseData["result"] = member
				break
			else:
				self.responseData["result"] = None
				break
		self.responseData["result"] = None
Пример #35
0
    def parseResponse(self):
        # Get the user's pwd.
        pwdPattern = PatternManager.getOrCompilePattern('accountPwd')
        pwdMatch = pwdPattern.search(self.responseText)
        self.responseData['pwd'] = pwdMatch.group(1)

        # Get the user's ID and name.
        pattern = PatternManager.getOrCompilePattern('accountUserNameAndId')
        match = pattern.search(self.responseText)
        self.responseData['userName'] = match.group(1)
        self.responseData['userId'] = int(match.group(2))
Пример #36
0
	def parseResponse(self):
		# Get the user's pwd.
		pwdPattern = PatternManager.getOrCompilePattern('accountPwd')
		pwdMatch = pwdPattern.search(self.responseText)
		self.responseData['pwd'] = pwdMatch.group(1)
		
		# Get the user's ID and name.
		pattern = PatternManager.getOrCompilePattern('accountUserNameAndId')
		match = pattern.search(self.responseText)
		self.responseData['userName'] = match.group(1)
		self.responseData['userId'] = int(match.group(2))
Пример #37
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 NotEnoughItemsError("That item is not in your inventory.")

        notEquipmentPattern = PatternManager.getOrCompilePattern("notEquip")
        match = notEquipmentPattern.search(self.responseText)
        if match:
            raise InvalidActionError("That is not an equippable item.")
Пример #38
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)
Пример #39
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)
Пример #40
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 NotEnoughItemsError("That item is not in your inventory.")

        notEquipmentPattern = PatternManager.getOrCompilePattern("notEquip")
        match = notEquipmentPattern.search(self.responseText)
        if match:
            raise InvalidActionError("That is not an equippable item.")
 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)
Пример #42
0
    def parseResponse(self):
        if len(self.responseText) < 10:
            raise Error.Error("You can't curse with that item.", Error.WRONG_KIND_OF_ITEM)

        dontHaveThatItemPattern = PatternManager.getOrCompilePattern("dontHaveThatItem")
        if dontHaveThatItemPattern.search(self.responseText):
            raise Error.Error("You don't have that item.", Error.ITEM_NOT_FOUND)

        playerNotFoundPattern = PatternManager.getOrCompilePattern("cantCursePlayerNotFound")
        if playerNotFoundPattern.search(self.responseText):
            raise Error.Error("That player could not be found.", Error.USER_NOT_FOUND)

        if self.curseItemId == 4939:
            cantFireAtSelfPattern = PatternManager.getOrCompilePattern("cantFireArrowAtSelf")
            if cantFireAtSelfPattern.search(self.responseText):
                raise Error.Error("You can't fire an arrow at yourself.", Error.INVALID_USER)

            cantFireHardcoreRonin = PatternManager.getOrCompilePattern("cantFireArrowAtHardcoreRonin")
            if cantFireHardcoreRonin.search(self.responseText):
                raise Error.Error(
                    "You can't fire an arrow at a person in hardcore or ronin.", Error.USER_IN_HARDCORE_RONIN
                )

            alreadyHitPattern = PatternManager.getOrCompilePattern("userAlreadyHitWithArrow")
            if alreadyHitPattern.search(self.responseText):
                raise Error.Error("That person has already been arrowed today.", Error.ALREADY_COMPLETED)

            successPattern = PatternManager.getOrCompilePattern("fireArrowSuccess")
            if not successPattern.search(self.responseText):
                print self.responseText
                raise Error.Error("Unknown error.", Error.REQUEST_GENERIC)

        elif self.curseItemId == 7698:
            cantUseOnSelfPattern = PatternManager.getOrCompilePattern("cantUseSpiderOnSelf")
            if cantUseOnSelfPattern.search(self.responseText):
                raise Error.Error("You can't use a rubber spider on yourself.", Error.INVALID_USER)

            cantUseHardcoreRonin = PatternManager.getOrCompilePattern("cantUseSpiderOnHardcoreRonin")
            if cantUseHardcoreRonin.search(self.responseText):
                raise Error.Error(
                    "You can't use a rubber spider on a person in hardcore or ronin.", Error.USER_IN_HARDCORE_RONIN
                )

            alreadyHitPattern = PatternManager.getOrCompilePattern("userAlreadyHitWithSpider")
            if alreadyHitPattern.search(self.responseText):
                raise Error.Error("That person already has a rubber spider on them.", Error.ALREADY_COMPLETED)

            successPattern = PatternManager.getOrCompilePattern("useSpiderSuccess")
            if not successPattern.search(self.responseText):
                print self.responseText
                raise Error.Error("Unknown error.", Error.REQUEST_GENERIC)
Пример #43
0
    def parseResponse(self):
        if len(self.responseText) == 0:
            raise Error.Error("You cannot use the Mind Control Device yet.", Error.INVALID_LOCATION)

        noAdventuresPattern = PatternManager.getOrCompilePattern('noAdvInstitue')
        invalidTurnsPattern = PatternManager.getOrCompilePattern('invalidAdvInstitute')
        if noAdventuresPattern.search(self.responseText):
            raise Error.Error("You don't have enough adventures to study at the institute.", Error.NOT_ENOUGH_ADVENTURES)
        if invalidTurnsPattern.search(self.responseText):
            raise Error.Error("That is an invalid number of turns for studying." Error.REQUEST_GENERIC)

        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)
Пример #44
0
    def parseResponse(self):
        # Get the set of clan ranks.
        ranks = []
        ranksById = {}
        rankContainerPattern = PatternManager.getOrCompilePattern('clanRankContainer')
        match = rankContainerPattern.search(self.responseText)
        if match:
            rankText = match.group(1)
            rankPattern = PatternManager.getOrCompilePattern('clanRank')
            for rankMatch in rankPattern.finditer(rankText):
                rank = {}
                rank["rankId"] = int(rankMatch.group(1))
                rank["rankName"] = rankMatch.group(2)
                rank["rankNumber"] = int(rankMatch.group(3))
                ranks.append(rank)
                ranksById[rank["rankId"]] = rank

        # Get a list of users who are whitelisted to the clan.
        members = []
        memberPattern = PatternManager.getOrCompilePattern('clanWhitelistMember')
        for match in memberPattern.finditer(self.responseText):
            member = {}
            member["userId"] = match.group('userId')
            member["userName"] = match.group('userName')
            member["clanTitle"] = match.group('clanTitle')
            rankId = match.group('clanRankId')
            rankName = match.group('clanRankName')
            rankNumber = None
            if rankId != None:
                rank = ranksById[int(rankId)]
                member["rankId"] = rank["rankId"]
                member["rankName"] = rank["rankName"]
                member["rankNumber"] = rank["rankNumber"]
            elif rankName != None:
                member["rankName"] = rankName
                foundRank = False
                for rank in ranks:
                    if rank["rankName"] == rankName:
                        foundRank = True
                        break
                if foundRank == False:
                    rank = {}
                    rank["rankId"] = -1
                    rank["rankName"] = rankName
                    rank["rankNumber"] = -1
                    ranks.append(rank)
            members.append(member)

        self.responseData["ranks"] = ranks
        self.responseData["members"] = members
Пример #45
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)
Пример #46
0
def parseStatsGainedLost(text,
                         checkMuscle=True,
                         checkMysticality=True,
                         checkMoxie=True):
    """
    Returns a dictionary describing how many stat points the user gained or lost. Please note that
    the user interface does not say how many points were gained or lost if the number is greater
    than 1. This method will return '2' or '-2' in these situations. If your program needs a more
    exact number then you should request the user's character pane.
    """
    statPoints = {}

    if checkMuscle:
        muscPattern = PatternManager.getOrCompilePattern('musclePointGainLoss')
        muscMatch = muscPattern.search(text)
        if muscMatch:
            modifier = 1
            if muscMatch.group(1) == "lose":
                modifier = -1
            if muscMatch.group(2) == 'a':
                statPoints["muscle"] = 1 * modifier
            else:
                statPoints["muscle"] = 2 * modifier

    if checkMysticality:
        mystPattern = PatternManager.getOrCompilePattern('mystPointGainLoss')
        mystMatch = mystPattern.search(text)
        if mystMatch:
            modifier = 1
            if mystMatch.group(1) == "lose":
                modifier = -1
            if mystMatch.group(2) == 'a':
                statPoints["mysticality"] = 1 * modifier
            else:
                statPoints["mysticality"] = 2 * modifier

    if checkMoxie:
        moxPattern = PatternManager.getOrCompilePattern('moxiePointGainLoss')
        moxMatch = moxPattern.search(text)
        if moxMatch:
            modifier = 1
            if moxMatch.group(1) == "lose":
                modifier = -1
            if moxMatch.group(2) == 'a':
                statPoints["moxie"] = 1 * modifier
            else:
                statPoints["moxie"] = 2 * modifier

    return statPoints
Пример #47
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
Пример #48
0
    def parseResponse(self):
        # Get the item name.
        itemNamePattern = PatternManager.getOrCompilePattern("itemName")
        match = itemNamePattern.search(self.responseText)
        self.responseData["name"] = match.group(1)

        # Get the item image.
        imagePattern = PatternManager.getOrCompilePattern("itemImage")
        match = imagePattern.search(self.responseText)
        self.responseData["image"] = match.group(1)

        # Get the item type.
        typePattern = PatternManager.getOrCompilePattern("itemType")
        match = typePattern.search(self.responseText)
        if match:
            self.responseData["type"] = match.group(1).rstrip()

        # Get the autosell value.
        autosellPattern = PatternManager.getOrCompilePattern("itemAutosell")
        match = autosellPattern.search(self.responseText)
        if match:
            self.responseData["autosell"] = int(match.group(1))
        else:
            self.responseData["autosell"] = 0

        # See if this is a cooking ingredient.
        cookingPattern = PatternManager.getOrCompilePattern(
            "isCookingIngredient")
        match = cookingPattern.search(self.responseText)
        if match:
            self.responseData["isCookingIngredient"] = True

        # See if the item is a cocktailcrafting ingredient.
        cocktailcraftingPattern = PatternManager.getOrCompilePattern(
            "isCocktailcraftingIngredient")
        match = cocktailcraftingPattern.search(self.responseText)
        if match:
            self.responseData["isCocktailcraftingIngredient"] = True

        # See if the item is a meatsmithing component.
        meatsmithingPattern = PatternManager.getOrCompilePattern(
            "isMeatsmithingComponent")
        match = meatsmithingPattern.search(self.responseText)
        if match:
            self.responseData["isMeatsmithingComponent"] = True

        # See if the item is a jewelrymaking component.
        jewelrymakingPattern = PatternManager.getOrCompilePattern(
            "isJewelrymakingComponent")
        match = jewelrymakingPattern.search(self.responseText)
        if match:
            self.responseData["isJewelrymakingComponent"] = True

        # See if the itemId is listed
        match = self._itemIdPattern.search(self.responseText)
        if match:
            self.responseData["id"] = int(match.group(1))
        else:
            self.responseData["id"] = None
Пример #49
0
	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)
Пример #50
0
    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)
Пример #51
0
 def parseResponse(self):
     # Get the set of clan ranks.
     ranks = []
     rankContainerPattern = PatternManager.getOrCompilePattern("clanRankContainer")
     match = rankContainerPattern.search(self.responseText)
     rankText = match.group(1)
     rankPattern = PatternManager.getOrCompilePattern("clanRank")
     for rankMatch in rankPattern.finditer(rankText):
         rank = {}
         rank["id"] = int(rankMatch.group(1))
         rank["name"] = rankMatch.group(2)
         rank["number"] = int(rankMatch.group(3))
         ranks.append(rank)
         print rank
     self.responseData["ranks"] = ranks
Пример #52
0
    def parseResponse(self):
        # Check for errors.
        notEnoughMeatPattern = PatternManager.getOrCompilePattern('noMeatForStore')
        cannotGoPattern = PatternManager.getOrCompilePattern('userShouldNotBeHere')
        notSoldPattern = PatternManager.getOrCompilePattern('notSoldHere')

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

        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:
            reponse["hp"] = hpResponse

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

        self.responseData = response