configs and defaults
This commit is contained in:
		
							parent
							
								
									f7d9afbd43
								
							
						
					
					
						commit
						abe38388b6
					
				
					 7 changed files with 17 additions and 3 deletions
				
			
		
							
								
								
									
										2
									
								
								pgbot
									
										
									
									
									
								
							
							
						
						
									
										2
									
								
								pgbot
									
										
									
									
									
								
							| 
						 | 
					@ -15,7 +15,7 @@ import pgbotlib.response
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def init(args: list) -> tuple:
 | 
					def init(args: list) -> tuple:
 | 
				
			||||||
    conf_path = args[0] if args else 'config.yml'
 | 
					    conf_path = args[0] if args else pgbotlib.misc.Paths.CONFIG
 | 
				
			||||||
    try:
 | 
					    try:
 | 
				
			||||||
        with open(conf_path, 'r', encoding='utf-8') as data:
 | 
					        with open(conf_path, 'r', encoding='utf-8') as data:
 | 
				
			||||||
            config = yaml.safe_load(data.read())
 | 
					            config = yaml.safe_load(data.read())
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -5,6 +5,7 @@ import yaml
 | 
				
			||||||
import aiocron
 | 
					import aiocron
 | 
				
			||||||
import telethon
 | 
					import telethon
 | 
				
			||||||
import pgbotlib.response
 | 
					import pgbotlib.response
 | 
				
			||||||
 | 
					import pgbotlib.misc
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Cron:
 | 
					class Cron:
 | 
				
			||||||
| 
						 | 
					@ -12,7 +13,8 @@ class Cron:
 | 
				
			||||||
                 config: dict,
 | 
					                 config: dict,
 | 
				
			||||||
                 client: telethon.TelegramClient,
 | 
					                 client: telethon.TelegramClient,
 | 
				
			||||||
                 responder: pgbotlib.response.Responder) -> None:
 | 
					                 responder: pgbotlib.response.Responder) -> None:
 | 
				
			||||||
        with open(config['schedule'], 'r', encoding='utf-8') as data:
 | 
					        schedule_conf = config.get('schedule', pgbot.misc.Paths.SCHEDULE)
 | 
				
			||||||
 | 
					        with open(schedule_conf, 'r', encoding='utf-8') as data:
 | 
				
			||||||
            self.sched = yaml.safe_load(data.read())
 | 
					            self.sched = yaml.safe_load(data.read())
 | 
				
			||||||
            self.responder = responder
 | 
					            self.responder = responder
 | 
				
			||||||
            self.client = client
 | 
					            self.client = client
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,7 +1,17 @@
 | 
				
			||||||
 | 
					import enum
 | 
				
			||||||
 | 
					import os
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import telethon
 | 
					import telethon
 | 
				
			||||||
import pgbotlib.dbstuff
 | 
					import pgbotlib.dbstuff
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class Paths(enum.Enum):
 | 
				
			||||||
 | 
					    CONFDIR = '/etc/pgbot'
 | 
				
			||||||
 | 
					    CONFIG = os.path.join(CONFDIR, 'pgbot.yml')
 | 
				
			||||||
 | 
					    TOKENS = os.path.join(CONFDIR, 'tokens.yml')
 | 
				
			||||||
 | 
					    SCHEDULE = os.path.join(CONFDIR, '/sched.yml')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class NameGenerator:
 | 
					class NameGenerator:
 | 
				
			||||||
    def __init__(self, config: dict, db: pgbotlib.dbstuff.DBConn) -> None:
 | 
					    def __init__(self, config: dict, db: pgbotlib.dbstuff.DBConn) -> None:
 | 
				
			||||||
        self.db = db
 | 
					        self.db = db
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -30,7 +30,9 @@ class Responder:
 | 
				
			||||||
        self.enabled = True
 | 
					        self.enabled = True
 | 
				
			||||||
        self.apiregex = re.compile(r'^\{(\w+)\}(.+)?$')
 | 
					        self.apiregex = re.compile(r'^\{(\w+)\}(.+)?$')
 | 
				
			||||||
        self.namegen = pgbotlib.misc.NameGenerator(config, db_connection)
 | 
					        self.namegen = pgbotlib.misc.NameGenerator(config, db_connection)
 | 
				
			||||||
        self.tokens = get_tokens(config['response_tokens'])
 | 
					        self.tokens = get_tokens(
 | 
				
			||||||
 | 
					            config.get('response_tokens', pgbotlib.misc.Paths.TOKENS)
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
        self.chats = config['chats']
 | 
					        self.chats = config['chats']
 | 
				
			||||||
        self.api = pgbotlib.api.ApiWrapper(self.tokens, db_connection)
 | 
					        self.api = pgbotlib.api.ApiWrapper(self.tokens, db_connection)
 | 
				
			||||||
        self.db_connection = db_connection
 | 
					        self.db_connection = db_connection
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue