def execute(self, message, user, params): alliance = Alliance() race = None size_mod = None size = None value_mod = None value = None bash = False attacker = user.planet cluster = None params = params.group(1).split() for p in params: m = self.bashre.match(p) if m and not bash: bash = True continue m = self.clusterre.match(p) if m and not cluster: cluster = int(m.group(1)) m = self.racere.match(p) if m and not race: race = m.group(1) continue m = self.rangere.match(p) if m and not size and int(m.group(2)) < 32768: size_mod = m.group(1) or '>' size = m.group(2) continue m = self.rangere.match(p) if m and not value: value_mod = m.group(1) or '<' value = m.group(2) continue m = self.alliancere.match(p) if m and not alliance.name and not self.clusterre.match(p): alliance = Alliance(name="Unknown") if m.group( 1).lower() == "unknown" else Alliance.load(m.group(1)) if alliance is None: message.reply("No alliance matching '%s' found" % (m.group(1), )) return continue maxcap = PA.getfloat("roids", "maxcap") mincap = PA.getfloat("roids", "mincap") modifier = (cast(Planet.value, Float).op("/")(float(attacker.value))).op("^")(0.5) caprate = func.float8larger( mincap, func.float8smaller(modifier.op("*")(maxcap), maxcap)) maxcap = cast(func.floor(cast(Planet.size, Float).op("*")(caprate)), Integer) bravery = (func.float8larger( 0.0, (func.float8smaller( 2.0, cast(Planet.value, Float).op("/")(float(attacker.value))) - 0.1) * (func.float8smaller( 2.0, cast(Planet.score, Float).op("/")(float(attacker.score))) - 0.2))).op("*")(10.0) xp_gain = cast(func.floor(maxcap.op("*")(bravery)), Integer) Q = session.query(Planet, Intel, xp_gain.label("xp_gain")) if alliance.id: Q = Q.join(Planet.intel) Q = Q.filter(Intel.alliance == alliance) else: Q = Q.outerjoin(Planet.intel) if alliance.name: Q = Q.filter(Intel.alliance == None) Q = Q.filter(Planet.active == True) if race: Q = Q.filter(Planet.race.ilike(race)) if size: Q = Q.filter(Planet.size.op(size_mod)(size)) if value: Q = Q.filter(Planet.value.op(value_mod)(value)) if bash: Q = Q.filter( or_( Planet.value.op(">")(attacker.value * PA.getfloat("bash", "value")), Planet.score.op(">")(attacker.score * PA.getfloat("bash", "score")))) if cluster: Q = Q.filter(Planet.x == cluster) Q = Q.order_by(desc("xp_gain")) Q = Q.order_by(desc(Planet.idle)) Q = Q.order_by(desc(Planet.value)) result = Q[:6] if len(result) < 1: reply = "No" if race: reply += " %s" % (race, ) reply += " planets" if alliance.name: reply += " in intel matching Alliance: %s" % (alliance.name, ) else: reply += " matching" if size: reply += " Size %s %s" % (size_mod, size) if value: reply += " Value %s %s" % (value_mod, value) message.reply(reply) return replies = [] for planet, intel, xp_gain in result[:5]: reply = "%s:%s:%s (%s)" % (planet.x, planet.y, planet.z, planet.race) reply += " Value: %s Size: %s Scoregain: %d" % ( planet.value, planet.size, xp_gain * PA.getint("numbers", "xp_value")) if intel: if intel.nick: reply += " Nick: %s" % (intel.nick, ) if not alliance.name and intel.alliance: reply += " Alliance: %s" % (intel.alliance.name, ) replies.append(reply) if len(result) > 5: replies[ -1] += " (Too many results to list, please refine your search)" message.reply("\n".join(replies))
def user_alliance(self, message, user, params): tick = Updates.current_tick() when = int(params.group(2) or 0) if when and when < 80: when += tick elif when and when <= tick: message.alert( "Can not check status on the past. You wanted tick %s, but current tick is %s." % ( when, tick, )) return if params.group(1) is None and not self.is_user(user): raise PNickParseError booker = User.load( params.group(1), exact=False, access="member") or User.load( params.group(1)) if params.group(1) is not None else user alliance = (Alliance( name="Unknown") if params.group(1).lower() == "unknown" else Alliance.load(params.group(1))) if booker is None else None if (booker or alliance) is None: message.reply("No alliance or user matching '%s' found" % (params.group(1), )) return # User if booker is not None: Q = session.query(Planet, Target.tick) Q = Q.join(Target.planet) Q = Q.join(Target.user) Q = Q.filter(Planet.active == True) Q = Q.filter(Target.user == booker) Q = Q.filter(Target.tick == when) if when else Q.filter( Target.tick > tick) Q = Q.order_by(asc(Target.tick)) Q = Q.order_by(asc(Planet.x)) Q = Q.order_by(asc(Planet.y)) Q = Q.order_by(asc(Planet.z)) result = Q.all() if len(result) < 1: reply = "No bookings matching user %s" % (booker.name, ) if when: reply += " for tick %s" % (when, ) message.reply(reply) return reply = "Bookings matching user %s" % (booker.name, ) reply += " landing on tick %s (eta %s): " % ( when, when - tick) if when else ": " prev = [] for planet, land in result: prev.append("(%s:%s:%s%s)" % ( planet.x, planet.y, planet.z, "" if when else " landing pt%s/eta %s" % ( land, land - tick, ), )) reply += ", ".join(prev) message.reply(reply) return # Alliance else: Q = session.query(Planet, User.name, Target.tick) Q = Q.join(Target.planet) Q = Q.join(Planet.intel) if alliance.id else Q.outerjoin( Planet.intel) Q = Q.join(Target.user) Q = Q.filter(Planet.active == True) Q = Q.filter(Intel.alliance == (alliance if alliance.id else None)) Q = Q.filter(Target.tick == when) if when else Q.filter( Target.tick > tick) Q = Q.order_by(asc(Planet.x)) Q = Q.order_by(asc(Planet.y)) Q = Q.order_by(asc(Planet.z)) result = Q.all() if len(result) < 1: reply = "No active bookings matching alliance %s" % ( alliance.name) if when: reply += " for tick %s." % (when, ) message.reply(reply) return reply = "Target information for %s" % (alliance.name) reply += " landing on tick %s (eta %s): " % ( when, when - tick) if when else ": " ticks = {} for planet, user, land in result: if not ticks.has_key(land): ticks[land] = [] ticks[land].append(( planet, user, )) sorted_keys = ticks.keys() sorted_keys.sort() replies = [] for land in sorted_keys: prev = [] for planet, user in ticks[land]: prev.append("(%s:%s:%s %s)" % (planet.x, planet.y, planet.z, user)) replies.append("Tick %s (eta %s) " % (land, land - tick) + ", ".join(prev)) replies[0] = reply + replies[0] message.reply("\n".join(replies)) return
def execute(self, message, user, params): alliance = Alliance(name="Unknown") if params.group( 1).lower() == "unknown" else Alliance.load(params.group(1)) if alliance is None: message.reply("No alliance matching '%s' found" % (params.group(1), )) return tick = Updates.current_tick() when = int(params.group(2) or 0) if when and when < PA.getint("numbers", "protection"): when += tick elif when and when <= tick: message.alert( "Can not check status on the past. You wanted tick %s, but current tick is %s." % ( when, tick, )) return Q = session.query(Planet, User.name, Target.tick) Q = Q.join(Target.planet) Q = Q.join(Planet.intel) if alliance.id else Q.outerjoin(Planet.intel) Q = Q.join(Target.user) Q = Q.filter(Planet.active == True) Q = Q.filter(Intel.alliance == (alliance if alliance.id else None)) Q = Q.filter(Target.tick == when) if when else Q.filter( Target.tick > tick) Q = Q.order_by(asc(Planet.x)) Q = Q.order_by(asc(Planet.y)) Q = Q.order_by(asc(Planet.z)) result = Q.all() if len(result) < 1: reply = "No active bookings matching alliance %s" % (alliance.name) if when: reply += " for tick %s." % (when, ) message.reply(reply) return reply = "Target information for %s" % (alliance.name) reply += " landing on tick %s (eta %s): " % (when, when - tick) if when else ": " ticks = {} for planet, user, land in result: if not ticks.has_key(land): ticks[land] = [] ticks[land].append(( planet, user, )) sorted_keys = ticks.keys() sorted_keys.sort() replies = [] for land in sorted_keys: prev = [] for planet, user in ticks[land]: prev.append("(%s:%s:%s %s)" % (planet.x, planet.y, planet.z, user)) replies.append("Tick %s (eta %s) " % (land, land - tick) + ", ".join(prev)) replies[0] = reply + replies[0] message.reply("\n".join(replies))
def execute(self, message, user, params): alliance = Alliance() race = None size_mod = None size = None value_mod = None value = None bash = False attacker = None cluster = None params = params.group(1).split() for p in params: m = self.bashre.match(p) if m and not bash: bash = True attacker = self.get_user_planet(user) continue m = self.clusterre.match(p) if m and not cluster: cluster = int(m.group(1)) m = self.racere.match(p) if m and not race: race = m.group(1) continue m = self.rangere.match(p) if m and not size and int(m.group(2)) < 32768: size_mod = m.group(1) or '>' size = m.group(2) continue m = self.rangere.match(p) if m and not value: value_mod = m.group(1) or '<' value = m.group(2) continue m = self.alliancere.match(p) if m and not alliance.name and not self.clusterre.match(p): alliance = Alliance(name="Unknown") if m.group( 1).lower() == "unknown" else Alliance.load(m.group(1)) if alliance is None: message.reply("No alliance matching '%s' found" % (m.group(1), )) return continue Q = session.query(Planet, Intel) if alliance.id: Q = Q.join(Planet.intel) Q = Q.filter(Intel.alliance == alliance) else: Q = Q.outerjoin(Planet.intel) if alliance.name: Q = Q.filter(Intel.alliance == None) Q = Q.filter(Planet.active == True) Q = Q.filter(Planet.x < 200) if race: Q = Q.filter(Planet.race.ilike(race)) if size: Q = Q.filter(Planet.size.op(size_mod)(size)) if value: Q = Q.filter(Planet.value.op(value_mod)(value)) if bash: Q = Q.filter( or_( Planet.value.op(">")(attacker.value * PA.getfloat("bash", "value")), Planet.score.op(">")(attacker.score * PA.getfloat("bash", "score")))) if cluster: Q = Q.filter(Planet.x == cluster) Q = Q.order_by(desc(Planet.idle)) Q = Q.order_by(desc(Planet.value)) result = Q[:6] if len(result) < 1: reply = "No" if race: reply += " %s" % (race, ) reply += " planets" if alliance.name: reply += " in intel matching Alliance: %s" % (alliance.name, ) else: reply += " matching" if size: reply += " Size %s %s" % (size_mod, size) if value: reply += " Value %s %s" % (value_mod, value) message.reply(reply) return replies = [] for planet, intel in result[:5]: reply = "%s:%s:%s (%s)" % (planet.x, planet.y, planet.z, planet.race) reply += " Value: %s Size: %s Idle: %s" % ( planet.value, planet.size, planet.idle) if intel: if intel.nick: reply += " Nick: %s" % (intel.nick, ) if not alliance.name and intel.alliance: reply += " Alliance: %s" % (intel.alliance.name, ) replies.append(reply) if len(result) > 5: replies[ -1] += " (Too many results to list, please refine your search)" message.reply("\n".join(replies))
def execute(self, message, user, params): alliance = Alliance() race = None size_mod = None size = None value_mod = None value = None bash = False attacker = None cluster = None params = params.group(1).split() for p in params: m = self.bashre.match(p) if m and not bash: bash = True attacker = self.get_user_planet(user) continue m = self.clusterre.match(p) if m and not cluster: cluster = int(m.group(1)) m = self.racere.match(p) if m and not race: race = m.group(1) continue m = self.rangere.match(p) if m and not size and int(m.group(2)) < 32768: size_mod = m.group(1) or '>' size = m.group(2) continue m = self.rangere.match(p) if m and not value: value_mod = m.group(1) or '<' value = m.group(2) continue m = self.alliancere.match(p) if m and not alliance.name and not self.clusterre.match(p): alliance = Alliance(name="Unknown") if m.group( 1).lower() == "unknown" else Alliance.load(m.group(1)) if alliance is None: message.reply("No alliance matching '%s' found" % (m.group(1), )) return continue tick = Updates.current_tick() target = aliased(Planet) target_intel = aliased(Intel) owner = aliased(Planet) owner_intel = aliased(Intel) Q = session.query(owner, owner_intel).distinct() Q = Q.join((FleetScan.owner, owner)) Q = Q.join((FleetScan.target, target)) Q = Q.join((target.intel, target_intel)) Q = Q.filter(target_intel.alliance == Alliance.load( Config.get("Alliance", "name"))) Q = Q.filter(FleetScan.landing_tick > tick) Q = Q.filter(FleetScan.mission == "Attack") if alliance.id: Q = Q.join((owner.intel, owner_intel)) Q = Q.filter(owner_intel.alliance == alliance) else: Q = Q.outerjoin((owner.intel, owner_intel)) if alliance.name: Q = Q.filter(owner_intel.alliance == None) Q = Q.filter(owner.active == True) if race: Q = Q.filter(owner.race.ilike(race)) if size: Q = Q.filter(owner.size.op(size_mod)(size)) if value: Q = Q.filter(owner.value.op(value_mod)(value)) if bash: Q = Q.filter( or_( owner.value.op(">")(attacker.value * PA.getfloat("bash", "value")), owner.score.op(">")(attacker.score * PA.getfloat("bash", "score")))) if cluster: Q = Q.filter(owner.x == cluster) Q = Q.order_by(desc(owner.size)) Q = Q.order_by(desc(owner.value)) result = Q[:6] if len(result) < 1: reply = "No" if race: reply += " %s" % (race, ) reply += " planets attacking %s" % (Config.get("Alliance", "name"), ) if alliance.name: reply += " in intel matching Alliance: %s" % (alliance.name, ) else: reply += " matching" if size: reply += " Size %s %s" % (size_mod, size) if value: reply += " Value %s %s" % (value_mod, value) message.reply(reply) return replies = [] for planet, intel in result[:5]: reply = "%s:%s:%s (%s)" % (planet.x, planet.y, planet.z, planet.race) reply += " Value: %s Size: %s" % (planet.value, planet.size) if intel: if intel.nick: reply += " Nick: %s" % (intel.nick, ) if not alliance.name and intel.alliance: reply += " Alliance: %s" % (intel.alliance.name, ) Q = session.query(FleetScan, Intel.nick).distinct() Q = Q.join(FleetScan.target) Q = Q.outerjoin(Planet.intel) Q = Q.filter(FleetScan.owner == planet) Q = Q.filter(FleetScan.landing_tick > tick) Q = Q.filter(FleetScan.mission == "Attack") result2 = Q.all() if len(result2): reply += " Hitting: " prev = [] for fleet, nick in result2: prev.append((nick or 'Unknown') + " (%s, lands: %s)" % (fleet.fleet_size, fleet.landing_tick)) reply += ', '.join(prev) replies.append(reply) if len(result) > 5: replies[ -1] += " (Too many results to list, please refine your search)" message.reply("\n".join(replies))
def execute(self, message, user, params): alliance = Alliance() race = None size_mod = None size = None value_mod = None value = None bash = False attacker = user.planet cluster = None limit = 5 params = params.group(1).split() for p in params: m = self.bashre.match(p) if m and not bash: bash = True continue m = self.clusterre.match(p) if m and not cluster: cluster = int(m.group(1)) m = self.racere.match(p) if m and not race: race = m.group(1) continue m = self.rangere.match(p) if m and not size and int(m.group(2)) < 32768: size_mod = m.group(1) or '>' size = m.group(2) continue m = self.rangere.match(p) if m and not value: value_mod = m.group(1) or '<' value = m.group(2) continue m = self.alliancere.match(p) if m and not alliance.name and not self.clusterre.match(p): alliance = Alliance(name="Unknown") if m.group( 1).lower() == "unknown" else Alliance.load(m.group(1)) if alliance is None: message.reply("No alliance matching '%s' found" % (m.group(1), )) return continue if p[:4] == "lots" and user.is_admin(): limit = int(p[4:]) maxcap = PA.getfloat("roids", "maxcap") mincap = PA.getfloat("roids", "mincap") modifier = (cast(Planet.value, Float).op("/")(float(attacker.value))).op("^")(0.5) caprate = func.greatest(mincap, func.least(modifier.op("*")(maxcap), maxcap)) maxcap = cast(func.floor(cast(Planet.size, Float).op("*")(caprate)), Integer) Q = session.query(Planet, Intel, maxcap.label("maxcap")) if alliance.id: Q = Q.join(Planet.intel) Q = Q.filter(Intel.alliance == alliance) else: Q = Q.outerjoin(Planet.intel) if alliance.name: Q = Q.filter(Intel.alliance == None) Q = Q.filter(Planet.active == True) if race: Q = Q.filter(Planet.race.ilike(race)) if size: Q = Q.filter(Planet.size.op(size_mod)(size)) if value: Q = Q.filter(Planet.value.op(value_mod)(value)) if bash: Q = Q.filter( or_( Planet.value.op(">")(attacker.value * PA.getfloat("bash", "value")), Planet.score.op(">")(attacker.score * PA.getfloat("bash", "score")))) if cluster: Q = Q.filter(Planet.x == cluster) Q = Q.order_by(desc("maxcap")) Q = Q.order_by(desc(Planet.size)) Q = Q.order_by(desc(Planet.value)) result = Q[:(limit + 1)] if len(result) < 1: reply = "No" if race: reply += " %s" % (race, ) reply += " planets" if alliance.name: reply += " in intel matching Alliance: %s" % (alliance.name, ) else: reply += " matching" if size: reply += " Size %s %s" % (size_mod, size) if value: reply += " Value %s %s" % (value_mod, value) message.reply(reply) return replies = [] for planet, intel, maxcap in result[:limit]: reply = "%s:%s:%s (%s)" % (planet.x, planet.y, planet.z, planet.race) reply += " Value: %s Size: %s MaxCap: %s" % (planet.value, planet.size, maxcap) if intel: if intel.nick: reply += " Nick: %s" % (intel.nick, ) if not alliance.name and intel.alliance: reply += " Alliance: %s" % (intel.alliance.name, ) replies.append(reply) print(len(replies)) if len(replies) == 5: message.reply("\n".join(replies)) replies = [] sleep(3) if len(result) > limit: replies.append( "(Too many results to list, please refine your search)") message.reply("\n".join(replies))