Example #1
0
File: adopt.py Project: munin/munin
    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

        u = self.load_user(user, irc_msg)
        if not u:
            return 0

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

        # assign param variables
        adoptee = m.group(1)

        if adoptee.lower() == self.config.get('Connection', 'nick').lower():
            irc_msg.reply("F**k off you stupid twat, stop trying to be a clever shit.")
            return 1

        if adoptee.lower() == u.pnick.lower():
            irc_msg.reply("Stop wanking your own dick and find a daddy to do it for you, retard.")
            return 1

        a = loadable.user(pnick=adoptee)
        a.load_from_db(self.cursor, irc_msg.round)
        if not a.id or a.userlevel < 100:
            irc_msg.reply("No members matching '%s'" % (adoptee,))
            return 1

        s = loadable.user(pnick=a.sponsor)
        s.load_from_db(self.cursor, irc_msg.round)
        if s.id and s.userlevel >= 100:
            irc_msg.reply("%s already has a daddy you filthy would-be kidnapper!" % (a.pnick,))
            return 1

        if u.has_ancestor(self.cursor, a.pnick, irc_msg.round):
            irc_msg.reply("Ew, incest.")
            return 1

        query = "UPDATE user_list"
        query += " SET sponsor = %s"
        query += " WHERE id = %s"
        self.cursor.execute(query, (u.pnick, a.id,))

        irc_msg.reply("Congratulations! You're now the proud father of a not-so newly born %s!" % (a.pnick,))
        return 1
Example #2
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 0

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

        victim = None
        attacker = None
        mcs = 0

        victim = loadable.planet(x=m.group(1),y=m.group(2),z=m.group(3))
        if not victim.load_most_recent(self.cursor):
            irc_msg.reply("%s:%s:%s is not a valid planet" % (victim.x,victim.y,victim.z))
            return 1

        if not victim:
            irc_msg.reply("Usage: %s" % (self.usage,))
            return 1

        if m.lastindex >= 6 and m.group(4) and m.group(5) and m.group(6):
            attacker = loadable.planet(x=m.group(4),y=m.group(5),z=m.group(6))
            if not attacker.load_most_recent(self.cursor):
                irc_msg.reply("%s:%s:%s is not a valid planet" % (attacker.x,attacker.y,attacker.z))
                return 1
        if not attacker:
            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 your planet is set with the pref command)")
                return 1
            if u.planet_id:
                attacker = u.planet
            else:
                irc_msg.reply("Usage: %s (make sure your planet is set with the pref command)" % (self.usage,))
                return 1

        if m.lastindex == 7:
            mcs = int(m.group(7))

        reply="Target %s:%s:%s (%s|%s) "%(victim.x,victim.y,victim.z,
                                          self.format_value(victim.value*100),self.format_value(victim.score*100))
        reply+="| Attacker %s:%s:%s (%s|%s) "%(attacker.x,attacker.y,attacker.z,
                                               self.format_value(attacker.value*100),self.format_value(attacker.score*100))

        bravery = attacker.bravery(victim)
        cap = int(attacker.cap_rate(victim)*victim.size)
        xp = int(attacker.calc_xp(victim, mcs))
        score = self.format_value(100 * 60 * xp)

        reply+="| Bravery: %.2f | Cap: %d | MCs: %d | XP: %d | Score: %s" % (bravery,cap,mcs,xp,score)
        irc_msg.reply(reply)

        return 1
Example #3
0
    def process_list_all_proposals(self,irc_msg,user):
        u=loadable.user(pnick=irc_msg.user)
        u.load_from_db(self.cursor)
        query="SELECT invite.id AS id, invite.person AS person, NULL AS question, 'invite' AS prop_type"
        query+=" FROM invite_proposal AS invite"
        query+=" WHERE invite.active"
        query+=" UNION ("
        query+="     SELECT kick.id AS id, t3.pnick AS person, NULL AS question, 'kick' AS prop_type"
        query+="     FROM kick_proposal AS kick"
        query+="     INNER JOIN user_list AS t3 ON kick.person_id=t3.id"
        query+="     WHERE kick.active"
        query+=" )"
        query+=" UNION ("
        query+="     SELECT poll.id AS id, NULL AS person, poll.question AS question, 'poll' AS prop_type"
        query+="     FROM poll_proposal AS poll"
        query+="     WHERE poll.active"
        query+=" )"
        self.cursor.execute(query,())
        a=[]
        for r in self.cursor.dictfetchall():
            prop_info="%s: %s %s"%(r['id'],r['prop_type'],r['person'] or r['question'] + '?')
            if not irc_msg.chan_reply():
                query="SELECT t1.vote AS vote, t1.carebears AS carebears FROM prop_vote AS t1"
                query+=" WHERE t1.prop_id=%s AND t1.voter_id=%s"
                self.cursor.execute(query,(r['id'],u.id))
                if self.cursor.rowcount > 0:
                    r=self.cursor.dictfetchone()
                    prop_info+=" (%s,%s)"%(r['vote'][0].upper(),r['carebears'])
            a.append(prop_info)

        reply="Propositions currently being voted on: %s"%(string.join(a, ", "),)
        irc_msg.reply(reply)
Example #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.search(m.group(1))
        if not m:
            irc_msg.reply("Usage: %s" % (self.usage,))
            return 0

        # assign param variables

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


        idiot=loadable.user(pnick=m.group(1))
        if not idiot.load_from_db(self.cursor):
            irc_msg.reply("That idiot doesn't exist")
            return 1

        # do stuff here

        if access < 1000 and idiot.sponsor.lower() != voter.pnick.lower() and idiot.pnick.lower() != voter.pnick.lower():
            reply="You are not %s's sponsor"%(idiot.pnick,)
            irc_msg.reply(reply)
            return 1

        query="UPDATE user_list SET userlevel = 1 WHERE id = %s"
        self.cursor.execute(query,(idiot.id,))
        irc_msg.client.privmsg('p','remuser #%s %s'%(self.config.get('Auth', 'home'), idiot.pnick,))
        irc_msg.client.privmsg('p',"ban #%s *!*@%s.users.netgamers.org Your sponsor doesn't like you anymore"%(self.config.get('Auth', 'home'), idiot.pnick,))

        if idiot.sponsor != voter.pnick:
            irc_msg.client.privmsg('p',"note send %s Some admin has removed you from %s for whatever reason. If you still wish to be a member, go ahead and find someone else to sponsor you back."%(idiot.pnick, self.config.get('Auth', 'alliance')))
            reply="%s has been reduced to level 1 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.pnick,idiot.sponsor,idiot.pnick)
        else:
            irc_msg.client.privmsg('p',"note send %s Your sponsor (%s) no longer wishes to be your sponsor for %s. If you still wish to be a member, go ahead and find someone else to sponsor you back."%(idiot.pnick,voter.pnick, self.config.get('Auth', 'alliance')))
            reply="%s has been reduced to level 1 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.pnick,idiot.pnick)
        irc_msg.reply(reply)
        return 1
Example #5
0
    def execute(self, user, access, irc_msg):
        m = irc_msg.match_command(self.commandre)
        if not m:
            return 0

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

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

        planet = None

        if m.lastindex == 3 and m.group(1) and m.group(2) and m.group(3):
            planet = loadable.planet(x=m.group(1), y=m.group(2), z=m.group(3))
            if not planet.load_most_recent(self.cursor, irc_msg.round):
                irc_msg.reply("%s:%s:%s is not a valid planet" % (planet.x, planet.y, planet.z))
                return 1
        else:
            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 automatic " +
                    self.__class__.__name__ +
                    " command (log in with P and set mode +x, then make sure your planet is set with the pref command)")
                return 1
            if u.planet_id:
                planet = u.planet
            else:
                irc_msg.reply("Usage: %s (make sure your planet is set with the pref command)" % (self.usage,))
                return 1

        if not planet:
            irc_msg.reply("Usage: %s" % (self.usage,))
            return 0

        query = "SELECT score"
        query += " FROM planet_dump"
        query += " WHERE tick=(SELECT max_tick(%s::smallint)) AND round=%s"
        query += " ORDER BY score_rank ASC"
        query += " LIMIT 20"
        self.cursor.execute(query, (irc_msg.round, irc_msg.round,))
        if self.cursor.rowcount < 1:
            irc_msg.reply("Error retrieving score of top 20 planets from database")
        top20_average_score = reduce(lambda s, p: s + float(p['score']) / 20.0,
                                     self.cursor.dictfetchall(),
                                     0.0)

        score_modifier = 0.5 * (1.0 - float(planet.score) / top20_average_score)
        race_bonus = self.config.getfloat('Planetarion', planet.race + '_salvage_bonus')
        salvage_rate = 0.3 * (1.0 + race_bonus) * (1.0 + score_modifier)
        reply = "%s:%s:%s (%s|%s) gets a defense salvage rate of %2.1f%%" % (planet.x, planet.y, planet.z, self.format_value(
            planet.value * 100), self.format_value(planet.score * 100), 100 * salvage_rate)
        irc_msg.reply(reply)
        return 1
Example #6
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
Example #7
0
File: c.py Project: kaaveland/munin
    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

        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 "+self.__class__.__name__+" command (log in with P and set mode +x)")
            return 1

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

        # assign param variables
        call_id=m.group(1)
        new_comment=m.group(3)

        # do stuff here
        d=loadable.defcall(call_id)
        if not d.load_most_recent(self.cursor):
            irc_msg.reply("No defcall matching id %s found" %(call_id,))
            return 0

        c=d.comment

        if not new_comment:
            if not c:
                reply="Defcall %s has no comment"%(d.id,)
            else:
                reply="Defcall %s has comment '%s'"%(d.id,c)
            irc_msg.reply(reply)
            return 1

        query="UPDATE defcalls SET comment=%s WHERE id=%s"
        args=(new_comment,d.id)

        self.cursor.execute(query,args)

        if self.cursor.rowcount < 1:
            irc_msg.reply("Something went wrong. Defcall id was %s and new comment was '%s'"%(d.id,new_comment))
        else:
            p=d.actual_target
            irc_msg.reply("Updated defcall %s on %s:%s:%s landing pt %s with comment '%s'"%(d.id,p.x,p.y,p.z,d.landing_tick,new_comment))

        return 1
