protected chats & tags
This commit is contained in:
		
							parent
							
								
									a9d5967996
								
							
						
					
					
						commit
						6d10fae743
					
				
					 1 changed files with 14 additions and 0 deletions
				
			
		
							
								
								
									
										14
									
								
								delojza.py
									
										
									
									
									
								
							
							
						
						
									
										14
									
								
								delojza.py
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -11,6 +11,7 @@ from configparser import ConfigParser
 | 
			
		|||
from datetime import datetime, timedelta
 | 
			
		||||
from glob import glob
 | 
			
		||||
from operator import itemgetter
 | 
			
		||||
from random import choice
 | 
			
		||||
 | 
			
		||||
import acoustid
 | 
			
		||||
import filetype
 | 
			
		||||
| 
						 | 
				
			
			@ -41,6 +42,7 @@ def datestr(date):
 | 
			
		|||
 | 
			
		||||
class DelojzaBot:
 | 
			
		||||
    def __init__(self, tg_api_key, out_dir, tmp_dir=None,
 | 
			
		||||
                 protected_chats=None, protected_tags=None,
 | 
			
		||||
                 acoustid_key=None, tumblr_name=None, tumblr_keys=None, markov=None):
 | 
			
		||||
        self.logger = logging.getLogger("delojza")
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -74,6 +76,9 @@ class DelojzaBot:
 | 
			
		|||
            self.tumblr_name = tumblr_name
 | 
			
		||||
            self.tumblr_client = pytumblr.TumblrRestClient(*tumblr_keys)
 | 
			
		||||
 | 
			
		||||
        self.protected_chats = protected_chats or []
 | 
			
		||||
        self.protected_tags = protected_tags or []
 | 
			
		||||
 | 
			
		||||
        self.last_downloaded = None
 | 
			
		||||
        self.last_hashtags = None
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -256,6 +261,13 @@ class DelojzaBot:
 | 
			
		|||
                self.logger.info("Ignoring %s due to no hashtag present..." % urls)
 | 
			
		||||
                return
 | 
			
		||||
 | 
			
		||||
            if any(hashtag in self.protected_tags for hashtag in hashtags):
 | 
			
		||||
                if message.chat.title not in self.protected_chats:
 | 
			
		||||
                    self.logger.info("Ignoring {} in chat {} due to protected hashtags: {}..."
 | 
			
		||||
                                     .format(urls, message.chat.title, hashtags))
 | 
			
		||||
                    message.reply_text(choice(["No.", "Nein", "Nope", ":(", "Error: Cannot.", "Fail."]))
 | 
			
		||||
                    return
 | 
			
		||||
 | 
			
		||||
            self.last_hashtags = None
 | 
			
		||||
 | 
			
		||||
            self.logger.info("Downloading %s under '%s'" % (urls, "/".join(hashtags)))
 | 
			
		||||
| 
						 | 
				
			
			@ -503,6 +515,8 @@ if __name__ == '__main__':
 | 
			
		|||
    delojza = DelojzaBot(config.get('delojza', 'tg_api_key'),
 | 
			
		||||
                         config.get('delojza', 'OUT_DIR', fallback=os.path.join(_DIR_, "out")),
 | 
			
		||||
                         tmp_dir=config.get('delojza', 'tmp_dir', fallback=tempfile.gettempdir()),
 | 
			
		||||
                         protected_chats=config.get('delojza', 'protected_chats').split(";"),
 | 
			
		||||
                         protected_tags=config.get('delojza', 'protected_tags').split(";"),
 | 
			
		||||
                         acoustid_key=config.get('delojza', 'acoustid_api_key'),
 | 
			
		||||
                         tumblr_name=config.get('tumblr', 'blog_name'),
 | 
			
		||||
                         tumblr_keys=(config.get('tumblr', 'consumer_key'),
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue