From aaa7200fa2c17f03ad8cd7a023ad92159a58d17c Mon Sep 17 00:00:00 2001 From: Steve 'Ashcrow' Milner Date: Sat, 6 Feb 2010 22:57:33 -0500 Subject: uses a config file now --- conf/example.conf | 9 +++++++++ logbot.py | 47 +++++++++++++++++++++++++++++++++-------------- 2 files changed, 42 insertions(+), 14 deletions(-) create mode 100644 conf/example.conf diff --git a/conf/example.conf b/conf/example.conf new file mode 100644 index 0000000..8346f0a --- /dev/null +++ b/conf/example.conf @@ -0,0 +1,9 @@ +[irc] +network = irc.freenode.net +port = 6667 +channels = #test2134 +nick = Testbot444324 +owners = some,people + +[log] +folder = logs diff --git a/logbot.py b/logbot.py index d1923d2..8017aa8 100644 --- a/logbot.py +++ b/logbot.py @@ -33,20 +33,13 @@ __license__ = "GPL2" import os import os.path import irclib + +from ConfigParser import ConfigParser from ftplib import FTP +from optparse import OptionParser from time import strftime -# Customizable Variables -######################## -network = 'irc.freenode.net' -port = 6667 -channels = ['#excid3', '#keryx'] -nick = 'Timber' -owner = ['excid3|asus', 'mac9416'] -logs_folder = 'logs' - - html_header = """ @@ -156,11 +149,37 @@ class LogBot(object): for channel in event.arguments(): self.server.join(channel) - -def main(): + +def main(conf): + """ + Start the bot using a config file. + + :Parameters: + - `conf`: config file location + """ + CONFIG = ConfigParser() + CONFIG.read(conf) + network = CONFIG.get('irc', 'network') + port = CONFIG.getint('irc', 'port') + channels = CONFIG.get('irc', 'channels').split(',') + nick = CONFIG.get('irc', 'nick') + owner = CONFIG.get('irc', 'owners').split(',') + logs_folder = CONFIG.get('log', 'folder') + bot = LogBot(network, port, channels, owner, nick, logs_folder) - bot.start() + try: + bot.start() + except KeyboardInterrupt: + pass if __name__ == '__main__': - main() + # Require a config + parser = OptionParser() + parser.add_option('-c', '--config', dest='conf', help='Config to use') + (options, args) = parser.parse_args() + + if not options.conf or not os.access(options.conf, os.R_OK): + parser.print_help() + raise SystemExit(1) + main(options.conf) -- cgit v1.2.3-54-g00ecf