Example #1
0
    def execute(self, message, user, params):

        # do stuff here
        if params.group(1).lower() == Config.get("Connection","nick").lower():
            message.reply("I'll peck your eyes out, c**t.")
            return
        idiot = User.load(name=params.group(1), access="member")
        if idiot is None:
            message.reply("That user isn't a member!")
            return
        if (not user.is_admin()) and user != idiot and idiot.sponsor != user.name:
            message.reply("You do not have sufficent access to demote this member.")
            return
        
        if "galmate" in Config.options("Access"):
            idiot.access = Config.getint("Access","galmate")
        else:
            idiot.access = 0
        
        if idiot.planet is not None and idiot.planet.intel is not None:
            intel = idiot.planet.intel
            alliance = Alliance.load(Config.get("Alliance","name"))
            if intel.alliance == alliance:
                intel.alliance = None
        
        session.commit()
        
        message.privmsg("remuser %s %s"%(Config.get("Channels","home"), idiot.name,),'p')
        message.privmsg("remuser %s %s"%(Config.get("Channels","core"), idiot.name,),'p')
        if idiot.sponsor != user.name:
#            message.privmsg("note send %s You have been removed from private channels."%(idiot.name,),'p')
            message.reply("%s has been reduced to \"galmate\" level and removed from the channel. "%(idiot.name,))
        else:
#            message.privmsg("note send %s You have been removed from private channels."%(idiot.name,),'p')
            message.reply("%s has been reduced to \"galmate\" level and removed from the channel."%(idiot.name,))
Example #2
0
 def update_available_cookies(self, user):
     now = datetime.datetime.now()
     now = datetime.datetime(now.year,now.month,now.day)
     if not user.last_cookie_date or (now - user.last_cookie_date).days > 0:
         user.available_cookies = Config.getint("Alliance","cookies")
         user.last_cookie_date = current_timestamp()
         session.commit()
Example #3
0
    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,
                                ))
Example #4
0
    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)
Example #5
0
 def execute(self, request, user, id, x, y, z, when):
     planet = Planet.load(x,y,z)
     if planet is None:
         return self.attack(request, user, id, "No planet with coords %s:%s:%s" %(x,y,z,))
     
     tick = Updates.current_tick()
     when = int(when)
     if when < PA.getint("numbers", "protection"):
         eta = when
         when += tick
     elif when <= tick:
         return self.attack(request, user, id, "Can not book targets in the past. You wanted tick %s, but current tick is %s." % (when, tick,))
     else:
         eta = when - tick
     if when > 32767:
         when = 32767        
     
     if planet.intel and planet.alliance and planet.alliance.name == Config.get("Alliance","name"):
         return self.attack(request, user, id, "%s:%s:%s is %s in %s. Quick, launch before they notice!" % (x,y,z, planet.intel.nick or 'someone', Config.get("Alliance","name"),))
     
     try:
         planet.bookings.append(Target(user=user, tick=when))
         session.commit()
     except IntegrityError:
         session.rollback()
         target = planet.bookings.filter(Target.tick == when).first()
         if target is not None:
             return self.attack(request, user, id, "Target %s:%s:%s is already booked for landing tick %s by user %s" % (x,y,z, when, target.user.name,))
     else:
         return self.attack(request, user, id, "Booked landing on %s:%s:%s tick %s (eta %s) for user %s" % (x,y,z, when, (when-tick), user.name,))
     
     return self.attack(request, user, id)
Example #6
0
    def execute(self, message, user, params):

        # assign param variables
        alias = params.group(1)
        if alias is None:
            m = message.get_msg().split()
            if len(m) > 1 and m[1] in self.nulls:
                pass
            else:
                message.reply("You are %s, your alias is %s" % (
                    user.name,
                    user.alias,
                ))
                return

        if alias is not None:
            if User.load(name=alias) is not None:
                message.reply(
                    "Your alias is already in use or is someone else's pnick (not allowed). Tough noogies."
                )
                return
            if session.query(User).filter(User.active == True).filter(
                    User.alias.ilike(alias)).first() is not None:
                message.reply(
                    "Your alias is already in use or is someone else's pnick (not allowed). Tough noogies."
                )
                return

        user.alias = alias
        session.commit()
        message.reply("Update alias for %s (that's you) to %s" % (
            user.name,
            user.alias,
        ))
Example #7
0
File: remuser.py Project: JDD/DLR
    def execute(self, message, user, params):

        username = params.group(1)
        member = User.load(name=username, active=False)
        if member is None:
            message.alert("No such user '%s'" % (username,))
            return
        if member.access > user.access:
            message.reply(
                "You may not remove %s, his or her access (%s) exceeds your own (%s)"
                % (member.name, member.access, user.access)
            )
            return

        mbraxx = Config.getint("Access", "member")
        home = Config.get("Channels", "home")
        coraxx = Config.getint("Access", "core")
        core = Config.get("Channels", "core")

        if member.active and member.access >= mbraxx:
            message.privmsg("remuser %s %s" % (home, member.name), "P")
        if member.active and member.access >= coraxx:
            message.privmsg("remuser %s %s" % (core, member.name), "P")
        session.delete(member)
        session.commit()
        message.reply("Removed user %s" % (member.name,))
        CUT.untrack_user(member.name)
