Commits

Anonymous committed 227d672

More code cleanup and minor tweaks

Comments (0)

Files changed (6)

         #Plugin.__init__(self, acl, server)
         super(Admin, self).__init__(acl, server)
 
-        self.ownerCommands = {':,add_admin':self.__addAdmin, ':,del_admin':self.__delAdmin,
-                              ':,die':self.__die, ':,join':self.__joinChan, ':,part':self.__partChan}
+        self.ownerCommands = {':,add_admin':self.__addAdmin,
+                              ':,del_admin':self.__delAdmin,
+                              ':,die':self.__die,
+                              ':,join':self.__joinChan,
+                              ':,part':self.__partChan}
 
-        self.adminCommands = {':,mute':self.__muteServer, ':,unmute':self.__unmuteServer,
-                              ':,ignore':self.__addIgnore, ':,unignore':self.__delIgnore}
+        self.adminCommands = {':,mute':self.__muteServer,
+                              ':,unmute':self.__unmuteServer,
+                              ':,ignore':self.__addIgnore,
+                              ':,unignore':self.__delIgnore}
 
-        self.anonCommands = {':,get_admin':self.__getAdmin, ':,help':self.help,
-                             ':,get_ignore':self.__getIgnore, ':,get_chans':self.__getChans }
+        self.anonCommands = {':,get_admin':self.__getAdmin,
+                             ':,help':self.help,
+                             ':,get_ignore':self.__getIgnore,
+                             ':,get_chans':self.__getChans }
 
     def read(self, message):
-        #print("Reading message: " + str(message))
         '''You are owner'''
         if self.ACL.getPermLvl(message.nick) == 0 :
             try:
             except KeyError:
                 pass
 
-        '''
-        You are an admin
-        '''
+        '''You are an admin'''
         if self.ACL.getPermLvl(message.nick) <= 1 :
             try:
                 self.adminCommands[message.message[0]](message)
             pass
 
     def __getChans(self, message):
-        self.SERVER.sendPRIVMessage(message.nick + ' :' + str(self.SERVER.chans))
+        self.SERVER.sendPRIVMessage(message.nick + ' :' +
+                                    str(self.SERVER.chans))
 
     def __joinChan(self, message):
         if len(message.message) > 1:
             self.SERVER.partChannel(messsage.message[1])
 
     def __getAdmin(self, message):
-        self.SERVER.sendPRIVMessage(message.nick + " :admins: " + str(self.ACL.getAdmins()))
+        self.SERVER.sendPRIVMessage(message.nick + " :admins: " +
+                                    str(self.ACL.getAdmins()))
 
     def __getIgnore(self, message):
-        self.SERVER.sendPRIVMessage(message.nick + ' :ignored: ' + str(self.ACL.getIgnore()))
+        self.SERVER.sendPRIVMessage(message.nick + ' :ignored: ' +
+                                    str(self.ACL.getIgnore()))
 
 
     def __muteServer(self, message):
-        self.SERVER.sendPRIVMessage(message.nick + ' :' + 'Cutting communications...')
+        self.SERVER.sendPRIVMessage(message.nick + ' :' +
+                                    'Cutting communications...')
         self.SERVER.mute()
 
     def __unmuteServer(self, message):
         self.SERVER.unMute()
-        self.SERVER.sendPRIVMessage(message.nick + ' :' + 'Establishing link...')
+        self.SERVER.sendPRIVMessage(message.nick + ' :' +
+                                    'Establishing link...')
 
     def __addAdmin(self, message):
 
         if len(message.message) > 1:
             self.ACL.addAdmin(message.message[1])
-            self.SERVER.sendPRIVMessage(message.nick + " :" + message.message[1] + " added to admins")
+            self.SERVER.sendPRIVMessage(message.nick + " :" +
+                                        message.message[1] +
+                                        " added to admins")
 
     def __delAdmin(self, message):
         if len(message.message) > 1:
             self.ACL.delAdmin(message.message[1])
