def base_context(request): context = {"name" : Config.get("Alliance", "name"), "slogan" : Config.get("Alliance", "name"), "tick" : Updates.current_tick(), "update" : Updates.load(), "graphs" : Config.get("Misc", "graphing") != "disabled", } if getattr(request, "user", None) is not None: context["user"] = request.user context["menu"] = menu.generate(request.user) if getattr(request, "session", None) is not None: slogan, count = Slogan.search("") if slogan is not None: context["slogan"] = str(slogan) if Config.has_section("FluxBB") and Config.getboolean("FluxBB", "enabled"): context["fluxurl"] = "<br><br><a href=\"%s\">Forum</a>" % (Config.get("FluxBB", "url")) return context
def base_context(request): context = { "name": Config.get("Alliance", "name"), "slogan": Config.get("Alliance", "name"), "tick": Updates.current_tick(), "update": Updates.load(), "graphs": Config.get("Misc", "graphing") != "disabled", } if getattr(request, "user", None) is not None: context["user"] = request.user context["menu"] = menu.generate(request.user) if getattr(request, "session", None) is not None: slogan, count = Slogan.search("") if slogan is not None: context["slogan"] = str(slogan) if Config.has_section("FluxBB") and Config.getboolean("FluxBB", "enabled"): context["fluxurl"] = "<br><br><a href=\"%s\">Forum</a>" % (Config.get( "FluxBB", "url")) return context
session.execute(text("INSERT INTO %scookie_log (log_time,year,week,howmany,giver_id,receiver_id) SELECT log_time,year,week,howmany,giver_id,receiver_id FROM %s.%scookie_log;" % (prefix, round, old_prefix))) print " - smslog" session.execute(text("INSERT INTO %ssms_log (sender_id,receiver_id,phone,sms_text,mode) SELECT sender_id,receiver_id,phone,sms_text,mode FROM %s.%ssms_log;" % (prefix, round, old_prefix))) except DBAPIError, e: print "An error occurred during migration: %s" %(str(e),) session.rollback() print "Reverting to previous schema" """session.execute(text("DROP SCHEMA public CASCADE;")) session.execute(text("ALTER SCHEMA %s RENAME TO public;" % (round,)))""" session.commit() sys.exit() else: session.commit() finally: session.close() if Config.has_section("FluxBB") and Config.getboolean("FluxBB", "enabled"): tables = session.execute(text("SELECT table_name FROM information_schema.tables WHERE table_schema='%s' AND table_name LIKE '%s%%';" % (round, Config.get("FluxBB", "prefix")))) for t in tables: session.execute(text("CREATE TABLE %s AS SELECT * FROM %s.%s;" % (t[0], round, t[0]))) session.commit() session.close() if round == "temp": print "Deleting temporary schema" session.execute(text("DROP SCHEMA temp CASCADE;")) session.commit() session.close() print "Inserting ship stats" shipstats.main()
def execute(self, message, user, params): tick = Updates.current_tick() # Galaxy Scan if params.group(5) is None: # Access Control: # Uncomment this and change "group" to the lowest group that can request galscans. # if not user.is_group(): # message.alert("Insufficient access for galaxy scans.") # return galaxy = Galaxy.load(*params.group(1,3)) if galaxy is None: message.alert("No galaxy with coords %s:%s" % params.group(1,3)) return planets = galaxy.planets galscan = Config.has_option("Misc", "galscans") and Config.getboolean("Misc", "galscans") else: 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 planets = [planet] galscan = False # Scan Quota if Config.has_section("ScanQuota"): opts = Config.options("ScanQuota") q = [] for o in opts: if int(o) >= user.access: q.append(int(o)) if q: ScanQuota = Config.getint("ScanQuota", str(min(q))) reqs = session.query(Request.id).filter(Request.requester_id == user.id).filter(Request.tick == tick).count() if (reqs + len(planets) * len(params.group(6).upper())) > ScanQuota: message.reply("This request will exceed your scan quota for this tick (%d scans remaining). " % (ScanQuota - reqs) +\ "Try searching with !planet, !dev, !unit, !news, !jgp, !au.") return dists = int(params.group(7) or 0) galdists = [] mergescans = (not galscan) and (Config.has_option("Misc", "maxscans") and len(planets)*len(params.group(6)) > Config.getint("Misc", "maxscans")) for planet in planets: if galscan or mergescans: galdists.append(planet.intel.dists if planet.intel else 0) if len(galdists) < len(planets): continue types = 0 for scantype in params.group(6).upper(): # Reject requests for incoming scans if not PA.getboolean(scantype, "request"): message.alert("%s scans cannot be requested." % (PA.get(scantype, "name"))) continue types += 1 if galscan or mergescans: # Request the scans for i in range(len(planets)): request = self.request(message, user, planets[i], scantype, galdists[i], galscan or mergescans) # Inform the requester if galscan and (message.get_chan() != self.scanchan()): message.reply("Requested a Galaxy %s Scan of %s:%s. !request cancel %s:%s to cancel the request." % (request.type, planet.x, planet.y, request.id-len(planets)+1, request.id)) # Check for existing scans scan = planet.scan(scantype) if scan and request.tick - scan.tick < PA.getint(scantype,"expire"): message.reply("%s Scan of %s:%s:%s is already available from %s ticks ago: %s. !request cancel %s if this is suitable." % ( scantype, planet.x, planet.y, planet.z, request.tick - scan.tick, scan.link, request.id,)) # Cancel requests with a 0-tick old scan, if required if (request.tick == scan.tick): req0age = Config.getint("Misc", "req0agej") if request.scantype == "J" else Config.getint("Misc", "req0age") if req0age == 1: Q = session.query(Request).filter(Request.tick == request.tick).filter(Request.planet_id == request.planet_id) Q = Q.filter(Request.scantype == request.scantype).filter(Request.requester_id == request.requester_id) if Q.count() == 1: request.active = False message.reply("Request %s cancelled due to an existing scan. If you really need a newer one, repeat your scan request." % (request.id)) message.privmsg("Cancelled scan request %s due to existing scan" % (request.id), self.scanchan()) elif req0age == 0: request.active = False message.reply("Request %s cancelled due to an existing scan." % (request.id)) message.privmsg("Cancelled scan request %s due to existing scan" % (request.id), self.scanchan()) # Tell the scanners requester = user.name if not Config.getboolean("Misc", "anonscans") else "Anon" if galscan: message.privmsg("[%s:%s] %s requested a Galaxy %s Scan of %s:%s Max Dists(i:%s%s) " % (request.id-len(planets)+1, request.id, requester, request.type, planet.x, planet.y, max(galdists), "/r:%s" % dists if dists > 0 else "") + Config.get("URL", "reqgscan") % (planet.x, planet.y) , self.scanchan()) else: request = self.request(message, user, planet, scantype, dists) if message.get_chan() != self.scanchan(): message.reply("Requested a %s Scan of %s:%s:%s. !request cancel %s to cancel the request." % (request.type, planet.x, planet.y, planet.z, request.id,)) # Check for existing scans scan = planet.scan(scantype) if scan and request.tick - scan.tick < PA.getint(scan.scantype,"expire"): message.reply("%s Scan of %s:%s:%s is already available from %s ticks ago: %s. !request cancel %s if this is suitable." % ( scantype, planet.x, planet.y, planet.z, request.tick - scan.tick, scan.link, request.id,)) # Cancel requests with a 0-tick old scan, if required if (request.tick == scan.tick): req0age = Config.getint("Misc", "req0agej") if request.scantype == "J" else Config.getint("Misc", "req0age") if req0age == 1: Q = session.query(Request).filter(Request.tick == request.tick).filter(Request.planet_id == request.planet_id) Q = Q.filter(Request.scantype == request.scantype).filter(Request.requester_id == request.requester_id) if Q.count() == 1: request.active = False message.reply("Request %s cancelled due to an existing scan. If you really need a newer one, repeat your scan request." % (request.id)) message.privmsg("Cancelled scan request %s due to existing scan" % (request.id), self.scanchan()) elif req0age == 0: request.active = False message.reply("Request %s cancelled due to an existing scan." % (request.id)) message.privmsg("Cancelled scan request %s due to existing scan" % (request.id), self.scanchan()) if mergescans: message.reply("Requested %d scans. !request cancel %s:%s to cancel the request." % (len(planets) * types, request.id-len(planets)*types+1, request.id)) message.privmsg("[%s:%s] %s requested %d scans (%s) Max Dists(i:%s%s). !request links for details " % (request.id-len(planets)*types+1, request.id, requester, len(planets)*types, params.group(6).upper(), max(galdists), "/r:%s" % dists if dists > 0 else ""), self.scanchan()) session.commit()
def execute(self, message, user, params): tick = Updates.current_tick() # Galaxy Scan if params.group(5) is None: # Access Control: # Uncomment this and change "group" to the lowest group that can request galscans. # if not user.is_group(): # message.alert("Insufficient access for galaxy scans.") # return galaxy = Galaxy.load(*params.group(1, 3)) if galaxy is None: message.alert("No galaxy with coords %s:%s" % params.group(1, 3)) return planets = galaxy.planets galscan = Config.has_option("Misc", "galscans") and Config.getboolean("Misc", "galscans") else: 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 planets = [planet] galscan = False # Scan Quota if Config.has_section("ScanQuota"): opts = Config.options("ScanQuota") q = [] for o in opts: if int(o) >= user.access: q.append(int(o)) if q: ScanQuota = Config.getint("ScanQuota", str(min(q))) reqs = ( session.query(Request.id) .filter(Request.requester_id == user.id) .filter(Request.tick == tick) .count() ) if (reqs + len(planets) * len(params.group(6).upper())) > ScanQuota: message.reply( "This request will exceed your scan quota for this tick (%d scans remaining). " % (ScanQuota - reqs) + "Try searching with !planet, !dev, !unit, !news, !jgp, !au." ) return dists = int(params.group(7) or 0) galdists = [] mergescans = (not galscan) and ( Config.has_option("Misc", "maxscans") and len(planets) * len(params.group(6)) > Config.getint("Misc", "maxscans") ) for planet in planets: if galscan or mergescans: galdists.append(planet.intel.dists if planet.intel else 0) if len(galdists) < len(planets): continue types = 0 for scantype in params.group(6).upper(): # Reject requests for incoming scans if not PA.getboolean(scantype, "request"): message.alert("%s scans cannot be requested." % (PA.get(scantype, "name"))) continue types += 1 if galscan or mergescans: # Request the scans for i in range(len(planets)): request = self.request(message, user, planets[i], scantype, galdists[i], galscan or mergescans) # Inform the requester if galscan and (message.get_chan() != self.scanchan()): message.reply( "Requested a Galaxy %s Scan of %s:%s. !request cancel %s:%s to cancel the request." % (request.type, planet.x, planet.y, request.id - len(planets) + 1, request.id) ) # Check for existing scans scan = planet.scan(scantype) if scan and request.tick - scan.tick < PA.getint(scantype, "expire"): message.reply( "%s Scan of %s:%s:%s is already available from %s ticks ago: %s. !request cancel %s if this is suitable." % (scantype, planet.x, planet.y, planet.z, request.tick - scan.tick, scan.link, request.id) ) # Cancel requests with a 0-tick old scan, if required if request.tick == scan.tick: req0age = ( Config.getint("Misc", "req0agej") if request.scantype == "J" else Config.getint("Misc", "req0age") ) if req0age == 1: Q = ( session.query(Request) .filter(Request.tick == request.tick) .filter(Request.planet_id == request.planet_id) ) Q = Q.filter(Request.scantype == request.scantype).filter( Request.requester_id == request.requester_id ) if Q.count() == 1: request.active = False message.reply( "Request %s cancelled due to an existing scan. If you really need a newer one, repeat your scan request." % (request.id) ) message.privmsg( "Cancelled scan request %s due to existing scan" % (request.id), self.scanchan() ) elif req0age == 0: request.active = False message.reply("Request %s cancelled due to an existing scan." % (request.id)) message.privmsg( "Cancelled scan request %s due to existing scan" % (request.id), self.scanchan() ) # Tell the scanners requester = user.name if not Config.getboolean("Misc", "anonscans") else "Anon" if galscan: message.privmsg( "[%s:%s] %s requested a Galaxy %s Scan of %s:%s Max Dists(i:%s%s) " % ( request.id - len(planets) + 1, request.id, requester, request.type, planet.x, planet.y, max(galdists), "/r:%s" % dists if dists > 0 else "", ) + Config.get("URL", "reqgscan") % (planet.x, planet.y), self.scanchan(), ) else: request = self.request(message, user, planet, scantype, dists) if message.get_chan() != self.scanchan(): message.reply( "Requested a %s Scan of %s:%s:%s. !request cancel %s to cancel the request." % (request.type, planet.x, planet.y, planet.z, request.id) ) # Check for existing scans scan = planet.scan(scantype) if scan and request.tick - scan.tick < PA.getint(scan.scantype, "expire"): message.reply( "%s Scan of %s:%s:%s is already available from %s ticks ago: %s. !request cancel %s if this is suitable." % (scantype, planet.x, planet.y, planet.z, request.tick - scan.tick, scan.link, request.id) ) # Cancel requests with a 0-tick old scan, if required if request.tick == scan.tick: req0age = ( Config.getint("Misc", "req0agej") if request.scantype == "J" else Config.getint("Misc", "req0age") ) if req0age == 1: Q = ( session.query(Request) .filter(Request.tick == request.tick) .filter(Request.planet_id == request.planet_id) ) Q = Q.filter(Request.scantype == request.scantype).filter( Request.requester_id == request.requester_id ) if Q.count() == 1: request.active = False message.reply( "Request %s cancelled due to an existing scan. If you really need a newer one, repeat your scan request." % (request.id) ) message.privmsg( "Cancelled scan request %s due to existing scan" % (request.id), self.scanchan() ) elif req0age == 0: request.active = False message.reply("Request %s cancelled due to an existing scan." % (request.id)) message.privmsg( "Cancelled scan request %s due to existing scan" % (request.id), self.scanchan() ) if mergescans: message.reply( "Requested %d scans. !request cancel %s:%s to cancel the request." % (len(planets) * types, request.id - len(planets) * types + 1, request.id) ) message.privmsg( "[%s:%s] %s requested %d scans (%s) Max Dists(i:%s%s). !request links for details " % ( request.id - len(planets) * types + 1, request.id, requester, len(planets) * types, params.group(6).upper(), max(galdists), "/r:%s" % dists if dists > 0 else "", ), self.scanchan(), ) session.commit()
def set_prefs(self, message, user, params): params = self.split_opts(params.group(1)) reply = "" flux_update = -1 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 Config.has_section("FluxBB"): flux_update = self.flux_passwd(user) 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 = None 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 (val[:1] in ['C', 'G']) and (Config.get("Misc", "sms") != "combined"): message.alert("Your alliance doesn't support SMS mode switching") continue if val[:1].upper() in User._sms_modes: if val[:1] == 'C' and not Config.get("clickatell", "user"): message.alert("Your alliance doesn't support Clickatell SMS") continue if val[:1] == 'G' and not Config.get("googlevoice", "user"): message.alert("Your alliance doesn't support Google Voice SMS") continue if val[:1] == 'T' and not Config.get("Twilio", "sid"): message.alert("Your alliance doesn't support Twilio SMS") continue if val[:1] == 'W' and not Config.get("WhatsApp", "login"): message.alert("Your alliance doesn't support WhatsApp") continue 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) if flux_update == 0: message.reply("Failed to update forum password.") elif flux_update == 1: message.reply("Updated forum password.")
def set_prefs(self, message, user, params): params = self.split_opts(params.group(1)) reply = "" flux_update = -1 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 Config.has_section("FluxBB"): flux_update = self.flux_passwd(user) 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 (val[:1] in ['C', 'G']) and (Config.get("Misc", "sms") != "combined"): message.alert("Your alliance doesn't support SMS mode switching") continue if val[:1].upper() in User._sms_modes: if val[:1] == 'C' and not Config.get("clickatell", "user"): message.alert("Your alliance doesn't support Clickatell SMS") continue if val[:1] == 'G' and not Config.get("googlevoice", "user"): message.alert("Your alliance doesn't support Google Voice SMS") continue if val[:1] == 'T' and not Config.get("Twilio", "sid"): message.alert("Your alliance doesn't support Twilio SMS") continue if val[:1] == 'W' and not Config.get("WhatsApp", "login"): message.alert("Your alliance doesn't support WhatsApp") continue 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) if flux_update == 0: message.reply("Failed to update forum password.") elif flux_update == 1: message.reply("Updated forum password.")
text( "INSERT INTO %ssms_log (sender_id,receiver_id,phone,sms_text,mode) SELECT sender_id,receiver_id,phone,sms_text,mode FROM %s.%ssms_log;" % (prefix, round, old_prefix))) except DBAPIError, e: print "An error occurred during migration: %s" % (str(e), ) session.rollback() print "Reverting to previous schema" """session.execute(text("DROP SCHEMA public CASCADE;")) session.execute(text("ALTER SCHEMA %s RENAME TO public;" % (round,)))""" session.commit() sys.exit() else: session.commit() finally: session.close() if Config.has_section("FluxBB") and Config.getboolean("FluxBB", "enabled"): tables = session.execute( text( "SELECT table_name FROM information_schema.tables WHERE table_schema='%s' AND table_name LIKE '%s%%';" % (round, Config.get("FluxBB", "prefix")))) for t in tables: session.execute( text("CREATE TABLE %s AS SELECT * FROM %s.%s;" % (t[0], round, t[0]))) session.commit() session.close() if round == "temp": print "Deleting temporary schema" session.execute(text("DROP SCHEMA temp CASCADE;")) session.commit()