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()