Example #8
0
File: s.py Project: kaaveland/munin
    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

        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 "+self.__class__.__name__+" command (log in with P and set mode +x)")
            return 1

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

        # assign param variables
        call_id=m.group(1)
        s_command=m.group(3)

        # do stuff here
        d=loadable.defcall(call_id)
        if not d.load_most_recent(self.cursor):
            irc_msg.reply("No defcall matching id %s found" %(call_id,))
            return 0

        p=d.actual_target

        if not s_command:
            irc_msg.reply(str(d))
            return 1

        query="SELECT id, status FROM defcall_status WHERE status ilike %s"
        self.cursor.execute(query,(s_command+'%',))
        s=self.cursor.dictfetchone()
        if not s:
            irc_msg.reply("%s is not a valid defcall status, defcall was not modified"%(s_command,))
            return 0

        query="UPDATE defcalls SET status = %s,claimed_by=%s WHERE id = %s"
        print str(u.id)
        self.cursor.execute(query,(s['id'],user,d.id))
        if self.cursor.rowcount < 1:
            irc_msg.reply("Something went wrong. Old status was %s, new status was %s, defcall id was %s"%(old_status,s['status'],d.id))
        else:
            irc_msg.reply("Updated defcall %s on %s:%s:%s landing pt %s from status '%s' to '%s'"%(d.id,p.x,p.y,p.z,d.landing_tick,d.actual_status,s['status']))

        return 1
Example #9
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
        search=m.group(1)

        # do stuff here

        if search.lower() == self.config.get('Connection','nick').lower():
            irc_msg.reply("I am Munin. Hear me roar.")
            return 1

        query="SELECT pnick,alias_nick,sponsor,invites,carebears"
        query+=" FROM user_list"
        query+=" WHERE pnick ilike %s"
        query+=" AND userlevel >= 100"

        self.cursor.execute(query,(search,))

        reply=""
        if self.cursor.rowcount < 1:
            self.cursor.execute(query,('%'+search+'%',))

        r=self.cursor.dictfetchone()

        if not r:
            reply+="No members matching '%s'"%(search,)
        else:
            u=loadable.user(pnick=r['pnick'])
            u.load_from_db( self.cursor)
            if r['pnick'] == irc_msg.user:
                reply+="You are %s. You are also known as %s. Your sponsor is %s. Your Munin number is %s. You have %d %s."
            else:
                reply+="Information about %s: They are also known as %s. Their sponsor is %s. Their Munin number is %s. They have %d %s."
            reply=reply%(r['pnick'],r['alias_nick'],r['sponsor'],self.munin_number_to_output(u),r['carebears'],self.pluralize(r['carebears'],"carebear"))

        irc_msg.reply(reply)

        return 1
Example #10
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
        planet = None
        param = m.group(1)
        m = self.paramre.search(param)

        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.round):
                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:
                planet = u.planet
            else:
                irc_msg.reply("Usage: %s" % (self.usage,))
                return 1
        else:
            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.round):
                        irc_msg.reply("No planet matching '%s' found" % (param,))
                        return 1
                    planet = p
            else:
                irc_msg.reply("Usage: %s (you must be registered for automatic lookup)" % (self.usage,))
                return 1
        if planet:
            reply = "%s:%s:%s can hit planets with value %d or above or score %d or above" % (
                planet.x, planet.y, planet.z, int(planet.value * .4), int(planet.score * .6))

        irc_msg.reply(reply)
        return 1
