コード例 #1
0
ファイル: whois.py プロジェクト: wanshot/merlin
    def execute(self, message, user, params):

        # assign param variables
        search = params.group(1)

        # do stuff here
        if search.lower() == Config.get("Connection", "nick").lower():
            message.reply("I am %s. Hear me roar." %
                          (Config.get("Connection", "nick"), ))
            return

        w***e = User.load(name=search, exact=False,
                          access="member") or User.load(name=search)
        if w***e is None:
            message.reply("No users matching '%s'" % (search, ))
            return

        reply = ""
        if w***e == user:
            reply += "You are %s, you are a %s" + (
                " and you are also known as %s" if w***e.alias else
                "%s") + ". Your sponsor is %s. You have %s carebears."
        else:
            reply += "Information about %s; they are a %s" + (
                " and they are also known as %s" if w***e.alias else
                "%s") + ". Their sponsor is %s. They have %s carebears."
        reply = reply % (
            w***e.name,
            w***e.level,
            w***e.alias or "",
            w***e.sponsor,
            w***e.carebears,
        )

        message.reply(reply)
コード例 #2
0
ファイル: actions.py プロジェクト: liam-wiltshire/merlin
 def privmsg(self, text, target=None, priority=0):
     if os.path.isfile("/tmp/meetingmode"):
         return
         # Privmsg someone. Target defaults to the person who triggered this line
         # Should we send colours?
     if (
         Config.has_option("Connection", "color")
         and not Config.has_option("NoColor", target)
         and not (target[0] in ["#", "&"] and Config.has_option("NoColorChan", target[1:]))
     ):
         text = "\x03" + Config.get("Connection", "color") + text + "\x0F"
         color = True
     else:
         color = False
     # If we're opped in a channel in common with the user, we can reply with
     #  CPRIVMSG instead of PRIVMSG which doesn't count towards the flood limit.
     if (
         (not target or target[0] not in "#&")
         and hasattr(self, "_channel")
         and CUT.opped(self.get_chan())
         and CUT.nick_in_chan(target or self.get_nick(), self.get_chan())
     ):
         self.write("CPRIVMSG %s %s :%s" % (target or self.get_nick(), self.get_chan(), text), color, priority)
     else:
         self.write("PRIVMSG %s :%s" % (target or self.get_nick(), text), color, priority)
コード例 #3
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)
コード例 #4
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)
コード例 #5
0
ファイル: context.py プロジェクト: wanshot/merlin
        def wrapper(hook):
            prefix = hook.__module__.split(".")[2] if pre else ""
            url = ("/%s/%s/%s/" % (
                prefix,
                hook.name,
                suffix,
            )).replace("//", "/")

            if head not in self.heads:
                self.heads.append(head)
                self.content[head] = {
                    "hook": hook,
                    "url": url,
                    "subs": [],
                    "content": {}
                }
                self.content[head][
                    "link"] = hook.name == "links" and not head == Config.get(
                        "Alliance", "name")
            if sub is not None:
                self.content[head]["subs"].append(sub)
                self.content[head]["content"][sub] = {"hook": hook, "url": url}
                self.content[head]["content"][sub][
                    "link"] = hook.name == "links" and not head == Config.get(
                        "Alliance", "name")

            return hook
コード例 #6
0
ファイル: addchan.py プロジェクト: ellonweb/merlin
    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,))
コード例 #7
0
ファイル: sharescan.py プロジェクト: berten/merlin
 def robocop(self, message, pa_id, group=False):
     if Config.get("Misc", "shareto"):
         if group:
             url = Config.get("URL", "viewgroup") % pa_id
         else:
             url = Config.get("URL", "viewscan") % pa_id
         message.privmsg(url, Config.get("Misc", "shareto"), priority=+10)
コード例 #8
0
ファイル: IMAPPush.py プロジェクト: TBBTNut/merlin
    def robonotify(self, header, body):
        # Check for correct "From" address?
        if Config.getboolean("imap", "singleaddr"):
            uname_re = "%s\+(.+)@.+" % Config.get("imap", "user").split("@")[0].lower()
        else:
            uname_re = "<?(.+)@.+"
        uname = re.findall(uname_re, header['To'].lower())[0]

        dsuff = Config.get("imap", "defsuffix")
        if dsuff:
            if uname[-len(dsuff):] == dsuff:
                uname = uname[:-len(dsuff)]
            else:
                self.forwardMail(uname, header, body)
                return

        # Check for the main notificatino types
        tick = re.findall("events in tick (\d+)", body)[0]
        newfleets = re.findall("We have detected an open jumpgate from (.+), located at (\d{1,2}):(\d{1,2}):(\d{1,2}). ".replace(" ","\s+") +\
                               "The fleet will approach our system in tick (\d+) and appears to have (\d+) visible ships.".replace(" ","\s+"), body)
        recalls = re.findall("The (.+) fleet from (\d{1,2}):(\d{1,2}):(\d{1,2}) has been recalled.".replace(" ","\s+"), body)
        cons = len(re.findall("Our construction team reports that .+ has been finished".replace(" ","\s+"), body))
        res = len(re.findall("Our scientists report that .+ has been finished".replace(" ","\s+"), body))

        # Wrap it up in a bow
        for line in newfleets:
            push("defcall", etype="new", uname=uname, tick=tick, name=line[0], x=line[1], y=line[2], z=line[3], eta=line[4], size=line[5])
        for line in recalls:
            push("defcall", etype="rec", uname=uname, tick=tick, name=line[0], x=line[1], y=line[2], z=line[3])
        if res + cons > 0:
            push("defcall", etype="fin", uname=uname, tick=tick, res=res, cons=cons)

        if len(newfleets) + len(recalls) + cons + res == 0:
            self.forwardMail(uname, header, body)
コード例 #9
0
ファイル: maps.py プロジェクト: 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
コード例 #10
0
ファイル: sharescan.py プロジェクト: JDD/merlin
 def robocop(self, message, pa_id, group=False):
     if Config.get("Misc", "shareto"):
         if group:
             url = Config.get("URL","viewgroup") % pa_id
         else:
             url = Config.get("URL","viewscan") % pa_id
         message.privmsg(url, Config.get("Misc","shareto"), priority=+10)
コード例 #11
0
ファイル: apenis.py プロジェクト: berten/merlin
 def execute(self, message, user, params):
     
     if params.group(1) is not None:
         alliance = Alliance.load(params.group(1))
         if alliance is None:
             message.alert("No alliances match %s" % (params.group(1),))
             return
     elif self.is_user(user) and user.is_member():
         alliance = Alliance.load(Config.get("Alliance","name"))
         if alliance is None:
             message.alert("No alliances match %s" % (Config.get("Alliance","name"),))
             return
     else:
         self.get_user_planet(user)
         if user.planet.intel is None or user.planet.alliance is None:
             message.alert("Make sure you've set your planet with !pref and alliance with !intel")
             return
         else:
             alliance = user.planet.alliance
     
     penis = alliance.apenis
     if penis is None:
         message.alert("No apenis stats matching %s" % (alliance.name,))
         return
     
     message.reply("apenis for %s is %s score long. This makes %s rank: %s apenis. The average peon is sporting a %s score epenis." % (
                     alliance.name, penis.penis, alliance.name, penis.rank, int(penis.penis/alliance.members),))
コード例 #12
0
def log(filename, log, traceback=True, spacing=True):
    def _log(file):
        file.write(encode(log) + "\n")
        if traceback is True:
            file.write(format_exc() + "\n")
        if spacing is True:
            file.write("\n\n")
    try:
        file = Config.get("Misc", filename)
        if file == "stdout":
            _log(stdout)
        else:
            with open(file, "a") as file:
                _log(file)
    finally:
        if filename == "excalibur":
            if "d" not in Config.get("Misc", "maillogs"):
                return
        elif filename[0] not in Config.get("Misc", "maillogs"):
            return
        if traceback:
            sep = "\n\n" if spacing else "\n"
            log = sep.join([log, format_exc()])
        for addr in Config.get("Misc", "logmail").split():
            send_email("%s: %s" % (Config.get("Connection", "nick"), filename), log, addr)
