Ejemplo n.º 1
0
    def execute(self,user,access,irc_msg):
        m=irc_msg.match_command(self.commandre)
        if not m:
            return 0

        if access < self.level:
            irc_msg.reply("You do not have enough access to use this command")
            return 0


        m=self.paramre.search(m.group(1))
        if not m or not m.group(1):
            u=loadable.user(pnick=irc_msg.user)
            if not u.load_from_db(self.cursor):
                irc_msg.reply("Usage: %s (you must be registered for automatic lookup)" % (self.usage,))
                return 1
            if u.planet:
                reply=self.surprise(x=u.planet.x,y=u.planet.y,z=u.planet.z)
                irc_msg.reply(reply)
            else:
                irc_msg.reply("Usage: %s (you must be registered for automatic lookup)" % (self.usage,))
            return 0

        # assign param variables
        param=m.group(1)
        m=self.coordre.search(param)
        if m:
            x=m.group(1)
            y=m.group(2)
            z=m.group(4)

            if z:
                p=loadable.planet(x=x,y=y,z=z)
                if not p.load_most_recent(self.cursor):
                    irc_msg.reply("No planet matching '%s' found"%(param,))
                    return 1
                reply=self.surprise(x=p.x,y=p.y,z=p.z)

                irc_msg.reply(reply)
                return 1
            else:
                g=loadable.galaxy(x=x,y=y)
                if not g.load_most_recent(self.cursor):
                    irc_msg.reply("No galaxy matching '%s' found"%(param,))
                    return 1
                reply=self.surprise(x=g.x,y=g.y)
                irc_msg.reply(reply)
                return 1

        a=loadable.alliance(name=param.strip())
        if not a.load_most_recent(self.cursor):
            irc_msg.reply("No alliance matching '%s' found" % (param,))
            return 1
        reply=self.surprise(alliance=a.name)
        irc_msg.reply(reply)

        return 1
Ejemplo n.º 2
0
    def execute(self, user, access, irc_msg):
        m = irc_msg.match_command(self.commandre)
        if not m:
            return 0

        if access < self.level:
            irc_msg.reply("You do not have enough access to use this command")
            return 0

        m = self.paramre.search(m.group(1))
        if not m:
            irc_msg.reply("Usage: %s" % (self.usage,))
            return 0

        # assign param variables

        alliance = m.group(1)
        bums = m.group(2) or 1

        a = loadable.alliance(name=alliance)

        if not a.load_most_recent(self.cursor, irc_msg.round):
            irc_msg.reply("No alliance matching '%s' found" % (alliance,))
            return 1

        query = "SELECT x,y,count(*) AS bums FROM planet_dump AS t1"
        query += " INNER JOIN intel AS t2 ON t1.id=t2.pid"
        query += " LEFT JOIN alliance_canon AS t3 ON t2.alliance_id=t3.id"
        query += " WHERE t1.tick=(SELECT max_tick(%s::smallint))"
        query += " AND t3.name ilike %s"
        query += " AND t1.round=%s"
        query += " GROUP BY x,y"
        query += " HAVING count(*) >= %s"
        query += " ORDER BY bums DESC, x ASC, y ASC"

        # do stuff here

        self.cursor.execute(query, (irc_msg.round, a.name, irc_msg.round, bums,))

        reply = ""
        if self.cursor.rowcount < 1:
            reply += "No galaxies with at least %s bumchums from %s" % (bums, a.name)
        else:
            prev = []
            for b in self.cursor.dictfetchall():
                prev.append("%s:%s (%s)" % (b['x'], b['y'], b['bums']))
            reply += "Galaxies with at least %s bums from %s: " % (bums, a.name) + ' | '.join(prev)

        irc_msg.reply(reply)

        return 1