Example #11
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 0

        # assign param variables
        when=None
        x=m.group(1)
        y=m.group(2)
        z=m.group(3)
        when=m.group(5)
        if when: when=int(when)
        override=m.group(7)

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

        curtick=self.current_tick()
        tick=-1

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

        u=loadable.user(pnick=irc_msg.user)
        if not u.load_from_db(self.cursor):
            u=None


        if when and when < 32:
            tick=curtick+when
        elif when and when < curtick:
            irc_msg.reply("Can not unbook targets in the past. You wanted tick %s, but current tick is %s."%(when,curtick))
            return 1
        elif when:
            tick=when

        if not override: # trying to unbook own target
            query="DELETE FROM target WHERE pid = %s "
            args=(p.id,)
            if when:
                query+=" AND tick = %s "
                args+=(tick,)
            else:
                query+=" AND tick > %s "
                args+=(curtick,)
            if u:
                #query+=" AND (uid ILIKE %s OR uid IS NULL)"
                query+=" AND uid = %s"
                args+=(u.id,)
            else:
                query+=" AND nick ILIKE %s"
                args+=(irc_msg.nick,)

            self.cursor.execute(query,args)
            if self.cursor.rowcount == 0:
                reply="You have no bookings matching %s:%s:%s" %(p.x,p.y,p.z)
                if when:
                    reply+=" for landing on tick %s"%(tick,)
                reply+=". If you are trying to unbook someone else's target, you must confirm with 'yes'."
            else:
                reply="You have unbooked %s:%s:%s"%(p.x,p.y,p.z)
                if when:
                    reply+=" for landing pt %s"%(tick,)
                else:
                    reply+=" for %d booking(s)"%(self.cursor.rowcount)
                reply+="."

        else:
            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 "
            query+=" FROM target AS t1 LEFT JOIN user_list AS t2 ON t1.uid=t2.id "
            query+=" WHERE t1.pid=%s "
            args=(p.id,)
            if when:
                query+=" AND tick=%s"
                args+=(tick,)
            else:
                query+=" AND tick > %s"
                args+=(curtick,)
            self.cursor.execute(query,args)
            if self.cursor.rowcount < 1:
                reply="No bookings matching %s:%s:%s" %(p.x,p.y,p.z)
                if when:
                    reply+=" for landing on tick %s"%(tick,)
                irc_msg.reply(reply)
                return 1

            res=self.cursor.dictfetchall()

            query="DELETE FROM target WHERE pid = %s "
            args=(p.id,)
            if when:
                query+=" AND tick = %s "
                args+=(tick,)
            else:
                query+=" AND tick > %s "
                args+=(curtick,)

            self.cursor.execute(query,args)

            reply="You have unbooked %s:%s:%s"%(p.x,p.y,p.z)
            if when:
                owner=res[0]['nick']
                type="nick"
                if res[0]['pnick']:
                    owner=res[0]['pnick']
                    type="user"
                reply+=" for landing pt %s (previously held by %s %s)"%(res[0]['tick'],type,owner)
            else:
                reply+=" for %d booking(s): "%(self.cursor.rowcount)
                prev=[]
                for r in res:
                    owner="nick: "+r['nick']
                    if r['pnick']:
                        owner="user: "******"(%s %s)" % (r['tick'],owner))
                reply+=" "+string.join(prev,', ')

        irc_msg.reply(reply)
        return 1
Example #12
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 0

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


        attacker=None
        u=loadable.user(pnick=irc_msg.user)
        if not u.load_from_db(self.cursor):
            irc_msg.reply("Usage: %s (you must set your planet in preferences to use this command (!pref planet=x:y:z))" % (self.usage,))
            return 1
        if u.planet_id:
            attacker = u.planet
        else:
            irc_msg.reply("Usage: %s (you must set your planet in preferences to use this command (!pref planet=x:y:z))" % (self.usage,))
            return 1


        # assign param variables

        if access < self.level:
            irc_msg.reply("You do not have enough access to use this command")
            return 0
        alliance=None
        race=None
        size_mod=None
        size=None
        value_mod=None
        value=None
        cluster=None
        param=m.group(1)
        params=param.split()

        for p in params:
            m=self.clusterre.search(p)
            if m and not cluster:
                cluster=int(m.group(1))
                continue
            m=self.racere.search(p)
            if m and not race:
                race=m.group(1)
                continue
            m=self.rangere.search(p)
            if m and not size and int(m.group(2)) < 32768:
                size_mod=m.group(1) or '>'
                size=m.group(2)
                continue
            m=self.rangere.search(p)
            if m and not value:
                value_mod=m.group(1) or '<'
                value=m.group(2)
                continue
            m=self.alliancere.search(p)
            if m and not alliance and not self.clusterre.search(p):
                alliance=m.group(1)
                continue


        victims=self.victim(alliance,race,size_mod,size,value_mod,value,attacker,True,cluster)
        i=0
        if not len(victims):
            reply="No"
            if race:
                reply+=" %s"%(race,)
            reply+=" planets"
            if alliance:
                reply+=" in intel matching alliance: %s"%(alliance,)
            else:
                reply+=" matching"
            if size:
                reply+=" Size %s %s" % (size_mod,size)
            if value:
                reply+=" Value %s %s" % (value_mod,value)
            irc_msg.reply(reply)
        for v in victims:
            reply="%s:%s:%s (%s)" % (v['x'],v['y'],v['z'],v['race'])
            reply+=" Value: %s Size: %s Scoregain: %d" % (v['value'],v['size'],v['xp_gain']*60)
            if v['nick']:
                reply+=" Nick: %s" % (v['nick'],)
            if not alliance and v['alliance']:
                reply+=" Alliance: %s" % (v['alliance'],)
            i+=1
            if i>4 and len(victims)>4:
                reply+=" (Too many victims to list, please refine your search)"
                irc_msg.reply(reply)
                break
            irc_msg.reply(reply)


        return 1
