Simplify assigning default config values

master
Robin Richtsfeld 2018-03-12 15:38:58 +01:00
parent f39902f30c
commit 2153d27b1b
1 changed files with 14 additions and 25 deletions

39
phenny
View File

@ -155,32 +155,21 @@ def main(argv=None):
module = imp.load_source(name, config_name) module = imp.load_source(name, config_name)
module.filename = config_name module.filename = config_name
if not hasattr(module, 'prefix'): defaults = {
module.prefix = r'\.' 'prefix': r'\.',
'name': 'Phenny Palmersbot, http://inamidst.com/phenny/',
'port': 6667,
'ssl': False,
'ca_certs': None,
'ssl_cert': None,
'ssl_key': None,
'ipv6': False,
'password': None,
}
if not hasattr(module, 'name'): for key, value in defaults.items():
module.name = 'Phenny Palmersbot, http://inamidst.com/phenny/' if not hasattr(module, key):
setattr(module, key, value)
if not hasattr(module, 'port'):
module.port = 6667
if not hasattr(module, 'ssl'):
module.ssl = False
if not hasattr(module, 'ca_certs'):
module.ca_certs = None
if not hasattr(module, 'ssl_cert'):
module.ssl_cert = None
if not hasattr(module, 'ssl_key'):
module.ssl_key = None
if not hasattr(module, 'ipv6'):
module.ipv6 = False
if not hasattr(module, 'password'):
module.password = None
if module.host == 'irc.example.net': if module.host == 'irc.example.net':
error = ('Error: you must edit the config file first!\n' + error = ('Error: you must edit the config file first!\n' +