Ejemplo n.º 3
0
    def execute(self,user,access,irc_msg):
        m=irc_msg.match_command(self.commandre)
        if not m:
            return 0

        m=self.paramre.search(m.group(1))
        if not m:
            irc_msg.reply("Usage: %s" % (self.usage,))
            return 1

        if access < self.level:
            irc_msg.reply("You do not have enough access to use this command")
            return 1

        #assign param variables
        par=m.group(1)
        m=self.planet_coordre.search(par)
        if not m:
            m=self.gal_coordre.search(par)
            if m:
                return self.exec_gal(irc_msg,m.group(1),m.group(2))
            else:
                irc_msg.reply("Usage: %s" % (self.usage,))
                return 1

        p=loadable.planet(x=m.group(1),y=m.group(2),z=m.group(3))

        params=m.group(4)

        if not p.load_most_recent(self.cursor):
            irc_msg.reply("No planet matching '%s:%s:%s' found"%(p.x,p.y,p.z,))
            return 1

        i=loadable.intel(pid=p.id)
        if not i.load_from_db(self.cursor):
            pass

        opts=self.split_opts(params)
        opts['pid']=p.id
        a=loadable.alliance(name=i.alliance)
        if i.alliance:
            a.load_most_recent(self.cursor)
        for opt, val in opts.items():
            if opt == "alliance":
                if val in self.nulls:
                    a=loadable.alliance(id=None)
                    continue
                a=loadable.alliance(name=val)
                if not a.load_most_recent(self.cursor):
                    irc_msg.reply("'%s' is not a valid alliance, your information was not added."%(val,))
                    return 1
                else:
                    opts['alliance'] = a.name
            if (opt in self.options) and (val in self.nulls):
                opts[opt] = None
                continue
            if opt in ("nick","fakenick","bg","gov","reportchan"):
                opts[opt] = val
            if opt in ("defwhore","covop","scanner","distwhore","relay"):
                if val in self.true:
                    opts[opt] = True
                if val in self.false:
                    opts[opt] = False
            if opt == "comment":
                opts[opt] = self.commentre.split(irc_msg.command)[1]

        for k in self.options:
            if not opts.has_key(k):
                opts[k]=getattr(i,k)

        if i.id:
            query="UPDATE intel SET "
            query+="pid=%s,nick=%s,fakenick=%s,defwhore=%s,gov=%s,bg=%s,covop=%s,alliance_id=%s,relay=%s,reportchan=%s,"
            query+="scanner=%s,distwhore=%s,comment=%s"
            query+=" WHERE id=%s"
            self.cursor.execute(query,(opts['pid'],opts['nick'],
                                       opts['fakenick'],opts['defwhore'],opts['gov'],opts['bg'],
                                       opts['covop'],a.id,opts['relay'],opts['reportchan'],
                                       opts['scanner'],opts['distwhore'],opts['comment'],i.id))
        elif params:
            query="INSERT INTO intel (pid,nick,fakenick,defwhore,gov,bg,covop,relay,reportchan,scanner,distwhore,comment,alliance_id) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)"
            self.cursor.execute(query,(opts['pid'],opts['nick'],
                                       opts['fakenick'],opts['defwhore'],opts['gov'],opts['bg'],
                                       opts['covop'],opts['relay'],opts['reportchan'],
                                       opts['scanner'],opts['distwhore'],
                                       opts['comment'],a.id))
        i=loadable.intel(pid=opts['pid'],nick=opts['nick'],fakenick=opts['fakenick'],defwhore=opts['defwhore'],gov=opts['gov'],bg=opts['bg'],
                         covop=opts['covop'],alliance=opts['alliance'],relay=opts['relay'],reportchan=opts['reportchan'],
                         scanner=opts['scanner'],distwhore=opts['distwhore'],comment=opts['comment'])

        reply="Information stored for %s:%s:%s - "% (p.x,p.y,p.z)
        reply+=i.__str__()
        irc_msg.reply(reply)

        return 1