Example #13
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
Example #14
0
File: pref.py Project: 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
Example #15
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

        u=None
        if user:
            u=loadable.user(pnick=irc_msg.user)
            if not u.load_from_db(self.cursor):
                pass

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

        # assign param variables

        x=m.group(1)
        y=m.group(2)
        z=m.group(3)

        # first, plain lookup

        p=loadable.planet(x=x,y=y,z=z)
        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

        irc_msg.reply(p.__str__())

        # next we do XP



        if u.planet_id:
            # this is a straight copy from xp. Dirty dirty.
            attacker = u.planet
            reply="Target "
            victim_val = p.value
            attacker_val = attacker.value
            victim_score = p.score
            attacker_score = attacker.score

            reply+="%s:%s:%s (%s|%s) "%(p.x,p.y,p.z,
                                        self.format_value(victim_val*100),self.format_value(victim_score*100))
            reply+="| Attacker %s:%s:%s (%s|%s) "%(attacker.x,attacker.y,attacker.z,
                                                   self.format_value(attacker_val*100),self.format_value(attacker_score*100))
            total_roids = p.size

            #bravery = min(20,10*(float(victim_val)/attacker_val))
            #bravery = min(20,5*(float(victim_val)/attacker_val)*(float(victim_score)/attacker_score))

            bravery = max(0,(min(2,float(victim_val)/attacker_val)-0.4 ) * (min(2,float(victim_score)/attacker_score)-0.6))
            #bravery = max(0,min(30,10*(min(2,float(victim_val)/attacker_val)  + min(2,float(victim_score)/attacker_score) - 1)))
            bravery *= 10

            reply+="| Bravery: %.2f " % (bravery,)

            cap=total_roids/4
            xp=int(cap*bravery)
            reply+="| Roids: %s | XP: %s | Score: %s" % (cap,xp,xp*60)
            irc_msg.reply(reply)

        i=loadable.intel(pid=p.id)
        reply="Information stored for %s:%s:%s - "% (p.x,p.y,p.z)
        if i.load_from_db(self.cursor) and i.id>0:
            reply+=i.__str__()
        irc_msg.reply(reply)


        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+=" WHERE t1.tick > (SELECT max_tick()) AND t3.tick = (SELECT max_tick()) AND t3.x=%s AND t3.y=%s AND t3.z=%s"

        self.cursor.execute(query,(p.x,p.y,p.z))
        if self.cursor.rowcount < 1:
            reply="No bookings matching planet %s:%s:%s"%(p.x,p.y,p.z)
        else:
            reply="Status for %s:%s:%s -" % (x,y,z)
            prev=[]
            for r in self.cursor.dictfetchall():
                owner="nick:"+r['nick']
                if r['pnick']:
                    owner="user:"******"(%s %s)" % (r['tick'],owner))

            reply+=" "+string.join(prev,', ')

        irc_msg.reply(reply)




        return 1
Example #16
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 0

        x=m.group(1)
        y=m.group(2)
        z=m.group(3)
        when=int(m.group(4))
        override=m.group(6)

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

        if access < 100 and not irc_msg.user:
            irc_msg.reply("I don't trust you. You have to set mode +x to book a target.")
            return 0


        p=loadable.planet(x=x,y=y,z=z)
        if not p.load_most_recent(self.cursor):
            irc_msg.reply("No planet matching '%s:%s:%s' found"%(x,y,z))
            return 1
        else:
            i=loadable.intel(pid=p.id)
            if not i.load_from_db(self.cursor):
                pass
            else:
                if i and i.alliance and i.alliance.lower()== self.config.get("Auth", "alliance").lower():
                    irc_msg.reply("%s:%s:%s is %s in %s. Quick, launch before they notice the highlight."%(x,y,z,i.nick or 'someone',self.config.get('Auth', 'alliance')))
                    return 0
        curtick=self.current_tick()
        tick=-1
        eta=-1

        if when < 32:
            tick=curtick+when
            eta=when
        elif when < curtick:
            irc_msg.reply("Can not book targets in the past. You wanted tick %s, but current tick is %s."%(when,curtick))
            return 1
        else:
            tick=when
            eta=tick-curtick
        if tick > 32767:
            tick=32767


        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+=" WHERE"
        query+=" t1.tick > %s"
        query+=" AND t3.tick = (SELECT max_tick()) AND t3.x=%s AND t3.y=%s"
        query+=" AND t3.z=%s"

        self.cursor.execute(query,(tick,x,y,z))

        if self.cursor.rowcount > 0 and not override:
            reply="There are already bookings for that target after landing pt %s (eta %s). To see status on this target, do !status %s:%s:%s." % (tick,eta,x,y,z)
            reply+=" To force booking at your desired eta/landing tick, use !book %s:%s:%s %s yes (Bookers:" %(x,y,z,tick)
            prev=[]
            for r in self.cursor.dictfetchall():
                owner="nick:"+r['nick']
                if r['pnick']:
                    owner="user:"******"(%s %s)" % (r['tick'],owner))
            reply+=" "+string.join(prev,', ')
            reply+=" )"
            irc_msg.reply(reply)
            return 1

        uid=None
        if irc_msg.user:
            u=loadable.user(pnick=irc_msg.user)
            if u.load_from_db(self.cursor):
                uid=u.id

        query="INSERT INTO target (nick,pid,tick,uid) VALUES (%s,%s,%s,%s)"
        try:
            self.cursor.execute(query,(irc_msg.nick,p.id,tick,uid))
            if uid:
                reply="Booked landing on %s:%s:%s tick %s for user %s" % (p.x,p.y,p.z,tick,irc_msg.user)
            else:
                reply="Booked landing on %s:%s:%s tick %s for nick %s" % (p.x,p.y,p.z,tick,irc_msg.nick)
        except psycopg.IntegrityError:
            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 "
            query+=" FROM target AS t1 LEFT JOIN user_list AS t2 ON t1.uid=t2.id "
            query+=" WHERE t1.pid=%s AND t1.tick=%s"

            self.cursor.execute(query,(p.id,tick))
            book=self.cursor.dictfetchone()
            if not book:
                raise Exception("Integrity error? Unable to booking for pid %s and tick %s"%(p.id,tick))
            if book['pnick']:
                reply="Target %s:%s:%s is already booked for landing tick %s by user %s" % (p.x,p.y,p.z,book['tick'],book['pnick'])
            else:
                reply="Target %s:%s:%s is already booked for landing tick %s by nick %s" % (p.x,p.y,p.z,book['tick'],book['nick'])
        except:
            raise

        irc_msg.reply(reply)

        return 1
