Commits

ubershmekel  committed b3acadb Draft

Avoid /r/baseball and don't reply to those clone metric bots.

  • Participants
  • Parent commits caf5e80

Comments (0)

Files changed (2)

File metricbot.py

 globthrot = Throttle()
 
 class MetricBot(RedditBot):
-    avoid_subreddits = ['flying', 'ladybonersgw', 'AskScience']
+    avoid_subreddits = ['flying', 'ladybonersgw', 'AskScience', 'baseball']
+    avoid_users = ['All-American-Bot', 'SI_Bot']
     
     def __init__(self, *args, **kwargs):
         RedditBot.__init__(self, *args, **kwargs)

File redditbot.py

 
 class RedditBot:
     avoid_subreddits = []
-
+    avoid_users = []
+    
     def __init__(self, user, pw):
         self.user = user
         self.pw = pw
         self.db = shelve.open(self.user + '.py.db')
         
         self.avoid_subreddits = [i.lower() for i in self.avoid_subreddits]
-    
+        self.avoid_users = [i.lower() for i in self.avoid_users]
+
+
     def log(self, text):
         # print text # caused unicode bugs
         logging.debug(text)
         self.error('NOT POSTED: %s' % e)
         time.sleep(10 * 60)
     
-    def is_me(self, author):
+    def _fix_username(self, author):
         if type(author) == type(u''):
             # this is an annoying little bug
             name = author
         else:
             name = author.name
         
-        if name.lower() == self.user.lower():
+        return name.lower()
+    
+    def is_me(self, name):
+        if name == self.user.lower():
             return True
         else:
             return False
         
         return res
     
+    def should_avoid(self, poster, place_holder, subreddit):
+        name = self._fix_username(poster)
+        if self.is_me(name) or name in self.avoid_users:
+            return True
+        
+        if self.handled_in_past(place_holder):
+            return True
+        
+        if subreddit.title.lower() in self.avoid_subreddits:
+            return True
+        
+        return False
+    
     def feed_comments(self):
         r = self.r
         comments = []
             
             print 'c',
             poster = comm.author
-            if self.is_me(poster):
+            
+            if self.should_avoid(poster, self.comment_place_holder, comm.subreddit):
                 continue
             
-            if self.handled_in_past(self.comment_place_holder):
-                continue
-            
-            if comm.subreddit.title.lower() in self.avoid_subreddits:
-                continue
-
             # handle
             comments.append(comm)
             
             self.link_place_holder = link.id
             print 'l',
             poster = link.author
-            if self.is_me(poster):
+            
+            if self.should_avoid(poster, self.link_place_holder, link.subreddit):
                 continue
-            
-            if self.handled_in_past(self.link_place_holder):
-                continue
-            
-            if link.subreddit.title.lower() in self.avoid_subreddits:
-                continue
-            
+
             # handle
             links.append(link)