-            self.SERVER.sendPRIVMessage(message.nick + " :" + message.message[1] + " removed from admins")
+            self.SERVER.sendPRIVMessage(message.nick + " :" +
+                                        message.message[1] +
+                                        " removed from admins")
 
     def __die(self, message):
         print('Master commanded me to quit')
     def __addIgnore(self, message):
         if len(message.message) > 1:
             self.ACL.addIgnore(message.message[1])
-            self.SERVER.sendPRIVMessage(message.message[1] + ' :' + 'You have been added to the ignore list. Probably because you are annoying...')
+            self.SERVER.sendPRIVMessage(message.message[1] + ' :' +
+                                        'You have been added to the ignore list. Probably because you are annoying...')
 
     def __delIgnore(self, message):
         if len(message.message) > 1:
             self.ACL.delIgnore(message.message[1])
-            self.SERVER.sendPRIVMessage(message.message[1] + ' :' + 'You have been removed from the ignore list, for now...')
+            self.SERVER.sendPRIVMessage(message.message[1] + ' :' +
+                                        'You have been removed from the ignore list, for now...')
 
     def mainHelp(self, message):
         helpstr = ['Meow Meow I am Karma Kat! ',
 
         self.__mkWTable()
 
-        self.ownerCommands = {':,nuke_karma':self.__nukeKarma, ':,nuke_words':self.__nukeWords}
+        self.ownerCommands = {':,nuke_karma':self.__nukeKarma,
+                              ':,nuke_words':self.__nukeWords}
 
-        self.adminCommands = {':,reset':self.__resetUser, ':,del_word':self.__delWord}
+        self.adminCommands = {':,reset':self.__resetUser,
+                              ':,del_word':self.__delWord}
 
-        self.anonCommands = {':++':self.__upVote, ':<3':self.__upVote,
-                             ':--':self.__downVote, ':</3':self.__downVote,
-                             ':,karma':self.__getKarma, ':,get_words':self.__getWords,
-                             ':,help':self.help, ':,get_users':self.__getUsers }
+        self.anonCommands = {':++':self.__upVote,
+                             ':<3':self.__upVote,
+                             ':--':self.__downVote,
+                             ':</3':self.__downVote,
+                             ':,karma':self.__getKarma,
+                             ':,get_words':self.__getWords,
+                             ':,help':self.help,
+                             ':,get_users':self.__getUsers }
 
     def read(self, message):
         '''You are owner'''
     def __getUsers(self, message):
         self.curs.execute('SELECT uname from vote')
         names = self.curs.fetchall()
-        self.SERVER.sendPRIVMessage(message.nick + " :" + "Known users: " + str(names))
+        self.SERVER.sendPRIVMessage(message.nick + " :" +
+                                    "Known users: " + str(names))
 
     def __nukeKarma(self, message):
         '''Nuke entire karma db
     def __getWords(self, message):
         self.curs.execute('SELECT word From vote2')
         words = self.curs.fetchall()
-        self.SERVER.sendPRIVMessage(message.nick + " :" + "Known words: " + str(words))
+        self.SERVER.sendPRIVMessage(message.nick + " :" +
+                                    "Known words: " + str(words))
 
     def __getKarma(self, message):
         '''This method gets the karma score for a word or a user'''
         if len(message.message) > 1:
             karma = ['']
-            self.curs.execute('SELECT * FROM vote WHERE uname = ?', [message.message[1]])
+            self.curs.execute('SELECT * FROM vote WHERE uname = ?',
+                              [message.message[1]])
             if len(self.curs.fetchall()) == 1 :
                 karma = self.__totalKKarma(message.message[1])
             else:
                 pass
 
-        self.curs.execute('SELECT * FROM vote2 WHERE word = ?', [message.message[1]])
+        self.curs.execute('SELECT * FROM vote2 WHERE word = ?',
+                          [message.message[1]])
         if len(self.curs.fetchall()) == 1 :
             karma = self.__totalWKarma(message.message[1])
         else:
             message.chan = message.nick
 
         if len(karma) == 4:
-            self.SERVER.sendPRIVMessage(message.chan + " :" + message.message[1] + " has a karma of: " + str(karma[0]) + " (U:" + str(karma[1]) + " D:" + str(karma[2]) + " V:" + str(karma[3]) + ")")
+            self.SERVER.sendPRIVMessage(message.chan + " :"
+                                        + message.message[1] +
+                                        " has a karma of: " + str(karma[0]) +
+                                        " (U:" + str(karma[1]) + " D:" +
+                                        str(karma[2]) + " V:" +
+                                        str(karma[3]) + ")")
         elif len(karma) == 3:
-            self.SERVER.sendPRIVMessage(message.chan + " :" + message.message[1] + " has a karma of: " + str(karma[0]) + " (U:" + str(karma[1]) + " D:" + str(karma[2]) + ")")
+            self.SERVER.sendPRIVMessage(message.chan + " :" +
+                                        message.message[1] +
+                                        " has a karma of: " + str(karma[0]) +
+                                        " (U:" + str(karma[1]) + " D:" +
+                                        str(karma[2]) + ")")
         else:
             pass
 
     def __upVote(self, message):
         '''This method will handle the logic for trying to upvote'''
         if len(message.message) > 1:
-            self.curs.execute('SELECT * FROM vote WHERE uname = ?', message.nick)
+            self.curs.execute('SELECT * FROM vote WHERE uname = ?',
+                              message.nick)
             if len(self.curs.fetchall()) == 1 :
                 if self.__nickCheck(message) :
                     if self.__isAllowed(message):
     def __downVote(self, message):
         '''This method will handle the logic for trying to downvote'''
         if len(message.message) > 1:
-            self.curs.execute('SELECT * FROM vote WHERE uname = ?', [message.nick])
+            self.curs.execute('SELECT * FROM vote WHERE uname = ?',
+                              [message.nick])
             if len(self.curs.fetchall()) == 1 :
                 if self.__nickCheck(message):
                     if self.__isAllowed(message):
 
     def __mkWTable(self):
         '''This method is used to make a new table'''
-        self.curs.execute(' CREATE TABLE IF NOT EXISTS vote2 (word TEXT PRIMARY KEY, up_vote INTEGER, down_vote INTEGER)')
+        self.curs.execute(' CREATE TABLE IF NOT EXISTS vote2 \
+            (word TEXT PRIMARY KEY, up_vote INTEGER, down_vote INTEGER)')
         self.conn.commit()
 
     def __wordCheck(self, message):
-        self.curs.execute('SELECT * FROM vote2 WHERE word = ?', [message.message[1]])
+        self.curs.execute('SELECT * FROM vote2 WHERE word = ?',
+                          [message.message[1]])
         if len(self.curs.fetchall()) == 1 :
             '''word in db'''
             return True
             return True
 
     def __nickCheck(self, message):
-        '''This method will check the nick to see if they are actually a person in the room
-        If they are, then it will see if they are in the DB yet. If they are in the DB,
-        return true, if not, return false
+        '''This method will check the nick to see if they are actually a 
+        person in the room. If they are, then it will see if they are in 
+        the DB yet. If they are in the DB, return true, if not, return false
         '''
         nicks = self.SERVER.getUsers(message.chan)
         if message.message[1] in nicks:
             '''Ok its a user, are they in the DB?'''
-            self.curs.execute('SELECT * FROM vote WHERE uname = ?', [message.message[1]])
+            self.curs.execute('SELECT * FROM vote WHERE uname = ?',
+                              [message.message[1]])
             if len(self.curs.fetchall()) == 1 :
                 '''You found an exisiting user'''
                 return True
             return False
 
     def __newUser(self, nick):
-        t = (nick, 0, 0, 0, datetime.datetime(1111, 1, 1, 0, 0, 0, 1).isoformat(' '))
+        t = (nick, 0, 0, 0,
+             datetime.datetime(1111, 1, 1, 0, 0, 0, 1).isoformat(' '))
         self.curs.execute('INSERT INTO vote values (?, ?, ?, ?, ?)', t)
         self.conn.commit()
 
     def __mOne(self, nick, voter):
         '''Add one down vote to specified user'''
         t = [datetime.datetime.now().isoformat(' '), voter ]
-        self.curs.execute('UPDATE vote SET lvt = ?, voted = (voted + 1) WHERE uname = ?', t)
-        self.curs.execute('UPDATE vote SET down_vote = (down_vote + 1) WHERE uname = ?', [nick])
+        self.curs.execute('UPDATE vote SET lvt = ?, voted = (voted + 1) \
+            WHERE uname = ?', t)
+        self.curs.execute('UPDATE vote SET down_vote = (down_vote + 1) \
+            WHERE uname = ?', [nick])
         self.conn.commit()
 
     def __totalKKarma(self, nick):
         '''Compute the total Karma for a user'''
-        self.curs.execute('SELECT up_vote, down_vote, voted FROM vote WHERE uname = ?', [nick])
+        self.curs.execute('SELECT up_vote, down_vote, voted FROM vote \
+            WHERE uname = ?', [nick])
         user = self.curs.fetchone()
         if user != None:
             return ([user[0] - user[1], user[0], user[1], user[2] ])
 
     def __totalWKarma(self, word):
         '''Compute the total Karma for a word'''
-        self.curs.execute('SELECT up_vote, down_vote FROM vote2 WHERE word = ?', [word])
+        self.curs.execute('SELECT up_vote, down_vote FROM vote2 WHERE word = ?',
+                          [word])
         word = self.curs.fetchone()
         if word != None:
             return ([word[0] - word[1], word[0], word[1] ])
 
 
     def __isAllowed(self, message):
-        '''This method Is used to determin if the person CASTING THE VOTE is allowed to do so
+        '''This method Is used to determin if the person CASTING THE VOTE is 
+        allowed to do so.
         Currently there are two constraints:
         rate limiting (4 votes a min)
         and name limiting (can't up vote yourself)
                 return False
             elif message.chan == self.SERVER.NICK:
                 '''This detects a PM vote'''
-                self.SERVER.sendPRIVMessage(message.nick + ' :' + 'Sorry but karma is meant to be public...')
+                self.SERVER.sendPRIVMessage(message.nick + ' :' +
+                                            'Sorry but karma is meant to be public...')
                 return False
             elif self.ACL.getPermLvl(message.nick) == 9:
-                self.SERVER.sendPRIVMessage(message.nick + ' :' + 'Sorry but you are on the naughty list...')
+                self.SERVER.sendPRIVMessage(message.nick + ' :' +
+                                            'Sorry but you are on the naughty list...')
                 return False
             else:
                 return True
             if self.__timeCheck(message.nick) == False:
                 return False
             elif message.chan == self.SERVER.NICK:
-                self.SERVER.sendPRIVMessage(message.nick + ' :' + 'Sorry but karma is meant to be public...')
+                self.SERVER.sendPRIVMessage(message.nick + ' :' +
+                                            'Sorry but karma is meant to be public...')
+                return False
+            elif self.ACL.getPermLvl(message.nick) == 9:
+                self.SERVER.sendPRIVMessage(message.nick + ' :' +
+                                            'Sorry but you are on the naughty list...')
                 return False
             else:
                 return True
 
 
     def __timeCheck(self, nick):
-        '''This method is for rate limiting. If a user trys to up/down vote too many times
-        in a minute this method will return false
+        '''This method is for rate limiting. If a user trys to up/down 
+        vote too many times in a minute this method will return false
         2011-06-21 16:24:46.645714
         
         '''
         if (now - lvt).seconds >= 15:
             return True
         else:
-            self.SERVER.sendPRIVMessage(nick + ' :' + 'You voted too recently...')
+            self.SERVER.sendPRIVMessage(nick + ' :' +
+                                        'You voted too recently...')
             return False
 
     def __resetUser(self, message):
         '''This method is to reset the karma score of a given user'''
         if len(message.message) > 1:
-            self.curs.execute('SELECT * FROM vote WHERE uname =?', message.message[1])
+            self.curs.execute('SELECT * FROM vote WHERE uname =?',
+                              message.message[1])
         if len(self.curs.fetchall()) == 1 :
-            self.curs.execute('DELETE FROM vote WHERE uname = ?', message.message[1])
+            self.curs.execute('DELETE FROM vote WHERE uname = ?',
+                              message.message[1])
             self.__newUser(nick)
         else:
             pass
     def __delWord(self, message):
         '''This method is to delete a word from the BD'''
         if len(message.message) > 1:
-            self.curs.execute('DELETE FROM vote2 WHERE word = ?', message.message[1])
+            self.curs.execute('DELETE FROM vote2 WHERE word = ?',
+                              message.message[1])
 
 
     def help(self, message):
 
 
     def parseLine(self, line):
-        '''This method takes a line from the server as input, and will parse it'''
+        '''This method takes a line from the server as input 
+        and will parse it'''
 
         if len(line) >= 4:
             '''We know the message is PROBABLY parseable'''
 
 
     def __sortMessage(self):
-        '''This method is used to look at the first word and see what kind of command it is'''
+        '''This method is used to look at the first word 
+        and see what kind of command it is'''
         if (self.message.message[0] == 'raw'):
             pass
 
 
         self.aSocket.connect((self.HOST, self.PORT))
         self.sendMessage('NICK ' + self.NICK)
-        self.sendMessage('USER ' + self.IDENT + ' ' + self.HOST + ' bla :' + self.REALNAME)
+        self.sendMessage('USER ' + self.IDENT + ' ' +
+                         self.HOST + ' bla :' + self.REALNAME)
 
         self.__chanAutoJoin()
 
         return line
 
     def __sendPong (self, reply):
-        '''This method sends a PONG reply to the server with the supplied reply'''
+        '''This method sends a PONG reply 
+        to the server with the supplied reply
+        '''
         self.sendMessage("PONG " + reply)
 
     def __chanAutoJoin (self):
 
         self.joinChannel(self.CHANNELINIT)
 
-
     ''' This pair of methods is used to control whether or not the 
-        will send its replies
-    '''
+        will send its replies'''
     def mute(self):
         self.muted = True
 
 
         self.urls = deque([])
 
+        self.knownCommands = {':,sl':self.__shortLink,
+                              ':,psl':self.__privateShortLink,
+                              ':,help':self.help }
+
 
     def read(self, message):
+        '''This whole method needs to be cleaned up and reimplemented'''
+
         if message.message[0] == ':,sl' and len(message.message) == 1:
             self.SERVER.sendPRIVMessage(message.chan + ' :' + self.__getLastURL())
 
         for hlp in helpstr:
             self.SERVER.sendPRIVMessage(message.nick + ' :' + hlp)
 
+    def __shortLink(self, message):
+        pass
+
+    def __privateShortLink(self, message):
+        pass
+
 
         '''Basic Configuration Section begins here'''
         #This Dictionary is for the server config
-        self.configDic = {'HOST': 'chat.freenode.net', 'PORT': 6667, 'NICK': 'Dr_Meowzers_b', 'IDENT': 'karma_kat', 'REALNAME': 'Karma Kat', 'CHANNELINIT': '#btreecat' }
+        self.configDic = {'HOST': 'chat.freenode.net',
+                          'PORT': 6667,
+                          'NICK': 'Dr_Meowzers_b',
+                          'IDENT': 'karma_kat',
+                          'REALNAME': 'Karma Kat',
+                          'CHANNELINIT': '#btreecat' }
 
         #Pets Owner
         self.OWNER = 'btreecat'