Esempio n. 1
0
File: remuser.py Progetto: 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)
Esempio n. 2
0
 def execute(self, message, user, params):
     reply = ""
     tick = Updates.current_tick()
     opts = params.group(1).split()
     for o in reversed(Config.options("Access")):
         if ("galmates" not in opts) and (Config.getint("Access", o) == 0):
             continue
         Q = session.query(User)
         Q = Q.filter(User.access == Config.getint("Access", o))
         Q = Q.order_by(asc(User.name))
         result = Q.all()
         if len(result) < 1:
             continue
         printable = map(
             lambda (u): "%s%s%s%s%s" %
             (u.name, ' (' + u.alias + ')'
              if u.alias else '', " (%d:%d:%d)" %
              (u.planet.x, u.planet.y, u.planet.z)
              if "coords" in opts and u.planet is not None else '', " (%s)"
              % ((u.fleetupdated or 0) - tick)
              if "defage" in opts else '', " (%s)" % (u.fleetupdated or 0)
              if "mydef" in opts else ''), result)
         reply += "%s:  " % (o)
         reply += ', '.join(printable)
         reply += '\n'
     message.reply(reply[:-1])
Esempio n. 3
0
    def execute(self, request, user, message=None):
        tick = Updates.current_tick()

        Q = session.query(Attack)
        if user.access < (
                Config.getint("Access", "hc")
                if "hc" in Config.options("Access") else 1000
        ):  # Hide attacks until they are active, unless the user has access
            Q = Q.filter(
                Attack.landtick <= tick + Config.getint("Misc", "attactive"))
        Q = Q.filter(
            Attack.landtick + Attack.waves >=
            tick)  # Hide attacks one tick after the last wave has landed
        Q = Q.order_by(asc(Attack.id))
        attacks = Q.all()

        Q = session.query(Planet, Target.tick)
        Q = Q.join(Target.planet)
        Q = Q.join(Target.user)
        Q = Q.filter(Planet.active == True)
        Q = Q.filter(Target.user == user)
        Q = Q.filter(
            Target.tick >=
            tick - 12)  # We shouldn't need any bookings 12 ticks after landing
        Q = Q.order_by(asc(Target.tick), asc(Planet.x), asc(Planet.y),
                       asc(Planet.z))

        bookings = []
        scans = []
        for planet, tock in Q.all():
            bookings.append((
                planet,
                tock,
                [],
            ))
            if planet.scan("P"):
                bookings[-1][2].append(planet.scan("P"))
                scans.append(planet.scan("P"))

            if planet.scan("D"):
                bookings[-1][2].append(planet.scan("D"))
                scans.append(planet.scan("D"))

            if planet.scan("A") or planet.scan("U"):
                bookings[-1][2].append(planet.scan("A") or planet.scan("U"))
                scans.append(planet.scan("A") or planet.scan("U"))

            if tock <= tick + Config.getint("Misc", "attjgp") and planet.scan(
                    "J"):
                bookings[-1][2].append(planet.scan("J"))
                scans.append(planet.scan("J"))

        return render("attacks.tpl",
                      request,
                      message=message,
                      attacks=attacks,
                      bookings=bookings,
                      scans=scans)
Esempio n. 4
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 ""))
Esempio n. 5
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),))
     # Bot access    
     if len(added):
         message.reply("Added users (%s) at level %s" % (",".join(added),access))
     # P access with netgamers.org (set up to adduser with access 100 to your Home channel from merlin.cfg)
     if len(added) and access == Config.getint("Access","member"):
         message.privmsg("adduser %s %s 100" %(Config.get("Channels","home"), ",".join(added),), "P")
         message.reply("Added users (%s) to %s with lvl 100 access" % (",".join(added), Config.get("Channels","home")))
     if len(added) and access >= Config.getint("Access","core"):
         message.privmsg("adduser %s %s 150" %(Config.get("Channels","home"), ",".join(added),), "P")
         message.reply("Added users (%s) to %s with lvl 150 access" % (",".join(added), Config.get("Channels","home")))
         message.privmsg("adduser %s %s 150" %(Config.get("Channels","core"), ",".join(added),), "P")
         message.reply("Added users (%s) to %s with lvl 150 access" % (",".join(added), Config.get("Channels","core")))
Esempio n. 6
0
 def execute(self, message, user, params):
     
     username = params.group(1)
     access = params.group(2).lower()
     if access.isdigit():
         access = int(access)
     elif access in self.true:
         access = True
     elif access in self.false:
         access = False
     else:
         try:
             access = Config.getint("Access",access)
         except Exception:
             message.reply("Invalid access level '%s'" % (access,))
             return
     
     member = User.load(name=username, active=False)
     if member is None:
         message.alert("No such user '%s'" % (username,))
         return
     
     if type(access) is int and not member.active:
         message.reply("You should first re-activate user %s" %(member.name,))
         return
     
     if access > user.access or member.access > user.access:
         message.reply("You may not change access higher than your own")
         return
     
     mbraxx = Config.getint("Access","member")
     home = Config.get("Channels","home")
     
     if type(access) == int:
         if member.active == True and member.access < mbraxx and access >= mbraxx:
             message.privmsg("adduser %s %s 399" %(home, member.name,), Config.get("Services", "nick"))
             message.reply("%s has been added to %s"%(member.name, home,))
         if member.active == True and member.access >= mbraxx and 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"))
         member.access = access
     else:
         if member.active != access and access == True and member.access >= mbraxx:
             message.privmsg("adduser %s %s 399" %(home, member.name,), Config.get("Services", "nick"))
             message.reply("%s has been added to %s"%(member.name, home,))
         if member.active != access and access == False 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"))
         member.active = access
     session.commit()
     message.reply("Editted user %s access: %s" % (member.name, access,))
     if not member.active:
         CUT.untrack_user(member.name)
Esempio n. 7
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"))
Esempio n. 8
0
File: attack.py Progetto: JDD/merlin
 def list(self, message, user, params):
     Q = session.query(Attack)
     if user.access < (Config.getint("Access",  "hc") if "hc" in Config.options("Access") else 1000): # Hide attacks until they are active, unless the user has access
         Q = Q.filter(Attack.landtick <= Updates.current_tick() + Config.getint("Misc", "attactive"))
     Q = Q.filter(Attack.landtick + Attack.waves >= Updates.current_tick()) # Hide attacks one tick after the last wave has landed
     Q = Q.order_by(asc(Attack.id))
     
     replies = []
     for attack in Q:
         replies.append("(%d LT: %d %s)" %(attack.id,attack.landtick,attack.comment,))
     
     reply = "Open attacks: " + " ".join(replies)
     message.reply(reply)
Esempio n. 9
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 ""))
Esempio n. 10
0
    def execute(self, request, user, message=None):
        tick = Updates.current_tick()

        Q = session.query(Attack)
        Q = Q.filter(
            Attack.landtick >= tick - Config.getint("Misc", "attactive"))
        Q = Q.order_by(asc(Attack.id))
        attacks = Q.all()

        Q = session.query(Planet, Target.tick)
        Q = Q.join(Target.planet)
        Q = Q.join(Target.user)
        Q = Q.filter(Planet.active == True)
        Q = Q.filter(Target.user == user)
        Q = Q.filter(Target.tick >= tick - Config.getint("Misc", "attactive"))
        Q = Q.order_by(asc(Target.tick), asc(Planet.x), asc(Planet.y),
                       asc(Planet.z))

        bookings = []
        scans = []
        for planet, tock in Q.all():
            bookings.append((
                planet,
                tock,
                [],
            ))
            if planet.scan("P"):
                bookings[-1][2].append(planet.scan("P"))
                scans.append(planet.scan("P"))

            if planet.scan("D"):
                bookings[-1][2].append(planet.scan("D"))
                scans.append(planet.scan("D"))

            if planet.scan("A") or planet.scan("U"):
                bookings[-1][2].append(planet.scan("A") or planet.scan("U"))
                scans.append(planet.scan("A") or planet.scan("U"))

            if tock <= tick + Config.getint("Misc", "attjgp") and planet.scan(
                    "J"):
                bookings[-1][2].append(planet.scan("J"))
                scans.append(planet.scan("J"))

        return render("attacks.tpl",
                      request,
                      message=message,
                      attacks=attacks,
                      bookings=bookings,
                      scans=scans)
Esempio n. 11
0
def join(message):
    # Someone is joining a channel
    if message.get_nick() != Merlin.nick:
        # That someone is not the bot
        if Config.getint("Misc", "defage") > 0:
            # mydef reminders are enabled
            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. 12
0
    def show(self, message, user, params):
        id = params.group(1)
        attack = Attack.load(id)

        if attack is None:
            message.alert("No attack exists with id %s" % (id))
            return
        if user.access < (Config.getint("Access", "hc")
                          if "hc" in Config.options("Access") else
                          1000) and attack.landtick > Updates.current_tick(
                          ) + Config.getint("Misc", "attactive"):
            message.alert("Attack %s is not open yet" % (id))
            return

        message.reply(str(attack))
