Add a check for non-existent config file
This commit is contained in:
parent
39da2633f5
commit
bf916e83fd
30
hybridbot.py
30
hybridbot.py
@ -258,28 +258,32 @@ class Intermedia:
|
||||
self.xmpp_users.remove(user)
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = SafeConfigParser()
|
||||
config = SafeConfigParser()
|
||||
shared_opts = {}
|
||||
xmpp_opts = {}
|
||||
irc_opts = {}
|
||||
|
||||
if len(sys.argv) > 1:
|
||||
parser.read(sys.argv[1])
|
||||
config.read(sys.argv[1])
|
||||
else:
|
||||
parser.read('config.ini')
|
||||
config.read('config.ini')
|
||||
|
||||
shared_opts['prefix'] = parser.get('Shared', 'prefix')
|
||||
shared_opts['owner'] = parser.get('Shared', 'owner')
|
||||
if not config.sections():
|
||||
sys.stderr.write('Error: Configuration file does not exist or is empty.\n')
|
||||
sys.exit(1)
|
||||
|
||||
irc_opts['chan'] = parser.get('IRC', 'channel')
|
||||
irc_opts['nick'] = parser.get('IRC', 'nick')
|
||||
irc_opts['server'] = parser.get('IRC', 'server')
|
||||
irc_opts['port'] = int(parser.get('IRC', 'port'))
|
||||
shared_opts['prefix'] = config.get('Shared', 'prefix')
|
||||
shared_opts['owner'] = config.get('Shared', 'owner')
|
||||
|
||||
xmpp_opts['jid'] = parser.get('XMPP', 'jid')
|
||||
xmpp_opts['passwd'] = parser.get('XMPP', 'password')
|
||||
xmpp_opts['muc'] = parser.get('XMPP', 'muc')
|
||||
xmpp_opts['nick'] = parser.get('XMPP', 'nick')
|
||||
irc_opts['chan'] = config.get('IRC', 'channel')
|
||||
irc_opts['nick'] = config.get('IRC', 'nick')
|
||||
irc_opts['server'] = config.get('IRC', 'server')
|
||||
irc_opts['port'] = int(config.get('IRC', 'port'))
|
||||
|
||||
xmpp_opts['jid'] = config.get('XMPP', 'jid')
|
||||
xmpp_opts['passwd'] = config.get('XMPP', 'password')
|
||||
xmpp_opts['muc'] = config.get('XMPP', 'muc')
|
||||
xmpp_opts['nick'] = config.get('XMPP', 'nick')
|
||||
|
||||
try:
|
||||
inter = Intermedia(shared_opts, irc_opts['chan'], xmpp_opts['muc'])
|
||||
|
Loading…
Reference in New Issue
Block a user