Esempio n. 1
0
 def privmsg(self, text, target=None, priority=0):
     if os.path.isfile("/tmp/meetingmode"):
         return
         # Privmsg someone. Target defaults to the person who triggered this line
         # Should we send colours?
     if (
         Config.has_option("Connection", "color")
         and not Config.has_option("NoColor", target)
         and not (target[0] in ["#", "&"] and Config.has_option("NoColorChan", target[1:]))
     ):
         text = "\x03" + Config.get("Connection", "color") + text + "\x0F"
         color = True
     else:
         color = False
     # If we're opped in a channel in common with the user, we can reply with
     #  CPRIVMSG instead of PRIVMSG which doesn't count towards the flood limit.
     if (
         (not target or target[0] not in "#&")
         and hasattr(self, "_channel")
         and CUT.opped(self.get_chan())
         and CUT.nick_in_chan(target or self.get_nick(), self.get_chan())
     ):
         self.write("CPRIVMSG %s %s :%s" % (target or self.get_nick(), self.get_chan(), text), color, priority)
     else:
         self.write("PRIVMSG %s :%s" % (target or self.get_nick(), text), color, priority)
Esempio n. 2
0
def catcher(message):
    try:
        user = User.load(name=message.get_pnick())
        uid = user.id if user else None
    except PNickParseError:
        uid = None
    for m in scanre.finditer(message.get_msg()):
        parse(uid, "scan", m.group(1)).start()
        if Config.has_option("Channels", "share"):
            message.privmsg(m.group(0), Config.get("Channels", "share"))
    for m in scangrpre.finditer(message.get_msg()):
        parse(uid, "group", m.group(1)).start()
        if Config.has_option("Channels", "share"):
            message.privmsg(m.group(0), Config.get("Channels", "share"))
Esempio n. 3
0
def catcher(message):
    try:
        user = User.load(name=message.get_pnick())
        uid = user.id if user else None
    except PNickParseError:
        uid = None
    for m in scanre.finditer(message.get_msg()):
        parse(uid, "scan", m.group(1)).start()
        if Config.has_option("Channels", "share"):
            sharechan = Config.get("Channels", "share")
            if message.get_chan().lower() != sharechan.lower():
                if Config.get("Misc", "shareto"):
                    message.privmsg(m.group(0), Config.get("Misc","shareto"), priority=+3)
    for m in scangrpre.finditer(message.get_msg()):
        parse(uid, "group", m.group(1)).start()
        if Config.has_option("Channels", "share"):
            sharechan = Config.get("Channels", "share")
            if message.get_chan().lower() != sharechan.lower():
                if Config.get("Misc", "shareto"):
                    message.privmsg(m.group(0), Config.get("Misc","shareto"), priority=+3)
Esempio n. 4
0
    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))
Esempio n. 5
0
def join(message):
    # Someone is joining a channel
    if message.get_nick() != Merlin.nick:
        # Someone is joining a channel we're in
        try:
            u = User.load(name=message.get_pnick())
            if u is None or not u.is_member():
                return
            defage = Updates.current_tick() - (u.fleetupdated or 0)
            if defage > (Config.getint("Misc", "defage") if Config.has_option("Misc", "defage") else 24):
                message.notice("Your mydef is %d ticks old. Update it now!" % (defage), message.get_nick())
        except PNickParseError:
            return
Esempio n. 6
0
 def privmsg(self, text, target=None, priority=0):
     # Privmsg someone. Target defaults to the person who triggered this line
     # Should we send colours?
     if (Config.has_option("Connection", "color")
             and not Config.has_option("NoColor", target)
             and not (target[0] in ['#', '&']
                      and Config.has_option("NoColorChan", target[1:]))):
         text = "\x03" + Config.get("Connection", "color") + text + "\x0F"
         color = True
     else:
         color = False
     # If we're opped in a channel in common with the user, we can reply with
     #  CPRIVMSG instead of PRIVMSG which doesn't count towards the flood limit.
     if (not target or target[0] not in "#&") and hasattr(
             self, "_channel") and CUT.opped(
                 self.get_chan()) and CUT.nick_in_chan(
                     target or self.get_nick(), self.get_chan()):
         self.write(
             "CPRIVMSG %s %s :%s" %
             (target or self.get_nick(), self.get_chan(), text), color,
             priority)
     else:
         self.write("PRIVMSG %s :%s" % (target or self.get_nick(), text),
                    color, priority)
Esempio n. 7
0
File: attack.py Progetto: JDD/merlin
    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))
Esempio n. 8
0
def join(message):
    # Someone is joining a channel
    if message.get_nick() != Merlin.nick:
        # Someone is joining a channel we're in
        try:
            u = User.load(name=message.get_pnick())
            if u is None or not u.is_member():
                return
            defage = Updates.current_tick() - (u.fleetupdated or 0)
            if defage > (Config.getint("Misc", "defage") if Config.has_option(
                    "Misc", "defage") else 24):
                message.notice(
                    "Your mydef is %d ticks old. Update it now!" % (defage),
                    message.get_nick())
        except PNickParseError:
            return
Esempio n. 9
0
File: parse.py Progetto: JDD/merlin
def catcher(message):
    try:
        user = User.load(name=message.get_pnick())
        uid = user.id if user else None
    except PNickParseError:
        uid = None

    share = True
    if Config.has_option("Channels", "share"):
        if message.get_chan().lower() == Config.get("Channels", "share").lower():
            share = False

    for m in scanre.finditer(message.get_msg()):
        parse(uid, "scan", m.group(1), share).start()

    for m in scangrpre.finditer(message.get_msg()):
        parse(uid, "group", m.group(1), share).start()
Esempio n. 10
0
def catcher(message):
    try:
        user = User.load(name=message.get_pnick())
        uid = user.id if user else None
    except PNickParseError:
        uid = None

    share = True
    if Config.has_option("Channels", "share"):
        if message.get_chan().lower() == Config.get("Channels",
                                                    "share").lower():
            share = False

    for m in scanre.finditer(message.get_msg()):
        parse(uid, "scan", m.group(1), share).start()

    for m in scangrpre.finditer(message.get_msg()):
        parse(uid, "group", m.group(1), share).start()
Esempio n. 11
0
    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()
Esempio n. 12
0
    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()
Esempio n. 13
0
    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")
Esempio n. 14
0
    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")
Esempio n. 15
0
 def privmsg(self, text, target=None):
     # Privmsg someone. Target defaults to the person who triggered this line
     if (Config.has_option("Connection", "color") and not Config.has_option("NoColor", target) and not (target[0] in ['#','&'] and Config.has_option("NoColorChan", target[1:]))):
         self.write("PRIVMSG %s :%s" % (target or self.get_nick(), "\x03"+Config.get("Connection", "color")+text+"\x0F"), True)
     else:
         self.write("PRIVMSG %s :%s" % (target or self.get_nick(), text))