Esempio n. 13
0
    def execute(self, message, user, params):
        
        count = self.short2num(params.group(1) or "1")
        name = params.group(2)

        ship = Ship.load(name=name)
        if ship is None:
            message.alert("No Ship called: %s" % (name,))
            return
        
        Q = session.query(User, UserFleet)
        Q = Q.join(User.fleets)
        Q = Q.filter(User.active == True)
        Q = Q.filter(User.access >= Config.getint("Access", "member"))
        Q = Q.filter(UserFleet.ship == ship)
        Q = Q.filter(UserFleet.ship_count >= count)
        Q = Q.filter(User.fleetcount > 0)
        Q = Q.order_by(desc(UserFleet.ship_count))
        result = Q.all()
        
        if len(result) < 1:
            message.reply("There are no planets with free fleets and at least %s ships matching '%s'"%(self.num2short(count),ship.name))
            return
        
        tick = Updates.current_tick()
        reply = "Fleets matching query: "
        reply+= " // ".join(map(lambda (u, x): "%s(%s) %s: %s %s ((%s))"%(u.name,u.fleetupdated-tick,u.fleetcount,self.num2short(x.ship_count),ship.name,u.fleetcomment),result))
        message.reply(reply)
Esempio n. 14
0
File: maps.py Progetto: munin/merlin
 def load(name=None, id=None, passwd=None, exact=True, active=True, access=0):
     assert id or name
     Q = session.query(User)
     if active is True:
         if access in Config.options("Access"):
             access = Config.getint("Access", access)
         elif type(access) is int:
             pass
         else:
             raise LoadableError("Invalid access level")
         Q = Q.filter(User.active == True).filter(User.access >= access)
     if id is not None:
         user = Q.filter(User.id == id).first()
     if name is not None:
         for filter in (
             User.name.ilike(name),
             User.name.ilike(name + "%"),
             User.alias.ilike(name),
             User.alias.ilike(name + "%"),
             User.name.ilike("%" + name + "%"),
             User.alias.ilike("%" + name + "%"),
         ):
             user = Q.filter(filter).first()
             if user is not None or exact is True:
                 break
     if (user and passwd) is not None:
         user = user if user.passwd == User.hasher(passwd) else None
     return user
Esempio n. 15
0
 def writeout(self):
     # Write to socket/server
     while True:
         try:
             (priority, sent, line) = self.output.get(True, 1)
         except Empty:
             if self.quitting:
                 break
             else:
                 continue
         try:
             while self.last + Config.getfloat(
                     "Connection",
                     "antiflood") * (1 + (len(line) > 300) +
                                     (priority > 10)) >= time.time():
                 time.sleep(0.5)
             # Warn admins if the wait is too long
             if priority < 10 and time.time() > sent + Config.getint(
                     "Connection", "maxdelay"):
                 if time.time() > self.wait_warned + 300:
                     self.wait_warned = time.time()
                     admin_msg(
                         "Message output message delay is too long: %.1f seconds"
                         % (time.time() - sent))
             self.sock.send(encode(line) + CRLF)
             self.last = time.time()
             print "%s >> %s" % (
                 time.strftime("%Y%m%d %H:%M:%S |"),
                 encode(line),
             )
             self.output.task_done()
             if line[:4].upper() == "QUIT":
                 break
         except socket.error as exc:
             raise Reboot(exc)
Esempio n. 16
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()
Esempio n. 17
0
 def execute(self, message, user, params):
     if params.group(1)[-6:].lower() == "hideme":
         notice = "%s" % (params.group(1)[:-6])
     else:
         notice = "(%s) %s" % (user.name, params.group(1))
     for chan in session.query(Channel).filter(Channel.userlevel > (Config.getint("Access",  "galmate") if "galmate" in Config.options("Access") else 0)).all():
         message.notice(notice, chan.name)
Esempio n. 18
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,))
Esempio n. 19
0
    def execute(self, message, user, params):

        count = self.short2num(params.group(1) or "1")
        name = params.group(2)

        ship = Ship.load(name=name)
        if ship is None:
            message.alert("No Ship called: %s" % (name, ))
            return

        Q = session.query(User, UserFleet)
        Q = Q.join(User.fleets)
        Q = Q.filter(User.active == True)
        Q = Q.filter(User.access >= Config.getint("Access", "member"))
        Q = Q.filter(UserFleet.ship == ship)
        Q = Q.filter(UserFleet.ship_count >= count)
        Q = Q.filter(User.fleetcount > 0)
        Q = Q.order_by(desc(UserFleet.ship_count))
        result = Q.all()

        if len(result) < 1:
            message.reply(
                "There are no planets with free fleets and at least %s ships matching '%s'"
                % (self.num2short(count), ship.name))
            return

        tick = Updates.current_tick()
        reply = "Fleets matching query: "
        reply += ", ".join(
            map(
                lambda (u, x): "%s(%s) %s: %s %s" %
                (u.name, u.fleetupdated - tick, u.fleetcount,
                 self.num2short(x.ship_count), ship.name), result))
        message.reply(reply)
