def blocks(self, message, user, params): id = params.group(1) dists = int(params.group(2)) + 1 request = Request.load(id) if request is None: message.reply("No open request number %s exists (idiot)." % (id,)) return if request.user is not user and not user.is_member() and not self.is_chan(message, self.scanchan()): message.reply("Scan request %s isn't yours and you're not a scanner!" % (id,)) return # Update Intel planet = request.target if planet.intel is None: planet.intel = Intel() planet.intel.dists = max(planet.intel.dists, dists) request.dists = max(request.dists, dists) session.commit() reply = "Updated request %s dists to %s" % (id, request.dists) message.reply(reply) if message.get_chan() != self.scanchan(): message.privmsg(reply, self.scanchan()) nicks = CUT.get_user_nicks(request.user.name) if message.get_nick() not in nicks: for nick in nicks: message.privmsg(reply, nick)
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 robocop(self, message, request_id, mode): request = Request.load(request_id, active=False) if request is None: return if mode == "cancel": reply = "Cancelled scan request %s" % (request.id,) message.privmsg(reply, self.scanchan()) nicks = CUT.get_user_nicks(request.user.name) for nick in nicks: message.privmsg(reply, nick) return if mode == "block": reply = "Updated request %s dists to %s" % (request.id, request.dists,) message.privmsg(reply, self.scanchan()) nicks = CUT.get_user_nicks(request.user.name) for nick in nicks: message.privmsg(reply, nick) return user = request.user planet = request.target requester = user.name if not Config.getboolean("Misc", "anonscans") else "Anon" dists_intel = planet.intel.dists if planet.intel else 0 message.privmsg("[%s] %s requested a %s Scan of %s:%s:%s Dists(i:%s%s) " % (request.id, requester, request.type, planet.x,planet.y,planet.z, dists_intel, "/r:%s" % request.dists if request.dists > 0 else "") + request.link, self.scanchan())
def blocks(self, message, user, params): id = params.group(1) dists = int(params.group(2))+1 request = Request.load(id) if request is None: message.reply("No open request number %s exists (idiot)."%(id,)) return if request.user is not user and not user.is_member() and not self.is_chan(message, self.scanchan()): message.reply("Scan request %s isn't yours and you're not a scanner!"%(id,)) return # Update Intel planet = request.target if planet.intel is None: planet.intel = Intel() planet.intel.dists = max(planet.intel.dists, dists) request.dists = max(request.dists, dists) session.commit() reply = "Updated request %s dists to %s" % (id, request.dists,) message.reply(reply) if message.get_chan() != self.scanchan(): message.privmsg(reply, self.scanchan()) nicks = CUT.get_user_nicks(request.user.name) if message.get_nick() not in nicks: for nick in nicks: message.privmsg(reply, nick)
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 cancel(self, message, user, params): id = params.group(1) request = Request.load(id) if request is None: message.reply("No open request number %s exists (idiot)." % (id, )) return if request.user is not user and not user.is_member( ) and not self.is_chan(message, self.scanchan()): message.reply( "Scan request %s isn't yours and you're not a scanner!" % (id, )) return request.active = False session.commit() reply = "Cancelled scan request %s" % (id, ) message.reply(reply) if message.get_chan() != self.scanchan(): message.privmsg(reply, self.scanchan()) nicks = CUT.get_user_nicks(request.user.name) if message.get_nick() not in nicks: for nick in nicks: message.privmsg(reply, nick)
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() return requests.execute(request, user, message="Updated request %s dists to %s" % (id, req.dists,))
def blocks(self, message, user, params): id = params.group(1) dists = int(params.group(2)) request = Request.load(id) if request is None: message.reply("No open request number %s exists (idiot)."%(id,)) return request.dists = max(request.dists, dists) session.commit() message.reply("Updated request %s dists to %s" % (id, request.dists,))
def robocop(self, message, request_id, mode): if mode == "cancel": message.privmsg("Cancelled scan request %s" % (request_id,), self.scanchan()) return request = Request.load(request_id) if request is None: return user = request.user planet = request.target dists_intel = planet.intel.dists if planet.intel else 0 message.privmsg("[%s] %s requested a %s Scan of %s:%s:%s Dists(i:%s/r:%s) " % (request.id, user.name, request.type, planet.x,planet.y,planet.z, dists_intel, request.dists,) + request.link, self.scanchan())
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 request(self, message, user, planet, scan, dists, gal=False): request = Request(target=planet, scantype=scan, dists=dists) user.requests.append(request) session.commit() if not gal: requester = user.name if not Config.getboolean("Misc", "anonscans") else "Anon" dists_intel = planet.intel.dists if planet.intel else 0 message.privmsg("[%s] %s requested a %s Scan of %s:%s:%s Dists(i:%s%s) " % (request.id, requester, request.type, planet.x,planet.y,planet.z, dists_intel, "/r:%s" % request.dists if request.dists > 0 else "") + request.link, self.scanchan()) return request
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, 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 cancel(self, message, user, params): id = params.group(1) request = Request.load(id) if request is None: message.reply("No open request number %s exists (idiot)."%(id,)) return if request.user is not user and not user.is_admin() and not self.is_chan(message, self.scanchan()): message.reply("Only %s may cancel request %s."%(request.user.name,id)) return request.active = False session.commit() message.reply("Cancelled scan request %s" % (id,)) if message.get_chan() != self.scanchan(): message.privmsg("Cancelled scan request %s" % (id,), self.scanchan())
def execute(self, message, user, params): if params.group(1).lower() == "cancel": request = Request.load(params.group(2)) return planet = Planet.load(*params.group(2,4,6)) if planet is None: message.alert("No planet with coords %s:%s:%s" % params.group(2,4,6)) return scan = params.group(1).upper() request = Request(target=planet, scantype=scan) request.dists = int(params.group(7) or 0) user.requests.append(request) session.commit() dists_intel = planet.intel.dists if planet.intel else 0 dists_request = request.dists message.reply("Requested a %s Scan of %s:%s:%s. !request cancel %s to cancel the request." % (PA.get(scan, "name"), planet.x, planet.y, planet.z, request.id,)) self.request(message, request.id, user.name, scan, planet.x, planet.y, planet.z, dists_intel, dists_request) return
def cancel(self, message, user, params): cancel_ids = [] reply_ids = [] noexist = [] noaccess = [] for id in params.group(1).split(): if ':' in id: [start,end] = id.split(':') cancel_ids += range(int(start), int(end)+1) elif '-' in id: [start,end] = id.split('-') cancel_ids += range(int(start), int(end)+1) else: cancel_ids.append(int(id)) for id in cancel_ids: id = str(id) request = Request.load(id) if request is None: noexist.append(id) continue if request.user is not user and not user.is_member() and not self.is_chan(message, self.scanchan()): noaccess.append(id) continue request.active = False session.commit() reply = "Cancelled scan request %s" % (id) nicks = CUT.get_user_nicks(request.user.name) if message.get_nick() not in nicks: for nick in nicks: message.privmsg(reply, nick) reply_ids.append(id) if len(noexist) > 0: message.reply("No open request number %s exists (idiot)."%(", ".join(noexist),)) if len(noaccess) > 0: message.reply("Scan requests: %s aren't yours and you're not a scanner!"%(", ".join(noaccess),)) if len(reply_ids) > 0: reply = "Cancelled scan request %s" % (", ".join(reply_ids)) message.reply(reply) if message.get_chan() != self.scanchan(): message.privmsg(reply, self.scanchan())
def cancel(self, message, user, params): cancel_ids = [] reply_ids = [] noexist = [] noaccess = [] for id in params.group(1).split(): if ":" in id: [start, end] = id.split(":") cancel_ids += range(int(start), int(end) + 1) elif "-" in id: [start, end] = id.split("-") cancel_ids += range(int(start), int(end) + 1) else: cancel_ids.append(int(id)) for id in cancel_ids: id = str(id) request = Request.load(id) if request is None: noexist.append(id) continue if request.user is not user and not user.is_member() and not self.is_chan(message, self.scanchan()): noaccess.append(id) continue request.active = False session.commit() reply = "Cancelled scan request %s" % (id) nicks = CUT.get_user_nicks(request.user.name) if message.get_nick() not in nicks: for nick in nicks: message.privmsg(reply, nick) reply_ids.append(id) if len(noexist) > 0: message.reply("No open request number %s exists (idiot)." % (", ".join(noexist),)) if len(noaccess) > 0: message.reply("Scan requests: %s aren't yours and you're not a scanner!" % (", ".join(noaccess),)) if len(reply_ids) > 0: reply = "Cancelled scan request %s" % (", ".join(reply_ids)) message.reply(reply) if message.get_chan() != self.scanchan(): message.privmsg(reply, self.scanchan())
def blocks(self, message, user, params): id = params.group(1) dists = int(params.group(2)) request = Request.load(id) if request is None: message.reply("No open request number %s exists (idiot)."%(id,)) return request.dists = max(request.dists, dists) session.commit() reply = "Updated request %s dists to %s" % (id, request.dists,) message.reply(reply) if message.get_chan() != self.scanchan(): message.privmsg(reply, self.scanchan()) nicks = CUT.list_user_nicks(request.user.name) if message.get_nick() not in nicks: for nick in nicks: message.privmsg(reply, nick)
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 cancel(self, message, user, params): id = params.group(1) request = Request.load(id) if request is None: message.reply("No open request number %s exists (idiot)." % (id,)) return if request.user is not user and not user.is_member() and not self.is_chan(message, self.scanchan()): message.reply("Scan request %s isn't yours and you're not a scanner!" % (id,)) return request.active = False session.commit() reply = "Cancelled scan request %s" % (id,) message.reply(reply) if message.get_chan() != self.scanchan(): message.privmsg(reply, self.scanchan()) nicks = CUT.get_user_nicks(request.user.name) if message.get_nick() not in nicks: for nick in nicks: message.privmsg(reply, nick)
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")