Skip to content
Fetching contributors…
Cannot retrieve contributors at this time
executable file 169 lines (129 sloc) 4.79 KB
#!/usr/bin/env python
jenni - An IRC Bot
Copyright 2008, Sean B. Palmer,
Licensed under the Eiffel Forum License 2.
Run ./jenni, then edit ~/.jenni/
Then run ./jenni again
import sys, os, imp, optparse
from textwrap import dedent as trim
dotdir = os.path.expanduser('~/.jenni')
configpath = os.path.expanduser(dotdir + '/')
def check_python_version():
if sys.version_info < (2, 4):
error = 'Error: Requires Python 2.4 or later, from'
print >> sys.stderr, error
def create_default_config(fn):
f = open(fn, 'w')
output = """\
nick = 'jenni'
host = ''
port = 6667
channels = ['#example', '#test']
owner = 'yournickname'
logchan_pm = ''
# password is the NickServ password, serverpass is the server password
# password = 'example'
# serverpass = 'serverpass'
# These are people who will be able to use's functions...
admins = [owner, 'someoneyoutrust']
# But is disabled by default, as follows:
exclude = ['admin', 'adminchannel', 'ai', 'resp', 'school']
# If you want to enumerate a list of modules rather than disabling
# some, use "enable = ['example']", which takes precedent over exclude
# enable = []
# Directories to load user modules from
# e.g. /path/to/my/modules
extra = ['""" + os.getcwd() + '/modules/' + """']
# Services to load: maps channel names to white or black lists
external = {
'#liberal': ['!'], # allow all
'#conservative': [], # allow none
'*': ['!'] # default whitelist, allow all
print >> f, trim(output)
def create_configfile(dotdir):
if not os.path.isdir(dotdir):
print 'Creating a config directory at ~/.jenni...'
try: os.mkdir(dotdir)
except Exception, e:
print >> sys.stderr, 'There was a problem creating %s:' % dotdir
print >> sys.stderr, e.__class__, str(e)
print >> sys.stderr, 'Please fix this and then run jenni again.'
print >> sys.stdout, 'Config file generated. Please edit it at ' + configpath + ' and run ./jenni again.'
def check_dotdir():
if not os.path.isdir(dotdir) or not os.path.isfile(configpath):
def config_names(config):
config = config or 'default'
def files(d):
names = os.listdir(d)
return list(os.path.join(d, fn) for fn in names if fn.endswith('.py'))
here = os.path.join('.', config)
if os.path.isfile(here):
return [here]
if os.path.isfile(here + '.py'):
return [here + '.py']
if os.path.isdir(here):
return files(here)
there = os.path.join(dotdir, config)
if os.path.isfile(there):
return [there]
if os.path.isfile(there + '.py'):
return [there + '.py']
if os.path.isdir(there):
return files(there)
def main(argv=None):
# Step One: Parse The Command Line
parser = optparse.OptionParser('%prog [options]')
parser.add_option('-c', '--config', metavar='fn',
help='use this configuration file or directory')
opts, args = parser.parse_args(argv)
# Step Two: Check Dependencies
check_python_version() # require python2.4 or later
check_dotdir() # require ~/.jenni, or make it and exit
# Step Three: Load The Configurations
config_modules = []
for config_name in config_names(opts.config):
name = os.path.basename(config_name).split('.')[0] + '_config'
module = imp.load_source(name, config_name)
module.filename = config_name
if not hasattr(module, 'prefix'):
module.prefix = r'\.'
if not hasattr(module, 'name'): = 'Jenni Yanosbot,'
if not hasattr(module, 'port'):
module.port = 6667
if not hasattr(module, 'password'):
module.password = None
if == '':
error = ('Error: you must edit the config file first!\n' +
"You're currently using %s" % module.filename)
print >> sys.stderr, error
# Step Four: Load Jenni
try: from __init__ import run
except ImportError:
try: from jenni import run
except ImportError:
print >> sys.stderr, "Error: Couldn't find jenni to import"
# Step Five: Initialise And Run The Jennies
# @@ ignore SIGHUP
for config_module in config_modules:
run(config_module) # @@ thread this
if __name__ == '__main__':
Jump to Line
Something went wrong with that request. Please try again.