Esempio n. 20
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))
Esempio n. 21
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)
Esempio n. 22
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,))
Esempio n. 23
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()
Esempio n. 24
0
File: members.py Progetto: JDD/DLR
 def execute(self, request, user, sort=None):
     
     levels = [] + User.levels
     if "galmate" in Config.options("Access"):
         levels.append(("Galaxy", Config.getint("Access","galmate"),))
     else:
         levels.append(("Galaxy", 0,))
     
     if sort is not None:
         levels = [("All", 0,),]
     
     order =  {"name"  : (asc(Channel.name),),
               "userlevel" : (desc(Channel.userlevel),),
               "maxlevel" : (desc(Channel.maxlevel),),
               }
     if sort not in order.keys():
         sort = "name"
     order = order.get(sort)
     
     channels = []
     for level in levels:
         Q = session.query(Channel.name, Channel.userlevel, Channel.maxlevel)
         Q = Q.filter(Channel.userlevel >= level[1])
         Q = Q.filter(Channel.userlevel < levels[levels.index(level)-1][1]) if levels.index(level) > 0 else Q
         for o in order:
             Q = Q.order_by(o)
         
         channels.append((level[0], Q.all(),))
     
     return render("channels.tpl", request, accesslist=channels)
Esempio n. 25
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))
Esempio n. 26
0
 def writeout(self):
     # Write to socket/server
     while True:
         try:
             (priority, sent, line) = self.output.get(True, 1)
         except Empty:
             if self.quitting:
                 break
             else:
                 continue
         try:
             while self.last + Config.getfloat("Connection", "antiflood") * (1 + (len(line) > 300) + (priority > 10)) >= time.time():
                 time.sleep(0.5)
             # Warn admins if the wait is too long
             if time.time() > sent + Config.getint("Connection", "maxdelay"):
                 if time.time() > self.wait_warned + 300:
                     self.wait_warned = time.time()
                     adminmsg("Message output message delay is too long: %.1f seconds" % (time.time() - sent))
             self.sock.send(encode(line) + CRLF)
             self.last = time.time()
             print "%s >>> %s" % (time.asctime(),encode(line),)
             self.output.task_done()
             if line[:4].upper() == "QUIT":
                 break
         except socket.error as exc:
             raise Reboot(exc)
Esempio n. 27
0
    def __new__(cls):
        self = super(loadable, cls).__new__(cls)
        self.name = cls.__name__
        self.doc = cls.__doc__

        self.routes = self.routes or []
        self.routes.extend([
            (
                name,
                route._ROUTE,
                route._ACCESS,
            ) for name, route in sorted(cls.__dict__.items())
            if hasattr(route, "_ROUTE") and hasattr(route, "_ACCESS")
        ])

        if cls.access in Config.options("Access"):
            self.access = Config.getint("Access", cls.access)
        elif type(cls.access) is int:
            self.access = cls.access
        else:
            self.access = min([
                route._ACCESS for route in cls.__dict__.values()
                if hasattr(route, "_ROUTE") and hasattr(route, "_ACCESS")
            ])

        return self
Esempio n. 28
0
    def connect(self, nick):
        # Configure socket
        server = Config.get("Connection", "server")
        port = Config.getint("Connection", "port")
        print "%s Connecting... (%s %s)" % (
            time.asctime(),
            server,
            port,
        )

        self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.sock.settimeout(330)
        self.sock.connect((
            server,
            port,
        ))

        passwd = Config.get("Connection", "servpass")
        if passwd:
            self.write("PASS %s" % (passwd, ))

        self.write("NICK %s" % (nick, ))
        self.write("USER %s 0 * :%s bot. Admin: %s" % (
            nick,
            Config.get("Alliance", "name"),
            Config.items("Admins")[0][0],
        ))
        return self.sock
Esempio n. 29
0
 def __init__(self, line, **kwargs):
     line = " ".join([line] + map(lambda i: "%s=%s" % i, kwargs.items()))
     port = Config.getint("Misc", "robocop")
     sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     sock.settimeout(30)
     sock.connect(("127.0.0.1", port))
     sock.send(line + CRLF)
Esempio n. 30
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,))
Esempio n. 31
0
 def execute(self, message, user, params):
     
     user = aliased(User)
     sponsor = aliased(User)
     Q = session.query(user.name)
     Q = Q.filter(and_(user.active == True, user.access >= Config.getint("Access", "member")))
     Q = Q.filter(user.sponsor.ilike(sponsor.name))
     Q = Q.filter(or_(sponsor.active == False, sponsor.access < Config.getint("Access", "member")))
     result = Q.all()
     
     if len(result) < 1:
         message.reply("There are no orphans. KILL A PARENT NOW.")
         return
     
     reply = "The following members are orphans: "
     reply+= ", ".join(map(lambda x:x[0],result))
     message.reply(reply)
