From 2153d27b1b05c20fa847f4894c2f41fca8c3c157 Mon Sep 17 00:00:00 2001 From: Robin Richtsfeld Date: Mon, 12 Mar 2018 15:38:58 +0100 Subject: [PATCH] Simplify assigning default config values --- phenny | 39 ++++++++++++++------------------------- 1 file changed, 14 insertions(+), 25 deletions(-) diff --git a/phenny b/phenny index 6411893..d02691e 100755 --- a/phenny +++ b/phenny @@ -155,32 +155,21 @@ def main(argv=None): module = imp.load_source(name, config_name) module.filename = config_name - if not hasattr(module, 'prefix'): - module.prefix = r'\.' + defaults = { + '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'): - module.name = 'Phenny Palmersbot, http://inamidst.com/phenny/' - - 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 + for key, value in defaults.items(): + if not hasattr(module, key): + setattr(module, key, value) if module.host == 'irc.example.net': error = ('Error: you must edit the config file first!\n' +