コード例 #13
0
    def execute(self, message, user, params):

        get = urlencode(
            {
                "user": Config.get("clickatell", "user"),
                "password": Config.get("clickatell", "pass"),
                "api_id": Config.get("clickatell", "api"),
            }
        )

        try:
            status, msg = urlopen("https://api.clickatell.com/http/getbalance", get).read().split(":")

            if status in ("Credit",):
                balance = float(msg.strip())
                if not balance:
                    message.reply("Help me help you. I need the kwan. SHOW ME THE MONEY")
                else:
                    message.reply("Current kwan balance: %d" % (balance,))
            elif status in ("ERR",):
                raise SMSError(msg.strip())
            else:
                message.reply(
                    "That wasn't supposed to happen. I don't really know what wrong. Maybe your mother dropped you."
                )

        except (URLError, SSLError, SMSError) as e:
            message.reply("Error sending message: %s" % (str(e),))
コード例 #14
0
ファイル: getanewdaddy.py プロジェクト: munin/merlin
    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))
コード例 #15
0
ファイル: members.py プロジェクト: 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)
コード例 #16
0
ファイル: sms.py プロジェクト: berten/merlin
    def send_clickatell(self, user, receiver, public_text, phone, message):
        try:
            # HTTP POST
            post = urlencode({
                "user": Config.get("clickatell", "user"),
                "password": Config.get("clickatell", "pass"),
                "api_id": Config.get("clickatell", "api"),
                "to": phone,
                "text": message,
            })
            # Send the SMS
            status, msg = urlopen("https://api.clickatell.com/http/sendmsg",
                                  post, 5).read().split(":")

            # Check returned status for error messages
            if status in (
                    "OK",
                    "ID",
            ):
                self.log_message(user, receiver, phone, public_text,
                                 "clickatell")
                return None
            elif status in ("ERR", ):
                raise SMSError(msg.strip())
            else:
                return ""

        except (URLError, SSLError, SMSError) as e:
            return "Error sending message: %s" % (str(e), )
コード例 #17
0
ファイル: members.py プロジェクト: davesherratt/merlin
 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])
コード例 #18
0
ファイル: sms.py プロジェクト: davesherratt/merlin
 def send_email(self, user, receiver, public_text, email, message):
     try:
         if (Config.get("smtp", "port") == "0"):
             smtp = SMTP("localhost")
         else:
             smtp = SMTP(Config.get("smtp", "host"), Config.get("smtp", "port"))
         
         if not ((Config.get("smtp", "host") == "localhost") or (Config.get("smtp", "host") == "127.0.0.1")): 
             try:
                 smtp.starttls()
             except SMTPException as e:
                 raise SMSError("unable to shift connection into TLS: %s" % (str(e),))
             
             try:
                 smtp.login(Config.get("smtp", "user"), Config.get("smtp", "pass"))
             except SMTPException as e:
                 raise SMSError("unable to authenticate: %s" % (str(e),))
         
         try:
              smtp.sendmail(Config.get("smtp", "frommail"), email, 
                           "To:%s\nFrom:%s\nSubject:%s\n\n%s\n" % (email,
                                                                 Config.get("smtp", "frommail"),
                                                                 Config.get("Alliance", "name"),
                                                                 message,))
         except SMTPSenderRefused as e:
             raise SMSError("sender refused: %s" % (str(e),))
         except SMTPRecipientsRefused as e:
             raise SMSError("unable to send: %s" % (str(e),))
         
         smtp.quit()
         self.log_message(user, receiver, email, public_text, "email")
         
     except (socket.error, SSLError, SMTPException, SMSError) as e:
         return "Error sending message: %s" % (str(e),)
コード例 #19
0
ファイル: remchan.py プロジェクト: davesherratt/merlin
    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, ))