Esempio n. 32
0
 def robocop(self, message, notice, target=None):
     if notice[:3] == "!#!":
         notice = " ".join(notice[3:].split("!#!"))
     if target:
         message.notice(notice, target)
     else:
         for chan in session.query(Channel).filter(Channel.userlevel > (Config.getint("Access",  "galmate") if "galmate" in Config.options("Access") else 0)).all():
             message.notice(notice, chan.name)
Esempio n. 33
0
 def write(self, line, priority=10):
     # Write to output queue
     self.output.put((priority, time.time(), line))
     # Warn admins if the queue is too long
     if self.output.qsize() > Config.getint("Connection", "maxqueue"):
         if time.time() > self.queue_warned + 300:
             self.queue_warned = time.time()
             adminmsg("Message output queue length is too long: %s messages" % self.output.qsize())
Esempio n. 34
0
def join(message):
    # Someone is joining a channel
    if message.get_nick() != Merlin.nick:
        # That someone is not the bot
        if Config.getint("Misc", "defage") > 0:
            # mydef reminders are enabled
            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. 35
0
 def is_user(self, user):
     if loadable.is_user(self, user):
         return True
     elif isinstance(user, User) and user.name == Config.get(
             "Connection", "nick") and user.access == Config.getint(
                 "Access", "admin"):
         return True
     else:
         return False
Esempio n. 36
0
    def connect(self):
        # Configure socket
        port = Config.getint("Misc", "robocop")
        print "%s RoboCop... (%s)" % (time.asctime(), port)

        self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.sock.settimeout(30)
        self.sock.bind(("127.0.0.1", port))
        self.sock.listen(5)
        return self.sock
Esempio n. 37
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():
         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 399" %(Config.get("Channels","home"), ",".join(added),), "P")
Esempio n. 38
0
 def write(self, line, priority=10):
     # Write to output queue
     self.output.put((priority, time.time(), line))
     # Warn admins if the queue is too long
     if self.output.qsize() > Config.getint("Connection", "maxqueue"):
         if time.time() > self.queue_warned + 300:
             self.queue_warned = time.time()
             admin_msg(
                 "Message output queue length is too long: %s messages" %
                 self.output.qsize())
Esempio n. 39
0
 def __init__(self, line, **kwargs):
     line = " ".join([line] + map(lambda i: "%s=%s" % i, kwargs.items()))
     port = Config.getint("Misc", "robocop")
     sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     sock.settimeout(30)
     sock.connect((
         "127.0.0.1",
         port,
     ))
     sock.send(line + CRLF)
Esempio n. 40
0
    def execute(self, message, user, params):

        reply = []

        Q = session.query(Channel)
        if not params.group(1):
            Q = Q.filter(Channel.userlevel > (Config.getint("Access",  "galmate") if "galmate" in Config.options("Access") else 0))
        for c in Q.all():
            reply.append(c.name)
        
        message.reply("Stored channels: %s" % (", ".join(reply)))
Esempio n. 41
0
 def list(self,message,user,params):
     Q = session.query(Attack)
     Q = Q.filter(Attack.landtick >= Updates.current_tick() - Config.getint("Misc", "attactive"))
     Q = Q.order_by(asc(Attack.id))
     
     replies = []
     for attack in Q:
         replies.append("(%d LT: %d %s)" %(attack.id,attack.landtick,attack.comment,))
     
     reply = "Open attacks: " + " ".join(replies)
     message.reply(reply)
Esempio n. 42
0
 def check_access(self, message, access=None, user=None, channel=None):
     try:
         user = loadable.check_access(self, message, access, user, channel)
         if not self.is_user(user):
             raise UserError
         else:
             return user
     except UserError:
         if message.get_pnick() in Config.options("Admins"):
             return User(name=Config.get("Connection", "nick"), access=Config.getint("Access", "admin"))
         else:
             raise
Esempio n. 43
0
 def __new__(cls):
     self = super(loadable, cls).__new__(cls)
     self.name = cls.__name__
     
     if cls.access in Config.options("Access"):
         self.access = Config.getint("Access", cls.access)
     elif type(cls.access) in (int, type(None),):
         self.access = cls.access
     else:
         raise LoadableError("Invalid access level")
     
     return self
Esempio n. 44
0
File: attack.py Progetto: JDD/merlin
 def show(self, message, user, params):
     id = params.group(1)
     attack = Attack.load(id)
     
     if attack is None:
         message.alert("No attack exists with id %s" %(id))
         return
     if user.access < (Config.getint("Access",  "hc") if "hc" in Config.options("Access") else 1000) and attack.landtick > Updates.current_tick() + Config.getint("Misc", "attactive"):
         message.alert("Attack %s is not open yet" %(id))
         return
     
     message.reply(str(attack))
