本文整理汇总了Python中Core.maps.Alliance类的典型用法代码示例。如果您正苦于以下问题:Python Alliance类的具体用法?Python Alliance怎么用?Python Alliance使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Alliance类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: execute
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),))
示例2: execute
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)
示例3: groups
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)
示例4: execute
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, cunt.")
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,))
示例5: execute
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)
示例6: execute
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, cunt.")
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))
示例7: execute
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 fucked up tag %s has been aliased to %s" % (alliance.name, alliance.alias,))
示例8: onegroup
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)
示例9: check_planet
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
示例10: execute
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)
示例11: execute
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)
示例12: execute
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
示例13: execute
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)
示例14: execute
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)}))
示例15: execute
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)