Example #8
0
    def execute(self, page, uid, pa_id, gid=None):
        scanlog("Scan: %s (group: %s)" %(pa_id,gid,))
        page = decode(page)
        
        m = re.search('>([^>]+) on (\d+)\:(\d+)\:(\d+) in tick (\d+)', page)
        if not m:
            scanlog("Expired/non-matchinng scan (id: %s)" %(pa_id,))
            return
        
        scantype = m.group(1)[0].upper()
        x = int(m.group(2))
        y = int(m.group(3))
        z = int(m.group(4))
        tick = int(m.group(5))

        m = re.search("<p class=\"right scan_time\">Scan time: ([^<]*)</p>", page)
        scantime = m.group(1)
        
        planet = Planet.load(x,y,z,)

        try:
            Q = session.query(Scan).filter(Scan.pa_id == pa_id).filter(Scan.planet_id == None)
            if Q.count() > 0:
                scan = Q.first()
            else:
                scan = Scan(pa_id=pa_id, scantype=scantype, tick=tick, time=scantime, group_id=gid, scanner_id=uid)
                session.add(scan)
            if planet:
                planet.scans.append(scan)
            session.commit()
            scan_id = scan.id
        except IntegrityError, e:
            session.rollback()
            scanlog("Scan %s may already exist: %s" %(pa_id,str(e),))
            return
Example #9
0
    def execute(self, message, user, params):

        # assign param variables 
        dists=params.group(1)
        user.dists = dists
        session.commit()
        message.reply("Update your distorters to %s"%(user.dists,))
Example #10
0
    def parse_N(self, scan_id, scan, page):
        #incoming fleets
        #<td class=left valign=top>Incoming</td><td valign=top>851</td><td class=left valign=top>We have detected an open jumpgate from Tertiary, located at 18:5:11. The fleet will approach our system in tick 855 and appears to have roughly 95 ships.</td>
        for m in re.finditer('<td class="left" valign="top">Incoming</td><td valign="top">(\d+)</td><td class="left" valign="top">We have detected an open jumpgate from ([^<]+), located at (\d+):(\d+):(\d+). The fleet will approach our system in tick (\d+) and appears to have roughly (\d+) ships.</td>', page):
            fleetscan = FleetScan()

            newstick = m.group(1)
            fleetname = m.group(2)
            originx = m.group(3)
            originy = m.group(4)
            originz = m.group(5)
            arrivaltick = int(m.group(6))
            numships = m.group(7)

            fleetscan.mission = "Unknown"
            fleetscan.fleet_name = fleetname
            fleetscan.launch_tick = newstick
            fleetscan.landing_tick = arrivaltick
            fleetscan.fleet_size = numships

            owner=Planet.load(originx,originy,originz)
            if owner is None:
                continue
            fleetscan.owner = owner
            fleetscan.target = scan.planet
            try:
                scan.fleets.append(fleetscan)
                session.commit()
            except Exception, e:
                session.rollback()
                print "Exception in news: "+e.__str__()
                traceback.print_exc()
                continue

            print 'Incoming: ' + newstick + ':' + fleetname + '-' + originx + ':' + originy + ':' + originz + '-' + arrivaltick + '|' + numships
Example #11
0
    def cancel(self, message, user, params):
        id = params.group(1)
        prop = self.load_prop(id)
        if prop is None:
            message.reply("No proposition number %s exists (idiot)." % (id, ))
            return
        if not prop.active:
            message.reply("You can't cancel prop %d, it's already expired." %
                          (prop.id, ))
            return
        if prop.proposer is not user and not user.is_admin():
            message.reply("Only %s may cancel proposition %d." %
                          (prop.proposer.name, prop.id))
            return

        self.recalculate_carebears(prop)

        yes, no, veto = self.sum_votes(prop)
        vote_result = "cancel"

        reply = self.text_result(vote_result, yes, no, veto)
        reply += self.text_summary(prop)
        message.reply(reply)

        prop.active = False
        prop.closed = current_timestamp()
        prop.vote_result = vote_result
        session.commit()
Example #12
0
 def execute(self, page, uid, pa_id, gid=None):
     scanlog("Scan: %s (group: %s)" %(pa_id,gid,))
     page = decode(page)
     
     m = re.search('>([^>]+) on (\d+)\:(\d+)\:(\d+) in tick (\d+)', page)
     if not m:
         scanlog("Expired/non-matchinng scan (id: %s)" %(pa_id,))
         return
     
     scantype = m.group(1)[0].upper()
     x = int(m.group(2))
     y = int(m.group(3))
     z = int(m.group(4))
     tick = int(m.group(5))
     
     planet = Planet.load(x,y,z)
     if planet is None:
         return
     try:
         scan = Scan(pa_id=pa_id, scantype=scantype, tick=tick, group_id=gid, scanner_id=uid)
         planet.scans.append(scan)
         session.commit()
         scan_id = scan.id
     except IntegrityError, e:
         session.rollback()
         scanlog("Scan %s may already exist: %s" %(pa_id,str(e),))
         return
Example #13
0
    def kick(self, message, user, params):
        person = params.group(1)
        if person.lower() == Config.get("Connection", "nick").lower():
            message.reply("I'll peck your eyes out, c**t.")
            return
        u = User.load(name=person, access="member")
        if u is None:
            message.reply(
                "Stupid %s, you can't kick %s, they're not a member." %
                (user.name, person))
            return
        if self.is_already_proposed_kick(person):
            message.reply("Silly %s, there's already a proposal to kick %s." %
                          (user.name, person))
            return
        if u.access > user.access:
            message.reply(
                "Unfortunately I like %s more than you. So none of that." %
                (u.name, ))
            return

        prop = Kick(proposer=user, kicked=u, comment_text=params.group(2))
        session.add(prop)
        session.commit()

        reply = "%s created a new proposition (nr. %d) to kick %s." % (
            user.name, prop.id, person)
        reply += " When people have been given a fair shot at voting you can call a count using !prop expire %d." % (
            prop.id, )
        message.reply(reply)