Example #17
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 0

        params=m.group(1)

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

        roid_count = -1

        victim = None
        attacker = None

        m=self.planet_coordre.search(params)
        if m:
            victim = loadable.planet(x=m.group(1),y=m.group(2),z=m.group(3))
            if not victim.load_most_recent(self.cursor):
                irc_msg.reply("%s:%s:%s is not a valid planet" % (victim.x,victim.y,victim.z))
                return 1
            params=params[m.end():]

        m=self.planet_coordre.search(params)
        if m:
            attacker = loadable.planet(x=m.group(1),y=m.group(2),z=m.group(3))
            if not attacker.load_most_recent(self.cursor):
                irc_msg.reply("%s:%s:%s is not a valid planet" % (attacker.x,attacker.y,attacker.z))
                return 1
            params=params[m.end():]

        if not victim:
            irc_msg.reply("Usage: %s" % (self.usage,))
            return 1

        if victim and not attacker:
            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 your planet is set with the pref command)")
                return 1
            if u.planet_id:
                attacker = u.planet
            else:
                irc_msg.reply("Usage: %s (you must be registered for automatic lookup)" % (self.usage,))
                return 1

        if roid_count > -1:
            reply="Capturing %s roids " % (roid_count,)
            victim_val = victim.value
            victim_score = victim.score
            reply+="from %s:%s:%s (%s|%s) "%(victim.x,victim.y,victim.z,
                                          self.format_value(victim_val*100),self.format_value(victim_score*100))

            attacker_val = attacker.value
            attacker_score = attacker.score
            reply+="will earn %s:%s:%s (%s|%s) "%(attacker.x,attacker.y,attacker.z,
                                               self.format_value(attacker_val*100),self.format_value(attacker_score*100))

            bravery = max(0,(min(2,float(victim_val)/attacker_val)-0.1 ) * (min(2,float(victim_score)/attacker_score)-0.2))
            bravery *= 10
            xp=int(bravery*roid_count)

            reply+="XP: %s, Score: %s (Bravery: %.2f)" % (xp,xp*60,bravery)
            irc_msg.reply(reply)
        else:
            reply="Target "
            victim_val = victim.value
            attacker_val = attacker.value
            victim_score = victim.score
            attacker_score = attacker.score

            reply+="%s:%s:%s (%s|%s) "%(victim.x,victim.y,victim.z,
                                     self.format_value(victim_val*100),self.format_value(victim_score*100))
            reply+="| Attacker %s:%s:%s (%s|%s) "%(attacker.x,attacker.y,attacker.z,
                                                self.format_value(attacker_val*100),self.format_value(attacker_score*100))

            bravery=attacker.bravery(victim)

            reply+="| Bravery: %.2f " % (bravery,)

            cap=int(attacker.cap_rate(victim)*victim.size)
            xp=attacker.calc_xp(victim)
            reply+="| Roids: %s | XP: %s | Score: %s" % (cap,xp,xp*60)
            irc_msg.reply(reply)

        return 1