コード例 #20
0
ファイル: shipstats.py プロジェクト: TBBTNut/merlin
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()
コード例 #21
0
ファイル: parser.py プロジェクト: berten/merlin
class parse(Thread):
    useragent = "Merlin (Python-urllib/%s); Alliance/%s; BotNick/%s; Admin/%s" % (
        urllib2.__version__, Config.get("Alliance", "name"),
        Config.get("Connection", "nick"), Config.items("Admins")[0][0])

    def __init__(self, uid, type, id, share=True):
        self.uid = uid
        self.type = type
        self.id = id
        self.share = share
        Thread.__init__(self)

    def run(self):
        scanlog(asctime())
        t_start = time()

        uid = self.uid
        type = self.type
        id = self.id
        try:
            if type == "scan":
                self.scan(uid, id)
            elif type == "group":
                self.group(uid, id)
        except Exception, e:
            scanlog("Exception in scan: %s" % (str(e), ), traceback=True)

        t1 = time() - t_start
        scanlog("Total time taken: %.3f seconds" % (t1, ), spacing=True)
        session.remove()
コード例 #22
0
    def robocop(self, message, scantype, pa_id, x, y, z, names):
        nicks = []
        reply = "%s on %s:%s:%s " % (
            PA.get(scantype, "name"),
            x,
            y,
            z,
        )
        reply += Config.get("URL", "viewscan") % (pa_id, )

        for name in names.split(","):
            user = User.load(name)
            for nick in CUT.get_user_nicks(name):
                nicks.append(nick)
                message.privmsg(self.url(reply, user), nick)

        reply = "%s on %s:%s:%s " % (
            PA.get(scantype, "name"),
            x,
            y,
            z,
        )
        reply += "delivered to: "
        reply += ", ".join(nicks) if not Config.getboolean(
            "Misc", "anonscans") else "Anon"
        from Hooks.scans.request import request
        message.privmsg(reply, request().scanchan())
コード例 #23
0
ファイル: connection.py プロジェクト: TBBTNut/merlin
 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)
コード例 #24
0
ファイル: remuser.py プロジェクト: 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)
コード例 #25
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
コード例 #26
0
    def execute(self, message, user, params):

        get = urlencode({
            "user": Config.get("clickatell", "user"),
            "password": Config.get("clickatell", "pass"),
            "api_id": Config.get("clickatell", "api"),
        })

        try:
            status, msg = urlopen("https://api.clickatell.com/http/getbalance",
                                  get).read().split(":")

            if status in ("Credit", ):
                balance = float(msg.strip())
                if not balance:
                    message.reply(
                        "Help me help you. I need the kwan. SHOW ME THE MONEY")
                else:
                    message.reply("Current kwan balance: %d" % (balance, ))
            elif status in ("ERR", ):
                raise SMSError(msg.strip())
            else:
                message.reply(
                    "That wasn't supposed to happen. I don't really know what wrong. Maybe your mother dropped you."
                )

        except (URLError, SSLError, SMSError) as e:
            message.reply("Error sending message: %s" % (str(e), ))
コード例 #27
0
ファイル: addchan.py プロジェクト: wanshot/merlin
 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,))
コード例 #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
コード例 #29
0
ファイル: actions.py プロジェクト: TBBTNut/merlin
    def write(self, text, color=False, priority=0):
        # Write something to the server, the message will be split up by newlines and at 450chars max

        # Set Priority
        l = len(text)
        p = 5 + priority
        if l < 100:
            p -= 1
        elif l > 150:
            p += min(l,400) // 100 + l // 450
        ##
        n = False
        try:
            n = self.get_pnick()
        except:
            p += 2
        if n:
            if n in Config.options("Admins"):
                p -= 2
            try:
                u = User.load(n)
                if u:
                    if u.is_admin():
                        p -= 1
                    elif u.is_galmate():
                        p += 1
                else:
                    p +=2
            except:
                p += 2

        # Split message and send
        colon = text.find(":")
        if colon != -1:
            while text[colon-1] != " " and colon != -1:
                colon = text.find(":",colon+1)
            if colon != -1:
                params = text[:colon+1]
                text = text[colon+1:]
        if colon == -1:
            params = text
            text = None
        if text:            
            if color:
                params += "\x03"+Config.get("Connection", "color")
            for line in text.split("\n"):
                line
                while line:
                    i = len(line)
                    while len(line[:i]) > (450 - len(params)):
                        i = line.rfind(" ", 0, i)
                        if i == -1:
                            Connection.write((params + line)[:450])
                            line = line[450 - len(params):]
                            continue
                    Connection.write(params + line[:i], p)
                    line = line[i+1:]
        else:
            Connection.write(params, p)