Example #14
0
def rollback(message):
    """Rollback to a given tick. Tick must be repeated for confirmation."""
    
    msg = message.get_msg().split()[1:]
    if len(msg) != 2:
        message.reply("rollback <tick> <tick>")
        return
    if msg[0] != msg[1]:
        message.reply("Ticks must match!")
        return
    if not msg[0].isdigit():
        message.reply("Ticks should be numeric.")
        return
    if int(msg[0]) > Updates.current_tick():
        message.reply("Timetravel module not installed. Cannot rollback to a future tick.")
        return

    session.execute(text("DELETE FROM updates WHERE id > %s;" % (msg[0])))
    session.execute(text("DELETE FROM planet_exiles WHERE tick > %s;" % (msg[0])))
    session.execute(text("DELETE FROM planet_idles WHERE tick > %s;" % (msg[0])))
    session.execute(text("DELETE FROM planet_value_drops WHERE tick > %s;" % (msg[0])))
    session.execute(text("DELETE FROM planet_landings WHERE tick > %s;" % (msg[0])))
    session.execute(text("DELETE FROM planet_landed_on WHERE tick > %s;" % (msg[0])))
    session.execute(text("DELETE from galaxy_history where tick > %s;" % (msg[0])))
    session.execute(text("DELETE from planet_history where tick > %s;" % (msg[0])))
    session.execute(text("DELETE from alliance_history where tick > %s;" % (msg[0])))
    session.execute(text("DELETE from cluster_history where tick > %s;" % (msg[0])))

    session.commit()
    message.reply("Rollback complete. Bot will update at next tick.")
Example #15
0
    def execute(self, message, user, params):

        # assign param variables 
        amp=params.group(1)
        user.amps = amp
        session.commit()
        message.reply("Update your Amplifiers to %s"%(user.amps,))
Example #16
0
    def new(self, message, user, params):
        tick = Updates.current_tick()
        comment = params.group(3) or ""
        when = int(params.group(1))
        if when < PA.getint("numbers", "protection"):
            eta = when
            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
        else:
            eta = when - tick
        if when > 32767:
            when = 32767

        attack = Attack(landtick=when, comment=comment)
        session.add(attack)

        for coord in re.findall(loadable.coord, params.group(2)):
            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))
Example #17
0
    def execute(self, message, user, params):
        
        fleetcount = int(params.group(1))
        comment = params.group(2)
        reply = ""

        if user.planet:
            scan = user.planet.scan("A")
            if scan is None:
                message.reply("Advanced Unit Scan not found for %s:%s:%s" % (user.planet.x, user.planet.y, user.planet.z))
                return
        else:
            message.reply("Planet not set. Use !pref planet=x:y:z")
            return

        scanage = Updates.current_tick() - scan.tick
        if scanage > 12:
            reply += "Warning: Scan is %d ticks old.\n" % scanage

        self.update_comment_and_fleetcount(user, fleetcount, comment)
        user.fleets.delete()
        for uscan in scan.units:
            user.fleets.append(UserFleet(ship_id=uscan.ship_id, ship_count=uscan.amount))
        session.commit()

        ships = user.fleets.all()
        
        reply += "Updated your def info to: fleetcount %s, updated: pt%s ships: " % (user.fleetcount, user. fleetupdated)
        reply += ", ".join(map(lambda x:"%s %s" % (self.num2short(x.ship_count), x.ship.name), ships))
        reply += " and comment: %s" %(user.fleetcomment)
        message.reply(reply)
Example #18
0
    def execute(self, message, user, params):

        # do stuff here
        if params.group(1).lower() == Config.get("Connection","nick").lower():
            message.reply("I'll peck your eyes out, c**t.")
            return
        idiot = User.load(name=params.group(1), access="member")
        if idiot is None:
            message.reply("That idiot isn't a member!")
            return
        if (not user.is_admin()) and user != idiot and idiot.sponsor != user.name:
            message.reply("You are not %s's sponsor"%(idiot.name,))
            return
        
        if "galmate" in Config.options("Access"):
            idiot.access = Config.getint("Access","galmate")
        else:
            idiot.access = 0
        
        if idiot.planet is not None and idiot.planet.intel is not None:
            intel = idiot.planet.intel
            alliance = Alliance.load(Config.get("Alliance","name"))
            if intel.alliance == alliance:
                intel.alliance = None
        
        session.commit()
        
        message.privmsg("remuser %s %s"%(Config.get("Channels","home"), idiot.name,),Config.get("Services", "nick"))
        message.privmsg("ban %s *!*@%s.%s Your sponsor doesn't like you anymore"%(Config.get("Channels","home"), idiot.name, Config.get("Services", "usermask"),),Config.get("Services", "nick"))
        if idiot.sponsor != user.name:
            message.privmsg("note send %s Some admin has removed you for whatever reason. If you still wish to be a member, go ahead and find someone else to sponsor you back."%(idiot.name,),Config.get("Services", "nick"))
            message.reply("%s has been reduced to \"galmate\" level and removed from the channel. %s is no longer %s's sponsor. If anyone else would like to sponsor that person back, they may."%(idiot.name,idiot.sponsor,idiot.name))
        else:
            message.privmsg("note send %s Your sponsor (%s) no longer wishes to be your sponsor. If you still wish to be a member, go ahead and find someone else to sponsor you back."%(idiot.name,user.name,),Config.get("Services", "nick"))
            message.reply("%s has been reduced to \"galmate\" level and removed from the channel. You are no longer %s's sponsor. If anyone else would like to sponsor that person back, they may."%(idiot.name,idiot.name))