Example #18
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
Example #19
0
File: i.py Project: kaaveland/munin
    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

        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 "+self.__class__.__name__+" command (log in with P and set mode +x)")
            return 1

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

        # assign param variables
        call_id=m.group(1)

        # do stuff here
        d=loadable.defcall(call_id)
        if not d.load_most_recent(self.cursor):
            irc_msg.reply("No defcall matching id %s found" %(call_id,))
            return 0

        query="SELECT t1.id AS fleet_id, t4.id AS defcall_id"
        query+=", t2.race AS race, t2.x AS owner_x, t2.y AS owner_y, t2.z AS owner_z"
        query+=", t3.x AS target_x, t3.y AS target_y, t3.z AS target_z"
        query+=", t1.fleet_size AS fleet_size, t1.fleet_name AS fleet_name"
        query+=", t1.landing_tick AS landing_tick, t1.mission AS mission"
        query+=" FROM fleet AS t1"
        query+=" INNER JOIN planet_dump AS t2 ON t1.owner_id=t2.id"
        query+=" INNER JOIN planet_dump AS t3 ON t1.target=t3.id"
        query+=" INNER JOIN defcalls AS t4"
        query+=" ON t1.target=t4.target AND t1.landing_tick=t4.landing_tick"
        query+=" WHERE t2.tick = (SELECT max_tick()) AND t3.tick = (SELECT max_tick())"
        query+=" AND t4.id=%s"
        
        self.cursor.execute(query,(int(d.id),))

        if self.cursor.rowcount < 1:
            irc_msg.reply("No fleets found for defcall with ID '%s'"%(call_id,))
            return 1

        all=self.cursor.dictfetchall()
        reply="Fleets hitting %s:%s:%s as part of defcall %s"%(d.actual_target.x,
                                                               d.actual_target.y,
                                                               d.actual_target.z,
                                                               d.id)
        reply+=" with eta %d"%(d.landing_tick-self.current_tick(),)
        irc_msg.reply(reply)

        for s in all:
            reply="-> (id: %s) from %s:%s:%s (%s)"%(s['fleet_id'],s['owner_x'],s['owner_y'],s['owner_z'],s['race'])
            reply+=" named '%s' with %s ships set to %s"%(s['fleet_name'],s['fleet_size'],s['mission'])
            irc_msg.reply(reply)



        return 1
Example #20
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 0


        # assign param variables

        if access < self.level:
            irc_msg.reply("You do not have enough access to use this command")
            return 0
        alliance=None
        race=None
        size_mod=None
        size=None
        value_mod=None
        value=None
        bash=False
        attacker=None
        cluster=None

        param=m.group(1)
        params=param.split()

        for p in params:
            m=self.bashre.search(p)
            if m and not bash:
                bash=True
                continue
            m=self.clusterre.search(p)
            if m and not cluster:
                cluster=int(m.group(1))
            m=self.racere.search(p)
            if m and not race:
                race=m.group(1)
                continue
            m=self.rangere.search(p)
            if m and not size and int(m.group(2)) < 32768:
                size_mod=m.group(1) or '>'
                size=m.group(2)
                continue
            m=self.rangere.search(p)
            if m and not value:
                value_mod=m.group(1) or '<'
                value=m.group(2)
                continue
            m=self.alliancere.search(p)
            if m and not alliance and not self.clusterre.search(p):
                alliance=m.group(1)
                continue



        if bash:
            if not user:
                irc_msg.reply("You must be registered to use the "+self.__class__.__name__+" command's bash option (log in with P and set mode +x)")
                return 1
            u=loadable.user(pnick=irc_msg.user)
            if not u.load_from_db(self.cursor):
                irc_msg.reply("Usage: %s (you must set your planet in preferences to use the bash option (!pref planet=x:y:z))" % (self.usage,))
                return 1
            if u.planet_id:
                attacker = u.planet
            else:
                irc_msg.reply("Usage: %s (you must set your planet in preferences to use the bash option (!pref planet=x:y:z))" % (self.usage,))
                return 1

        victims=self.cunts(alliance,race,size_mod,size,value_mod,value,attacker,bash,cluster)

        i=0
        if not len(victims):
            reply="No"
            if race:
                reply+=" %s"%(race,)
            reply+=" planets attacking %s" % self.config.get('Auth', 'alliance')
            if alliance:
                reply+=" in intel matching Alliance: %s"%(alliance,)
            else:
                reply+=" matching"
            if size:
                reply+=" Size %s %s" % (size_mod,size)
            if value:
                reply+=" Value %s %s" % (value_mod,value)
            if cluster:
                reply+=" Cluster %s" %(cluster,)
            irc_msg.reply(reply)
        for v in victims:
            reply="%s:%s:%s (%s)" % (v['x'],v['y'],v['z'],v['race'])
            reply+=" Value: %s Size: %s" % (v['value'],v['size'])
            if v['nick']:
                reply+=" Nick: %s" % (v['nick'],)
            if not alliance and v['alliance']:
                reply+=" Alliance: %s" % (v['alliance'],)
            targs=self.attacking(v['pid'])
            if targs:
                reply+=" Hitting: "
                print targs
                a=[]
                for t in targs:
                    if t:
                        a.append((t['nick'] or 'Unknown') + " (%s, lands: %s)"% (t['fleet_size'],t['landing_tick']))

                reply+=', '.join(a)
            i+=1
            if i>4 and len(victims)>4:
                reply+=" (Too many victims to list, please refine your search)"
                irc_msg.reply(reply)
                break
            irc_msg.reply(reply)


        return 1