Esempio n. 45
0
    def execute(self, message, user, params):

        user = aliased(User)
        sponsor = aliased(User)
        Q = session.query(user.name)
        Q = Q.filter(
            and_(user.active == True,
                 user.access >= Config.getint("Access", "member")))
        Q = Q.filter(user.sponsor.ilike(sponsor.name))
        Q = Q.filter(
            or_(sponsor.active == False,
                sponsor.access < Config.getint("Access", "member")))
        result = Q.all()

        if len(result) < 1:
            message.reply("There are no orphans. KILL A PARENT NOW.")
            return

        reply = "The following members are orphans: "
        reply += ", ".join(map(lambda x: x[0], result))
        message.reply(reply)
Esempio n. 46
0
 def connect(self, nick):
     # Configure socket
     server = Config.get("Connection", "server")
     port = Config.getint("Connection", "port")
     print "%s Connecting... (%s %s)" % (time.asctime(), server, port,)
     
     self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     self.sock.settimeout(330)
     self.sock.connect((server, port,))
     self.write("NICK %s" % (nick,))
     self.write("USER %s 0 * : %s" % (nick, nick,))
     return self.sock
Esempio n. 47
0
 def execute(self, message, user, params):
     reply = ""
     tick=Updates.current_tick()
     opts = params.group(1).split()
     for o in reversed(Config.options("Access")):
         if ("galmates" not in opts) and (Config.getint("Access", o) == 0):
             continue;
         Q = session.query(User)
         Q = Q.filter(User.access == Config.getint("Access", o))
         Q = Q.order_by(asc(User.name))
         result = Q.all()
         if len(result) < 1:
             continue
         printable=map(lambda (u): "%s%s%s%s%s" % (u.name,' ('+u.alias+')' if u.alias else '',
             " (%d:%d:%d)" % (u.planet.x, u.planet.y, u.planet.z) if "coords" in opts and u.planet is not None else '', 
             " (%s)" % ((u.fleetupdated or 0)-tick) if "defage" in opts else '',
             " (%s)" % (u.fleetupdated or 0) if "mydef" in opts else ''),result)
         reply += "%s:  " % (o)
         reply += ', '.join(printable)
         reply += '\n'
     message.reply(reply[:-1])
Esempio n. 48
0
File: attack.py Progetto: JDD/merlin
 def execute(self, request, user, message=None):
     tick = Updates.current_tick()
     
     Q = session.query(Attack)
     if user.access < (Config.getint("Access",  "hc") if "hc" in Config.options("Access") else 1000): # Hide attacks until they are active, unless the user has access
         Q = Q.filter(Attack.landtick <= tick + Config.getint("Misc", "attactive"))
     Q = Q.filter(Attack.landtick + Attack.waves >= tick) # Hide attacks one tick after the last wave has landed
     Q = Q.order_by(asc(Attack.id))
     attacks = Q.all()
     
     Q = session.query(Planet, Target.tick)
     Q = Q.join(Target.planet)
     Q = Q.join(Target.user)
     Q = Q.filter(Planet.active == True)
     Q = Q.filter(Target.user == user)
     Q = Q.filter(Target.tick >= tick - 12) # We shouldn't need any bookings 12 ticks after landing
     Q = Q.order_by(asc(Target.tick), asc(Planet.x), asc(Planet.y), asc(Planet.z))
     
     bookings = []
     scans = []
     for planet, tock in Q.all():
         bookings.append((planet, tock, [],))
         if planet.scan("P"):
             bookings[-1][2].append(planet.scan("P"))
             scans.append(planet.scan("P"))
         
         if planet.scan("D"):
             bookings[-1][2].append(planet.scan("D"))
             scans.append(planet.scan("D"))
         
         if planet.scan("A") or planet.scan("U"):
             bookings[-1][2].append(planet.scan("A") or planet.scan("U"))
             scans.append(planet.scan("A") or planet.scan("U"))
         
         if tock <= tick + Config.getint("Misc", "attjgp") and planet.scan("J"):
             bookings[-1][2].append(planet.scan("J"))
             scans.append(planet.scan("J"))
     
     return render("attacks.tpl", request, message=message, attacks=attacks, bookings=bookings, scans=scans)
Esempio n. 49
0
 def check_access(self, message, access=None, user=None, channel=None):
     try:
         user = loadable.check_access(self, message, access, user, channel)
         if not self.is_user(user):
             raise UserError
         else:
             return user
     except UserError:
         if message.get_pnick() in Config.options("Admins"):
             return User(name=Config.get("Connection", "nick"),
                         access=Config.getint("Access", "admin"))
         else:
             raise