Example #19
0
    def execute(self, message, user, params):

        username = params.group(1)
        member = User.load(name=username, active=False)
        if member is None:
            message.alert("No such user '%s'" % (username, ))
            return
        if member.access > user.access:
            message.reply(
                "You may not remove %s, his or her access (%s) exceeds your own (%s)"
                % (
                    member.name,
                    member.access,
                    user.access,
                ))
            return

        mbraxx = Config.getint("Access", "member")
        home = Config.get("Channels", "home")

        if member.active and member.access >= mbraxx:
            message.privmsg("remuser %s %s" % (
                home,
                member.name,
            ), Config.get("Services", "nick"))
#            message.privmsg("ban %s *!*@%s.%s GTFO, EAAD"%(home, member.name, Config.get("Services", "usermask"),), Config.get("Services", "nick"))
        session.delete(member)
        session.commit()
        message.reply("Removed user %s" % (member.name, ))
        CUT.untrack_user(member.name)
Example #20
0
 def scan(self, uid, pa_id, gid=None):
     page = urlopen(Config.get("URL","viewscan")%(pa_id,)).read()
     page = decode(page)
     
     m = re.search('>([^>]+) on (\d+)\:(\d+)\:(\d+) in tick (\d+)', page)
     if not m:
         print "Expired/non-matchinng scan (id: %s)" %(pa_id,)
         return
     
     scantype = m.group(1)[0].upper()
     x = int(m.group(2))
     y = int(m.group(3))
     z = int(m.group(4))
     tick = int(m.group(5))
     
     planet = Planet.load(x,y,z)
     if planet is None:
         return
     try:
         scan = Scan(pa_id=pa_id, scantype=scantype, tick=tick, group_id=gid, scanner_id=uid)
         planet.scans.append(scan)
         session.commit()
         scan_id = scan.id
     except IntegrityError, e:
         session.rollback()
         print "Scan %s may already exist" %(pa_id,)
         print e.__str__()
         return
Example #21
0
    def execute(self, message, user, params):

        # do stuff here
        if params.group(1).lower() == Config.get("Connection","nick").lower():
            message.reply("I'll peck your eyes out, c**t.")
            return
        idiot = User.load(name=params.group(1), access="member")
        if idiot is None:
            message.reply("That idiot isn't a member!")
            return
        if (not user.is_admin()) and user != idiot and idiot.sponsor != user.name:
            message.reply("You are not %s's sponsor"%(idiot.name,))
            return
        
        if "galmate" in Config.options("Access"):
            idiot.access = Config.getint("Access","galmate")
        else:
            idiot.access = 0
        
        if idiot.planet is not None and idiot.planet.intel is not None:
            intel = idiot.planet.intel
            alliance = Alliance.load(Config.get("Alliance","name"))
            if intel.alliance == alliance:
                intel.alliance = None
        
        session.commit()
        
        message.privmsg("remuser %s %s"%(Config.get("Channels","home"), idiot.name,),'p')
        message.privmsg("ban %s *!*@%s.users.netgamers.org Your sponsor doesn't like you anymore"%(Config.get("Channels","home"), idiot.name,),'p')
        if idiot.sponsor != user.name:
            message.privmsg("note send %s Some admin has removed you for whatever reason. If you still wish to be a member, go ahead and find someone else to sponsor you back."%(idiot.name,),'p')
            message.reply("%s has been reduced to \"galmate\" level and removed from the channel. %s is no longer %s's sponsor. If anyone else would like to sponsor that person back, they may."%(idiot.name,idiot.sponsor,idiot.name))
        else:
            message.privmsg("note send %s Your sponsor (%s) no longer wishes to be your sponsor. If you still wish to be a member, go ahead and find someone else to sponsor you back."%(idiot.name,user.name,),'p')
            message.reply("%s has been reduced to \"galmate\" level and removed from the channel. You are no longer %s's sponsor. If anyone else would like to sponsor that person back, they may."%(idiot.name,idiot.name))
Example #22
0
 def invite(self, message, user, params):
     person = params.group(1)
     if person.lower() == Config.get("Connection","nick").lower():
         message.reply("I am already here, shitface.")
         return
     u = User.load(name=person,access="member")
     if u is not None:
         message.reply("Stupid %s, that wanker %s is already a member."%(user.name,person))
         return
     if self.is_already_proposed_invite(person):
         message.reply("Silly %s, there's already a proposal to invite %s."%(user.name,person))
         return
     if not self.member_count_below_limit():
         message.reply("You have tried to invite somebody, but we have too many losers and I can't be bothered dealing with more than %s of you."%(Config.getint("Alliance", "members"),))
         return
     anc = user.has_ancestor(person)
     if anc is True:
         message.reply("Ew, incest.")
         return
     if anc is None:
         message.reply("Filthy orphans should be castrated.")
         return
     
     prop = Invite(proposer=user, person=person, comment_text=params.group(2))
     session.add(prop)
     session.commit()
     
     reply = "%s created a new proposition (nr. %d) to invite %s." %(user.name, prop.id, person)
     reply+= " When people have been given a fair shot at voting you can call a count using !prop expire %d."%(prop.id,)
     message.reply(reply)
Example #23
0
File: prop.py Project: JDD/merlin
 def cancel(self, message, user, params):
     id = params.group(1)
     prop = self.load_prop(id)
     if prop is None:
         message.reply("No proposition number %s exists (idiot)."%(id,))
         return
     if not prop.active:
         message.reply("You can't cancel prop %d, it's already expired."%(prop.id,))
         return
     if prop.proposer is not user and not user.is_admin():
         message.reply("Only %s may cancel proposition %d."%(prop.proposer.name,prop.id))
         return
     
     self.recalculate_carebears(prop)
     
     yes, no, veto = self.sum_votes(prop)
     vote_result = "cancel"
     
     reply = self.text_result(vote_result, yes, no, veto)
     reply+= self.text_summary(prop)
     message.reply(reply)
     
     prop.active = False
     prop.closed = current_timestamp()
     prop.vote_result = vote_result
     session.commit()