コード例 #30
0
def secure(message):
    """Secures the PNick of the bot."""
    message.privmsg("SET MAXLOGINS 2\nSET INVISIBLE ON\nSET AUTOKILL ON",
                    Config.get("Services", "nick"))
    message.reply("Secured the %s nick" % (Config.get("Services", "nick"), ))
    for chan, name in Config.items("Channels"):
        message.privmsg("SET %s AUTOINVITE ON" % (name, ),
                        Config.get("Services", "nick"))
コード例 #31
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)
コード例 #32
0
ファイル: adduser.py プロジェクト: davesherratt/merlin
 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
コード例 #33
0
    def execute(self, message, user, params):

        links = [
            Config.get("URL", "game"),
            Config.get("URL", "bcalc"),
            Config.get("URL", "arthur"),
        ]

        message.reply(self.url("Links: " + " | ".join(links), user))
コード例 #34
0
ファイル: sms.py プロジェクト: Go3Media/merlin
    def execute(self, message, user, params):
        
        rec = params.group(1)
        public_text = params.group(2) + ' - %s' % (user.name,)
        text = public_text.encode('latin-1') + '/%s' %(user.phone,)
        receiver=User.load(name=rec,exact=False)
        if not receiver:
            message.reply("Who exactly is %s?" % (rec,))
            return

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

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

        if len(text) >= 160:
            message.reply("Max length for a text is 160 characters. Your text was %i characters long. Super secret message not sent." % (len(text),))
            return
        if not receiver.googlevoice:
            get = urlencode({"user": Config.get("clickatell", "user"),
                        "password": Config.get("clickatell", "pass"),
                        "api_id": Config.get("clickatell", "api"),
                        "to": phone,
                        "text": text,
            })
	
            status, msg = urlopen("https://api.clickatell.com/http/sendmsg", get).read().split(":")
	
            if status in ("OK","ID",):
	        message.reply("Successfully processed To: %s Message: %s" % (receiver.name,text))
	        self.log_message(user,receiver,phone, public_text)
            elif status in ("ERR",):
	        message.reply("Error sending message: %s" % (msg.strip(),))
            else:
	        message.reply("That wasn't supposed to happen. I don't really know what wrong. Maybe your mother dropped you.")
            return

	email = Config.get("googlevoice", "email")
        password = Config.get("googlevoice", "pass")
        gvoice = GoogleVoiceLogin(email, password)
        if not gvoice.logged_in:
            message.reply("Could not log in with provided credentials")
            return
        else:
            text_sender = TextSender(gvoice.opener, gvoice.key)
            text_sender.text = text
            number = phone
            text_sender.send_text(phone)
            if text_sender.response:
                message.reply("Sending message to {0} at {1}".format(receiver.name, phone),)
            else:
                message.reply("Failed!!")
コード例 #35
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 ""))
コード例 #36
0
ファイル: context.py プロジェクト: munin/merlin
def base_context(request):
    context = {"name": Config.get("Alliance", "name"), "slogan": Config.get("Alliance", "name")}
    if request.session is not None:
        slogan, count = Slogan.search("")
        if slogan is not None:
            context["slogan"] = str(slogan)
        context["user"] = request.session.user
        context["menu"] = menu.generate(request.session.user)
        context["tick"] = Updates.current_tick()
    return context
コード例 #37
0
ファイル: home.py プロジェクト: Hardware-Hacks/merlin
 def execute(self, request, user, link):
     link = {
             "game"        : Config.get("URL","game"),
             "forums"      : "http://pirate.planetarion.com",
             "bcalc"       : Config.get("URL","bcalc"),
             name          : reverse("alliance_members", kwargs={"name":name}),
            }.get(link)
     if link is None:
         return page_not_found(request)
     return HttpResponseRedirect(self.url(link, user))
