Merged ashcrow's addition of a config file

This commit is contained in:
Chris Oliver 2010-02-07 10:14:14 -06:00
commit f7d6cb90d7
2 changed files with 44 additions and 15 deletions

9
conf/example.conf Normal file
View file

@ -0,0 +1,9 @@
[irc]
network = irc.freenode.net
port = 6667
channels = #test2134
nick = Testbot444324
owners = some,people
[log]
folder = logs

View file

@ -33,20 +33,13 @@ __license__ = "GPL2"
import os import os
import os.path import os.path
import irclib import irclib
from ConfigParser import ConfigParser
from ftplib import FTP from ftplib import FTP
from optparse import OptionParser
from time import strftime 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 = """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" html_header = """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
@ -116,7 +109,6 @@ class LogBot(object):
write(event.target(), write(event.target(),
"%s left the room (Kicked by %s (%s))" % \ "%s left the room (Kicked by %s (%s))" % \
( (
def handleMode(self, connection, event): def handleMode(self, connection, event):
"""Handles mode changes """Handles mode changes
@ -197,9 +189,37 @@ class LogBot(object):
def write(self): def write(self):
pass pass
def main():
bot = LogBot(network, port, channels, owner, nick, logs_folder) def main(conf):
bot.start() """
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)
try:
bot.start()
except KeyboardInterrupt:
pass
if __name__ == '__main__': 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)