Example #24
0
File: prop.py Project: JDD/merlin
 def invite(self, message, user, params):
     person = params.group(1)
     if person.lower() == Config.get("Connection","nick").lower():
         message.reply("I am already here, shitface.")
         return
     u = User.load(name=person,access="member")
     if u is not None:
         message.reply("Stupid %s, that wanker %s is already a member."%(user.name,person))
         return
     if self.is_already_proposed_invite(person):
         message.reply("Silly %s, there's already a proposal to invite %s."%(user.name,person))
         return
     if not self.member_count_below_limit():
         message.reply("You have tried to invite somebody, but we have too many losers and I can't be bothered dealing with more than %s of you."%(Config.getint("Alliance", "members"),))
         return
     anc = user.has_ancestor(person)
     if anc is True:
         message.reply("Ew, incest.")
         return
     if anc is None:
         message.reply("Filthy orphans should be castrated.")
         return
     
     prop = Invite(id=self.new_prop_id(), proposer=user, person=person, comment_text=params.group(2))
     session.add(prop)
     session.commit()
     
     reply = "%s created a new proposition (nr. %d) to invite %s." %(user.name, prop.id, person)
     reply+= " When people have been given a fair shot at voting you can call a count using !prop expire %d."%(prop.id,)
     message.reply(reply)
Example #25
0
 def authenticate(self, request):
     request.session = None
     request.user = None
     key = request.COOKIES.get(SESSION_KEY)
     if key:
         auth = Arthur.load(key, datetime.now())
         if auth is None:
             raise UserError("Your session has expired, please login again.")
         if request.path == LOGOUT:
             session.delete(auth)
             session.commit()
             raise UserError("Logged out.")
         request.session = auth
         return auth.user, None, key
     elif (request.POST.get(USER) and request.POST.get(PASS)):
         user = User.load(name=request.POST.get(USER), passwd=request.POST.get(PASS))
         if user is None:
             raise UserError("Invalid user.")
         else:
             key = self.generate_key(user)
             auth = Arthur(key=key, expire=datetime.now()+timedelta(days=1), user=user)
             session.query(Arthur).filter(Arthur.user == user).delete()
             session.add(auth)
             session.commit()
             request.session = auth
             return user, key, key
     else:
         return None, None, None
Example #26
0
 def remove(self, message, user, params):
     id = int(params.group(1))
     attack = Attack.load(id)
     if attack is None:
         message.alert("No attack exists with id %d" %(id))
         return
     
     for coord in re.findall(loadable.coord, params.group(2)):
         if not coord[4]:
             galaxy = Galaxy.load(coord[0],coord[2], active=False)
             if galaxy:
                 attack.removeGalaxy(galaxy)
         
         else:
             planet = Planet.load(coord[0],coord[2],coord[4], active=False)
             if planet:
                 attack.removePlanet(planet)
     
     if not len(attack.planets):
         session.delete(attack)
     
     session.commit()
     
     if attack in session:
         message.reply(str(attack))
     else:
         message.reply("Deleted Attack %d LT: %d | %s" %(attack.id,attack.landtick,attack.comment,))
Example #27
0
 def land(self, message, user, params):
     id = int(params.group(1))
     attack = Attack.load(id)
     if attack is None:
         message.alert("No attack exists with id %d" %(id))
         return
     
     tick = Updates.current_tick()
     when = int(params.group(2))
     
     if when == 0:
         session.delete(attack)
         session.commit()
         message.reply("Deleted Attack %d LT: %d | %s" %(attack.id,attack.landtick,attack.comment,))
         return
     
     if when < PA.getint("numbers", "protection"):
         eta = when
         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
     else:
         eta = when - tick
     if when > 32767:
         when = 32767
     
     old = attack.landtick
     attack.landtick = when
     
     session.commit()
     message.reply("Changed LT for attack %d from %d to %d"%(id,old,when))
Example #28
0
    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

        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)
Example #29
0
 def run(self, message):
     m = self.match(message, self.commandre)
     if m is None:
         if self.match(message, self.helpre) is not None:
             self.help(message)
         return
     command = m.group(2)
     
     try:
         route, subcommand, user, params = self.router(message, command)
         
         route(message, user, params)
         
         session = Session()
         session.add(Command(command_prefix = message.get_prefix(),
                             command = self.name,
                             subcommand = subcommand,
                             command_parameters = self.hide_passwords(self.name, message.get_msg()[len(m.group(1))+1:].strip()),
                             nick = message.get_nick(),
                             username = "" if user is True else user.name,
                             hostname = message.get_hostmask(),
                             target = message.get_chan() if message.in_chan() else message.get_nick(),))
         session.commit()
         session.close()
         
     except PNickParseError:
         message.alert(self.PParseError)
     except UserError:
         message.alert(self.AccessError)
     except PrefError:
         message.alert(self.PrefError)
     except ChanParseError, e:
         message.alert(self.ChanError%e)