Esempio n. 50
0
    def list(self, message, user, params):
        Q = session.query(Attack)
        if user.access < (
                Config.getint("Access", "hc")
                if "hc" in Config.options("Access") else 1000
        ):  # Hide attacks until they are active, unless the user has access
            Q = Q.filter(Attack.landtick <= Updates.current_tick() +
                         Config.getint("Misc", "attactive"))
        Q = Q.filter(Attack.landtick + Attack.waves >= Updates.current_tick()
                     )  # Hide attacks one tick after the last wave has landed
        Q = Q.order_by(asc(Attack.id))

        replies = []
        for attack in Q:
            replies.append("(%d LT: %d %s)" % (
                attack.id,
                attack.landtick,
                attack.comment,
            ))

        reply = "Open attacks: " + " ".join(replies)
        message.reply(reply)
Esempio n. 51
0
    def execute(self, message, user, params):

        reply = []

        Q = session.query(Channel)
        if not params.group(1):
            Q = Q.filter(Channel.userlevel > (
                Config.getint("Access", "galmate") if "galmate" in
                Config.options("Access") else 0))
        for c in Q.all():
            reply.append(c.name)

        message.reply("Stored channels: %s" % (", ".join(reply)))
Esempio n. 52
0
    def execute(self, message, user, params):
        if not Config.get("Twilio", "sid"):
            message.reply(
                "Twilio support not configured. Tell the admin. If you are the admin, configure Twilio or disable !call to prevent this message."
            )
            return

        rec = params.group(1)
        receiver = User.load(name=rec, exact=False,
                             access="member") or User.load(name=rec)
        if not receiver:
            message.reply("Who exactly is %s?" % (rec, ))
            return
        if receiver.smsmode == "Retard":
            message.reply(
                "I refuse to talk to that incompetent retard. Check %s's mydef comment and use !phone show to try sending it using your own phone."
                % (receiver.name, ))
            return

        if not (receiver.pubphone or user in receiver.phonefriends
                or user.is_admin()):
            message.reply(
                "%s's phone number is private or they have not chosen to share their number with you. No call made."
                % (receiver.name, ))
            return

        phone = self.prepare_phone_number(receiver.phone)
        if not phone or len(phone) <= 7:
            message.reply(
                "%s has no phone number or their phone number is too short to be valid (under 6 digits). No call made."
                % (receiver.name, ))
            return

        client = Client(Config.get("Twilio", "sid"),
                        Config.get("Twilio", "auth_token"))
        if Config.getboolean("Twilio", "warn"):
            url="http://twimlets.com/echo?Twiml=%3CResponse%3E%3CSay%20voice%3D%22alice%22%20language%3D%22en-GB%22%20%3EHello.%20This%20is%20" +\
                Config.get("Connection", "nick") + ".%20Stop%20wasting%20our%20credit!%3C%2FSay%3E%3CHangup%2F%3E%3C%2FResponse%3E&",
        else:
            url = "http://twimlets.com/echo?Twiml=%3CResponse%3E%3CHangup%2F%3E%3C%2FResponse%3E&",
        tw = client.api.account.calls.create(
            to=phone,
            from_=Config.get("Twilio", "number"),
            url=url,
            timeout=Config.getint("Twilio", "timeout"))

        if tw.sid:
            message.reply("Successfully called %s." % (receiver.name))
        else:
            message.reply("Error: Failed to get call ID from Twilio server.")
Esempio n. 53
0
    def execute(self, message, user, params):
        if not Config.get("Twilio", "sid"):
            message.reply(
                "Twilio support not configured. Tell the admin. If you are the admin, configure Twilio or disable !call to prevent this message."
            )
            return

        rec = params.group(1)
        receiver = User.load(
            name=rec, exact=False, access="member") or User.load(name=rec)
        if not receiver:
            message.reply("Who exactly is %s?" % (rec, ))
            return
        if receiver.smsmode == "Retard":
            message.reply(
                "I refuse to talk to that incompetent retard. Check %s's mydef comment and use !phone show to try sending it using your own phone."
                % (receiver.name, ))
            return

        if not (receiver.pubphone or user in receiver.phonefriends
                or user.is_admin()):
            message.reply(
                "%s's phone number is private or they have not chosen to share their number with you. No call made."
                % (receiver.name, ))
            return

        phone = self.prepare_phone_number(receiver.phone)
        if not phone or len(phone) <= 7:
            message.reply(
                "%s has no phone number or their phone number is too short to be valid (under 6 digits). No call made."
                % (receiver.name, ))
            return

        client = TwilioRestClient(
            Config.get("Twilio", "sid"), Config.get("Twilio", "auth_token"))
        if Config.getboolean("Twilio", "warn"):
            url="http://twimlets.com/echo?Twiml=%3CResponse%3E%3CSay%20voice%3D%22alice%22%20language%3D%22en-GB%22%20%3EHello.%20This%20is%20" +\
                Config.get("Connection", "nick") + ".%20Stop%20wasting%20our%20credit!%3C%2FSay%3E%3CHangup%2F%3E%3C%2FResponse%3E&",
        else:
            url = "http://twimlets.com/echo?Twiml=%3CResponse%3E%3CHangup%2F%3E%3C%2FResponse%3E&",
        tw = client.calls.create(
            to=phone,
            from_=Config.get("Twilio", "number"),
            url=url,
            Timeout=Config.getint("Twilio", "timeout"))

        if tw.sid:
            message.reply("Successfully called %s." % (receiver.name))
        else:
            message.reply("Error: Failed to get call ID from Twilio server.")