Ejemplo n.º 4
0
    def execute(self, user, access, irc_msg):
        m = irc_msg.match_command(self.commandre)
        if not m:
            return 0

        if access < self.level:
            irc_msg.reply("You do not have enough access to use this command")
            return 0

        m = self.paramre.match(m.group(1))
        if not m:
            irc_msg.reply("Usage: %s" % (self.usage,))
            return 0

        alliance_name = m.group(1)
        a = loadable.alliance(name=alliance_name)
        if not a.load_most_recent(self.cursor, irc_msg.round):
            irc_msg.reply("No alliance matching '%s' found" % (alliance_name))
            return 0

        query = "SELECT rel.type, rel.end_tick, canon1.name AS initiator, canon2.name AS acceptor"
        query += " FROM alliance_relation AS rel"
        query += " INNER JOIN alliance_canon AS canon1 ON rel.initiator = canon1.id"
        query += " INNER JOIN alliance_canon AS canon2 ON rel.acceptor = canon2.id"
        query += " WHERE ( canon1.id = %s OR canon2.id = %s )"
        query += " AND rel.end_tick > (SELECT max_tick(%s::smallint))"
        self.cursor.execute(query, (a.id, a.id, irc_msg.round))

        if self.cursor.rowcount == 0:
            reply = '%s is neutral. Easy targets!' % (a.name)
        else:
            alliances = []
            naps = []
            wars = []
            for row in self.cursor.dictfetchall():
                if row['type'] == 'Ally':
                    if a.name == row['initiator']:
                        alliances.append(row['acceptor'])
                    else:
                        alliances.append(row['initiator'])
                elif row['type'] == 'NAP':
                    if a.name == row['initiator']:
                        naps.append(row['acceptor'])
                    else:
                        naps.append(row['initiator'])
                elif row['type'] == 'War':
                    if a.name == row['initiator']:
                        wars.append("%s (until pt%d)" % (row['acceptor'], row['end_tick']))
                    else:
                        wars.append("%s (until pt%d)" % (row['initiator'], row['end_tick']))

            # <alliance> is allied with: X, Y, Z | <alliance> has a NAP with A, B, C | <alliance> is at war with: H
            # <alliance> is not allied with anyone | <alliance> does not have any NAPs | <alliance> is not at war with anyone
            reply = a.name
            if len(alliances) == 0:
                reply += ' is not allied with anyone'
            else:
                reply += ' is allied with ' + ', '.join(alliances)
            reply += ' | ' + a.name
            if len(naps) == 0:
                reply += ' does not have any NAPs'
            else:
                reply += ' has NAPs with ' + ', '.join(naps)
            reply += ' | ' + a.name
            if len(wars) == 0:
                reply += ' is not at war with anyone'
            else:
                reply += ' is at war with ' + ', '.join(wars)
        irc_msg.reply(reply)
        return 1
