def init(params=None): global _haltEvent # Create the event which can be used to halt all bots. _haltEvent = threading.Event() # Initialize the databases. ItemDatabase.init() SkillDatabase.init() # Force HTTP requests to timeout after 5 minutes. socket.setdefaulttimeout(300)
def init(params=None): global _haltEvent # Create the event which can be used to halt all bots. _haltEvent = threading.Event() # Initialize the databases. ItemDatabase.init() SkillDatabase.init() # Force HTTP requests to timeout after 5 minutes. socket.setdefaulttimeout(300) # Seed the pseudo-random number generator. random.seed()
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
def __init__(self, session, skillId, numTimes=1, targetPlayer=None): super(UseSkillRequest, self).__init__(session) self.url = session.serverURL + "skills.php" self.requestData["pwd"] = session.pwd self.requestData["action"] = "Skillz" self.requestData["whichskill"] = skillId skill = SkillDatabase.getSkillFromId(skillId) if skill["type"] == "Buff": self.requestData["bufftimes"] = numTimes if targetPlayer != None: self.requestData["specificplayer"] = targetPlayer self.requestData["targetplayer"] = "" else: self.requestData["specificplayer"] = "" self.requestData["targetplayer"] = session.userId else: self.requestData["quantity"] = numTimes
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
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)