Example #30
0
    def execute(self, message, user, params):

        channel = params.group(1)
        chan = Channel.load(channel)
        if chan is None:
            message.reply("Channel '%s' does not exist" % (channel, ))
            if user.is_admin():
                #                message.privmsg("remuser %s %s" %(channel, Config.get('Connection', 'nick')),Config.get("Services", "nick"))
                message.privmsg("set %s autoinvite off" % (channel),
                                Config.get("Services", "nick"))
                message.part(channel)
            return

        if chan.userlevel >= user.access and not user.is_admin():
            message.reply(
                "You may not remove %s, the channel's access (%s) exceeds your own (%s)"
                % (
                    chan.name,
                    chan.userlevel,
                    user.access,
                ))
            return

        session.delete(chan)
        session.commit()

        #        message.privmsg("remuser %s %s" %(chan.name, Config.get('Connection', 'nick')),Config.get("Services", "nick"))
        message.privmsg("set %s autoinvite off" % (channel),
                        Config.get("Services", "nick"))
        message.part(chan.name)
        message.reply("Removed channel %s" % (chan.name, ))
Example #31
0
 def update_available_cookies(self, user):
     now = datetime.datetime.now()
     now = datetime.datetime(now.year, now.month, now.day)
     if not user.last_cookie_date or (now - user.last_cookie_date).days > 0:
         user.available_cookies = Config.getint("Alliance", "cookies")
         user.last_cookie_date = current_timestamp()
         session.commit()
Example #32
0
def main(url=Config.get("URL", "ships"), debug=False):
    stats = urllib2.urlopen(url).read()
    session.execute(Ship.__table__.delete())
    session.execute(
        text("SELECT setval('ships_id_seq', 1, :false);", bindparams=[false]))

    for line in sre.findall(stats):
        ship = Ship()
        line = list(line)
        for index, key in enumerate(keys):
            if line[index] in mapping:
                line[index] = mapping[line[index]]
            elif line[index].isdigit():
                line[index] = int(line[index])
            if line[index] not in (
                    '-',
                    '',
            ):
                setattr(ship, key, line[index])
        ship.total_cost = ship.metal + ship.crystal + ship.eonium
        if debug:
            print "%12s%12s%12s%12s" % (
                ship.name,
                ship.class_,
                ship.race,
                ship.type,
            )

        session.add(ship)

    session.commit()
    session.close()
Example #33
0
def main(url = Config.get("URL", "ships"), debug=False):
    req = urllib2.Request(url)
    req.add_header('User-Agent', useragent)
    stats = urllib2.urlopen(req).read()
    session.execute(Ship.__table__.delete())
    if Config.get("DB", "dbms") == "mysql":
        session.execute(text("ALTER TABLE ships AUTO_INCREMENT=1;", bindparams=[false]))
    else:
        session.execute(text("SELECT setval('ships_id_seq', 1, :false);", bindparams=[false]))
    
    for line in sre.findall(stats):
        ship = Ship()
        line = list(line)
        for index, key in enumerate(keys):
            if line[index] in mapping:
                line[index] = mapping[line[index]]
            elif line[index].isdigit():
                line[index] = int(line[index])
            if line[index] not in ('-', '',):
                setattr(ship,key,line[index])
        ship.total_cost = ship.metal + ship.crystal + ship.eonium
        if debug: print "%12s%12s%12s%12s" % (ship.name, ship.class_, ship.race, ship.type,)
        
        session.add(ship)
    
    session.commit()
    session.close()
Example #34
0
    def execute(self, message, user, params):

        adoptee = params.group(1)
        if adoptee.lower() == Config.get("Connection", "nick").lower():
            message.reply("F**k off you stupid twat, stop trying to be a clever shit.")
            return
        if adoptee.lower() == user.name.lower():
            message.reply("Stop wanking your own dick and find a daddy to do it for you, retard.")
            return

        a = User.load(name=adoptee, access="member")
        if a is None:
            message.reply("No members matching '%s'" % (adoptee,))
            return

        s = User.load(name=a.sponsor, access="member") if a.sponsor else None
        if s is not None:
            message.reply("%s already has a daddy you filthy would-be kidnapper!" % (a.name,))
            return

        anc = user.has_ancestor(a.name)
        if anc is True:
            message.reply("Ew, incest.")
            return
        if anc is None:
            message.reply("Filthy orphans should be castrated.")
            return

        a.sponsor = user.name
        session.commit()
        message.reply("Congratulations! You're now the proud father of a not-so newly born %s!" % (a.name,))
Example #35
0
    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)
Example #36
0
    def run(self, request, **kwargs):
        try:
            user, cookie, key, planet_id = self.router(request)
            response = self.execute(request, user, **kwargs)

            session = Session()
            session.add(
                PageView(
                    page=self.name,
                    full_request=request.get_full_path(),
                    username=user.name,
                    session=key,
                    planet_id=user.planet.id if user.planet else None,
                    hostname=request.META['REMOTE_ADDR'],
                ))
            session.commit()

            if cookie is not None:
                response.set_cookie(SESSION_KEY,
                                    cookie,
                                    expires=request.session.expire)

            if planet_id is False:
                response.delete_cookie(PLANET_KEY)
            elif planet_id is not True:
                response.set_cookie(PLANET_KEY,
                                    planet_id,
                                    expires=datetime.now() +
                                    timedelta(days=65))

            return response

        except UserError, e:
            return self.login_page(request, str(e))
Example #37
0
    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)
Example #38
0
 def run(self, request, **kwargs):
     try:
         user, cookie, key, planet_id = self.router(request)
         response = self.execute(request, user, **kwargs)
         
         session = Session()
         session.add(PageView(page = self.name,
                              full_request = request.get_full_path(),
                              username = user.name,
                              session = key,
                              planet_id = user.planet.id if user.planet else None,
                              hostname = request.META['REMOTE_ADDR'],))
         session.commit()
         
         if cookie is not None:
             response.set_cookie(SESSION_KEY, cookie, expires=request.session.expire)
         
         if planet_id is False:
             response.delete_cookie(PLANET_KEY)
         elif planet_id is not True:
             response.set_cookie(PLANET_KEY, planet_id, expires=datetime.now()+timedelta(days=65))
         
         return response
     
     except UserError, e:
         return self.login_page(request, str(e))