Ejemplo n.º 5
0
    def execute(self,user,access,irc_msg):
        m=irc_msg.match_command(self.commandre)
        if not m:
            return 0

        if access < self.level:
            irc_msg.reply("You do not have enough access to use this command")
            return 0


        m=self.paramre.search(m.group(1))
        if not m:
            irc_msg.reply(self.usage)
            return 0

        search=m.group(2)
        u=loadable.user(pnick=irc_msg.user)
        if search is not None:
            a=loadable.alliance(name=search)
            if not a.load_most_recent(self.cursor):
                reply="No alliances match %s" % (search,)
                irc_msg.reply(reply)
                return 1
        elif u.load_from_db(self.cursor) and u.userlevel >= 100:
            a=loadable.alliance(name=self.config.get('Auth', 'alliance'))
            if not a.load_most_recent(self.cursor):
                reply="No alliances match %s" % (search,)
                irc_msg.reply(reply)
                return 1
        elif u.id > -1 and u.planet is not None:
            i=loadable.intel(pid=u.planet.id)
            if (not i.load_from_db(self.cursor)) or i.alliance is None:
                reply="Make sure you've set your planet with !pref and alliance with !intel"
                irc_msg.reply(reply)
                return 1
            else:
                a=loadable.alliance(name=i.alliance)
        else:
            reply="Make sure you've set your planet with !pref and alliance with !intel"
            irc_msg.reply(reply)
            return 1

        query="DROP TABLE apenis;DROP SEQUENCE al_activity_rank;"
        try:
            self.cursor.execute(query)
        except:
            pass

        query="CREATE TEMP SEQUENCE al_activity_rank"
        self.cursor.execute(query)
        query="SELECT setval('al_activity_rank',1,false)"
        self.cursor.execute(query)


        query="CREATE TEMP TABLE apenis AS"
        query+=" (SELECT *,nextval('al_activity_rank') AS activity_rank"
        query+=" FROM (SELECT t1.name, t1.members, t1.score-t5.score AS activity"
        query+=" FROM alliance_dump AS t1"
        query+=" INNER JOIN alliance_dump AS t5"
        query+=" ON t1.id=t5.id AND t1.tick - 72 = t5.tick"
        query+=" WHERE t1.tick = (select max(tick) from updates)"
        query+=" ORDER BY activity DESC) AS t8)"

        self.cursor.execute(query)

        query="SELECT name,activity,activity_rank,members"
        query+=" FROM apenis"
        query+=" WHERE name ILIKE %s"

        self.cursor.execute(query,(a.name,))
        if self.cursor.rowcount < 1:
            query="SELECT name,activity,activity_rank"
            query+=" FROM apenis"
            query+=" WHERE name ILIKE %s"

            self.cursor.execute(query,(a.name,))

        res=self.cursor.dictfetchone()
        if not res:
            reply="No apenis stats matching %s"% (a.name,)
        else:
            person=res['name']
            reply ="apenis for %s is %s score long. This makes %s rank: %s apenis. The average peon is sporting a %s score epenis." % (person,res['activity'],person,res['activity_rank'],int(res['activity']/res['members']))

        irc_msg.reply(reply)

        return 1
Ejemplo n.º 6
0
Archivo: pref.py Proyecto: munin/munin
    def execute(self, user, access, irc_msg):
        m = irc_msg.match_command(self.commandre)
        if not m:
            return 0

        m = self.paramre.search(m.group(1))
        if not m:
            irc_msg.reply("Usage: %s" % (self.usage,))
            return 0

        u = loadable.user(pnick=irc_msg.user)
        if not u.load_from_db(self.cursor, irc_msg.round):
            irc_msg.reply(
                "You must be registered to use the " +
                self.__class__.__name__ +
                " command (log in with P and set mode +x)")
            return 1

        param_dict = self.split_opts(m.group(1))
        if param_dict is None:
            irc_msg.reply("Usage: %s" % (self.usage,))
            return 1

        if access < self.level:
            irc_msg.reply("You do not have enough access to use this command")
            return 0

        for opt in param_dict:
            val = param_dict[opt]
            if opt == "planet":
                m = self.planet_coordre.search(val)
                if m:
                    x = m.group(1)
                    y = m.group(2)
                    z = m.group(3)
                else:
                    irc_msg.reply("You must provide coordinates (x:y:z) for the planet option")
                    continue
                pid = self.save_planet(irc_msg, u, x, y, z, irc_msg.round)
                if pid > 0 and u.userlevel >= 100:
                    a = loadable.alliance(name=self.config.get('Auth', 'alliance'))
                    if a.load_most_recent(self.cursor, irc_msg.round):
                        i = loadable.intel(pid=pid)
                        i.load_from_db(self.cursor, irc_msg.round)
                        if i.id:
                            query = "UPDATE intel SET "
                            query += "nick=%s,alliance_id=%s"
                            query += " WHERE id=%s"
                            self.cursor.execute(query, (user, a.id, i.id))
                        else:
                            query = "INSERT INTO intel (pid,nick,alliance_id,round) VALUES (%s,%s,%s,%s)"
                            self.cursor.execute(query, (pid, user, a.id, irc_msg.round,))
            if opt == "stay":
                self.save_stay(irc_msg, u, val, access, irc_msg.round)
            if opt == "pubphone":
                self.save_pubphone(irc_msg, u, val, access)
            if opt == "password":
                self.save_password(irc_msg, u, val)
            if opt == "phone":
                self.save_phone(irc_msg, u, val)

        return 1
Ejemplo n.º 7
0
    def execute(self,user,access,irc_msg):
        m=irc_msg.match_command(self.commandre)
        if not m:
            return 0
        print access, irc_msg.access, irc_msg.target
        if access < self.level:
            irc_msg.reply("You do not have enough access to use this command")
            return 0


        m=self.paramre.search(m.group(1))
        if not m or not m.group(1):
            u=loadable.user(pnick=irc_msg.user)
            if not u.load_from_db(self.cursor):
                irc_msg.reply("You must be registered to use the automatic "+self.__class__.__name__+" command (log in with P and set mode +x, then make sure you've set your planet with the pref command)")
                return 1
            if u.planet:
                irc_msg.reply(str(u.planet))
            else:
                irc_msg.reply("Usage: %s" % (self.usage,))
            return 1
        param=m.group(1)
        m=self.coordre.search(param)
        if m:
            x=m.group(1)
            y=m.group(2)
            z=m.group(4)
            # assign param variables

            if z:
                p=loadable.planet(x=x,y=y,z=z)
                if not p.load_most_recent(self.cursor):
                    irc_msg.reply("No planet matching '%s' found"%(param,))
                    return 1
                irc_msg.reply(str(p))
                return 1
            else:
                g=loadable.galaxy(x=x,y=y)
                if not g.load_most_recent(self.cursor):
                    irc_msg.reply("No galaxy matching '%s' found"%(param,))
                    return 1
                irc_msg.reply(str(g))
                return 1

        #check if this is an alliance
        a=loadable.alliance(name=param.strip())
        if a.load_most_recent(self.cursor):
            irc_msg.reply(str(a))
            return
        u=self.load_user_from_pnick(param.strip())
        if u and irc_msg.access >= 100:
            if u.planet:
                irc_msg.reply(str(u.planet))
            else:
                irc_msg.reply("User %s has not entered their planet details" % (u.pnick,))
            return 
        irc_msg.reply("No alliance or user matching '%s' found" % (param,))
        return
        

        # do stuff here

        return
Ejemplo n.º 8
0
    def execute(self,user,access,irc_msg):
        m=irc_msg.match_command(self.commandre)
        if not m:
            return 0

        if access < self.level:
            irc_msg.reply("You do not have enough access to use this command")
            return 0
        curtick=self.current_tick()


        m=self.paramre.search(m.group(1))
        if not m:
            irc_msg.reply("Usage: %s" % (self.usage,))
            return 0
        # assign param variables

        subject=m.group(1)
        when=m.group(3)
        if when: when=int(when)
        if subject: subject=subject.strip()

        a=loadable.alliance(name=subject)
        if a.name.lower() != "unknown":
            if not a.load_most_recent(self.cursor):
                irc_msg.reply("'%s' is not a valid alliance."%(subject,))
                return 1

        if when and when < 32:
            tick=curtick+when
        elif when and when < curtick:
            irc_msg.reply("Can not check status on the past. You wanted tick %s, but current tick is %s. (If you really need to know, poke %s.)"%(when,curtick, self.config.get('Auth', 'owner_nick')))
            return 1
        elif when:
            tick=when

        args=()
        query="SELECT t1.id AS id, t1.nick AS nick, t1.pid AS pid, t1.tick AS tick, t1.uid AS uid, t2.pnick AS pnick, t2.userlevel AS userlevel, t3.x AS x, t3.y AS y, t3.z AS z"
        query+=" FROM target AS t1"
        query+=" INNER JOIN planet_dump AS t3 ON t1.pid=t3.id"
        query+=" LEFT JOIN user_list AS t2 ON t1.uid=t2.id"
        query+=(" INNER" if a.id else " LEFT")+" JOIN intel AS t4 ON t1.pid=t4.pid"
        query+=" WHERE"

        if when:
            query+=" t1.tick = %s"
            args+=(tick,)
        else:
            query+=" t1.tick > (SELECT max_tick())"

        query+=" AND t3.tick = (SELECT max_tick())"
        query+=" AND t4.alliance_id "+("=" if a.id else "IS")+" %s"
        query+=" ORDER BY tick, x, y, z"
        self.cursor.execute(query,args+(a.id,))

        if self.cursor.rowcount < 1:
            reply="No active bookings matching alliance %s" %(a.name)
            if when:
                reply+=" for tick %s"%(tick,)
            irc_msg.reply(reply)
            return 1

        ticks={}
        for r in self.cursor.dictfetchall():
            if not ticks.has_key(r['tick']):
                ticks[r['tick']]=[]
            ticks[r['tick']].append(r)

        reply="Target information for %s"%(a.name)
        if when:
            reply+=" for landing on tick %s (eta %s):"%(tick,tick-curtick)
        sorted_keys=ticks.keys()
        sorted_keys.sort()
        for k in sorted_keys:
            reply=string.join([reply,"Tick %s (eta %s)" % (k,k-curtick)])
            booked_list=ticks[k]
            prev=[]
            for p in booked_list:
                owner="nick:"+p['nick']
                if p['pnick']:
                    owner="user:"******"(%s:%s:%s %s)" % (p['x'],p['y'],p['z'],owner))


            reply+=" "+string.join(prev,', ')
            irc_msg.reply(reply.strip())
            reply=""
        return 1