コード例 #38
0
ファイル: loadable.py プロジェクト: JDD/merlin
def user_in(chan):
    if not chan.find("#") == 0:
        if chan in Config.options("Channels"):
            chan = Config.get("Channels",chan)
        else:
            raise LoadableError("Invalid channel")
    def wrapper(execute):
        execute._USER_IN = chan
        return execute
    return wrapper
コード例 #39
0
ファイル: auth.py プロジェクト: wanshot/merlin
def loggedin(message):
    # Authentication complete
    if "is now your hidden host" == message.get_msg():
        nick = Config.get("Connection", "nick")
        if Merlin.nick != nick:
            message.nick(nick)
        return # This is now deprecated in favour of
               #  setting autoinvite when adding the chan
        for channel in session.query(Channel):
            message.privmsg("INVITE %s" % (channel.name,), Config.get("Services", "nick"))
コード例 #40
0
ファイル: auth.py プロジェクト: berten/merlin
def PNS(message):
    # Message from P or NickServ
    if message.get_hostmask().lower() in (Config.get("Services", "host").lower(),Config.get("Services", "nickserv").lower(),):
        if re.match(r"^(Recover Successful For|Unable to find)", message.get_msg()):
            # Ghosted
            message.nick(Config.get("Connection", "nick"))
            login(message)
        if re.match(r"^Your nickname is registered", message.get_msg()):
            # Login
            login(message)
コード例 #41
0
ファイル: home.py プロジェクト: wanshot/merlin
 def execute(self, request, user, link):
     link = {
         "game": Config.get("URL", "game"),
         "forums": "http://pirate.planetarion.com",
         "bcalc": Config.get("URL", "bcalc"),
         name: reverse("alliance_members", kwargs={"name": name}),
     }.get(link)
     if link is None:
         return page_not_found(request)
     return HttpResponseRedirect(self.url(link, user))
コード例 #42
0
ファイル: auth.py プロジェクト: berten/merlin
def connected(message):
    # Successfully registered on the IRC server, check what nick
    Merlin.nick = message.get_chan()
    # Hide ourself
    message.write("MODE %s +ix" % Merlin.nick)
    # Kill the ghost
    nick = Config.get("Connection", "nick")
    if Merlin.nick != nick:
        message.privmsg("RECOVER %s %s %s" % (nick, nick, Config.get("Connection", "passwd")), Config.get("Services", "login"))
    login(message)
コード例 #43
0
def send_email(subject, message, addr):
    try:
        if (Config.get("smtp", "port") == "0"):
            smtp = SMTP("localhost")
        else:
            smtp = SMTP(Config.get("smtp", "host"), Config.get("smtp", "port"))

        if not ((Config.get("smtp", "host") == "localhost") or (Config.get("smtp", "host") == "127.0.0.1")):
            try:
                smtp.starttls()
            except SMTPException as e:
                raise SMSError("unable to shift connection into TLS: %s" % (str(e),))

            try:
                smtp.login(Config.get("smtp", "user"), Config.get("smtp", "pass"))
            except SMTPException as e:
                raise SMSError("unable to authenticate: %s" % (str(e),))

        try:
             smtp.sendmail(Config.get("smtp", "frommail"), addr, "To:%s\nFrom:%s\nSubject:%s\n%s\n" % (addr, "\"%s\" <%s>" % (
                                                           Config.get("Connection", "nick"), Config.get("smtp", "frommail")), subject, message))
        except SMTPSenderRefused as e:
            raise SMSError("sender refused: %s" % (str(e),))
        except SMTPRecipientsRefused as e:
            raise SMSError("unable to send: %s" % (str(e),))

        smtp.quit()

    except (socket.error, SSLError, SMTPException, SMSError) as e:
        return "Error sending message: %s" % (str(e),)
コード例 #44
0
ファイル: links.py プロジェクト: JDD/DLR
 def execute(self, message, user, params):
     
     links = [Config.get("URL","arthur"),
              Config.get("URL","PA"),
              "http://progression-uk.com/DLR/forum/index.php",
              "http://sandmans.co.uk",
              "http://game.planetarion.com/bcalc.pl",
              Config.get("URL","ships"),
             ]
     
     message.reply("Links: "+" | ".join(links))