Example #39
0
    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
Example #40
0
 def execute(self, message, user, params):
     
     chan = params.group(1)
     access = params.group(2)
     if not access.isdigit():
         try:
             access = Config.getint("Access",access)
         except Exception:
             message.reply("Invalid access level '%s'" % (access,))
             return
     else:
         access = int(access)
     
     if access > user.access:
         message.reply("You may not add a user with higher access to your own")
         return
     
     try:
         session.add(Channel(name=chan, userlevel=access, maxlevel=user.access))
         session.commit()
         message.reply("Added chan %s at level %s" % (chan,access,))
         message.privmsg("set %s autoinvite on" %(chan,),Config.get("Services", "nick"));
         message.privmsg("invite %s" %(chan,),Config.get("Services", "nick"));
     except IntegrityError:
         session.rollback()
         message.reply("Channel %s already exists" % (chan,))
Example #41
0
 def authenticate(self, request):
     request.session = None
     request.user = None
     key = request.COOKIES.get(SESSION_KEY)
     if key:
         auth = Arthur.load(key, datetime.now())
         if auth is None:
             raise UserError(
                 "Your session has expired, please login again.")
         if request.path == LOGOUT:
             session.delete(auth)
             session.commit()
             raise UserError("Logged out.")
         request.session = auth
         return auth.user, None, key
     elif (request.REQUEST.get(USER) and request.REQUEST.get(PASS)):
         user = User.load(name=request.REQUEST.get(USER),
                          passwd=request.REQUEST.get(PASS))
         if user is None:
             raise UserError("Invalid user.")
         else:
             key = self.generate_key(user)
             auth = Arthur(key=key,
                           expire=datetime.now() + timedelta(days=1),
                           user=user)
             session.query(Arthur).filter(Arthur.user == user).delete()
             session.add(auth)
             session.commit()
             request.session = auth
             return user, key, key
     else:
         return None, None, None
Example #42
0
    def execute(self, message, user, params):

        chan = params.group(1)
        access = params.group(2)
        if not access.isdigit():
            try:
                access = Config.getint("Access", access)
            except Exception:
                message.reply("Invalid access level '%s'" % (access,))
                return
        else:
            access = int(access)

        if access > user.access:
            message.reply("You may not add a user with higher access to your own")
            return

        try:
            session.add(Channel(name=chan, userlevel=access, maxlevel=user.access))
            session.commit()
            message.reply("Added chan %s at level %s" % (chan, access))
            message.privmsg("set %s autoinvite on" % (chan,), Config.get("Services", "nick"))
            message.privmsg("invite %s" % (chan,), Config.get("Services", "nick"))
        except IntegrityError:
            session.rollback()
            message.reply("Channel %s already exists" % (chan,))
Example #43
0
File: sms.py Project: berten/merlin
 def log_message(self, sender, receiver, phone, text, mode):
     session.add(
         SMS(sender=sender,
             receiver=receiver,
             phone=phone,
             sms_text=text,
             mode=mode))
     session.commit()
Example #44
0
 def suggest(self,message,user,params):
     prop = Suggestion(proposer=user, comment_text=params.group(1))
     session.add(prop)
     session.commit()
     
     reply = "%s created a new proposition (nr. %d) : %s" %(user.name,prop.id,prop.comment_text)
     reply+= " When people have been given a fair shot at voting you can call a count using !prop expire %d."%(prop.id,)
     message.reply(reply)
Example #45
0
 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,))
Example #46
0
File: prop.py Project: JDD/merlin
 def suggest(self,message,user,params):
     prop = Suggestion(id=self.new_prop_id(), proposer=user, comment_text=params.group(1))
     session.add(prop)
     session.commit()
     
     reply = "%s created a new proposition (nr. %d) : %s" %(user.name,prop.id,prop.comment_text)
     reply+= " When people have been given a fair shot at voting you can call a count using !prop expire %d."%(prop.id,)
     message.reply(reply)
Example #47
0
 def execute(self, message, user, params):
     
     params = params.group(1)
     params=self.timestampre.sub(' ',params).strip()
     
     session.add(Slogan(text=params))
     session.commit()
     
     message.reply("Added your shitty slogan: "+params)
Example #48
0
    def execute(self, message, user, params):

        params = params.group(1)
        params = self.timestampre.sub(' ', params).strip()

        session.add(Quote(text=params))
        session.commit()

        message.reply("Added your shitty quote: " + params)
Example #49
0
 def execute(self, message, user, params):
     alliance = Alliance.load(params.group(1), alias=False)
     if alliance is None:
         message.reply("There's no morons playing under the tag %s" % (params.group(1),))
         return
     
     alliance.alias = params.group(2)
     session.commit()
     message.reply("That f****d up tag %s has been aliased to %s" % (alliance.name, alliance.alias,))