Example #21
0
File: aids.py Project: munin/munin
    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
        search = m.group(1)

        # do stuff here

        mynick = self.config.get('Connection', 'nick')
        if search.lower() == mynick:
            irc_msg.reply("I am %s. I gave aids to all y'all bitches." % (mynick,))
            return 1

        u = loadable.user(pnick=search)
        if not u.load_from_db(self.cursor, irc_msg.round):
            irc_msg.reply("No users matching '%s'" % (search,))
            return 1
        if u.userlevel < 100:
            irc_msg.reply("%s is not a member, his aids is worthless." % (u.pnick,))
            return 1

        query = "SELECT pnick,sponsor,invites"
        query += " FROM user_list"
        query += " WHERE sponsor ilike %s"
        query += " AND userlevel >= 100"

        self.cursor.execute(query, (u.pnick,))

        reply = ""

        if u.pnick == irc_msg.user:
            reply += "You are %s." % (u.pnick,)
            if self.cursor.rowcount < 1:
                reply += " You have greedily kept your aids all to yourself."
            else:
                reply += " You have given aids to: "
                prev = []
                for r in self.cursor.dictfetchall():
                    prev.append(r['pnick'])
                reply += ", ".join(prev)
        else:
            if self.cursor.rowcount < 1:
                reply += "%s hasn't given anyone aids, what a selfish prick" % (u.pnick,)
            else:
                reply += "%s has given aids to: " % (u.pnick,)
                prev = []
                for r in self.cursor.dictfetchall():
                    prev.append(r['pnick'])
                reply += ", ".join(prev)

        irc_msg.reply(reply)

        return 1
Example #22
0
File: phone.py Project: munin/munin
    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

        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 0

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

        # assign param variables
        cmd = m.group(1)

        if "list".find(cmd) > -1:
            luser = None
            second_person = True
            if m.group(3):
                luser = loadable.user(pnick=m.group(3))
                if not luser.load_from_db(self.cursor, irc_msg.round):
                    irc_msg.reply("'%s' did not match any members." % (luser.pnick,))
                    return
                second_person = False
            else:
                luser = u
            return self.list_for_user(irc_msg, luser, second_person)

        trustee = m.group(3)
        if not trustee:
            irc_msg.reply("Usage: %s" % (self.usage,))
            return 1
        t_user = loadable.user(pnick=trustee)

        if not t_user.load_from_db(self.cursor, irc_msg.round):
            irc_msg.reply("%s is not a valid user." % (trustee,))
            return 0

        if "allow".find(cmd) > -1:
            results = self.phone_query_builder(u, "AND t1.friend_id=%s", (t_user.id,))
            if len(results) > 0:
                reply = "%s can already access your phone number." % (t_user.pnick,)
            else:
                query = "INSERT INTO phone (user_id,friend_id) VALUES (%s,%s)"
                args = (u.id, t_user.id)
                self.cursor.execute(query, args)
                reply = "Added %s to the list of people able to view your phone number." % (t_user.pnick,)
            irc_msg.reply(reply)
            return 1
        elif "deny".find(cmd) > -1:
            query = "DELETE FROM phone WHERE user_id=%s and friend_id=%s"
            args = (u.id, t_user.id)
            self.cursor.execute(query, args)

            reply = ""
            if self.cursor.rowcount < 1:
                reply = "Could not find %s among the people allowed to see your phone number." % (t_user.pnick,)
            else:
                reply = "Removed %s from the list of people allowed to see your phone number." % (t_user.pnick,)
            irc_msg.reply(reply)
            return 1
        elif "show".find(cmd) > -1:
            if u.id == t_user.id:
                if u.phone:
                    reply = "Your phone number is %s." % (u.phone,)
                    reply += " Your pubphone setting is: %s" % (["off", "on"][u.pubphone],)
                else:
                    reply = "You haven't set your phone number. To set your phone number, do !pref phone=1-800-HOT-BIRD."
                irc_msg.reply(reply)
                return 1

            if irc_msg.chan_reply():
                irc_msg.reply("Don't look up phone numbers in public, Alki might see them")
                return 1
            if t_user.pubphone and u.userlevel >= 100:
                reply = "%s says their phone number is %s" % (t_user.pnick, t_user.phone)
            else:
                results = self.phone_query_builder(t_user, "AND t1.friend_id=%s", (u.id,))
                if len(results) < 1:
                    reply = "%s won't let you see their phone number. That paranoid c**t just doesn't trust you I guess." % (
                        t_user.pnick,)
                else:
                    if t_user.phone:
                        reply = "%s says their phone number is %s" % (t_user.pnick, t_user.phone)
                    else:
                        reply = "%s hasn't shared their phone number. What a paranoid c**t ." % (t_user.pnick,)

            irc_msg.reply(reply)
            return 1
        # if we're still here someone did something wrong
        irc_msg.reply("Usage: %s" % (self.usage,))

        return 1