コード例 #45
0
ファイル: pref.py プロジェクト: TBBTNut/merlin
 def flux_passwd(self, user):
     if not Config.getboolean("FluxBB", "enabled"):
         return -1
     if session.execute("SELECT username FROM %susers WHERE LOWER(username) LIKE '%s';" % (Config.get("FluxBB", "prefix"), user.name.lower())).rowcount > 0:
         return session.execute("UPDATE %susers SET password='******' WHERE LOWER(username) LIKE '%s';" % (Config.get("FluxBB", "prefix"), user.passwd, user.name.lower())).rowcount
     else:
         group = Config.get("FluxBB", "memgroup") if user.is_member() else Config.get("FluxBB", "galgroup")
         if group == 0:
             return -1
         return session.execute("INSERT INTO %susers (group_id, username, password, email, title) VALUES ('%s', '%s', '%s', '%s', '%s');" % (
                                Config.get("FluxBB", "prefix"), group, user.name, user.passwd, user.email, user.level)).rowcount
コード例 #46
0
 def flux_passwd(self, user):
     if not Config.getboolean("FluxBB", "enabled"):
         return -1
     if session.execute("SELECT username FROM %susers WHERE LOWER(username) LIKE '%s';" % (Config.get("FluxBB", "prefix"), user.name.lower())).rowcount > 0:
         return session.execute("UPDATE %susers SET password='******' WHERE LOWER(username) LIKE '%s';" % (Config.get("FluxBB", "prefix"), user.passwd, user.name.lower())).rowcount
     else:
         group = Config.get("FluxBB", "memgroup") if user.is_member() else Config.get("FluxBB", "galgroup")
         if group == 0:
             return -1
         return session.execute("INSERT INTO %susers (group_id, username, password, email, title) VALUES ('%s', '%s', '%s', '%s', '%s');" % (
                                Config.get("FluxBB", "prefix"), group, user.name, user.passwd, user.email, user.level)).rowcount
コード例 #47
0
 def execute(self, message, user, params):
     
     links = [Config.get("URL","game"),
              Config.get("URL","bcalc"),
              Config.get("URL","arthur"),
              Config.get("URL","ships"),
              "http://progression-uk.com/DLR/forum/index.php (Forums)",
              "http://kia.cthq.net/index.php (CT's sandmans)"
             ]
     
     message.reply(self.url("Links: "+" | ".join(links), user))
コード例 #48
0
ファイル: loadable.py プロジェクト: d7415/merlin
 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
コード例 #49
0
ファイル: loadable.py プロジェクト: JDD/merlin
def channel(chan):
    if not chan.find("#") == 0:
        if chan in Config.options("Channels"):
            chan = Config.get("Channels",chan)
        elif chan == "PM":
            chan = Config.get("Connection","nick")
        else:
            raise LoadableError("Invalid channel")
    def wrapper(execute):
        execute._CHANNEL = chan
        return execute
    return wrapper
コード例 #50
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))
コード例 #51
0
 def forwardMail(self, uname, header, body):
     if not Config.getboolean("imap", "forwarding"):
         return
     body = "Original Message from %s\n\n" % (header['From']) + body
     user = User.load(uname)
     if user:
         addr = user.email
     else:
         addr = Config.get("imap", "bounce")
         body = "Bad username: %s\n\n" % (uname) + body
     if addr:
         self.send_email(header['Subject'], body, addr)
コード例 #52
0
def user_in(chan):
    if not chan.find("#") == 0:
        if chan in Config.options("Channels"):
            chan = Config.get("Channels", chan)
        else:
            raise LoadableError("Invalid channel")

    def wrapper(execute):
        execute._USER_IN = chan
        return execute

    return wrapper
コード例 #53
0
ファイル: adduser.py プロジェクト: Hardware-Hacks/merlin
 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
コード例 #54
0
ファイル: attack.py プロジェクト: 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))