def execute(self, message, user, params): if params.group(1) is not None: alliance = Alliance.load(params.group(1)) if alliance is None: message.alert("No alliances match %s" % (params.group(1),)) return elif self.is_user(user) and user.is_member(): alliance = Alliance.load(Config.get("Alliance","name")) if alliance is None: message.alert("No alliances match %s" % (Config.get("Alliance","name"),)) return else: self.get_user_planet(user) if user.planet.intel is None or user.planet.alliance is None: message.alert("Make sure you've set your planet with !pref and alliance with !intel") return else: alliance = user.planet.alliance penis = alliance.apenis if penis is None: message.alert("No apenis stats matching %s" % (alliance.name,)) return message.reply("apenis for %s is %s score long. This makes %s rank: %s apenis. The average peon is sporting a %s score epenis." % ( alliance.name, penis.penis, alliance.name, penis.rank, int(penis.penis/alliance.members),))
def execute(self, message, user, params): alliance = Alliance.load(params.group(1)) if alliance is None: message.reply("No alliance matching '%s' found" % (params.group(1), )) return if params.group(2): alliance2 = Alliance.load(params.group(2)) if alliance2 is None: message.reply("No alliance matching '%s' found" % (params.group(2), )) return bums = int(params.group(3) or 2) Q = session.query(Galaxy.x, Galaxy.y, count()) Q = Q.join(Galaxy.planets) Q = Q.join(Planet.intel) Q = Q.filter(Galaxy.active == True) Q = Q.filter(Planet.active == True) if params.group(2): R = Q.filter(Intel.alliance == alliance2) R = R.group_by(Galaxy.x, Galaxy.y) R = R.having(count() >= bums) Q = Q.filter(Intel.alliance == alliance) Q = Q.group_by(Galaxy.x, Galaxy.y) Q = Q.having(count() >= bums) prev = [] if params.group(2): for x1, y1, c1 in Q.all(): for x2, y2, c2 in R.all(): if x1 == x2 and y1 == y2: prev.append("%s:%s (%s,%s)" % (x1, y1, c1, c2)) if len(prev) < 1: message.reply( "No galaxies with at least %s bumchums from %s and %s" % (bums, alliance.name, alliance2.name)) return reply = "Galaxies with at least %s bums from %s and %s: " % ( bums, alliance.name, alliance2.name) + ' | '.join(prev) else: result = Q.all() if len(result) < 1: message.reply("No galaxies with at least %s bumchums from %s" % ( bums, alliance.name, )) return prev = [] for x, y, chums in result: prev.append("%s:%s (%s)" % (x, y, chums)) reply = "Galaxies with at least %s bums from %s: " % ( bums, alliance.name) + ' | '.join(prev) message.reply(reply)
def execute(self, message, user, params): alliance = Alliance.load(params.group(1)) if alliance is None: message.reply("No alliance matching '%s' found" % (params.group(1),)) return if params.group(2): alliance2 = Alliance.load(params.group(2)) if alliance2 is None: message.reply("No alliance matching '%s' found" % (params.group(2),)) return bums = int(params.group(3) or 2) Q = session.query(Galaxy.x, Galaxy.y, count()) Q = Q.join(Galaxy.planets) Q = Q.join(Planet.intel) Q = Q.filter(Galaxy.active == True) Q = Q.filter(Planet.active == True) if params.group(2): R = Q.filter(Intel.alliance == alliance2) R = R.group_by(Galaxy.x, Galaxy.y) R = R.having(count() >= bums) Q = Q.filter(Intel.alliance == alliance) Q = Q.group_by(Galaxy.x, Galaxy.y) Q = Q.having(count() >= bums) prev = [] if params.group(2): for x1, y1, c1 in Q.all(): for x2, y2, c2 in R.all(): if x1 == x2 and y1 == y2: prev.append("%s:%s (%s,%s)" % (x1, y1, c1, c2)) if len(prev) < 1: message.reply( "No galaxies with at least %s bumchums from %s and %s" % (bums, alliance.name, alliance2.name) ) return reply = "Galaxies with at least %s bums from %s and %s: " % ( bums, alliance.name, alliance2.name, ) + " | ".join(prev) else: result = Q.all() if len(result) < 1: message.reply("No galaxies with at least %s bumchums from %s" % (bums, alliance.name)) return prev = [] for x, y, chums in result: prev.append("%s:%s (%s)" % (x, y, chums)) reply = "Galaxies with at least %s bums from %s: " % (bums, alliance.name) + " | ".join(prev) message.reply(reply)
def execute(self, message, user, params): # do stuff here if params.group(1).lower() == Config.get("Connection","nick").lower(): message.reply("I'll peck your eyes out, c**t.") return idiot = User.load(name=params.group(1), access="member") if idiot is None: message.reply("That user isn't a member!") return if (not user.is_admin()) and user != idiot and idiot.sponsor != user.name: message.reply("You do not have sufficent access to demote this member.") return if "galmate" in Config.options("Access"): idiot.access = Config.getint("Access","galmate") else: idiot.access = 0 if idiot.planet is not None and idiot.planet.intel is not None: intel = idiot.planet.intel alliance = Alliance.load(Config.get("Alliance","name")) if intel.alliance == alliance: intel.alliance = None session.commit() message.privmsg("remuser %s %s"%(Config.get("Channels","home"), idiot.name,),'p') message.privmsg("remuser %s %s"%(Config.get("Channels","core"), idiot.name,),'p') if idiot.sponsor != user.name: # message.privmsg("note send %s You have been removed from private channels."%(idiot.name,),'p') message.reply("%s has been reduced to \"galmate\" level and removed from the channel. "%(idiot.name,)) else: # message.privmsg("note send %s You have been removed from private channels."%(idiot.name,),'p') message.reply("%s has been reduced to \"galmate\" level and removed from the channel."%(idiot.name,))
def user_alliance(self, message, user, params): alliance = Alliance.load( params.group(1)) if params.group(1) is not None else None # Alliance if alliance is not None: message.reply(str(alliance)) return # User if not self.is_user(user): raise PNickParseError elif not user.is_member(): message.reply("No alliance matching '%s' found" % (params.group(1), )) return else: lookup = User.load(params.group(1), exact=False, access="member") or User.load(params.group(1)) if lookup is None: message.reply("No alliance or user matching '%s' found" % (params.group(1), )) return elif lookup.planet is None: message.reply("User %s has not entered their planet details" % (lookup.name, )) return else: message.reply(str(lookup.planet)) return
def groups(self, message, user, params): opts = params.group(1).lower().split() alliance = None sortby = "score" race = None for opt in opts: if opt in ["score", "value", "size", "xp"]: sortby = opt elif opt in [ "terran"[:len(opt)], "cathaar"[:len(opt)], "xandathrii"[:len(opt)], "zikonian"[:len(opt)], "eitraides"[:len(opt)] ]: if opt[0] == "t": race = "Ter" elif opt[0] == "c": race = "Cat" elif opt[0] == "x": race = "Xan" elif opt[0] == "z": race = "Zik" elif opt[0] == "e": race = "Etd" else: alliance = Alliance.load(opt) if alliance is None: message.reply("No alliance or user matching '%s' found" % (params.group(1), )) self.execute(message, alliance=alliance, race=race, sortby=sortby)
def execute(self, message, user, params): alliance = Alliance.load(params.group(1)) if alliance is None: message.reply("No alliance matching '%s' found" % (params.group(1), )) return bums = int(params.group(2) or 2) Q = session.query(Galaxy.x, Galaxy.y, count()) Q = Q.join(Galaxy.planets) Q = Q.join(Planet.intel) Q = Q.filter(Galaxy.active == True) Q = Q.filter(Planet.active == True) Q = Q.filter(Intel.alliance == alliance) Q = Q.group_by(Galaxy.x, Galaxy.y) Q = Q.having(count() >= bums) result = Q.all() if len(result) < 1: message.reply("No galaxies with at least %s bumchums from %s" % ( bums, alliance.name, )) return prev = [] for x, y, chums in result: prev.append("%s:%s (%s)" % (x, y, chums)) reply = "Galaxies with at least %s bums from %s: " % ( bums, alliance.name) + ' | '.join(prev) message.reply(reply)
def execute(self, message, user, params): alliance = Alliance.load(params.group(1)) if alliance is None: message.reply("No alliance matching '%s' found"%(params.group(1),)) return Q = session.query(sum(Planet.value), sum(Planet.score), sum(Planet.size), sum(Planet.xp), count(), Planet.race) Q = Q.join(Planet.intel) Q = Q.filter(Planet.active == True) Q = Q.filter(Intel.alliance==alliance) Q = Q.group_by(Intel.alliance_id, Planet.race) Q = Q.order_by(asc(Planet.race)) result = Q.all() if len(result) < 1: message.reply("No planets in intel match alliance %s"%(alliance.name,)) return prev=[] for value, score, size, xp, members, race in result: reply="%s %s Val(%s)" % (members,race,self.num2short(value/members),) reply+=" Score(%s)" % (self.num2short(score/members),) reply+=" Size(%s) XP(%s)" % (size/members,self.num2short(xp/members),) prev.append(reply) reply="Demographics for %s: "%(alliance.name,)+ ' | '.join(prev) message.reply(reply)
def execute(self, message, user, params): # do stuff here if params.group(1).lower() == Config.get("Connection","nick").lower(): message.reply("I'll peck your eyes out, c**t.") return idiot = User.load(name=params.group(1), access="member") if idiot is None: message.reply("That idiot isn't a member!") return if (not user.is_admin()) and user != idiot and idiot.sponsor != user.name: message.reply("You are not %s's sponsor"%(idiot.name,)) return if "galmate" in Config.options("Access"): idiot.access = Config.getint("Access","galmate") else: idiot.access = 0 if idiot.planet is not None and idiot.planet.intel is not None: intel = idiot.planet.intel alliance = Alliance.load(Config.get("Alliance","name")) if intel.alliance == alliance: intel.alliance = None session.commit() message.privmsg("remuser %s %s"%(Config.get("Channels","home"), idiot.name,),Config.get("Services", "nick")) message.privmsg("ban %s *!*@%s.%s Your sponsor doesn't like you anymore"%(Config.get("Channels","home"), idiot.name, Config.get("Services", "usermask"),),Config.get("Services", "nick")) if idiot.sponsor != user.name: message.privmsg("note send %s Some admin has removed you for whatever reason. If you still wish to be a member, go ahead and find someone else to sponsor you back."%(idiot.name,),Config.get("Services", "nick")) message.reply("%s has been reduced to \"galmate\" level and removed from the channel. %s is no longer %s's sponsor. If anyone else would like to sponsor that person back, they may."%(idiot.name,idiot.sponsor,idiot.name)) else: message.privmsg("note send %s Your sponsor (%s) no longer wishes to be your sponsor. If you still wish to be a member, go ahead and find someone else to sponsor you back."%(idiot.name,user.name,),Config.get("Services", "nick")) message.reply("%s has been reduced to \"galmate\" level and removed from the channel. You are no longer %s's sponsor. If anyone else would like to sponsor that person back, they may."%(idiot.name,idiot.name))
def execute(self, message, user, params): # do stuff here if params.group(1).lower() == Config.get("Connection","nick").lower(): message.reply("I'll peck your eyes out, c**t.") return idiot = User.load(name=params.group(1), access="member") if idiot is None: message.reply("That idiot isn't a member!") return if (not user.is_admin()) and user != idiot and idiot.sponsor != user.name: message.reply("You are not %s's sponsor"%(idiot.name,)) return if "galmate" in Config.options("Access"): idiot.access = Config.getint("Access","galmate") else: idiot.access = 0 if idiot.planet is not None and idiot.planet.intel is not None: intel = idiot.planet.intel alliance = Alliance.load(Config.get("Alliance","name")) if intel.alliance == alliance: intel.alliance = None session.commit() message.privmsg("remuser %s %s"%(Config.get("Channels","home"), idiot.name,),'p') message.privmsg("ban %s *!*@%s.users.netgamers.org Your sponsor doesn't like you anymore"%(Config.get("Channels","home"), idiot.name,),'p') if idiot.sponsor != user.name: message.privmsg("note send %s Some admin has removed you for whatever reason. If you still wish to be a member, go ahead and find someone else to sponsor you back."%(idiot.name,),'p') message.reply("%s has been reduced to \"galmate\" level and removed from the channel. %s is no longer %s's sponsor. If anyone else would like to sponsor that person back, they may."%(idiot.name,idiot.sponsor,idiot.name)) else: message.privmsg("note send %s Your sponsor (%s) no longer wishes to be your sponsor. If you still wish to be a member, go ahead and find someone else to sponsor you back."%(idiot.name,user.name,),'p') message.reply("%s has been reduced to \"galmate\" level and removed from the channel. You are no longer %s's sponsor. If anyone else would like to sponsor that person back, they may."%(idiot.name,idiot.name))
def groups(self, message, user, params): opts=params.group(1).lower().split() alliance=None sortby="score" race=None for opt in opts: if opt in ["score","value","size","xp"]: sortby=opt elif opt in ["terran"[:len(opt)], "cathaar"[:len(opt)], "xandathrii"[:len(opt)], "zikonian"[:len(opt)], "eitraides"[:len(opt)]]: if opt[0] == "t": race="Ter" elif opt[0] == "c": race="Cat" elif opt[0] == "x": race="Xan" elif opt[0] == "z": race="Zik" elif opt[0] == "e": race="Etd" else: alliance=Alliance.load(opt) if alliance is None: message.reply("No alliance or user matching '%s' found" % (params.group(1),)) self.execute(message, alliance=alliance, race=race, sortby=sortby)
def execute(self, message, user, params): alliance = Alliance.load(params.group(1), alias=False) if alliance is None: message.reply("There's no morons playing under the tag %s" % (params.group(1),)) return alliance.alias = params.group(2) session.commit() message.reply("That f****d up tag %s has been aliased to %s" % (alliance.name, alliance.alias,))
class alliance(graphs): load = staticmethod(lambda x, y, z, name: Alliance.load(name, exact=True)) title = staticmethod(lambda o: "%s" % (o.name, )) left, right = { 'values': yellow, 'ranks': cyan }, { 'values': green, 'ranks': green } query = { 'values': session.query(AllianceHistory.tick, AllianceHistory.size, AllianceHistory.score, AllianceHistory.members), 'ranks': session.query(AllianceHistory.tick, AllianceHistory.size_rank, AllianceHistory.score_rank, AllianceHistory.points_rank), } plot = { 'values': lambda ax, Q: ( ( ax[1].plot(Q[0], Q[1], yellow)[0], "Size", ), ( ax[2].plot(Q[0], Q[2], green)[0], "Score", ), ( ax[0].plot(Q[0], Q[3], pink)[0], "Members", ), ), 'ranks': lambda ax, Q: ( ( ax[2].plot(Q[0], Q[1], yellow)[0], "Size", ), ( ax[2].plot(Q[0], Q[2], green)[0], "Score", ), ( ax[1].plot(Q[0], Q[3], cyan)[0], "Points", ), ), } ax = { 'values': lambda i, Q: [Q[3], Q[1], Q[2]][i], 'ranks': lambda i, Q: [(0, ), Q[3], Q[2]][i], }
def execute(self, request, user, name): alliance = Alliance.load(name) if alliance is None: return HttpResponseRedirect(reverse("alliance_ranks")) ph = aliased(PlanetHistory) members = count().label("members") size = sum(ph.size).label("size") value = sum(ph.value).label("value") score = sum(ph.score).label("score") avg_size = size.op("/")(members).label("avg_size") avg_value = value.op("/")(members).label("avg_value") t10v = count(case(whens=((ph.value_rank <= 10 ,1),), else_=None)).label("t10v") t100v = count(case(whens=((ph.value_rank <= 100 ,1),), else_=None)).label("t100v") pho = aliased(PlanetHistory) sizeo = sum(pho.size).label("sizeo") valueo = sum(pho.value).label("valueo") scoreo = sum(pho.score).label("scoreo") Q = session.query(PlanetHistory.tick.label("tick"), Alliance.id.label("id"), literal_column("rank() OVER (PARTITION BY planet_history.tick ORDER BY sum(planet_history.size) DESC)").label("size_rank"), literal_column("rank() OVER (PARTITION BY planet_history.tick ORDER BY sum(planet_history.value) DESC)").label("value_rank"), ) Q = Q.filter(PlanetHistory.active == True) Q = Q.join(PlanetHistory.current) Q = Q.join(Planet.intel) Q = Q.join(Intel.alliance) Q = Q.group_by(PlanetHistory.tick, Alliance.id) ranks = Q.subquery() Q = session.query(ph.tick, members, size, value, avg_size, avg_value, size-sizeo, value-valueo, score-scoreo, t10v, t100v, ) Q = Q.filter(ph.active == True) Q = Q.join(ph.current) Q = Q.join(Planet.intel) Q = Q.join(Intel.alliance) Q = Q.outerjoin((pho, and_(ph.id==pho.id, ph.tick-1==pho.tick),)) Q = Q.filter(Intel.alliance == alliance) Q = Q.group_by(ph.tick) Q = Q.from_self().add_columns(ranks.c.size_rank, ranks.c.value_rank) Q = Q.outerjoin((ranks, and_(ph.tick == ranks.c.tick, alliance.id == ranks.c.id),)) Q = Q.order_by(desc(ph.tick)) history = Q.all() return render("ialliancehistory.tpl", request, alliance=alliance, members=alliance.intel_members, history=history)
def onegroup(self, message, user, params): opt = params.group(1).lower() if opt in ["score","value","size","xp"]: self.execute(message, sortby=opt) elif opt in ["terran"[:len(opt)], "cathaar"[:len(opt)], "xandathrii"[:len(opt)], "zikonian"[:len(opt)], "eitraides"[:len(opt)]]: self.execute(message, race=opt) else: alliance = Alliance.load(opt) if alliance is None: message.reply("No alliance or user matching '%s' found" % (params.group(1),)) else: self.execute(message, alliance=alliance)
def check_planet(self, request, user): coords = request.POST.get(PLANET) or "" if coords == "Clear": if self.user_has_planet(user): user.planet = None session.commit() return False m = self.coord.match(coords) if m: planet = Planet.load(*m.group(1,3,5)) else: planet = None if planet is not None: if self.is_user(user): user.planet = planet if user.is_member(): alliance = Alliance.load(Config.get("Alliance","name")) if planet.intel is None: planet.intel = Intel(nick=user.name, alliance=alliance) else: planet.intel.nick = user.name planet.intel.alliance = alliance session.commit() else: user.planet = planet session.expunge(user) return user.planet.id pa_id = request.COOKIES.get(PLANET_KEY) if self.user_has_planet(user): if pa_id == user.planet.id: return True else: return user.planet.id elif self.is_user(user): if pa_id: return False else: return True else: if pa_id: planet = session.query(Planet).filter_by(id=pa_id).first() if planet is None: return False else: user.planet = planet session.expunge(user) return True else: return True
def check_planet(self, request, user): coords = request.REQUEST.get(PLANET) or "" if coords == "Clear": if self.user_has_planet(user): user.planet = None session.commit() return False m = self.coord.match(coords) if m: planet = Planet.load(*m.group(1, 3, 5)) else: planet = None if planet is not None: if self.is_user(user): user.planet = planet if user.is_member(): alliance = Alliance.load(Config.get("Alliance", "name")) if planet.intel is None: planet.intel = Intel(nick=user.name, alliance=alliance) else: planet.intel.nick = user.name planet.intel.alliance = alliance session.commit() else: user.planet = planet session.expunge(user) return user.planet.id pa_id = request.COOKIES.get(PLANET_KEY) if self.user_has_planet(user): if pa_id == user.planet.id: return True else: return user.planet.id elif self.is_user(user): if pa_id: return False else: return True else: if pa_id: planet = session.query(Planet).filter_by(id=pa_id).first() if planet is None: return False else: user.planet = planet session.expunge(user) return True else: return True
def set_intel(self, message, user, params): planet = Planet.load(*params.group(1, 3, 5)) if planet is None: message.alert("No planet with coords %s:%s:%s" % params.group(1, 3, 5)) return if planet.intel is None: planet.intel = Intel() params = self.split_opts(message.get_msg()) for opt, val in params.items(): if opt == "alliance": if val in self.nulls: planet.intel.alliance = None continue alliance = Alliance.load(val) if alliance is None: message.alert("No alliances match %s" % (val, )) continue planet.intel.alliance = alliance if (opt in options) and (val in self.nulls): setattr(planet.intel, opt, None) continue if opt in ("nick", "fakenick", "bg", "gov", "reportchan"): setattr(planet.intel, opt, val) if opt in ("defwhore", "covop", "relay"): if val.lower() in self.true: setattr(planet.intel, opt, True) if val.lower() in self.false: setattr(planet.intel, opt, False) if opt in ("amps", "dists"): if val.isdigit(): setattr(planet.intel, opt, int(val)) if opt == "comment": planet.intel.comment = message.get_msg( )[message.get_msg().lower().index("comment=") + len("comment="):] session.commit() if planet.intel and str(planet.intel): message.reply("Information stored for %s:%s:%s -%s" % ( planet.x, planet.y, planet.z, str(planet.intel), )) else: message.reply("No information stored for %s:%s:%s" % ( planet.x, planet.y, planet.z, ))
def execute(self, message, user, params): params = self.split_opts(params.group(1)) reply = "" for opt, val in params.items(): if opt == "planet": m = self.planet_coordre.match(val) if m: planet = Planet.load(*m.group(1,3,5)) if planet is None: continue user.planet = planet reply += " planet=%s:%s:%s"%(planet.x,planet.y,planet.z) if user.is_member(): alliance = Alliance.load(Config.get("Alliance","name")) if planet.intel is None: planet.intel = Intel(nick=user.name, alliance=alliance) else: planet.intel.nick = user.name planet.intel.alliance = alliance elif val in self.nulls: user.planet = None reply += " planet=None" if opt == "password": user.passwd = val reply += " password=%s"%(val) if opt == "email": try: user.email = val except AssertionError: pass else: reply += " email=%s"%(val) if opt == "phone": user.phone = val reply += " phone=%s"%(val) if opt == "pubphone": if val.lower() in self.true: user.pubphone = True reply += " pubphone=%s"%(True) elif val.lower() in self.false: user.pubphone = False reply += " pubphone=%s"%(False) if opt == "googlevoice": if val.lower() in self.true: user.googlevoice = True reply += " googlevoice=%s"%(True) elif val.lower() in self.false: user.googlevoice = False reply += " googlevoice=%s"%(False) session.commit() message.reply("Updated your preferences:"+reply)
def user_alliance(self, message, user, params): alliance = Alliance.load(params.group(1)) if alliance is None: u = User.load(name=params.group(1), exact=False, access="member") if u is None: message.reply("No alliance or user matching '%s' found" % (params.group(1),)) elif u.planet is None: message.reply("User %s has not entered their planet details" % (u.name,)) else: planet = u.planet self.execute(message, planet=planet) else: self.execute(message, alliance=alliance)
def execute(self, message, user, params): if params.group(1) is not None: alliance = Alliance.load(params.group(1)) if alliance is None: message.alert("No alliances match %s" % (params.group(1), )) return elif self.is_user(user) and user.is_member(): alliance = Alliance.load(Config.get("Alliance", "name")) if alliance is None: message.alert("No alliances match %s" % (Config.get("Alliance", "name"), )) return else: self.get_user_planet(user) if user.planet.intel is None or user.planet.alliance is None: message.alert( "Make sure you've set your planet with !pref and alliance with !intel" ) return else: alliance = user.planet.alliance penis = alliance.apenis if penis is None: message.alert("No alliance growth stats matching %s" % (alliance.name, )) return message.reply( "alliance growth for %s is %s scoreg. This makes %s rank: %s in score. The average membern is sporting a %s score growth." % ( alliance.name, penis.penis, alliance.name, penis.rank, int(penis.penis / alliance.members), ))
def execute(self, message, user, params): tag_count = PA.getint("numbers", "tag_count") alliance = Alliance.load(params.group(1)) if alliance is None: message.reply("No alliance matching '%s' found"%(params.group(1),)) return Q = session.query(sum(Planet.value), sum(Planet.score), sum(Planet.size), sum(Planet.xp), count()) Q = Q.join(Planet.intel) Q = Q.filter(Planet.active == True) Q = Q.filter(Intel.alliance==alliance) Q = Q.group_by(Intel.alliance_id) result = Q.first() if result is None: message.reply("No planets in intel match alliance %s"%(alliance.name,)) return value, score, size, xp, members = result if members <= tag_count: reply="%s Members: %s/%s, Value: %s, Avg: %s," % (alliance.name,members,alliance.members,value,value//members) reply+=" Score: %s, Avg: %s," % (score,score//members) reply+=" Size: %s, Avg: %s, XP: %s, Avg: %s" % (size,size//members,xp,xp//members) message.reply(reply) return Q = session.query(Planet.value, Planet.score, Planet.size, Planet.xp, Intel.alliance_id) Q = Q.join(Planet.intel) Q = Q.filter(Planet.active == True) Q = Q.filter(Intel.alliance==alliance) Q = Q.order_by(desc(Planet.score)) Q = Q.limit(tag_count) Q = Q.from_self(sum(Planet.value), sum(Planet.score), sum(Planet.size), sum(Planet.xp), count()) Q = Q.group_by(Intel.alliance_id) ts_result = Q.first() ts_value, ts_score, ts_size, ts_xp, ts_members = ts_result reply="%s Members: %s/%s (%s)" % (alliance.name,members,alliance.members,ts_members) reply+=", Value: %s (%s), Avg: %s (%s)" % (value,ts_value,value//members,ts_value//ts_members) reply+=", Score: %s (%s), Avg: %s (%s)" % (score,ts_score,score//members,ts_score//ts_members) reply+=", Size: %s (%s), Avg: %s (%s)" % (size,ts_size,size//members,ts_size//ts_members) reply+=", XP: %s (%s), Avg: %s (%s)" % (xp,ts_xp,xp//members,ts_xp//ts_members) message.reply(reply)
def execute(self, message, user, params): # Planet or Galaxy if len(params.groups()) == 5: # Planet if params.group(5) is not None: planet = Planet.load(*params.group(1, 3, 5)) if planet is None: message.reply("No planet with coords %s:%s:%s found" % params.group(1, 3, 5)) return message.reply(str(planet)) return # Galaxy else: galaxy = Galaxy.load(*params.group(1, 3)) if galaxy is None: message.reply("No galaxy with coords %s:%s" % params.group(1, 3)) return message.reply(str(galaxy)) return # User or Alliance else: alliance = Alliance.load(params.group(1)) if params.group(1) is not None else None # Alliance if alliance is not None: message.reply(str(alliance)) return # User if params.group(1) is None: message.reply(str(self.get_user_planet(user))) return elif not self.is_user(user): raise PNickParseError elif not user.is_member(): message.reply("No alliance matching '%s' found" % (params.group(1),)) return else: lookup = User.load(params.group(1), exact=False) if lookup is None: message.reply("No alliance or user matching '%s' found" % (params.group(1),)) return elif lookup.planet is None: message.reply("User %s has not entered their planet details" % (lookup.name,)) return else: message.reply(str(lookup.planet)) return
def execute(self, request, user): lookup = (request.REQUEST.get("lookup") or "").strip() if not lookup: if user.is_member(): return HttpResponseRedirect(reverse("dashboard", kwargs={"username":user.name})) return HttpResponseRedirect("/") scans = scanre.findall(lookup) groups = scangrpre.findall(lookup) if len(scans) or len(groups): for url in scans: parse(user.id, "scan", url).start() for url in groups: parse(user.id, "group", url).start() return HttpResponseRedirect(reverse("requests")) m = self.coord.match(lookup) if m is None: alliance = Alliance.load(lookup) if lookup else None if alliance: return HttpResponseRedirect(reverse("alliance", kwargs={"name":alliance.name})) elif not user.is_member(): return HttpResponseRedirect(reverse("alliance_ranks")) else: member = User.load(lookup, exact=False, access="member") if lookup else None if member: return HttpResponseRedirect(reverse("dashboard", kwargs={"username":member.name})) else: Q = session.query(Planet) Q = Q.join(Planet.intel) Q = Q.filter(Planet.active == True) Q = Q.filter(Intel.nick.ilike(lookup+"%")) planet = Q.first() if planet: return HttpResponseRedirect(reverse("planet", kwargs={"x":planet.x, "y":planet.y, "z":planet.z})) else: return HttpResponseRedirect(reverse("alliance_ranks")) elif m.group(5) is not None: return HttpResponseRedirect(reverse("planet", kwargs={"x":m.group(1), "y":m.group(3), "z":m.group(5)})) elif m.group(3) is not None: return HttpResponseRedirect(reverse("galaxy", kwargs={"x":m.group(1), "y":m.group(3)}))
def execute(self, request, user, name, page="1", sort="score", race="all"): page = int(page) offset = (page - 1)*50 order = {"score" : (asc(Planet.score_rank),), "value" : (asc(Planet.value_rank),), "size" : (asc(Planet.size_rank),), "xp" : (asc(Planet.xp_rank),), "ratio" : (desc(Planet.ratio),), "race" : (asc(Planet.race), asc(Planet.size_rank),), "xyz" : (asc(Planet.x), asc(Planet.y), asc(Planet.z),), "score_growth" : (desc(Planet.score_growth),), "value_growth" : (desc(Planet.value_growth),), "size_growth" : (desc(Planet.size_growth),), "xp_growth" : (desc(Planet.xp_growth),), "score_growth_pc" : (desc(Planet.score_growth_pc),), "value_growth_pc" : (desc(Planet.value_growth_pc),), "size_growth_pc" : (desc(Planet.size_growth_pc),), "xp_growth_pc" : (desc(Planet.xp_growth_pc),), } if sort not in order.keys(): sort = "score" order = order.get(sort) alliance = Alliance.load(name) if alliance is None: return HttpResponseRedirect(reverse("alliance_ranks")) Q = session.query(Planet, Intel.nick, Alliance.name) Q = Q.join(Planet.intel) Q = Q.join(Intel.alliance) Q = Q.filter(Planet.active == True) Q = Q.filter(Intel.alliance == alliance) if race.lower() in PA.options("races"): Q = Q.filter(Planet.race.ilike(race)) else: race = "all" count = Q.count() pages = count/50 + int(count%50 > 0) pages = range(1, 1+pages) for o in order: Q = Q.order_by(o) Q = Q.limit(50).offset(offset) return render("palliance.tpl", request, alliance=alliance, planets=Q.all(), offset=offset, pages=pages, page=page, sort=sort, race=race)
def user_alliance(self, message, user, params): alliance = Alliance.load(params.group(1)) if params.group(1) is not None else None resources = 0 scansneeded = "" tick = Updates.current_tick() # Alliance if alliance is not None: for planet in alliance.intel_planets: scan = planet.scan("P") if scan and (int(tick) <= scan.tick + 12): resources += scan.planetscan.res_metal + scan.planetscan.res_crystal + scan.planetscan.res_eonium else: scansneeded += "%d:%d:%d " % (planet.x, planet.y, planet.z) message.reply("Stocked resources: %d Added value: %d Need scans for (%s)" %(resources, int(round((resources / 100) - (resources / 150))), scansneeded)) return else: message.reply("No alliance matching '%s' found" % (params.group(1)))
def execute(self, request, user, name, page="1", sort="score", race="all"): page = int(page) offset = (page - 1)*50 order = {"score" : (asc(Planet.score_rank),), "value" : (asc(Planet.value_rank),), "size" : (asc(Planet.size_rank),), "xp" : (asc(Planet.xp_rank),), "ratio" : (desc(Planet.ratio),), "race" : (asc(Planet.race), asc(Planet.size_rank),), "xyz" : (asc(Planet.x), asc(Planet.y), asc(Planet.z),), "score_growth" : (desc(Planet.score_growth),), "value_growth" : (desc(Planet.value_growth),), "size_growth" : (desc(Planet.size_growth),), "xp_growth" : (desc(Planet.xp_growth),), "score_growth_pc" : (desc(Planet.score_growth_pc),), "value_growth_pc" : (desc(Planet.value_growth_pc),), "size_growth_pc" : (desc(Planet.size_growth_pc),), "xp_growth_pc" : (desc(Planet.xp_growth_pc),), } if sort not in order.keys(): sort = "score" order = order.get(sort) alliance = Alliance.load(name) if alliance is None: return HttpResponseRedirect(reverse("alliance_ranks")) Q = session.query(Planet, Intel.nick, Alliance.name) Q = Q.join(Planet.intel) Q = Q.join(Intel.alliance) Q = Q.filter(Planet.active == True) Q = Q.filter(Intel.alliance == alliance) if race.lower() in PA.options("races"): Q = Q.filter(Planet.race.ilike(race)) else: race = "all" count = Q.count() pages = count//50 + int(count%50 > 0) pages = range(1, 1+pages) for o in order: Q = Q.order_by(o) Q = Q.limit(50).offset(offset) return render("palliance.tpl", request, alliance=alliance, members=alliance.intel_members, planets=Q.all(), offset=offset, pages=pages, page=page, sort=sort, race=race)
def execute(self, message, user, params): alliance = Alliance.load(params.group(1)) if (alliance is None) and (params.group(1).lower() not in ["None", "<>", "?"]): message.alert("No alliances match %s" % (params.group(1))) return reply = "Planets added to '%s':" % (alliance.name if alliance else "None") planets = self.planet_coordre.findall(params.group(2)) for coord in planets: planet=Planet.load(coord[0],coord[2],coord[4]) if planet: if planet.intel is None: planet.intel = Intel() planet.intel.alliance=alliance reply += " %s:%s:%s" % (coord[0],coord[2],coord[4]) session.commit() message.reply(reply)
def execute(self, request, user, name, h=False, hs=False, ticks=None): alliance = Alliance.load(name) if alliance is None: return HttpResponseRedirect(reverse("alliance_ranks")) ticks = int(ticks or 0) if h else 12 if not hs: sizediffvalue = AllianceHistory.rdiff * PA.getint( "numbers", "roid_value") scorediffwsizevalue = AllianceHistory.sdiff - sizediffvalue Q = session.query( AllianceHistory, sizediffvalue, scorediffwsizevalue, ) Q = Q.filter(AllianceHistory.current == alliance) Q = Q.order_by(desc(AllianceHistory.tick)) history = Q[:ticks] if ticks else Q.all() else: history = None if not h: Q = session.query(AllianceHistory) Q = Q.filter( or_(AllianceHistory.hour == 23, AllianceHistory.tick == Updates.current_tick())) Q = Q.filter(AllianceHistory.current == alliance) Q = Q.order_by(desc(AllianceHistory.tick)) hsummary = Q.all() if hs else Q[:14] else: hsummary = None return render( ["alliance.tpl", ["halliance.tpl", "hsalliance.tpl"][hs]][h or hs], request, alliance=alliance, members=alliance.intel_members, history=history, hsummary=hsummary, ticks=ticks, )
def set_intel(self, message, user, params): planet = Planet.load(*params.group(1,3,5)) if planet is None: message.alert("No planet with coords %s:%s:%s" % params.group(1,3,5)) return if planet.intel is None: planet.intel = Intel() params = self.split_opts(message.get_msg()) for opt, val in params.items(): if opt == "alliance": if val in self.nulls: planet.intel.alliance = None continue alliance = Alliance.load(val) if alliance is None: message.alert("No alliances match %s" % (val,)) continue planet.intel.alliance = alliance if (opt in options) and (val in self.nulls): setattr(planet.intel, opt, None) continue if opt in ("nick","fakenick","bg","gov","reportchan"): setattr(planet.intel, opt, val) if opt in ("defwhore","covop","scanner","relay"): if val.lower() in self.true: setattr(planet.intel, opt, True) if val.lower() in self.false: setattr(planet.intel, opt, False) if opt == "dists": try: planet.intel.dists = int(val) except ValueError: pass if opt == "comment": planet.intel.comment = message.get_msg().split("comment=")[1] session.commit() if planet.intel and str(planet.intel): message.reply("Information stored for %s:%s:%s -%s"% (planet.x, planet.y, planet.z, str(planet.intel),)) else: message.reply("No information stored for %s:%s:%s"% (planet.x, planet.y, planet.z,))
def execute(self, message, user, params): alliance = Alliance.load(Config.get("Alliance","name")) if alliance is None: message.reply("No alliance matching '%s' found"%(Config.get("Alliance","name"),)) return Q = session.query(User, epenis) Q = Q.join(User.epenis) Q = Q.order_by(asc(epenis.rank)) result = Q[:5] if len(result) < 1: message.alert("There is no penis") return prev = [] for user, penis in result: prev.append("%d:%s (%s)"%(penis.rank, user.name, self.num2short(penis.penis))) reply="Big dicks: " + ", ".join(prev) message.reply(reply)
def execute(self, message, user, params): alliance = Alliance.load(params.group(1), active=False) if alliance is None: message.reply("No alliance matching '%s' found"%(params.group(1),)) return Q = session.query(Planet, Intel) Q = Q.join(Planet.intel) Q = Q.filter(Planet.active == True) Q = Q.filter(Intel.alliance==alliance) Q = Q.order_by(asc(Planet.x), asc(Planet.y), asc(Planet.z)) result = Q.all() if len(result) < 1: message.reply("No planets in intel match alliance %s"%(alliance.name,)) return printable=map(lambda (p, i): "%s:%s:%s" % (p.x,p.y,p.z),result) reply="Spam on alliance %s - " %(alliance.name) reply += ' | '.join(printable) message.reply(reply)
def execute(self, message, user, params): alliance = Alliance.load(params.group(1)) if (alliance is None) and (params.group(1).lower() not in ["None", "<>", "?"]): message.alert("No alliances match %s" % (params.group(1))) return reply = "Planets added to '%s':" % (alliance.name if alliance else "None") planets = self.planet_coordre.findall(params.group(2)) for coord in planets: planet = Planet.load(coord[0], coord[2], coord[4]) if planet: if planet.intel is None: planet.intel = Intel() planet.intel.alliance = alliance reply += " %s:%s:%s" % (coord[0], coord[2], coord[4]) session.commit() message.reply(reply)
def intel_alliance(self, message, user, params): alliance = Alliance.load(params.group(1)) if alliance is None: message.reply("No alliance matching '%s' found"%(params.group(1),)) return Q = session.query(sum(Planet.value), sum(Planet.score), sum(Planet.size), sum(Planet.xp), count(), Planet.race) Q = Q.join(Planet.intel) Q = Q.filter(Planet.active == True) Q = Q.filter(Intel.alliance==alliance) Q = Q.group_by(Intel.alliance_id, Planet.race) Q = Q.order_by(asc(Planet.race)) result = Q.all() if len(result) < 1: message.reply("No planets in intel match alliance %s"%(alliance.name,)) return self.execute(message, alliance.name, result)
def user_alliance(self, message, user, params): alliance = Alliance.load( params.group(1)) if params.group(1) is not None else None resources = 0 scansneeded = "" tick = Updates.current_tick() # Alliance if alliance is not None: for planet in alliance.intel_planets: scan = planet.scan("P") if scan and (int(tick) <= scan.tick + 12): resources += scan.planetscan.res_metal + scan.planetscan.res_crystal + scan.planetscan.res_eonium else: scansneeded += "%d:%d:%d " % (planet.x, planet.y, planet.z) message.reply( "Stocked resources: %d Added value: %d Need scans for (%s)" % (resources, int(round((resources / 100) - (resources / 150))), scansneeded)) return else: message.reply("No alliance matching '%s' found" % (params.group(1)))
def execute(self, message, user, params): alliance = Alliance.load(params.group(1)) if alliance is None: message.reply("No alliance matching '%s' found"%(params.group(1),)) return bums = int(params.group(2) or 1) Q = session.query(Galaxy.x, Galaxy.y, count()) Q = Q.join(Galaxy.planets) Q = Q.join(Planet.intel) Q = Q.filter(Galaxy.active == True) Q = Q.filter(Intel.alliance==alliance) Q = Q.group_by(Galaxy.x, Galaxy.y) Q = Q.having(count() >= bums) result = Q.all() if len(result) < 1: message.reply("No galaxies with at least %s bumchums from %s"%(bums,alliance.name,)) return prev=[] for x, y, chums in result: prev.append("%s:%s (%s)"%(x, y, chums)) reply="Galaxies with at least %s bums from %s: "%(bums,alliance.name)+ ' | '.join(prev) message.reply(reply)
def execute(self, request, user, name, h=False, hs=False, ticks=None): alliance = Alliance.load(name) if alliance is None: return HttpResponseRedirect(reverse("alliance_ranks")) ticks = int(ticks or 0) if h else 12 if not hs: sizediffvalue = AllianceHistory.rdiff * PA.getint("numbers", "roid_value") scorediffwsizevalue = AllianceHistory.sdiff - sizediffvalue Q = session.query(AllianceHistory, sizediffvalue, scorediffwsizevalue, ) Q = Q.filter(AllianceHistory.current == alliance) Q = Q.order_by(desc(AllianceHistory.tick)) history = Q[:ticks] if ticks else Q.all() else: history = None if not h: Q = session.query(AllianceHistory) Q = Q.filter(or_(AllianceHistory.hour == 23, AllianceHistory.tick == Updates.current_tick())) Q = Q.filter(AllianceHistory.current == alliance) Q = Q.order_by(desc(AllianceHistory.tick)) hsummary = Q.all() if hs else Q[:14] else: hsummary = None return render(["alliance.tpl",["halliance.tpl","hsalliance.tpl"][hs]][h or hs], request, alliance = alliance, members = alliance.intel_members, history = history, hsummary = hsummary, ticks = ticks, )
def user_alliance(self, message, user, params): alliance = Alliance.load(params.group(1)) if params.group(1) is not None else None # Alliance if alliance is not None: message.reply(str(alliance)) return # User if not self.is_user(user): raise PNickParseError elif not user.is_member(): message.reply("No alliance matching '%s' found" % (params.group(1),)) return else: lookup = User.load(params.group(1), exact=False, access="member") or User.load(params.group(1)) if lookup is None: message.reply("No alliance or user matching '%s' found" % (params.group(1),)) return elif lookup.planet is None: message.reply("User %s has not entered their planet details" % (lookup.name,)) return else: message.reply(str(lookup.planet)) return
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*60) 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, request, user, params=""): Q = session.query(Planet, Intel.nick, Alliance.name) Q = Q.outerjoin(Planet.intel) Q = Q.outerjoin(Intel.alliance) Q = Q.join(Planet.galaxy) Q = Q.filter(Planet.active == True) query = False page = 1 search = { "ruler": "", "planet": "", "galaxy": "", "nick": "", "alliance": "", "ter": 'checked="checked"', "cat": 'checked="checked"', "xan": 'checked="checked"', "zik": 'checked="checked"', "etd": 'checked="checked"', "sizemin": "", "sizemax": "", "valuemin": "", "valuemax": "", "scoremin": "", "scoremax": "", "x": "", "galsizemin": "", "galsizemax": "", "galvaluemin": "", "galvaluemax": "", "galscoremin": "", "galscoremax": "", "planets": "", "bash": "" if params else 'checked="checked"', "rankmin": "", "rankmax": "", "galrankmin": "", "galrankmax": "", "ratiomin": "", "ratiomax": "", "galratiomin": "", "galratiomax": "", "order1": "", "order1o": "", "order2": "", "order2o": "", } intfilts = { "score": Planet.score, "value": Planet.value, "size": Planet.size, "xp": Planet.xp, "galscore": Galaxy.score, "galreal_score": Galaxy.real_score, "galvalue": Galaxy.value, "galsize": Galaxy.size, "galxp": Galaxy.xp, "idle": Planet.idle, "x": Planet.x, "y": Planet.y, "planets": Galaxy.members, "totalroundroids": Planet.totalroundroids, "totallostroids": Planet.totallostroids, "ticksroiding": Planet.ticksroiding, "ticksroided": Planet.ticksroided, "tickroids": Planet.tickroids, } floatfilts = { "ratio": Planet.ratio, "galratio": Galaxy.ratio, "avroids": Planet.avroids, } rankfilts = { "rank": Planet.score_rank, "valuerank": Planet.value_rank, "sizerank": Planet.size_rank, "xprank": Planet.xp_rank, "galrank": Galaxy.score_rank, "galrealrank": Galaxy.real_score_rank, "galvaluerank": Galaxy.value_rank, "galsizerank": Galaxy.size_rank, "galxprank": Galaxy.xp_rank, } filters = {} filters.update(intfilts) filters.update(floatfilts) filters.update(rankfilts) order = { "xyz": ( Planet.x, Planet.y, Planet.z, ), "score_growth": Planet.score_growth, "value_growth": Planet.value_growth, "size_growth": Planet.size_growth, "xp_growth": Planet.xp_growth, "score_growth_pc": Planet.score_growth_pc, "value_growth_pc": Planet.value_growth_pc, "size_growth_pc": Planet.size_growth_pc, "xp_growth_pc": Planet.xp_growth_pc, "galscore_growth": Galaxy.score_growth, "galreal_score_growth": Galaxy.real_score_growth, "galvalue_growth": Galaxy.value_growth, "galsize_growth": Galaxy.size_growth, "galxp_growth": Galaxy.xp_growth, "galscore_growth_pc": Galaxy.score_growth_pc, "galreal_score_growth_pc": Galaxy.real_score_growth_pc, "galvalue_growth_pc": Galaxy.value_growth_pc, "galsize_growth_pc": Galaxy.size_growth_pc, "galxp_growth_pc": Galaxy.xp_growth_pc, } order.update(filters) orders = [] wordfilts = { "ruler": Planet.rulername, "planet": Planet.planetname, "galaxy": Galaxy.name, } if request.REQUEST.get("search"): r = request.REQUEST search = "/search/" for word in wordfilts.keys() + ["nick", "alliance"]: filt = (r.get(word) or "").strip() if not filt: continue search += "%s:%s/" % ( word, filt, ) for filt in filters.keys(): one = (r.get("min" + filt) or "").strip() two = (r.get("max" + filt) or "").strip() if not one and not two: continue if one and one == two: search += "%s:%s/" % ( filt, one, ) elif one and not two: search += "%s:%s|/" % ( filt, one, ) elif two and not one: search += "%s:|%s/" % ( filt, two, ) elif one and two: search += "%s:%s|%s/" % ( filt, one, two, ) races = [] for race in PA.options("races"): if (r.get(race) or "").strip(): races.append(race) if len(races) != len(PA.options("races")): search += "race:%s/" % ("|".join(races), ) if (r.get("bash") or "").strip(): search += "bash/" o1 = (r.get("order1") or "").strip() o1o = (r.get("order1o") or "").strip() o2 = (r.get("order2") or "").strip() o2o = (r.get("order2o") or "").strip() if o1 not in order: o1, o1o = o2, o2o if o1 in order and (o1 == o2 or o2 not in order): if o1 == "score" and o1o == "desc": pass else: o1o = "^" if o1o == "asc" else "_" search += "order:%s%s/" % ( o1o, o1, ) elif o1 in order and o2 in order: o1o = "^" if o1o == "asc" else "_" o2o = "^" if o2o == "asc" else "_" search += "order:%s%s|%s%s/" % ( o1o, o1, o2o, o2, ) return HttpResponseRedirect(search) for param in params.lower().split("/"): if param == "bash" and user.planet is not None: Q = Q.filter( or_( Planet.value.op(">")(user.planet.value * PA.getfloat("bash", "value")), Planet.score.op(">")(user.planet.score * PA.getfloat("bash", "score")))) Q = Q.filter(Planet.x < 200) search[param] = 'checked="checked"' continue arg, sep, val = param.partition(":") if not (arg and val): continue if arg in filters: one, two = "", "" if "|" not in val: one, two = val, val elif val[-1] == "|": one, two = val[:-1], "" elif val[0] == "|": one, two = "", val[1:] elif "|" in val: one, two = val.split("|", 1) else: continue try: if one: one = float(one) if arg in floatfilts else int(one) if two: two = float(two) if arg in floatfilts else int(two) except ValueError: continue if one and one == two: Q = Q.filter(filters[arg] == one) elif one and not two: Q = Q.filter( filters[arg] <= one) if arg in rankfilts else Q.filter( filters[arg] >= one) elif two and not one: Q = Q.filter( filters[arg] >= two) if arg in rankfilts else Q.filter( filters[arg] <= two) elif one and two: Q = Q.filter(filters[arg].between(min(one, two), max(one, two))) else: continue search[arg + "min"], search[arg + "max"] = one, two query = True elif arg in wordfilts: Q = Q.filter(wordfilts[arg].ilike("%" + val + "%")) search[arg] = val query = True elif arg == "nick" and getattr( user, "is_" + Config.get("Arthur", "intel"))(): Q = Q.filter(Intel.nick.ilike("%" + val + "%")) search["nick"] = val query = True elif arg == "alliance" and getattr( user, "is_" + Config.get("Arthur", "intel"))(): if val[0] == "!": val = val[1:] inv = True else: inv = False alliance = Alliance.load(val) if alliance: Q = Q.filter( Intel.alliance == alliance) if not inv else Q.filter( Intel.alliance != alliance) search["alliance"] = ["", "!"][inv] + alliance.name query = True elif arg == "race": races = [] for race in val.split("|"): if race in PA.options("races") and race not in races: races.append(Planet.race.ilike(race)) search[race] = True if len(races): Q = Q.filter(or_(*races)) for race in PA.options("races"): search[race] = 'checked="checked"' if search[ race] is True else "" query = True elif arg == "order": for sort in val.split("|"): if sort[0] == "^": f = asc elif sort[0] == "_": f = desc else: continue if sort[1:] in order: orders.append(( f, sort[1:], )) query = True elif arg == "page" and val.isdigit(): page = int(val) if len(orders) < 1: orders.append(( desc, "score", )) if len(orders) < 2: orders.append(( desc, "score", )) search["order1"] = orders[0][1] search["order1o"] = orders[0][0].__name__ search["order2"] = orders[1][1] search["order2o"] = orders[1][0].__name__ for d, os in orders: if type(order[os]) is tuple: for o in order[os]: Q = Q.order_by(d(o)) else: Q = Q.order_by(d(order[os])) showsort = True if search["order1"] not in ( "xyz", "size", "value", "score", "ratio", "xp", "size_growth", "value_growth", "score_growth", "size_growth_pc", "value_growth_pc", "score_growth_pc", ) else False count = Q.count() pages = count / 50 + int(count % 50 > 0) pages = range(1, 1 + pages) offset = (page - 1) * 50 Q = Q.limit(50).offset(offset) results = Q.all() if query else None return render("search.tpl", request, planets=results, sort=search["order1"], showsort=showsort, s=search, params=params, offset=offset, pages=pages, page=page)
def execute(self, message, user, params): if params.group(5) is None: galaxy = Galaxy.load(*params.group(1,3)) if galaxy is None: message.alert("No galaxy with coords %s:%s" % params.group(1,3)) return Q = session.query(Planet) Q = Q.filter(Planet.active == True) Q = Q.filter(Planet.galaxy == galaxy) Q = Q.order_by(asc(Planet.z)) prev = [] for planet in Q: if planet.intel is not None: reply = "#%s"%(planet.z,) if planet.intel.nick: reply += " %s"%(planet.intel.nick,) if planet.alliance: reply += " [%s]"%(planet.alliance.name[:3],) prev.append(reply) if len(prev): reply ="Intel %d:%d - "%(galaxy.x,galaxy.y,) reply+="Score (%d) Value (%d) Size (%d)"%(galaxy.score_rank,galaxy.value_rank,galaxy.size_rank) reply+=" - " reply+=" - ".join(prev) message.reply(reply) else: message.reply("No information stored for %s:%s" % (galaxy.x, galaxy.y,)) return planet = Planet.load(*params.group(1,3,5)) if planet is None: message.alert("No planet with coords %s:%s:%s" % params.group(1,3,5)) return if planet.intel is None: planet.intel = Intel() params = self.split_opts(message.get_msg()) for opt, val in params.items(): if opt == "alliance": if val in self.nulls: planet.intel.alliance = None continue alliance = Alliance.load(val) if alliance is None: message.alert("No alliances match %s" % (val,)) continue planet.intel.alliance = alliance if (opt in options) and (val in self.nulls): setattr(planet.intel, opt, None) continue if opt in ("nick","fakenick","bg","gov","reportchan"): setattr(planet.intel, opt, val) if opt in ("defwhore","covop","scanner","relay"): if val.lower() in self.true: setattr(planet.intel, opt, True) if val.lower() in self.false: setattr(planet.intel, opt, False) if opt == "dists": try: planet.intel.dists = int(val) except ValueError: pass if opt == "comment": planet.intel.comment = message.get_msg().split("comment=")[1] session.commit() if planet.intel: message.reply("Information stored for %s:%s:%s -%s"% (planet.x, planet.y, planet.z, str(planet.intel),)) else: message.reply("No information stored for %s:%s:%s"% (planet.x, planet.y, planet.z,))
def expire(self, message, user, params): id = params.group(1) prop = self.load_prop(id) if prop is None: message.reply("No proposition number %s exists (idiot)." % (id, )) return if not prop.active: message.reply("You can't expire prop %d, it's already expired." % (prop.id, )) return if prop.proposer is not user and not user.is_admin(): message.reply("Only %s may expire proposition %d." % (prop.proposer.name, prop.id)) return if prop.type == "invite" and not self.member_count_below_limit(): message.reply( "You have tried to invite somebody, but we have too many losers and I can't be bothered dealing with more than %s of you." % (Config.getint("Alliance", "members"), )) return self.recalculate_carebears(prop) yes, no, veto = self.sum_votes(prop) passed = yes > no and veto <= 0 vote_result = ['no', 'yes'][passed] reply = self.text_result(vote_result, yes, no, veto) reply += self.text_summary(prop) message.reply(reply) if prop.type == "invite" and passed: pnick = prop.person access = Config.getint("Access", "member") member = User.load(name=pnick, active=False) if member is None: member = User(name=pnick, access=access, sponsor=prop.proposer.name) session.add(member) elif not member.active: member.active = True member.access = access member.sponsor = prop.proposer.name elif not member.is_member(): member.access = access member.sponsor = prop.proposer.name message.privmsg( "adduser %s %s 24" % ( Config.get("Channels", "home"), pnick, ), Config.get("Services", "nick")) message.reply( "%s has been added to %s and given member level access to me." % (pnick, Config.get("Channels", "home"))) if prop.type == "kick" and passed: idiot = prop.kicked if "galmate" in Config.options("Access"): idiot.access = Config.getint("Access", "galmate") else: idiot.access = 0 if idiot.planet is not None and idiot.planet.intel is not None: intel = idiot.planet.intel alliance = Alliance.load(Config.get("Alliance", "name")) if intel.alliance == alliance: intel.alliance = None message.privmsg( "remuser %s %s" % ( Config.get("Channels", "home"), idiot.name, ), Config.get("Services", "nick")) # message.privmsg("ban %s *!*@%s.%s Your sponsor doesn't like you anymore"%(Config.get("Channels","home"), idiot.name, Config.get("Services", "usermask"),),Config.get("Services", "nick")) message.privmsg( "note send %s A proposition to kick you from %s has been raised by %s with reason '%s' and passed by a vote of %s to %s." % (idiot.name, Config.get("Alliance", "name"), prop.proposer.name, prop.comment_text, yes, no), Config.get("Services", "nick")) message.reply( "%s has been reduced to \"galmate\" level and removed from the channel." % (idiot.name, )) if prop.type == "suggestion" and passed: message.reply("Suggestion \"%s\" has passed" % (prop.comment_text)) prop.active = False prop.closed = current_timestamp() prop.vote_result = vote_result session.commit()
def execute(self, request, user, name): alliance = Alliance.load(name) if alliance is None: return HttpResponseRedirect(reverse("alliance_ranks")) ph = aliased(PlanetHistory) members = count().label("members") size = sum(ph.size).label("size") value = sum(ph.value).label("value") score = sum(ph.score).label("score") avg_size = size.op("/")(members).label("avg_size") avg_value = value.op("/")(members).label("avg_value") t10v = count(case(whens=((ph.value_rank <= 10, 1), ), else_=None)).label("t10v") t100v = count(case(whens=((ph.value_rank <= 100, 1), ), else_=None)).label("t100v") pho = aliased(PlanetHistory) sizeo = sum(pho.size).label("sizeo") valueo = sum(pho.value).label("valueo") scoreo = sum(pho.score).label("scoreo") Q = session.query( PlanetHistory.tick.label("tick"), Alliance.id.label("id"), literal_column( "rank() OVER (PARTITION BY planet_history.tick ORDER BY sum(planet_history.size) DESC)" ).label("size_rank"), literal_column( "rank() OVER (PARTITION BY planet_history.tick ORDER BY sum(planet_history.value) DESC)" ).label("value_rank"), ) Q = Q.filter(PlanetHistory.active == True) Q = Q.join(PlanetHistory.current) Q = Q.join(Planet.intel) Q = Q.join(Intel.alliance) Q = Q.group_by(PlanetHistory.tick, Alliance.id) ranks = Q.subquery() Q = session.query( ph.tick, members, size, value, avg_size, avg_value, size - sizeo, value - valueo, score - scoreo, t10v, t100v, ) Q = Q.filter(ph.active == True) Q = Q.join(ph.current) Q = Q.join(Planet.intel) Q = Q.join(Intel.alliance) Q = Q.outerjoin(( pho, and_(ph.id == pho.id, ph.tick - 1 == pho.tick), )) Q = Q.filter(Intel.alliance == alliance) Q = Q.group_by(ph.tick) Q = Q.from_self().add_columns(ranks.c.size_rank, ranks.c.value_rank) Q = Q.outerjoin(( ranks, and_(ph.tick == ranks.c.tick, alliance.id == ranks.c.id), )) Q = Q.order_by(desc(ph.tick)) history = Q.all() return render("ialliancehistory.tpl", request, alliance=alliance, members=alliance.intel_members, history=history)
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 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 search(self, message, user, params): Q = session.query(Planet, Intel) Q = Q.join(Planet.intel) alliance = None nick = None reportchan = None amps = None dists = None size = None value = None race = None comment = None sort = None order = { "score": (asc(Planet.score_rank), ), "value": (asc(Planet.value_rank), ), "size": (asc(Planet.size_rank), ), "xp": (asc(Planet.xp_rank), ), "amps": (desc(Intel.amps), ), "dists": (desc(Intel.dists), ), "planet": ( asc(Planet.x), asc(Planet.y), asc(Planet.z), ), } page = 1 offset = 0 params = self.split_opts(message.get_msg()) for opt, val in params.items(): if opt == "alliance": alliance = Alliance.load(val) if alliance is None: message.alert("No alliances match %s" % (val, )) return Q = Q.filter(Intel.alliance == alliance) if opt == "nick": nick = val Q = Q.filter( or_(Intel.nick.ilike("%" + nick + "%"), Intel.fakenick.ilike("%" + nick + "%"))) if opt == "reportchan": reportchan = val Q = Q.filter(Intel.reportchan.ilike(reportchan)) if opt == "amps" and val.isdigit(): amps = val Q = Q.filter(Intel.amps.op('>=')(amps)) if not sort: sort = order["amps"] if opt == "dists" and val.isdigit(): dists = val Q = Q.filter(Intel.dists.op('>=')(dists)) if not sort: sort = order["dists"] if opt == "size" and (val.isdigit() or (val[0] in ( '>', '<', ) and val[1:].isdigit())): if val[0] in ( '>', '<', ): smod = val[0] + '=' size = val[1:] else: smod = '>=' size = val Q = Q.filter(Planet.size.op(smod)(size)) if not sort: sort = order["size"] if opt == "value" and (val.isdigit() or (val[0] in ( '>', '<', ) and val[1:].isdigit())): if val[0] in ( '>', '<', ): vmod = val[0] + '=' value = val[1:] else: vmod = '<=' value = val Q = Q.filter(Planet.value.op(vmod)(value)) if not sort: sort = order["value"] if opt == "race" and self.racere.match(val): race = val Q = Q.filter(Planet.race.ilike(race)) if opt == "comment": comment = message.get_msg().split("comment=")[1] Q = Q.filter(Intel.comment.ilike(comment.replace(" ", "%"))) if opt == "sort" and val in order: sort = order[val] if opt == "page" and val.isdigit(): page = int(val) or 1 offset = (page - 1) * 5 if not sort: sort = order["score"] for order in sort: Q = Q.order_by(order) Q = Q.order_by(Planet.id) result = Q.limit(6).offset(offset).all() if len(result) < 1: reply = "No" if race: reply += " %s" % (race, ) reply += " planets" if alliance: reply += " in Alliance: %s" % (alliance.name, ) if nick: reply += " with nick '%s'" % (nick, ) if reportchan: reply += " with reportchan '%s'" % (reportchan, ) if amps: reply += " with at least %s amps" % (amps, ) if dists: reply += " with at least %s dists" % (dists, ) if comment: reply += " with a comment like '%s'" % (comment, ) if size: reply += " Size %s %s" % (smod, size) if value: reply += " Value %s %s" % (vmod, 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) if value or size: reply += " Value: %s Size: %s" % ( planet.value, planet.size, ) if amps: reply += " Amps: %s" % (intel.amps, ) if dists: reply += " Dists: %s" % (intel.dists, ) if reportchan: reply += " Reportchan: '%s'" % (intel.reportchan, ) if intel.nick: reply += " Nick: %s" % (intel.nick, ) if intel.alliance: reply += " Alliance: %s" % (intel.alliance.name, ) if comment: reply += " Comment: '%s'" % (intel.comment, ) replies.append(reply) if len(result) > 5: replies[ -1] += " (Too many results to list, please refine your search or use page=%s)" % ( page + 1, ) message.reply("\n".join(replies))
def execute(self, message, user, params): planet = None galaxy = None alliance = None # Planet or Galaxy if len(params.groups()) == 5: # Planet if params.group(5) is not None: planet = Planet.load(*params.group(1, 3, 5)) if planet is None: message.reply("No planet with coords %s:%s:%s found" % params.group(1, 3, 5)) return # Galaxy else: galaxy = Galaxy.load(*params.group(1, 3)) if galaxy is None: message.reply("No galaxy with coords %s:%s" % params.group(1, 3)) return # Alliance or User else: # Self if params.group(1) is None: planet = self.get_user_planet(user) # Alliance or User else: alliance = Alliance.load(params.group(1)) # User if alliance is None: u = User.load(params.group(1)) if u is None: message.reply("No alliance or user matching '%s' found" % (params.group(1),)) return elif u.planet is None: message.reply("User %s has not entered their planet details" % (u.name,)) return else: planet = u.planet tick = Updates.current_tick() target = aliased(Planet) target_intel = aliased(Intel) owner = aliased(Planet) owner_intel = aliased(Intel) Q = session.query(owner.x, owner.y, owner.z, count()) Q = Q.join((FleetScan.owner, owner)) Q = Q.join((FleetScan.target, target)) Q = Q.filter(FleetScan.mission == "Attack") if planet: Q = Q.filter(FleetScan.target == planet) if galaxy: Q = Q.filter(target.galaxy == galaxy) if alliance: Q = Q.join((target.intel, target_intel)) Q = Q.filter(target_intel.alliance == alliance) Q = Q.group_by(owner.x, owner.y, owner.z) Q = Q.order_by(desc(count())) result = Q.all() if len(result) < 1: reply = "No fleets found targetting" if planet: reply += " coords %s:%s:%s" % (planet.x, planet.y, planet.z) if galaxy: reply += " coords %s:%s" % (galaxy.x, galaxy.y) if alliance: reply += " alliance %s" % (alliance.name,) message.reply(reply) return reply = "Top attackers on" if planet: reply += " coords %s:%s:%s" % (planet.x, planet.y, planet.z) if galaxy: reply += " coords %s:%s" % (galaxy.x, galaxy.y) if alliance: reply += " alliance %s" % (alliance.name,) reply += " are (total: %s) " % (sum([attacks for x, y, z, attacks in result]),) prev = [] for x, y, z, attacks in result[:5]: prev.append("%s:%s:%s - %s" % (x, y, z, attacks)) message.reply(reply + " | ".join(prev))
def execute(self, request, user, params=""): Q = session.query(Planet, Intel.nick, Alliance.name) Q = Q.outerjoin(Planet.intel) Q = Q.outerjoin(Intel.alliance) Q = Q.join(Planet.galaxy) Q = Q.filter(Planet.active == True) query = False page = 1 search = { "ruler" : "", "planet" : "", "galaxy" : "", "nick" : "", "alliance" : "", "ter" : 'checked="checked"', "cat" : 'checked="checked"', "xan" : 'checked="checked"', "zik" : 'checked="checked"', "etd" : 'checked="checked"', "sizemin" : "", "sizemax" : "", "valuemin" : "", "valuemax" : "", "scoremin" : "", "scoremax" : "", "x" : "", "galsizemin" : "", "galsizemax" : "", "galvaluemin" : "", "galvaluemax" : "", "galscoremin" : "", "galscoremax" : "", "planets" : "", "bash" : "" if params else 'checked="checked"', "rankmin" : "", "rankmax" : "", "galrankmin" : "", "galrankmax" : "", "ratiomin" : "", "ratiomax" : "", "galratiomin" : "", "galratiomax" : "", "order1" : "", "order1o" : "", "order2" : "", "order2o" : "", } intfilts = { "score" : Planet.score, "value" : Planet.value, "size" : Planet.size, "xp" : Planet.xp, "galscore" : Galaxy.score, "galreal_score" : Galaxy.real_score, "galvalue" : Galaxy.value, "galsize" : Galaxy.size, "galxp" : Galaxy.xp, "idle" : Planet.idle, "x" : Planet.x, "y" : Planet.y, "planets" : Galaxy.members, "totalroundroids" : Planet.totalroundroids, "totallostroids" : Planet.totallostroids, "ticksroiding" : Planet.ticksroiding, "ticksroided" : Planet.ticksroided, "tickroids" : Planet.tickroids, } floatfilts = { "ratio" : Planet.ratio, "galratio" : Galaxy.ratio, "avroids" : Planet.avroids, } rankfilts = { "rank" : Planet.score_rank, "valuerank" : Planet.value_rank, "sizerank" : Planet.size_rank, "xprank" : Planet.xp_rank, "galrank" : Galaxy.score_rank, "galrealrank" : Galaxy.real_score_rank, "galvaluerank" : Galaxy.value_rank, "galsizerank" : Galaxy.size_rank, "galxprank" : Galaxy.xp_rank, } filters = {} filters.update(intfilts) filters.update(floatfilts) filters.update(rankfilts) order = { "xyz" : (Planet.x, Planet.y, Planet.z,), "score_growth" : Planet.score_growth, "value_growth" : Planet.value_growth, "size_growth" : Planet.size_growth, "xp_growth" : Planet.xp_growth, "score_growth_pc" : Planet.score_growth_pc, "value_growth_pc" : Planet.value_growth_pc, "size_growth_pc" : Planet.size_growth_pc, "xp_growth_pc" : Planet.xp_growth_pc, "galscore_growth" : Galaxy.score_growth, "galreal_score_growth" : Galaxy.real_score_growth, "galvalue_growth" : Galaxy.value_growth, "galsize_growth" : Galaxy.size_growth, "galxp_growth" : Galaxy.xp_growth, "galscore_growth_pc" : Galaxy.score_growth_pc, "galreal_score_growth_pc" : Galaxy.real_score_growth_pc, "galvalue_growth_pc" : Galaxy.value_growth_pc, "galsize_growth_pc" : Galaxy.size_growth_pc, "galxp_growth_pc" : Galaxy.xp_growth_pc, } order.update(filters) orders = [] wordfilts = { "ruler" : Planet.rulername, "planet" : Planet.planetname, "galaxy" : Galaxy.name, } if request.POST.get("search"): r = request.POST search = "/search/" for word in wordfilts.keys() + ["nick", "alliance"]: filt = (r.get(word) or "").strip() if not filt: continue search += "%s:%s/" %(word,filt,) for filt in filters.keys(): one = (r.get("min"+filt) or "").strip() two = (r.get("max"+filt) or "").strip() if not one and not two: continue if one and one == two: search += "%s:%s/" %(filt,one,) elif one and not two: search += "%s:%s|/" %(filt,one,) elif two and not one: search += "%s:|%s/" %(filt,two,) elif one and two: search += "%s:%s|%s/" %(filt,one,two,) races = [] for race in PA.options("races"): if (r.get(race) or "").strip(): races.append(race) if len(races) != len(PA.options("races")): search += "race:%s/" %("|".join(races),) if (r.get("bash") or "").strip(): search += "bash/" o1 = (r.get("order1") or "").strip() o1o = (r.get("order1o") or "").strip() o2 = (r.get("order2") or "").strip() o2o = (r.get("order2o") or "").strip() if o1 not in order: o1, o1o = o2, o2o if o1 in order and (o1 == o2 or o2 not in order): if o1 == "score" and o1o == "desc": pass else: o1o = "^" if o1o == "asc" else "_" search += "order:%s%s/" %(o1o,o1,) elif o1 in order and o2 in order: o1o = "^" if o1o == "asc" else "_" o2o = "^" if o2o == "asc" else "_" search += "order:%s%s|%s%s/" %(o1o,o1,o2o,o2,) return HttpResponseRedirect(search) for param in params.lower().split("/"): if param == "bash" and user.planet is not None: Q = Q.filter(or_(Planet.value.op(">")(user.planet.value*PA.getfloat("bash","value")), Planet.score.op(">")(user.planet.score*PA.getfloat("bash","score")))) Q = Q.filter(Planet.x < 200) search[param] = 'checked="checked"' continue arg, sep, val = param.partition(":") if not (arg and val): continue if arg in filters: one, two = "", "" if "|" not in val: one, two = val, val elif val[-1] == "|": one, two = val[:-1], "" elif val[0] == "|": one, two = "", val[1:] elif "|" in val: one, two = val.split("|",1) else: continue try: if one: one = float(one) if arg in floatfilts else int(one) if two: two = float(two) if arg in floatfilts else int(two) except ValueError: continue if one and one == two: Q = Q.filter(filters[arg] == one) elif one and not two: Q = Q.filter(filters[arg] <= one) if arg in rankfilts else Q.filter(filters[arg] >= one) elif two and not one: Q = Q.filter(filters[arg] >= two) if arg in rankfilts else Q.filter(filters[arg] <= two) elif one and two: Q = Q.filter(filters[arg].between(min(one,two), max(one,two))) else: continue search[arg+"min"], search[arg+"max"] = one, two query = True elif arg in wordfilts: Q = Q.filter(wordfilts[arg].ilike("%"+val+"%")) search[arg] = val query = True elif arg == "nick" and getattr(user, "is_" + Config.get("Arthur", "intel"))(): Q = Q.filter(Intel.nick.ilike("%"+val+"%")) search["nick"] = val query = True elif arg == "alliance" and getattr(user, "is_" + Config.get("Arthur", "intel"))(): if val[0] == "!": val = val[1:] inv = True else: inv = False alliance = Alliance.load(val) if alliance: Q = Q.filter(Intel.alliance == alliance) if not inv else Q.filter(Intel.alliance != alliance) search["alliance"] = ["","!"][inv] + alliance.name query = True elif arg == "race": races = [] for race in val.split("|"): if race in PA.options("races") and race not in races: races.append(Planet.race.ilike(race)) search[race] = True if len(races): Q = Q.filter(or_(*races)) for race in PA.options("races"): search[race] = 'checked="checked"' if search[race] is True else "" query = True elif arg == "order": for sort in val.split("|"): if sort[0] == "^": f = asc elif sort[0] == "_": f = desc else: continue if sort[1:] in order: orders.append((f, sort[1:],)) query = True elif arg == "page" and val.isdigit(): page = int(val) if len(orders) < 1: orders.append((desc, "score",)) if len(orders) < 2: orders.append((desc, "score",)) search["order1"] = orders[0][1] search["order1o"] = orders[0][0].__name__ search["order2"] = orders[1][1] search["order2o"] = orders[1][0].__name__ for d, os in orders: if type(order[os]) is tuple: for o in order[os]: Q = Q.order_by(d(o)) else: Q = Q.order_by(d(order[os])) showsort = True if search["order1"] not in ("xyz","size","value","score","ratio","xp", "size_growth","value_growth","score_growth", "size_growth_pc","value_growth_pc","score_growth_pc",) else False count = Q.count() pages = count//50 + int(count%50 > 0) pages = range(1, 1+pages) offset = (page - 1)*50 Q = Q.limit(50).offset(offset) results = Q.all() if query else None return render("search.tpl", request, planets=results, sort=search["order1"], showsort=showsort, s=search, params=params, offset=offset, pages=pages, page=page)
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 set_prefs(self, message, user, params): params = self.split_opts(params.group(1)) reply = "" for opt, val in params.items(): if opt == "planet": m = self.planet_coordre.match(val) if m: planet = Planet.load(*m.group(1, 3, 5)) if planet is None: message.alert("No planet with coords %s:%s:%s" % m.group(1, 3, 5)) continue user.planet = planet reply += " planet=%s:%s:%s" % (planet.x, planet.y, planet.z) if user.is_member(): alliance = Alliance.load(Config.get( "Alliance", "name")) if planet.intel is None: planet.intel = Intel(nick=user.name, alliance=alliance) else: planet.intel.nick = user.name planet.intel.alliance = alliance elif val in self.nulls: user.planet = None reply += " planet=None" if opt == "password": if message.in_chan(): message.reply("Don't set your password in public you shit") continue user.passwd = val reply += " password=%s" % (val) if opt == "url": if val == "game" or val in self.nulls: user.url = None val = Config.get("URL", "game") elif val not in Config.options("alturls"): ret = "Valid URLs are: game: %s, " % (Config.get( "URL", "game"), ) ret += ", ".join([ "%s: %s" % ( k, v, ) for k, v in Config.items("alturls") ]) message.reply(ret) continue else: user.url = val val = Config.get("alturls", val) reply += " url: %s" % (val) if opt == "email": if val in self.nulls: user.email = None reply += " email=None" else: try: user.email = val except AssertionError: reply += " email=%s" % (user.email) else: reply += " email=%s" % (val) if opt == "phone": if val in self.nulls: user.phone = "" reply += " phone=None" else: user.phone = val reply += " phone=%s" % (val) if opt == "pubphone": if val.lower() in self.true: user.pubphone = True reply += " pubphone=%s" % (True) elif val.lower() in self.false: user.pubphone = False reply += " pubphone=%s" % (False) if opt == "smsmode": if Config.get("Misc", "sms") != "combined": message.alert( "Your alliance doesn't support SMS mode switching") continue if val[:1].upper() in User._sms_modes: user.smsmode = val reply += " smsmode=%s" % (user.smsmode, ) elif val[:1].lower() == "b" or val in self.nulls: user._smsmode = None reply += " smsmode=None" session.commit() if len(reply) > 0: message.reply("Updated your preferences:" + reply)
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