Esempio n. 54
0
    def __new__(cls):
        self = super(loadable, cls).__new__(cls)
        self.name = cls.__name__

        if cls.access in Config.options("Access"):
            self.access = Config.getint("Access", cls.access)
        elif type(cls.access) in (
                int,
                type(None),
        ):
            self.access = cls.access
        else:
            raise LoadableError("Invalid access level")

        return self
Esempio n. 55
0
    def get_user(self, name, channel, pnick=None, pnickf=None):
        # Regular user check
        if (pnick is None) and (pnickf is None):
            # This shouldn't happen
            return None

        nick = self.Nicks.get(name)

        if (nick and nick.puser) is not None:
            # They already have a user associated
            pnick = nick.puser
        elif pnickf is not None:
            # Call the pnick function, might raise PNickParseError
            try:
                pnick = pnickf()
            except PNickParseError:
                return None

        user = User.load(name=pnick)
        if user is None and Config.getboolean("Misc", "autoreg"):
            if nick and not nick.puser:
                if "galmate" in Config.options("Access"):
                    access = Config.getint("Access", "galmate")
                else:
                    access = 0
                user = User.load(name=pnick, active=False)
                if user is None:
                    user = User(name=pnick, access=access)
                    session.add(user)
                else:
                    user.active = True
                    user.access = access
                session.commit()
        if user is None:
            return None

        if (nick is not None) and self.mode_is("rapid", "join"):
            if self.Pusers.get(user.name) is None:
                # Add the user to the tracker
                self.Pusers[user.name] = Puser(user.name)

            if nick.puser is None:
                # Associate the user and nick
                nick.puser = user.name
                self.Pusers[user.name].nicks.add(nick.name)

        # Return the SQLA User
        return user
Esempio n. 56
0
    def connect(self):
        # Configure socket
        port = Config.getint("Misc", "robocop")
        print "%s RoboCop... (%s)" % (
            time.asctime(),
            port,
        )

        self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.sock.settimeout(30)
        self.sock.bind((
            "127.0.0.1",
            port,
        ))
        self.sock.listen(5)
        return self.sock
Esempio n. 57
0
    def list(self, message, user, params):
        Q = session.query(Attack)
        Q = Q.filter(Attack.landtick >= Updates.current_tick() -
                     Config.getint("Misc", "attactive"))
        Q = Q.order_by(asc(Attack.id))

        replies = []
        for attack in Q:
            replies.append("(%d LT: %d %s)" % (
                attack.id,
                attack.landtick,
                attack.comment,
            ))

        reply = "Open attacks: " + " ".join(replies)
        message.reply(reply)
Esempio n. 58
0
    def execute(self, request, user, sort=None):

        levels = [] + User.levels
        if "galmate" in Config.options("Access"):
            levels.append((
                "Galaxy",
                Config.getint("Access", "galmate"),
            ))
        else:
            levels.append((
                "Galaxy",
                0,
            ))

        if sort is not None:
            levels = [
                (
                    "All",
                    0,
                ),
            ]

        order = {
            "name": (asc(Channel.name), ),
            "userlevel": (desc(Channel.userlevel), ),
            "maxlevel": (desc(Channel.maxlevel), ),
        }
        if sort not in order.keys():
            sort = "name"
        order = order.get(sort)

        channels = []
        for level in levels:
            Q = session.query(Channel.name, Channel.userlevel,
                              Channel.maxlevel)
            Q = Q.filter(Channel.userlevel >= level[1])
            Q = Q.filter(Channel.userlevel < levels[levels.index(level) - 1][1]
                         ) if levels.index(level) > 0 else Q
            for o in order:
                Q = Q.order_by(o)

            channels.append((
                level[0],
                Q.all(),
            ))

        return render("channels.tpl", request, accesslist=channels)