Ejemplo n.º 9
0
    def execute(self, user, access, irc_msg):
        m = self.commandre.search(irc_msg.command)
        if not m:
            return 0

        if access < self.level:
            irc_msg.reply("You do not have enough access to use this command")
            return 0

        m = self.paramre.search(m.group(1))
        if not m:
            irc_msg.reply("Usage: %s" % (self.usage,))
            return 0

        # assign param variables
        alliance_name = m.group(1)
        coord_list = re.split(self.coordsplitre, m.group(2))

        if len(coord_list) % 3 != 0:
            irc_msg.reply("You did not give me a set of complete coords, you dumbass!")
            return 0

        # do stuff here
        a = loadable.alliance(name=alliance_name)
        if not a.load_most_recent(self.cursor, irc_msg.round):
            irc_msg.reply("No alliance matching ' %s' found" % (alliance_name))
            return 0

        # Separate X from Y from Z coords.
        xs = coord_list[0::3]
        ys = coord_list[1::3]
        zs = coord_list[2::3]

        # Get planet IDs for the given coords.
        pids = ()
        coords = ()
        skipped = ()
        for i in range(0, len(xs)):
            p = loadable.planet(x=xs[i], y=ys[i], z=zs[i])
            if p.load_most_recent(self.cursor, irc_msg.round):
                pids += (p.id,)
                coords += ("%s:%s:%s" % (p.x, p.y, p.z),)
            else:
                skipped += ("%s:%s:%s" % (p.x, p.y, p.z),)

        if len(skipped) > 0:
            irc_msg.reply("The following coords do not exist, try again: %s" % (", ".join(skipped)))
            return 0

        # Interleave alliance ID with the current round number and planet IDs:
        # pid1, aid, round, pid2, aid, round, etc.
        aids = (a.id,) * len(pids)
        rounds= (irc_msg.round,) * len(pids)
        values = tuple(val for pair in zip(pids, aids,rounds) for val in pair)

        # Make a query with 'len(pids)' value lists.
        query = "INSERT INTO intel (pid, alliance_id, round) VALUES %s" % (" , ".join(("(%s, %s, %s)",) * len(pids)))
        query += " ON CONFLICT (pid) DO"
        query += " UPDATE SET alliance_id = EXCLUDED.alliance_id"
        self.cursor.execute(query, values)
        if self.cursor.rowcount < 1:
            irc_msg.reply("Failed to change intel, go whine to the bot owner.")
            return 0

        irc_msg.reply("Set alliance for %s to %s" % (", ".join(coords), a.name,))
        return 1