Example #50
0
    def execute(self, message, user, params):

        # Sort out parameters
        chan = params.group(1)
        access = params.group(2)
        maxaccess = params.group(3)

        # Load Channel
        c = Channel.load(chan)
        if c is None:
            message.reply("'%s'? Is that even a channel?" % (chan, ))
            return
        elif c.userlevel > user.access:
            message.reply(
                "You may not edit a channel with higher access than you")

        # Parse access
        if not access.isdigit():
            try:
                access = Config.getint("Access", access)
            except Exception:
                message.reply("Invalid access level '%s'" % (access, ))
                return
        else:
            access = int(access)

        if access > user.access:
            message.reply(
                "You may not give a channel a higher access level than your own"
            )
            return

        # Parse maxaccess
        if maxaccess:
            if not maxaccess.isdigit():
                try:
                    maxaccess = Config.getint("Access", maxaccess)
                except Exception:
                    message.reply("Invalid access level '%s'" % (maxaccess, ))
                    return
            else:
                maxaccess = int(maxaccess)

            if maxaccess > user.access:
                message.reply(
                    "You may not give a channel a higher access level than your own"
                )
                return

        c.userlevel = access
        if maxaccess:
            c.maxlevel = maxaccess
        session.commit()
        message.reply("Edited channel %s access to %s%s" %
                      (chan, access,
                       (" (max: %s)" % maxaccess) if maxaccess else ""))
Example #51
0
    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)
        planetscan.res_metal = m.group(2)
        planetscan.roid_crystal = m.group(3)
        planetscan.res_crystal = m.group(4)
        planetscan.roid_eonium = m.group(5)
        planetscan.res_eonium = m.group(6)

        #        m=re.search(r"""
        #            <tr><th[^>]*>Value</th><th[^>]*>Score</th></tr>\s*
        #            <tr><td[^>]*>(\d+)</td><td[^>]*>(\d+)</td></tr>\s*
        #        """,page,re.VERBOSE)
        #
        #        value = m.group(1)
        #        score = m.group(2)

        m = re.search(
            r"""
            <tr><th[^>]*>Agents</th><th[^>]*>Security\s+Guards</th></tr>\s*
            <tr><td[^>]*>([^<]+)</td><td[^>]*>([^<]+)</td></tr>\s*
        """, page, re.VERBOSE)

        planetscan.agents = m.group(1)
        planetscan.guards = m.group(2)

        m = re.search(
            r"""
            <tr><th[^>]*>Light</th><th[^>]*>Medium</th><th[^>]*>Heavy</th></tr>\s*
            <tr><td[^>]*>([^<]+)</td><td[^>]*>([^<]+)</td><td[^>]*>([^<]+)</td></tr>
        """, page, re.VERBOSE)

        planetscan.factory_usage_light = m.group(1)
        planetscan.factory_usage_medium = m.group(2)
        planetscan.factory_usage_heavy = m.group(3)

        #atm the only span tag is the one around the hidden res.
        m = re.findall(r"""<span[^>]*>(\d+)</span>""", page, re.VERBOSE)

        planetscan.prod_res = m[0]
        planetscan.sold_res = m[1]

        session.commit()
Example #52
0
 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
Example #53
0
 def drop_ships(self, user, taker, ships):
     removed = {}
     tick = Updates.current_tick()
     for name in ships.split():
         ship = Ship.load(name=name)
         if ship is None:
             continue
         for fleet in user.fleets.filter_by(ship=ship):
             removed[fleet.ship.name] = fleet.ship_count
             self.delete_ships(user, taker, fleet, tick)
     session.commit()
     return removed
Example #54
0
    def check_planet(self, request, user):
        coords = request.REQUEST.get(PLANET) or ""

        if coords == "Clear":
            if self.user_has_planet(user):
                user.planet = None
                session.commit()
            return False

        m = self.coord.match(coords)
        if m:
            planet = Planet.load(*m.group(1, 3, 5))
        else:
            planet = None

        if planet is not None:
            if self.is_user(user):
                user.planet = planet
                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
                session.commit()
            else:
                user.planet = planet
                session.expunge(user)
            return user.planet.id

        pa_id = request.COOKIES.get(PLANET_KEY)
        if self.user_has_planet(user):
            if pa_id == user.planet.id:
                return True
            else:
                return user.planet.id
        elif self.is_user(user):
            if pa_id:
                return False
            else:
                return True
        else:
            if pa_id:
                planet = session.query(Planet).filter_by(id=pa_id).first()
                if planet is None:
                    return False
                else:
                    user.planet = planet
                    session.expunge(user)
                    return True
            else:
                return True
Example #55
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))
Example #56
0
    def execute(self, message, user, params):

        pnicks = params.group(1)
        access = params.group(2)
        if not access.isdigit():
            try:
                access = Config.getint("Access", access)
            except Exception:
                message.reply("Invalid access level '%s'" % (access, ))
                return
        else:
            access = int(access)

        if access > user.access:
            message.reply(
                "You may not add a user with higher access to your own")
            return

        added = []
        exists = []
        for pnick in pnicks.split():
            if pnick.lower() == Config.get("Connection", "nick").lower():
                message.reply("I am already here, shitface.")
                continue
            member = User.load(name=pnick, active=False)
            if member is None:
                member = User(name=pnick, access=access, sponsor=user.name)
                session.add(member)
                added.append(pnick)
            elif not member.active:
                member.active = True
                member.access = access
                member.sponsor = user.name
                added.append(pnick)
            elif not member.is_member():
                member.access = access
                member.sponsor = user.name
                added.append(pnick)
            else:
                exists.append(pnick)
        session.commit()
        if len(exists):
            message.reply("Users (%s) already exist" % (",".join(exists), ))
        if len(added):
            message.reply("Added users (%s) at level %s" %
                          (",".join(added), access))
        if len(added) and access >= Config.getint("Access", "member"):
            message.privmsg(
                "adduser %s %s 24" % (
                    Config.get("Channels", "home"),
                    ",".join(added),
                ), Config.get("Services", "nick"))