def execute(self, request, user, id, dists): req = Request.load(id) if req is None: return requests.execute( request, user, message="No open request number %s exists (idiot)." % (id, )) if req.user is not user and not user.is_member(): return requests.execute( request, user, message="Scan request %s isn't yours and you're not a scanner!" % (id, )) req.dists = max(req.dists, int(dists) + 1) session.commit() push("request", request_id=req.id, mode="block") return requests.execute(request, user, message="Updated request %s dists to %s" % ( id, req.dists, ))
def execute(self, request, user, x, y, z, type, dists): from Arthur.views.scans.list import scans tick = Updates.current_tick() type = type.upper() planet = Planet.load(x, y, z) if planet is None: return scans.execute(request, user, message="No planet with coords %s:%s:%s" % ( x, y, z, )) dists = int(dists or 0) req = Request(target=planet, scantype=type, dists=dists) user.requests.append(req) session.commit() push("request", request_id=req.id, mode="request") return scans.execute(request, user, message="Requested a %s Scan of %s:%s:%s" % ( req.type, x, y, z, ), planet=planet)
def execute(self, request, user, id, dists): req = Request.load(id) if req is None: return requests.execute(request, user, message="No open request number %s exists (idiot)."%(id,)) req.dists = max(req.dists, int(dists)) session.commit() push("request", request_id=req.id, mode="block") return requests.execute(request, user, message="Updated request %s dists to %s" % (id, req.dists,))
def new(self, message, user, params): tick = Updates.current_tick() comment = params.group(4) or "" when = int(params.group(1)) waves = params.group(2) or Config.get("Misc", "attwaves") if when < PA.getint("numbers", "protection"): when += tick elif when <= tick: message.alert( "Can not create attacks in the past. You wanted tick %s, but current tick is %s." % ( when, tick, )) return if when > 32767: when = 32767 attack = Attack(landtick=when, comment=comment, waves=int(waves)) session.add(attack) for coord in re.findall(loadable.coord, params.group(3)): if not coord[4]: galaxy = Galaxy.load(coord[0], coord[2]) if galaxy: attack.addGalaxy(galaxy) else: planet = Planet.load(coord[0], coord[2], coord[4]) if planet: attack.addPlanet(planet) session.commit() message.reply(str(attack)) # Request scans if Config.has_option("Misc", "attscans"): scantypes = Config.get("Misc", "attscans") else: scantypes = "" for stype in scantypes: for p in attack.planets: scan = p.scan(stype) if scan and (int(tick) == scan.tick): return else: req = Request(target=p, scantype=stype, dists=0) user.requests.append(req) session.commit() push("request", request_id=req.id, mode="request") if scantypes: message.reply("Scans requested: %s" % (scantypes))
def execute(self, request, user, id, dists): req = Request.load(id) if req is None: return requests.execute(request, user, message="No open request number %s exists (idiot)."%(id,)) if req.user is not user and not user.is_member(): return requests.execute(request, user, message="Scan request %s isn't yours and you're not a scanner!"%(id,)) req.dists = max(req.dists, int(dists)+1) session.commit() push("request", request_id=req.id, mode="block") return requests.execute(request, user, message="Updated request %s dists to %s" % (id, req.dists,))
def execute(self, request, user, id): req = Request.load(id) if req is None: return requests.execute(request, user, message="No open request number %s exists (idiot)."%(id,)) if req.user is not user and not user.is_member(): return requests.execute(request, user, message="Scan request %s isn't yours and you're not a scanner!"%(id,)) req.active = False session.commit() push("request", request_id=req.id, mode="cancel") return requests.execute(request, user, message="Cancelled scan request %s" % (id,))
def execute(self, request, user, id): req = Request.load(id) if req is None: return requests.execute(request, user, message="No open request number %s exists (idiot)."%(id,)) if req.user is not user and not user.is_admin(): return requests.execute(request, user, message="Only %s may cancel request %s."%(req.user.name,id)) req.active = False session.commit() push("request", request_id=req.id, mode="cancel") return requests.execute(request, user, message="Cancelled scan request %s" % (id,))
def execute(self, message, user, params): 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 notice = "DEFCALL: %s wants %s to %s:%s:%s eta %s" % (user.name, params.group(7), params.group(1), params.group(3), params.group(5), params.group(6)) if Config.getboolean("Misc", "globaldef"): push("broadcast", notice="!#!"+notice.replace(" ","!#!")) else: message.notice(notice, Config.get("Channels", "home"))
def execute(self, message, user, params): 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 notice = "DEFCALL: %s wants %s to %s:%s:%s eta %s" % ( user.name, params.group(7), params.group(1), params.group(3), params.group(5), params.group(6)) if Config.getboolean("Misc", "globaldef"): push("broadcast", notice="!#!" + notice.replace(" ", "!#!")) else: message.notice(notice, Config.get("Channels", "home"))
def new(self, message, user, params): tick = Updates.current_tick() comment = params.group(4) or "" when = int(params.group(1)) waves = params.group(2) or Config.get("Misc", "attwaves") if when < PA.getint("numbers", "protection"): when += tick elif when <= tick: message.alert("Can not create attacks in the past. You wanted tick %s, but current tick is %s." % (when, tick,)) return if when > 32767: when = 32767 attack = Attack(landtick=when,comment=comment,waves=int(waves)) session.add(attack) for coord in re.findall(loadable.coord, params.group(3)): if not coord[4]: galaxy = Galaxy.load(coord[0],coord[2]) if galaxy: attack.addGalaxy(galaxy) else: planet = Planet.load(coord[0],coord[2],coord[4]) if planet: attack.addPlanet(planet) session.commit() message.reply(str(attack)) # Request scans if Config.has_option("Misc", "attscans"): scantypes = Config.get("Misc", "attscans") else: scantypes = "" for stype in scantypes: for p in attack.planets: scan = p.scan(stype) if scan and (int(tick) == scan.tick): return else: req = Request(target=p, scantype=stype, dists=0) user.requests.append(req) session.commit() push("request", request_id=req.id, mode="request") if scantypes: message.reply("Scans requested: %s" % (scantypes))
def execute(self, request, user, x, y, z, type, dists): from Arthur.scans.list import scans tick = Updates.current_tick() type = type.upper() planet = Planet.load(x,y,z) if planet is None: return scans.execute(request, user, message="No planet with coords %s:%s:%s" %(x,y,z,)) dists = int(dists or 0) req = Request(target=planet, scantype=type, dists=dists) user.requests.append(req) session.commit() push("request", request_id=req.id, mode="request") return scans.execute(request, user, message="Requested a %s Scan of %s:%s:%s"%(req.type, x,y,z,), planet=planet)
def robonotify(self, header, body): # Check for correct "From" address? uname = re.findall("(.+)@.+", header['To'])[0].split()[1] dsuff = Config.get("imap", "defsuffix") if dsuff: if uname[-len(dsuff):] == dsuff: uname = uname[:-len(dsuff)] else: self.forwardMail(uname, header, body) return tick = re.findall("events in tick (\d+)", body)[0] newfleets = re.findall("We have detected an open jumpgate from (.+), located at (\d{1,2}):(\d{1,2}):(\d{1,2}). " +\ "The fleet will approach our system in tick (\d+) and appears to have (\d+) visible ships.", body) recalls = re.findall("The (.+) fleet from (\d{1,2}):(\d{1,2}):(\d{1,2}) has been recalled.", body) cons = len(re.findall("Our construction team reports that .+ has been finished", body)) res = len(re.findall("Our scientists report that .+ has been finished", body)) # Wrap it up in a bow for line in newfleets: push("defcall", etype="new", uname=uname, tick=tick, name=line[0], x=line[1], y=line[2], z=line[3], eta=line[4], size=line[5]) for line in recalls: push("defcall", etype="rec", uname=uname, tick=tick, name=line[0], x=line[1], y=line[2], z=line[3]) if res + cons > 0: push("defcall", etype="fin", uname=uname, tick=tick, res=res, cons=cons) if len(newfleets) + len(recalls) + cons + res == 0: self.forwardMail(uname, header, body)
def execute(self, request, user, id): req = Request.load(id) if req is None: return requests.execute( request, user, message="No open request number %s exists (idiot)." % (id, )) if req.user is not user and not user.is_member(): return requests.execute( request, user, message="Scan request %s isn't yours and you're not a scanner!" % (id, )) req.active = False session.commit() push("request", request_id=req.id, mode="cancel") return requests.execute(request, user, message="Cancelled scan request %s" % (id, ))
def robonotify(self, header, body): # Check for correct "From" address? uname = re.findall("(.+)@.+", header['To'])[0].split()[1] dsuff = Config.get("imap", "defsuffix") if dsuff: if uname[-len(dsuff):] == dsuff: uname = uname[:-len(dsuff)] else: self.forwardMail(uname, header, body) return tick = re.findall("events in tick (\d+)", body)[0] newfleets = re.findall("We have detected an open jumpgate from (.+), located at (\d{1,2}):(\d{1,2}):(\d{1,2}). " +\ "The fleet will approach our system in tick (\d+) and appears to have (\d+) visible ships.", body) recalls = re.findall( "The (.+) fleet from (\d{1,2}):(\d{1,2}):(\d{1,2}) has been recalled.", body) cons = len( re.findall( "Our construction team reports that .+ has been finished", body)) res = len( re.findall("Our scientists report that .+ has been finished", body)) # Wrap it up in a bow for line in newfleets: push("defcall", etype="new", uname=uname, tick=tick, name=line[0], x=line[1], y=line[2], z=line[3], eta=line[4], size=line[5]) for line in recalls: push("defcall", etype="rec", uname=uname, tick=tick, name=line[0], x=line[1], y=line[2], z=line[3]) if res + cons > 0: push("defcall", etype="fin", uname=uname, tick=tick, res=res, cons=cons) if len(newfleets) + len(recalls) + cons + res == 0: self.forwardMail(uname, header, body)
def robonotify(self, header, body): if Config.getboolean("imap", "singleaddr"): uname_re = "%s\+(.+)@.+" % Config.get("imap", "user").split("@")[0].lower() try: uname = re.findall(uname_re, header['To'].lower())[0] except IndexError: uname = "Unknown" else: uname_re = "<?(.+)@.+" uname = re.findall(uname_re, header['To'].lower())[0] dsuff = Config.get("imap", "defsuffix") if dsuff: if uname[-len(dsuff):] == dsuff: uname = uname[:-len(dsuff)] else: self.forwardMail(uname, header, body) return # Check the email "From" header says it's from Planetarion. if not "@planetarion.com" in header['From'].lower(): self.forwardMail(uname, header, body) return # Get the tick number (if this is a notification email). try: tick = re.findall("events in tick (\d+)", body)[0] except IndexError: self.forwardMail(uname, header, body) return # Check for the main notificatino types newfleets = re.findall("We have detected an open jumpgate from (.+), located at (\d{1,2}):(\d{1,2}):(\d{1,2}). ".replace(" ","\s+") +\ "The fleet will approach our system in tick (\d+) and appears to have (\d+) visible ships.".replace(" ","\s+"), body) recalls = re.findall("The (.+) fleet from (\d{1,2}):(\d{1,2}):(\d{1,2}) has been recalled.".replace(" ","\s+"), body) cons = len(re.findall("Our construction team reports that .+ has been finished".replace(" ","\s+"), body)) res = len(re.findall("Our scientists report that .+ has been finished".replace(" ","\s+"), body)) # Wrap it up in a bow for line in newfleets: push("defcall", etype="new", uname=uname, tick=tick, name=("!#!" + line[0].replace(" ", "!#!")), x=line[1], y=line[2], z=line[3], eta=line[4], size=line[5]) for line in recalls: push("defcall", etype="rec", uname=uname, tick=tick, name=("!#!" + line[0].replace(" ", "!#!")), x=line[1], y=line[2], z=line[3]) if res + cons > 0: push("defcall", etype="fin", uname=uname, tick=tick, res=res, cons=cons) if len(newfleets) + len(recalls) + cons + res == 0: self.forwardMail(uname, header, body)
def robonotify(self, header, body): if Config.getboolean("imap", "singleaddr"): uname_re = "%s\+(.+)@.+" % Config.get( "imap", "user").split("@")[0].lower() try: uname = re.findall(uname_re, header['To'].lower())[0] except IndexError: uname = "Unknown" else: uname_re = "<?(.+)@.+" uname = re.findall(uname_re, header['To'].lower())[0] dsuff = Config.get("imap", "defsuffix") if dsuff: if uname[-len(dsuff):] == dsuff: uname = uname[:-len(dsuff)] else: self.forwardMail(uname, header, body) return # Check the email "From" header says it's from Planetarion. if not "@planetarion.com" in header['From'].lower(): self.forwardMail(uname, header, body) return # Get the tick number (if this is a notification email). try: tick = re.findall("events in tick (\d+)", body)[0] except IndexError: self.forwardMail(uname, header, body) return # Check for the main notificatino types newfleets = re.findall("We have detected an open jumpgate from (.+), located at (\d{1,2}):(\d{1,2}):(\d{1,2}). ".replace(" ","\s+") +\ "The fleet will approach our system in tick (\d+) and appears to have (\d+) visible ships.".replace(" ","\s+"), body) recalls = re.findall( "The (.+) fleet from (\d{1,2}):(\d{1,2}):(\d{1,2}) has been recalled." .replace(" ", "\s+"), body) cons = len( re.findall( "Our construction team reports that .+ has been finished". replace(" ", "\s+"), body)) res = len( re.findall( "Our scientists report that .+ has been finished".replace( " ", "\s+"), body)) # Wrap it up in a bow for line in newfleets: push("defcall", etype="new", uname=uname, tick=tick, name=("!#!" + line[0].replace(" ", "!#!")), x=line[1], y=line[2], z=line[3], eta=line[4], size=line[5]) for line in recalls: push("defcall", etype="rec", uname=uname, tick=tick, name=("!#!" + line[0].replace(" ", "!#!")), x=line[1], y=line[2], z=line[3]) if res + cons > 0: push("defcall", etype="fin", uname=uname, tick=tick, res=res, cons=cons) if len(newfleets) + len(recalls) + cons + res == 0: self.forwardMail(uname, header, body)
)) request.scan_id = scan_id request.active = False users.append(request.user.name) req_ids.append(str(request.id)) else: scanlog("Scan %s matches request %s for %s but is old." % ( pa_id, request.id, request.user.name, )) push("scans", scantype=scantype, pa_id=pa_id, x=planet.x, y=planet.y, z=planet.z, names=request.user.name, scanner=uid, reqs=request.id, old=True) session.commit() if len(users) > 0: push("scans", scantype=scantype, pa_id=pa_id, x=planet.x, y=planet.y, z=planet.z, names=",".join(users),
def robocop(self, message, etype, uname="Unknown", tick=0, x=0, y=0, z=0, name="", eta=0, size=0, res=0, cons=0): notice = "" email = "" if name[:3] == "!#!": name = " ".join(name[3:].split("!#!")) user = User.load(uname) if user is None: errorlog("Defcall: Invalid user in email. Idiot.") uname = "%s (whoever that is??)" % (uname) ucoords = "x:x:x" addr = Config.get("imap", "bounce") email = "Bad username in notifications: %s\n\nOriginal notification:\n\n\n" % (uname) else: uname = "%s%s" % (user.name, ("(%s)" % (user.alias)) if user.alias else "") if user.planet: ucoords = "%d:%d:%d" % (user.planet.x, user.planet.y, user.planet.z) else: ucoords = "idiot" addr = user.email if etype != "fin": p = Planet.load(x,y,z) if p is None: errorlog("Defcall: Invalid planet in email. Probably an exile.") if etype == "new": # Message to DC channel / main channel. Request scans. if p is None: arace = "??" aally = "Unknown" else: arace = p.race i = p.intel if i and i.alliance: aally = i.alliance.name else: aally = "Unknown" notice = "DEFCALL: %s (%s) has incoming eta %s(%s) from %s:%s:%s (%s, %s) - Fleet: %s Visible Ships: %s" % (uname, ucoords, eta, int(eta)-int(tick), x, y, z, arace, aally, name, size) email += "Notification from Planetarion in tick %s\n\n" % (tick) +\ "Incoming Fleet %s from %s:%s:%s with %s visible ships expected to land in tick %s." % (name, x, y, z, size, eta) +\ "\n\nThis has been reported to the %s DCs." % (Config.get("Alliance", "name")) elif etype == "rec": # Message to DC channel *and* main channel notice = "RECALL: %s (%s) has had a recall: Fleet: %s from %s:%s:%s" % (uname, ucoords, name, x, y, z) email += "Notification from Planetarion in tick %s\n\n" % (tick) +\ "Incoming Fleet %s from %s:%s:%s has recalled." % (name, x, y, z) +\ "\n\nThis has been reported to %s." % (Config.get("Alliance", "name")) elif etype == "fin": # Nothing to see here. Move along. notice = "" what = "" if int(res): what = "research" if int(cons): what += " and construction" else: what = "construction" email += "Notification from Planetarion in tick %s\n\nAll %s has finished and none is queued." % (tick, what) else: return # Send email - pref? if notice: if Config.getboolean("Misc", "globaldef"): push("broadcast", notice="!#!"+notice.replace(" ","!#!")) else: if etype == "new" and Config.has_option("Channels", "def"): message.notice(notice, Config.get("Channels", "def")) else: message.notice(notice, Config.get("Channels", "home")) if email and addr: self.send_email("Relayed PA Notifications from tick %s" % (tick), email, addr) # Check for scans if etype == "new" and p and user: if Config.has_option("Misc", "autoscans"): scantypes = Config.get("Misc", "autoscans") else: scantypes = "A" scanage = (Config.getint("Misc", "scanage") or 2) for stype in scantypes: scan = p.scan(stype) if scan and (int(tick) - scan.tick <= scanage): return else: req = Request(target=p, scantype=stype, dists=0) user.requests.append(req) session.commit() push("request", request_id=req.id, mode="request")
for request in result: scanlog("Scan %s matches request %s for %s" % ( pa_id, request.id, request.user.name, )) request.scan_id = scan_id request.active = False users.append(request.user.name) session.commit() if len(users) > 0: push("scans", scantype=scantype, pa_id=pa_id, x=planet.x, y=planet.y, z=planet.z, names=",".join(users)) def parse_P(self, scan_id, scan, page): planetscan = scan.planetscan = PlanetScan() #m = re.search('<tr><td class="left">Asteroids</td><td>(\d+)</td><td>(\d+)</td><td>(\d+)</td></tr><tr><td class="left">Resources</td><td>(\d+)</td><td>(\d+)</td><td>(\d+)</td></tr><tr><th>Score</th><td>(\d+)</td><th>Value</th><td>(\d+)</td></tr>', page) #m = re.search(r"""<tr><td class="left">Asteroids</td><td>(\d+)</td><td>(\d+)</td><td>(\d+)</td></tr><tr><td class="left">Resources</td><td>(\d+)</td><td>(\d+)</td><td>(\d+)</td></tr><tr><th>Score</th><td>(\d+)</td><th>Value</th><td>(\d+)</td></tr>""", page) page = re.sub(',', '', page) m = re.search( r""" <tr><td[^>]*>Metal</td><td[^>]*>(\d+)</td><td[^>]*>(\d+)</td></tr>\s* <tr><td[^>]*>Crystal</td><td[^>]*>(\d+)</td><td[^>]*>(\d+)</td></tr>\s*
def robocop(self, message, etype, uname="Unknown", tick=0, x=0, y=0, z=0, name="", eta=0, size=0, res=0, cons=0): notice = "" email = "" user = User.load(uname) if user is None: errorlog("Defcall: Invalid user in email. Idiot.") uname = "%s (whoever that is??)" % (uname) ucoords = "x:x:x" addr = Config.get("imap", "bounce") email = "Bad username in notifications: %s\n\nOriginal notification:\n\n\n" % (uname) else: uname = "%s%s" % (user.name, ("(%s)" % (user.alias)) if user.alias else "") if user.planet: ucoords = "%d:%d:%d" % (user.planet.x, user.planet.y, user.planet.z) else: ucoords = "idiot" addr = user.email if etype != "fin": p = Planet.load(x,y,z) if p is None: errorlog("Defcall: Invalid planet in email. Probably an exile.") if etype == "new": # Message to DC channel / main channel. Request scans. if p is None: arace = "??" aally = "Unknown" else: arace = p.race i = p.intel if i and i.alliance: aally = i.alliance.name else: aally = "Unknown" notice = "DEFCALL: %s (%s) has incoming eta %s(%s) from %s:%s:%s (%s, %s) - Fleet: %s Visible Ships: %s" % (uname, ucoords, eta, int(eta)-int(tick), x, y, z, arace, aally, name, size) email += "Notification from Planetarion in tick %s\n\n" % (tick) +\ "Incoming Fleet %s from %s:%s:%s with %s visible ships expected to land in tick %s." % (name, x, y, z, size, eta) +\ "\n\nThis has been reported to the %s DCs." % (Config.get("Alliance", "name")) elif etype == "rec": # Message to DC channel *and* main channel notice = "RECALL: %s (%s) has had a recall: Fleet: %s from %s:%s:%s" % (uname, ucoords, name, x, y, z) email += "Notification from Planetarion in tick %s\n\n" % (tick) +\ "Incoming Fleet %s from %s:%s:%s with eta %s(%s) has recalled." % (name, x, y, z, eta, int(eta)-int(tick)) +\ "\n\nThis has been reported to %s." % (Config.get("Alliance", "name")) elif etype == "fin": # Nothing to see here. Move along. notice = "" what = "" if int(res): what = "research" if int(cons): what += " and construction" else: what = "construction" email += "Notification from Planetarion in tick %s\n\nAll %s has finished and none is queued." % (tick, what) else: return # Send email - pref? if notice: if etype == "new" and Config.has_option("Channels", "def"): message.notice(notice, Config.get("Channels", "def")) else: message.notice(notice, Config.get("Channels", "home")) if email and addr: self.send_email("Relayed PA Notifications from tick %s" % (tick), email, addr) # Check for scans if etype == "new" and p and user: if Config.has_option("Misc", "autoscans"): scantypes = Config.get("Misc", "autoscans") else: scantypes = "A" scanage = (Config.getint("Misc", "scanage") or 2) for stype in scantypes: scan = p.scan(stype) if scan and (int(tick) - scan.tick <= scanage): return else: req = Request(target=p, scantype=stype, dists=0) user.requests.append(req) session.commit() push("request", request_id=req.id, mode="request")
Q = session.query(Request) Q = Q.filter(Request.scantype==scantype) Q = Q.filter(Request.target==planet) Q = Q.filter(Request.scan==None) Q = Q.filter(Request.active==True) result = Q.all() users = [] for request in result: request.scan_id = scan_id request.active = False users.append(request.user.name) session.commit() if len(users) > 0: push("scans", scantype=scantype, pa_id=pa_id, x=planet.x, y=planet.y, z=planet.z, names=",".join(users)) def parse_P(self, scan_id, scan, page): planetscan = scan.planetscan = PlanetScan() #m = re.search('<tr><td class="left">Asteroids</td><td>(\d+)</td><td>(\d+)</td><td>(\d+)</td></tr><tr><td class="left">Resources</td><td>(\d+)</td><td>(\d+)</td><td>(\d+)</td></tr><tr><th>Score</th><td>(\d+)</td><th>Value</th><td>(\d+)</td></tr>', page) #m = re.search(r"""<tr><td class="left">Asteroids</td><td>(\d+)</td><td>(\d+)</td><td>(\d+)</td></tr><tr><td class="left">Resources</td><td>(\d+)</td><td>(\d+)</td><td>(\d+)</td></tr><tr><th>Score</th><td>(\d+)</td><th>Value</th><td>(\d+)</td></tr>""", page) page=re.sub(',','',page) m=re.search(r""" <tr><td[^>]*>Metal</td><td[^>]*>(\d+)</td><td[^>]*>(\d+)</td></tr>\s* <tr><td[^>]*>Crystal</td><td[^>]*>(\d+)</td><td[^>]*>(\d+)</td></tr>\s* <tr><td[^>]*>Eonium</td><td[^>]*>(\d+)</td><td[^>]*>(\d+)</td></tr>\s* """,page,re.VERBOSE) planetscan.roid_metal = m.group(1)