Added new options, more user-friendliness.

This commit is contained in:
Jeremy Fincher 2003-08-28 22:55:42 +00:00
parent 3c8a7c2387
commit 1b2b18c375

View File

@ -124,31 +124,43 @@ if __name__ == '__main__':
### ###
# Modules. # Modules.
### ###
filenames = os.listdir(conf.pluginDir)
plugins = []
for filename in filenames:
if filename.endswith('.py') and \
filename.lower() != filename:
plugins.append(os.path.splitext(filename)[0])
plugins.sort()
if yn('Would you like to see a list of the available modules?') == 'y': if yn('Would you like to see a list of the available modules?') == 'y':
filenames = os.listdir(conf.pluginDir)
plugins = []
for filename in filenames:
if filename.endswith('.py') and \
filename.lower() != filename:
plugins.append(os.path.splitext(filename)[0])
print 'The available plugins are:\n %s' % '\n '.join(plugins) print 'The available plugins are:\n %s' % '\n '.join(plugins)
while yn('Would you like to add a plugin?') == 'y': while yn('Would you like to add a plugin?') == 'y':
plugin = expect('What plugin?', plugins) plugin = expect('What plugin?', plugins)
moduleInfo = imp.find_module(plugin) moduleInfo = imp.find_module(plugin)
try: try:
module = imp.load_module(plugin, *moduleInfo) module = imp.load_module(plugin, *moduleInfo)
except ImportError, e: except ImportError, e:
print 'Sorry, this plugin cannot be loaded. You need the ' \ print 'Sorry, this plugin cannot be loaded. You need the ' \
'python module %s to load it.' % e.args[0].split()[-1] 'python module %s to load it.' % e.args[0].split()[-1]
continue continue
if module.__doc__:
print module.__doc__ print module.__doc__
if yn('Would you like to add this plugin?') == 'y': else:
if hasattr(module, 'configure'): print 'This plugin has no documentation.'
module.configure(onStart, afterConnect, advanced) if hasattr(module, 'example'):
else: print
onStart.append('load %s' % plugin) print 'Here\'s an example of usage of this module:'
if 'load %s' % plugin in onStart: print
plugins.remove(plugin) print module.example
if yn('Would you like to add this plugin?') == 'y':
if hasattr(module, 'configure'):
module.configure(onStart, afterConnect, advanced)
else:
onStart.append('load %s' % plugin)
for s in onStart:
if s.startswith('load'):
(_, plugin) = s.split()
if plugin in plugins:
plugins.remove(plugin)
### ###
# Commands # Commands
@ -160,7 +172,12 @@ if __name__ == '__main__':
'to run before the bot connects to the server?' 'to run before the bot connects to the server?'
onStart.append(anything('What command?')) onStart.append(anything('What command?'))
if yn('Do you want the bot to join any channels?') == 'y': if yn('Do you want the bot to join any channels?') == 'y':
channels = anything('What channels? (separate channels by spaces)') channels = something('What channels? (separate channels by spaces)')
while not all(ircutils.isChannel, channels.split()):
for channel in channels.split():
if not ircutils.isChannel(channel):
print '%r isn\'t a valid channel.' % channel
channels = something('What channels?')
afterConnect.append('join %s' % channels) afterConnect.append('join %s' % channels)
postConnect = 'Would you like any commands to run ' \ postConnect = 'Would you like any commands to run ' \
'when the bot is finished connecting to the server?' 'when the bot is finished connecting to the server?'
@ -169,33 +186,41 @@ if __name__ == '__main__':
'when the bot is finished connecting to the server?' 'when the bot is finished connecting to the server?'
afterConnect.append(anything('What command?')) afterConnect.append(anything('What command?'))
template = template.replace('%%onStart%%', pprint.pformat(onStart))
template = template.replace('%%afterConnect%%',
pprint.pformat(afterConnect))
### ###
# Set owner user. # Set owner user.
### ###
if yn('Would you like to add an owner user?') == 'y': if yn('Would you like to add an owner user?') == 'y':
owner = anything('What should the owner\'s username be?') owner = something('What should the owner\'s username be?')
password = anything('What should the owner\'s password be?') password = something('What should the owner\'s password be?')
user = ircdb.IrcUser() user = ircdb.IrcUser()
user.setPassword(password) user.setPassword(password)
user.addCapability('owner') user.addCapability('owner')
while yn('Would you like to add a hostmask for the owner?') == 'y': while yn('Would you like to add a hostmask for the owner?') == 'y':
user.addHostmask(anything('What hostmask?')) user.addHostmask(something('What hostmask?'))
ircdb.users.setUser(owner, user) ircdb.users.setUser(owner, user)
###
# Finito!
###
template = template.replace('%%onStart%%', pprint.pformat(onStart))
template = template.replace('%%afterConnect%%',
pprint.pformat(afterConnect))
### ###
# Configuration variables in conf.py. # Configuration variables in conf.py.
### ###
configVariables = {} configVariables = {}
if advanced and \ if advanced and \
yn('Would you like to modify the default config variables?')=='y': yn('Would you like to modify the default config variables?')=='y':
pass print 'Supybot can use various "drivers" for actually handling the '
print 'network connects the bot makes. One of the most robust of '
print 'these is the Twisted <http://www.twistedmatrix.com/> driver. '
if yn('Would you like to use the Twisted driver?') == 'y':
try:
import twistedDrivers
configVariables['driverModule'] = 'twistedDrivers'
except:
print 'Sorry, twisted doesn\'t seem to be installed.'
template = template.replace('%%configVariables%%', template = template.replace('%%configVariables%%',
pprint.pformat(configVariables)) pprint.pformat(configVariables))