2005-01-19 14:14:38 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
###
|
|
|
|
# Copyright (c) 2003-2004, Jeremiah Fincher
|
2012-09-01 16:16:48 +02:00
|
|
|
# Copyright (c) 2009, James McCoy
|
2005-01-19 14:14:38 +01:00
|
|
|
# All rights reserved.
|
|
|
|
#
|
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
|
|
# modification, are permitted provided that the following conditions are met:
|
|
|
|
#
|
|
|
|
# * Redistributions of source code must retain the above copyright notice,
|
|
|
|
# this list of conditions, and the following disclaimer.
|
|
|
|
# * Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
# this list of conditions, and the following disclaimer in the
|
|
|
|
# documentation and/or other materials provided with the distribution.
|
|
|
|
# * Neither the name of the author of this software nor the name of
|
|
|
|
# contributors to this software may be used to endorse or promote products
|
|
|
|
# derived from this software without specific prior written consent.
|
|
|
|
#
|
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
# POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
###
|
|
|
|
|
2015-06-12 22:22:16 +02:00
|
|
|
from __future__ import print_function
|
|
|
|
|
2005-01-19 14:14:38 +01:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
2005-01-26 14:26:44 +01:00
|
|
|
def error(s):
|
|
|
|
sys.stderr.write(s)
|
|
|
|
if not s.endswith(os.linesep):
|
|
|
|
sys.stderr.write(os.linesep)
|
2005-01-19 14:14:38 +01:00
|
|
|
sys.exit(-1)
|
2005-01-31 16:24:36 +01:00
|
|
|
|
2012-09-01 16:06:50 +02:00
|
|
|
if sys.version_info < (2, 6, 0):
|
|
|
|
error('This program requires Python >= 2.6.0')
|
2005-01-19 14:14:38 +01:00
|
|
|
|
|
|
|
import supybot
|
|
|
|
|
|
|
|
import re
|
|
|
|
import time
|
|
|
|
import pydoc
|
|
|
|
import pprint
|
|
|
|
import socket
|
|
|
|
import logging
|
|
|
|
import optparse
|
|
|
|
|
2011-06-23 10:27:52 +02:00
|
|
|
import supybot.i18n as i18n
|
2005-01-19 14:14:38 +01:00
|
|
|
import supybot.ansi as ansi
|
|
|
|
import supybot.utils as utils
|
|
|
|
import supybot.ircutils as ircutils
|
|
|
|
import supybot.registry as registry
|
2011-06-23 10:27:52 +02:00
|
|
|
# supybot.plugin, supybot.log, and supybot.conf will be imported later,
|
|
|
|
# because we need to set a language before loading the conf
|
2005-01-19 14:14:38 +01:00
|
|
|
|
|
|
|
import supybot.questions as questions
|
|
|
|
from supybot.questions import output, yn, anything, something, expect, getpass
|
|
|
|
|
|
|
|
def getPlugins(pluginDirs):
|
2005-05-06 04:31:42 +02:00
|
|
|
plugins = set([])
|
|
|
|
join = os.path.join
|
2005-01-19 14:14:38 +01:00
|
|
|
for pluginDir in pluginDirs:
|
|
|
|
try:
|
2005-05-06 04:31:42 +02:00
|
|
|
for filename in os.listdir(pluginDir):
|
|
|
|
fname = join(pluginDir, filename)
|
|
|
|
if (filename.endswith('.py') or os.path.isdir(fname)) \
|
|
|
|
and filename[0].isupper():
|
|
|
|
plugins.add(os.path.splitext(filename)[0])
|
2005-01-19 14:14:38 +01:00
|
|
|
except OSError:
|
|
|
|
continue
|
|
|
|
plugins.discard('Owner')
|
|
|
|
plugins = list(plugins)
|
|
|
|
plugins.sort()
|
|
|
|
return plugins
|
|
|
|
|
|
|
|
def loadPlugin(name):
|
2005-01-26 14:26:44 +01:00
|
|
|
import supybot.plugin as plugin
|
2005-01-19 14:14:38 +01:00
|
|
|
try:
|
2005-01-26 14:26:44 +01:00
|
|
|
module = plugin.loadPluginModule(name)
|
2005-01-19 14:14:38 +01:00
|
|
|
if hasattr(module, 'Class'):
|
|
|
|
return module
|
|
|
|
else:
|
|
|
|
output("""That plugin loaded fine, but didn't seem to be a real
|
|
|
|
Supybot plugin; there was no Class variable to tell us what class
|
|
|
|
to load when we load the plugin. We'll skip over it for now, but
|
|
|
|
you can always add it later.""")
|
|
|
|
return None
|
2013-04-27 16:16:08 +02:00
|
|
|
except Exception as e:
|
2005-01-19 14:14:38 +01:00
|
|
|
output("""We encountered a bit of trouble trying to load plugin %r.
|
|
|
|
Python told us %r. We'll skip over it for now, you can always add it
|
2005-01-31 14:06:43 +01:00
|
|
|
later.""" % (name, utils.gen.exnToString(e)))
|
2005-01-19 14:14:38 +01:00
|
|
|
return None
|
|
|
|
|
|
|
|
def describePlugin(module, showUsage):
|
|
|
|
if module.__doc__:
|
|
|
|
output(module.__doc__, unformatted=False)
|
|
|
|
elif hasattr(module.Class, '__doc__'):
|
|
|
|
output(module.Class.__doc__, unformatted=False)
|
|
|
|
else:
|
|
|
|
output("""Unfortunately, this plugin doesn't seem to have any
|
|
|
|
documentation. Sorry about that.""")
|
|
|
|
if showUsage:
|
|
|
|
if hasattr(module, 'example'):
|
|
|
|
if yn('This plugin has a usage example. '
|
|
|
|
'Would you like to see it?', default=False):
|
|
|
|
pydoc.pager(module.example)
|
|
|
|
else:
|
|
|
|
output("""This plugin has no usage example.""")
|
|
|
|
|
|
|
|
def clearLoadedPlugins(plugins, pluginRegistry):
|
|
|
|
for plugin in plugins:
|
|
|
|
try:
|
|
|
|
pluginKey = pluginRegistry.get(plugin)
|
|
|
|
if pluginKey():
|
|
|
|
plugins.remove(plugin)
|
|
|
|
except registry.NonExistentRegistryEntry:
|
|
|
|
continue
|
|
|
|
|
|
|
|
_windowsVarRe = re.compile(r'%(\w+)%')
|
2005-04-04 05:15:09 +02:00
|
|
|
def getDirectoryName(default, basedir=os.curdir, prompt=True):
|
2005-01-19 14:14:38 +01:00
|
|
|
done = False
|
|
|
|
while not done:
|
2005-04-04 05:15:09 +02:00
|
|
|
if prompt:
|
|
|
|
dir = something('What directory do you want to use?',
|
|
|
|
default=os.path.join(basedir, default))
|
|
|
|
else:
|
|
|
|
dir = os.path.join(basedir, default)
|
2005-01-19 14:14:38 +01:00
|
|
|
orig_dir = dir
|
|
|
|
dir = os.path.expanduser(dir)
|
|
|
|
dir = _windowsVarRe.sub(r'$\1', dir)
|
|
|
|
dir = os.path.expandvars(dir)
|
|
|
|
dir = os.path.abspath(dir)
|
|
|
|
try:
|
|
|
|
os.makedirs(dir)
|
|
|
|
done = True
|
2013-04-27 16:16:08 +02:00
|
|
|
except OSError as e:
|
2009-05-26 22:27:53 +02:00
|
|
|
# 17 is File exists for Linux (and likely other POSIX systems)
|
|
|
|
# 183 is the same for Windows
|
|
|
|
if e.args[0] == 17 or (os.name == 'nt' and e.args[0] == 183):
|
|
|
|
done = True
|
|
|
|
else:
|
2005-01-19 14:14:38 +01:00
|
|
|
output("""Sorry, I couldn't make that directory for some
|
|
|
|
reason. The Operating System told me %s. You're going to
|
|
|
|
have to pick someplace else.""" % e)
|
2005-04-04 05:15:09 +02:00
|
|
|
prompt = True
|
2005-01-19 14:14:38 +01:00
|
|
|
return (dir, os.path.dirname(orig_dir))
|
|
|
|
|
2011-06-23 10:27:52 +02:00
|
|
|
|
2005-01-19 14:14:38 +01:00
|
|
|
def main():
|
2011-06-23 10:27:52 +02:00
|
|
|
import supybot.version as version
|
2005-01-19 14:14:38 +01:00
|
|
|
parser = optparse.OptionParser(usage='Usage: %prog [options]',
|
2011-06-23 10:27:52 +02:00
|
|
|
version='Supybot %s' % version.version)
|
2005-01-19 14:14:38 +01:00
|
|
|
parser.add_option('', '--allow-root', action='store_true',
|
|
|
|
dest='allowRoot',
|
|
|
|
help='Determines whether the wizard will be allowed to '
|
|
|
|
'run as root. You don\'t want this. Don\'t do it.'
|
|
|
|
' Even if you think you want it, you don\'t. '
|
|
|
|
'You\'re probably dumb if you do this.')
|
2013-02-24 09:47:48 +01:00
|
|
|
parser.add_option('', '--allow-home', action='store_true',
|
|
|
|
dest='allowHome',
|
|
|
|
help='Determines whether the wizard will be allowed to '
|
|
|
|
'run directly in the HOME directory. '
|
|
|
|
'You should not do this unless you want it to '
|
|
|
|
'create multiple files in your HOME directory.')
|
2005-01-19 14:14:38 +01:00
|
|
|
parser.add_option('', '--no-network', action='store_false',
|
|
|
|
dest='network',
|
|
|
|
help='Determines whether the wizard will be allowed to '
|
|
|
|
'run without a network connection.')
|
|
|
|
(options, args) = parser.parse_args()
|
|
|
|
if os.name == 'posix':
|
|
|
|
if (os.getuid() == 0 or os.geteuid() == 0) and not options.allowRoot:
|
2005-01-26 14:26:44 +01:00
|
|
|
error('Please, don\'t run this as root.')
|
2013-02-24 09:47:48 +01:00
|
|
|
if os.name == 'posix':
|
|
|
|
if (os.getcwd() == os.path.expanduser('~')) and not options.allowHome:
|
|
|
|
error('Please, don\'t run this in your HOME directory.')
|
2013-05-21 17:30:14 +02:00
|
|
|
if os.path.isfile(os.path.join('scripts', 'supybot-wizard')) or \
|
|
|
|
os.path.isfile(os.path.join('..', 'scripts', 'supybot-wizard')):
|
|
|
|
print('')
|
|
|
|
print('+------------------------------------------------------------+')
|
|
|
|
print('| +--------------------------------------------------------+ |')
|
|
|
|
print('| | Warning: It looks like you are running the wizard from | |')
|
|
|
|
print('| | the Supybot source directory. This is not recommended. | |')
|
|
|
|
print('| | Please press Ctrl-C and change to another directory. | |')
|
|
|
|
print('| +--------------------------------------------------------+ |')
|
|
|
|
print('+------------------------------------------------------------+')
|
|
|
|
print('')
|
2005-01-19 14:14:38 +01:00
|
|
|
|
|
|
|
if args:
|
|
|
|
parser.error('This program takes no non-option arguments.')
|
|
|
|
output("""This is a wizard to help you start running supybot. What it
|
2005-11-30 16:55:16 +01:00
|
|
|
will do is create the necessary config files based on the options you
|
|
|
|
select here. So hold on tight and be ready to be interrogated :)""")
|
2005-01-19 14:14:38 +01:00
|
|
|
|
|
|
|
|
|
|
|
output("""First of all, we can bold the questions you're asked so you can
|
|
|
|
easily distinguish the mostly useless blather (like this) from the
|
|
|
|
questions that you actually have to answer.""")
|
|
|
|
if yn('Would you like to try this bolding?', default=True):
|
|
|
|
questions.useBold = True
|
|
|
|
if not yn('Do you see this in bold?'):
|
|
|
|
output("""Sorry, it looks like your terminal isn't ANSI compliant.
|
|
|
|
Try again some other day, on some other terminal :)""")
|
|
|
|
questions.useBold = False
|
|
|
|
else:
|
|
|
|
output("""Great!""")
|
|
|
|
|
|
|
|
###
|
|
|
|
# Preliminary questions.
|
|
|
|
###
|
|
|
|
output("""We've got some preliminary things to get out of the way before
|
|
|
|
we can really start asking you questions that directly relate to what your
|
|
|
|
bot is going to be like.""")
|
|
|
|
|
|
|
|
# Advanced?
|
|
|
|
output("""We want to know if you consider yourself an advanced Supybot
|
|
|
|
user because some questions are just utterly boring and useless for new
|
|
|
|
users. Others might not make sense unless you've used Supybot for some
|
|
|
|
time.""")
|
|
|
|
advanced = yn('Are you an advanced Supybot user?', default=False)
|
|
|
|
|
2011-06-23 10:27:52 +02:00
|
|
|
# Language?
|
|
|
|
output("""This version of Supybot (known as Limnoria) includes another
|
|
|
|
language. This can be changed at any time. You need to answer with a short
|
|
|
|
id for the language, such as 'en', 'fr', 'it' (without the quotes). If
|
|
|
|
you want to use English, just press enter.""")
|
|
|
|
language = something('What language do you want to use?', default='en')
|
|
|
|
|
|
|
|
class Empty:
|
|
|
|
"""This is a hack to allow the i18n to get the current language, before
|
|
|
|
loading the conf module, before the conf module needs i18n to set the
|
|
|
|
default strings."""
|
|
|
|
def __call__(self):
|
|
|
|
return self.value
|
|
|
|
fakeConf = Empty()
|
|
|
|
fakeConf.supybot = Empty()
|
|
|
|
fakeConf.supybot.language = Empty()
|
|
|
|
fakeConf.supybot.language.value = language
|
|
|
|
i18n.conf = fakeConf
|
|
|
|
i18n.currentLocale = language
|
|
|
|
i18n.reloadLocales()
|
|
|
|
import supybot.log as log
|
|
|
|
log._stdoutHandler.setLevel(100) # *Nothing* gets through this!
|
|
|
|
import supybot.conf as conf
|
|
|
|
i18n.import_conf() # It imports the real conf module
|
|
|
|
import supybot.plugin as plugin
|
|
|
|
|
2005-01-19 14:14:38 +01:00
|
|
|
### Directories.
|
|
|
|
# We set these variables in cache because otherwise conf and log will
|
|
|
|
# create directories for the default values, which might not be what the
|
|
|
|
# user wants.
|
2005-04-04 05:15:09 +02:00
|
|
|
if advanced:
|
|
|
|
output("""Now we've got to ask you some questions about where some of
|
|
|
|
your directories are (or, perhaps, will be :)). If you're running this
|
|
|
|
wizard from the directory you'll actually be starting your bot from and
|
|
|
|
don't mind creating some directories in the current directory, then
|
|
|
|
just don't give answers to these questions and we'll create the
|
|
|
|
directories we need right here in this directory.""")
|
|
|
|
|
|
|
|
# conf.supybot.directories.log
|
2014-07-13 17:23:11 +02:00
|
|
|
output("""Your bot will need to put its logs somewhere. Do you have
|
2005-04-04 05:15:09 +02:00
|
|
|
any specific place you'd like them? If not, just press enter and we'll
|
|
|
|
make a directory named "logs" right here.""")
|
|
|
|
(logDir, basedir) = getDirectoryName('logs')
|
|
|
|
conf.supybot.directories.log.setValue(logDir)
|
2005-01-19 14:14:38 +01:00
|
|
|
|
2005-04-04 05:15:09 +02:00
|
|
|
# conf.supybot.directories.data
|
|
|
|
output("""Your bot will need to put various data somewhere. Things
|
|
|
|
like databases, downloaded files, etc. Do you have any specific place
|
|
|
|
you'd like the bot to put these things? If not, just press enter and
|
|
|
|
we'll make a directory named "data" right here.""")
|
|
|
|
(dataDir, basedir) = getDirectoryName('data', basedir=basedir)
|
|
|
|
conf.supybot.directories.data.setValue(dataDir)
|
2005-01-19 14:14:38 +01:00
|
|
|
|
2005-04-04 05:15:09 +02:00
|
|
|
# conf.supybot.directories.conf
|
2014-07-13 17:23:11 +02:00
|
|
|
output("""Your bot must know where to find its configuration files.
|
2005-04-04 05:15:09 +02:00
|
|
|
It'll probably only make one or two, but it's gotta have some place to
|
|
|
|
put them. Where should that place be? If you don't care, just press
|
|
|
|
enter and we'll make a directory right here named "conf" where it'll
|
2014-07-13 17:23:11 +02:00
|
|
|
store its stuff. """)
|
2005-04-04 05:15:09 +02:00
|
|
|
(confDir, basedir) = getDirectoryName('conf', basedir=basedir)
|
|
|
|
conf.supybot.directories.conf.setValue(confDir)
|
2005-01-19 14:14:38 +01:00
|
|
|
|
2005-04-04 05:15:09 +02:00
|
|
|
# conf.supybot.directories.backup
|
|
|
|
output("""Your bot must know where to place backups of its conf and
|
|
|
|
data files. Where should that place be? If you don't care, just press
|
|
|
|
enter and we'll make a directory right here named "backup" where it'll
|
2014-07-13 17:23:11 +02:00
|
|
|
store its stuff.""")
|
2005-04-04 05:15:09 +02:00
|
|
|
(backupDir, basedir) = getDirectoryName('backup', basedir=basedir)
|
|
|
|
conf.supybot.directories.backup.setValue(backupDir)
|
2005-01-19 14:14:38 +01:00
|
|
|
|
2005-04-04 05:15:09 +02:00
|
|
|
# pluginDirs
|
2014-07-13 17:23:11 +02:00
|
|
|
output("""Your bot will also need to know where to find its plugins at.
|
2014-05-07 08:42:01 +02:00
|
|
|
Of course, it already knows where the plugins that it came with are,
|
2005-04-04 05:15:09 +02:00
|
|
|
but your own personal plugins that you write for will probably be
|
|
|
|
somewhere else.""")
|
|
|
|
pluginDirs = conf.supybot.directories.plugins()
|
|
|
|
output("""Currently, the bot knows about the following directories:""")
|
2009-05-18 09:26:57 +02:00
|
|
|
output(format('%L', pluginDirs + [plugin._pluginsDir]))
|
2005-04-04 05:15:09 +02:00
|
|
|
while yn('Would you like to add another plugin directory? '
|
|
|
|
'Adding a local plugin directory is good style.',
|
|
|
|
default=True):
|
|
|
|
(pluginDir, _) = getDirectoryName('plugins', basedir=basedir)
|
|
|
|
if pluginDir not in pluginDirs:
|
|
|
|
pluginDirs.append(pluginDir)
|
|
|
|
conf.supybot.directories.plugins.setValue(pluginDirs)
|
|
|
|
else:
|
|
|
|
output("""Your bot needs to create some directories in order to store
|
2005-05-06 00:38:27 +02:00
|
|
|
the various log, config, and data files.""")
|
2005-04-04 05:15:09 +02:00
|
|
|
basedir = something("""Where would you like to create these
|
2005-05-06 00:38:27 +02:00
|
|
|
directories?""", default=os.curdir)
|
2005-04-04 05:15:09 +02:00
|
|
|
# conf.supybot.directories.log
|
2014-09-03 16:35:03 +02:00
|
|
|
(logDir, basedir) = getDirectoryName('logs',
|
|
|
|
basedir=basedir, prompt=False)
|
2005-04-04 05:15:09 +02:00
|
|
|
conf.supybot.directories.log.setValue(logDir)
|
|
|
|
# conf.supybot.directories.data
|
|
|
|
(dataDir, basedir) = getDirectoryName('data',
|
|
|
|
basedir=basedir, prompt=False)
|
|
|
|
conf.supybot.directories.data.setValue(dataDir)
|
|
|
|
# conf.supybot.directories.conf
|
|
|
|
(confDir, basedir) = getDirectoryName('conf',
|
|
|
|
basedir=basedir, prompt=False)
|
|
|
|
conf.supybot.directories.conf.setValue(confDir)
|
|
|
|
# conf.supybot.directories.backup
|
|
|
|
(backupDir, basedir) = getDirectoryName('backup',
|
|
|
|
basedir=basedir, prompt=False)
|
|
|
|
conf.supybot.directories.backup.setValue(backupDir)
|
|
|
|
# pluginDirs
|
|
|
|
pluginDirs = conf.supybot.directories.plugins()
|
2005-04-04 07:25:59 +02:00
|
|
|
(pluginDir, _) = getDirectoryName('plugins',
|
|
|
|
basedir=basedir, prompt=False)
|
2005-01-19 14:14:38 +01:00
|
|
|
if pluginDir not in pluginDirs:
|
|
|
|
pluginDirs.append(pluginDir)
|
2005-04-04 05:15:09 +02:00
|
|
|
conf.supybot.directories.plugins.setValue(pluginDirs)
|
2005-01-19 14:14:38 +01:00
|
|
|
|
|
|
|
output("Good! We're done with the directory stuff.")
|
|
|
|
|
|
|
|
###
|
|
|
|
# Bot stuff
|
|
|
|
###
|
|
|
|
output("""Now we're going to ask you things that actually relate to the
|
|
|
|
bot you'll be running.""")
|
|
|
|
|
|
|
|
network = None
|
|
|
|
while not network:
|
|
|
|
output("""First, we need to know the name of the network you'd like to
|
|
|
|
connect to. Not the server host, mind you, but the name of the
|
2014-05-17 09:33:40 +02:00
|
|
|
network. If you plan to connect to chat.freenode.net, for instance,
|
|
|
|
you should answer this question with 'freenode' (without the quotes).
|
|
|
|
""")
|
2005-01-19 14:14:38 +01:00
|
|
|
network = something('What IRC network will you be connecting to?')
|
|
|
|
if '.' in network:
|
|
|
|
output("""There shouldn't be a '.' in the network name. Remember,
|
|
|
|
this is the network name, not the actual server you plan to connect
|
|
|
|
to.""")
|
|
|
|
network = None
|
|
|
|
elif not registry.isValidRegistryName(network):
|
|
|
|
output("""That's not a valid name for one reason or another. Please
|
|
|
|
pick a simpler name, one more likely to be valid.""")
|
|
|
|
network = None
|
|
|
|
|
|
|
|
conf.supybot.networks.setValue([network])
|
|
|
|
network = conf.registerNetwork(network)
|
|
|
|
|
|
|
|
defaultServer = None
|
|
|
|
server = None
|
|
|
|
ip = None
|
|
|
|
while not ip:
|
|
|
|
serverString = something('What server would you like to connect to?',
|
|
|
|
default=defaultServer)
|
|
|
|
if options.network:
|
|
|
|
try:
|
|
|
|
output("""Looking up %s...""" % serverString)
|
|
|
|
ip = socket.gethostbyname(serverString)
|
|
|
|
except:
|
|
|
|
output("""Sorry, I couldn't find that server. Perhaps you
|
|
|
|
misspelled it? Also, be sure not to put the port in the
|
|
|
|
server's name -- we'll ask you about that later.""")
|
|
|
|
else:
|
|
|
|
ip = 'no network available'
|
|
|
|
|
|
|
|
output("""Found %s (%s).""" % (serverString, ip))
|
2014-05-17 12:24:14 +02:00
|
|
|
|
|
|
|
if advanced:
|
|
|
|
# conf.supybot.networks.<network>.ssl
|
|
|
|
output("""Some servers allow you to use a secure connection via SSL.
|
|
|
|
This requires having pyOpenSSL installed.""")
|
|
|
|
if yn('Do you want to use an SSL connection?', default=False):
|
|
|
|
network.ssl.setValue(True)
|
|
|
|
|
|
|
|
output("""IRC servers almost always accept connections on port
|
2014-05-17 12:27:56 +02:00
|
|
|
6667 (or 6697 when using SSL). They can, however, accept connections
|
2014-05-17 12:24:14 +02:00
|
|
|
anywhere their admins feel like they want to accept connections from.""")
|
2005-01-19 14:14:38 +01:00
|
|
|
if yn('Does this server require connection on a non-standard port?',
|
|
|
|
default=False):
|
|
|
|
port = 0
|
|
|
|
while not port:
|
|
|
|
port = something('What port is that?')
|
|
|
|
try:
|
|
|
|
i = int(port)
|
|
|
|
if not (0 < i < 65536):
|
2013-04-27 16:16:08 +02:00
|
|
|
raise ValueError()
|
2005-01-19 14:14:38 +01:00
|
|
|
except ValueError:
|
|
|
|
output("""That's not a valid port.""")
|
|
|
|
port = 0
|
|
|
|
else:
|
2014-05-17 12:24:14 +02:00
|
|
|
if network.ssl.value:
|
|
|
|
port = 6697
|
|
|
|
else:
|
|
|
|
port = 6667
|
2005-01-19 14:14:38 +01:00
|
|
|
server = ':'.join([serverString, str(port)])
|
|
|
|
network.servers.setValue([server])
|
|
|
|
|
|
|
|
# conf.supybot.nick
|
2014-05-07 08:42:01 +02:00
|
|
|
# Force the user into specifying a nick if it didn't have one already
|
2005-01-19 14:14:38 +01:00
|
|
|
while True:
|
|
|
|
nick = something('What nick would you like your bot to use?',
|
|
|
|
default=None)
|
|
|
|
try:
|
|
|
|
conf.supybot.nick.set(nick)
|
|
|
|
break
|
|
|
|
except registry.InvalidRegistryValue:
|
|
|
|
output("""That's not a valid nick. Go ahead and pick another.""")
|
|
|
|
|
|
|
|
# conf.supybot.user
|
|
|
|
if advanced:
|
|
|
|
output("""If you've ever done a /whois on a person, you know that IRC
|
|
|
|
provides a way for users to show the world their full name. What would
|
|
|
|
you like your bot's full name to be? If you don't care, just press
|
|
|
|
enter and it'll be the same as your bot's nick.""")
|
|
|
|
user = ''
|
|
|
|
user = something('What would you like your bot\'s full name to be?',
|
|
|
|
default=nick)
|
|
|
|
conf.supybot.user.set(user)
|
|
|
|
# conf.supybot.ident (if advanced)
|
2011-06-27 18:09:54 +02:00
|
|
|
defaultIdent = 'limnoria'
|
2005-01-19 14:14:38 +01:00
|
|
|
if advanced:
|
|
|
|
output("""IRC servers also allow you to set your ident, which they
|
2005-04-04 05:16:06 +02:00
|
|
|
might need if they can't find your identd server. What would you like
|
|
|
|
your ident to be? If you don't care, press enter and we'll use
|
|
|
|
'supybot'. In fact, we prefer that you do this, because it provides
|
|
|
|
free advertising for Supybot when users /whois your bot. But, of
|
|
|
|
course, it's your call.""")
|
2005-01-19 14:14:38 +01:00
|
|
|
while True:
|
|
|
|
ident = something('What would you like your bot\'s ident to be?',
|
|
|
|
default=defaultIdent)
|
|
|
|
try:
|
|
|
|
conf.supybot.ident.set(ident)
|
|
|
|
break
|
|
|
|
except registry.InvalidRegistryValue:
|
2005-04-04 05:16:06 +02:00
|
|
|
output("""That was not a valid ident. Go ahead and pick
|
|
|
|
another.""")
|
2005-01-19 14:14:38 +01:00
|
|
|
else:
|
|
|
|
conf.supybot.ident.set(defaultIdent)
|
|
|
|
|
2005-12-14 04:29:31 +01:00
|
|
|
# conf.supybot.networks.<network>.password
|
2005-01-19 14:14:38 +01:00
|
|
|
output("""Some servers require a password to connect to them. Most
|
|
|
|
public servers don't. If you try to connect to a server and for some
|
|
|
|
reason it just won't work, it might be that you need to set a
|
|
|
|
password.""")
|
|
|
|
if yn('Do you want to set such a password?', default=False):
|
|
|
|
network.password.set(getpass())
|
|
|
|
|
|
|
|
# conf.supybot.networks.<network>.channels
|
|
|
|
output("""Of course, having an IRC bot isn't the most useful thing in the
|
|
|
|
world unless you can make that bot join some channels.""")
|
2014-05-07 08:42:01 +02:00
|
|
|
if yn('Do you want your bot to join some channels when it connects?',
|
2005-01-19 14:14:38 +01:00
|
|
|
default=True):
|
|
|
|
defaultChannels = ' '.join(network.channels())
|
|
|
|
output("""Separate channels with spaces. If the channel is locked
|
|
|
|
with a key, follow the channel name with the key separated
|
|
|
|
by a comma. For example:
|
2005-02-02 00:22:02 +01:00
|
|
|
#supybot-bots #mychannel,mykey #otherchannel""");
|
2005-01-19 14:14:38 +01:00
|
|
|
while True:
|
|
|
|
channels = something('What channels?', default=defaultChannels)
|
|
|
|
try:
|
|
|
|
network.channels.set(channels)
|
|
|
|
break
|
2013-04-27 16:16:08 +02:00
|
|
|
except registry.InvalidRegistryValue as e:
|
2005-04-04 07:26:44 +02:00
|
|
|
output(""""%s" is an invalid IRC channel. Be sure to prefix
|
|
|
|
the channel with # (or +, or !, or &, but no one uses those
|
2005-04-04 05:05:52 +02:00
|
|
|
channels, really). Be sure the channel key (if you are
|
|
|
|
supplying one) does not contain a comma.""" % e.channel)
|
2005-01-19 14:14:38 +01:00
|
|
|
else:
|
|
|
|
network.channels.setValue([])
|
|
|
|
|
|
|
|
###
|
|
|
|
# Plugins
|
|
|
|
###
|
|
|
|
def configurePlugin(module, advanced):
|
|
|
|
if hasattr(module, 'configure'):
|
|
|
|
output("""Beginning configuration for %s...""" %
|
|
|
|
module.Class.__name__)
|
|
|
|
module.configure(advanced)
|
2013-04-27 16:16:08 +02:00
|
|
|
print() # Blank line :)
|
2005-01-19 14:14:38 +01:00
|
|
|
output("""Done!""")
|
|
|
|
else:
|
|
|
|
conf.registerPlugin(module.__name__, currentValue=True)
|
|
|
|
|
2009-05-18 09:26:57 +02:00
|
|
|
plugins = getPlugins(pluginDirs + [plugin._pluginsDir])
|
2014-02-22 00:55:41 +01:00
|
|
|
for s in ('Admin', 'User', 'Channel', 'Misc', 'Config', 'Utilities'):
|
2005-01-26 14:26:44 +01:00
|
|
|
m = loadPlugin(s)
|
|
|
|
if m is not None:
|
|
|
|
configurePlugin(m, advanced)
|
|
|
|
else:
|
|
|
|
error('There was an error loading one of the core plugins that '
|
|
|
|
'under almost all circumstances are loaded. Go ahead and '
|
|
|
|
'fix that error and run this script again.')
|
2005-01-19 14:14:38 +01:00
|
|
|
clearLoadedPlugins(plugins, conf.supybot.plugins)
|
|
|
|
|
|
|
|
output("""Now we're going to run you through plugin configuration. There's
|
|
|
|
a variety of plugins in supybot by default, but you can create and
|
|
|
|
add your own, of course. We'll allow you to take a look at the known
|
|
|
|
plugins' descriptions and configure them
|
|
|
|
if you like what you see.""")
|
|
|
|
|
|
|
|
# bulk
|
|
|
|
addedBulk = False
|
|
|
|
if advanced and yn('Would you like to add plugins en masse first?'):
|
|
|
|
addedBulk = True
|
2005-01-31 15:52:27 +01:00
|
|
|
output(format("""The available plugins are: %L.""", plugins))
|
2005-01-19 14:14:38 +01:00
|
|
|
output("""What plugins would you like to add? If you've changed your
|
|
|
|
mind and would rather not add plugins in bulk like this, just press
|
2011-07-16 13:37:56 +02:00
|
|
|
enter and we'll move on to the individual plugin configuration.
|
2014-10-13 10:21:20 +02:00
|
|
|
We suggest you to add Aka, Ctcp, Later, Network, Plugin, String,
|
2011-07-16 13:37:56 +02:00
|
|
|
and Utilities""")
|
2005-02-10 08:35:49 +01:00
|
|
|
massPlugins = anything('Separate plugin names by spaces or commas:')
|
2005-01-19 14:14:38 +01:00
|
|
|
for name in re.split(r',?\s+', massPlugins):
|
|
|
|
module = loadPlugin(name)
|
|
|
|
if module is not None:
|
|
|
|
configurePlugin(module, advanced)
|
|
|
|
clearLoadedPlugins(plugins, conf.supybot.plugins)
|
|
|
|
|
|
|
|
# individual
|
|
|
|
if yn('Would you like to look at plugins individually?'):
|
|
|
|
output("""Next comes your opportunity to learn more about the plugins
|
|
|
|
that are available and select some (or all!) of them to run in your
|
|
|
|
bot. Before you have to make a decision, of course, you'll be able to
|
|
|
|
see a short description of the plugin and, if you choose, an example
|
|
|
|
session with the plugin. Let's begin.""")
|
|
|
|
# until we get example strings again, this will default to false
|
|
|
|
#showUsage =yn('Would you like the option of seeing usage examples?')
|
|
|
|
showUsage = False
|
|
|
|
name = expect('What plugin would you like to look at?',
|
|
|
|
plugins, acceptEmpty=True)
|
|
|
|
while name:
|
|
|
|
module = loadPlugin(name)
|
|
|
|
if module is not None:
|
|
|
|
describePlugin(module, showUsage)
|
|
|
|
if yn('Would you like to load this plugin?', default=True):
|
|
|
|
configurePlugin(module, advanced)
|
|
|
|
clearLoadedPlugins(plugins, conf.supybot.plugins)
|
|
|
|
if not yn('Would you like add another plugin?'):
|
|
|
|
break
|
|
|
|
name = expect('What plugin would you like to look at?', plugins)
|
|
|
|
|
|
|
|
###
|
|
|
|
# Sundry
|
|
|
|
###
|
|
|
|
output("""Although supybot offers a supybot-adduser script, with which
|
|
|
|
you can add users to your bot's user database, it's *very* important that
|
|
|
|
you have an owner user for you bot.""")
|
|
|
|
if yn('Would you like to add an owner user for your bot?', default=True):
|
|
|
|
import supybot.ircdb as ircdb
|
|
|
|
name = something('What should the owner\'s username be?')
|
|
|
|
try:
|
|
|
|
id = ircdb.users.getUserId(name)
|
|
|
|
u = ircdb.users.getUser(id)
|
|
|
|
if u._checkCapability('owner'):
|
|
|
|
output("""That user already exists, and has owner capabilities
|
|
|
|
already. Perhaps you added it before? """)
|
|
|
|
if yn('Do you want to remove its owner capability?',
|
|
|
|
default=False):
|
|
|
|
u.removeCapability('owner')
|
|
|
|
ircdb.users.setUser(id, u)
|
|
|
|
else:
|
|
|
|
output("""That user already exists, but doesn't have owner
|
|
|
|
capabilities.""")
|
|
|
|
if yn('Do you want to add to it owner capabilities?',
|
|
|
|
default=False):
|
|
|
|
u.addCapability('owner')
|
|
|
|
ircdb.users.setUser(id, u)
|
|
|
|
except KeyError:
|
|
|
|
password = getpass('What should the owner\'s password be?')
|
|
|
|
u = ircdb.users.newUser()
|
|
|
|
u.name = name
|
|
|
|
u.setPassword(password)
|
|
|
|
u.addCapability('owner')
|
|
|
|
ircdb.users.setUser(u)
|
|
|
|
|
|
|
|
output("""Of course, when you're in an IRC channel you can address the bot
|
|
|
|
by its nick and it will respond, if you give it a valid command (it may or
|
|
|
|
may not respond, depending on what your config variable replyWhenNotCommand
|
|
|
|
is set to). But your bot can also respond to a short "prefix character,"
|
|
|
|
so instead of saying "bot: do this," you can say, "@do this" and achieve
|
|
|
|
the same effect. Of course, you don't *have* to have a prefix char, but
|
|
|
|
if the bot ends up participating significantly in your channel, it'll ease
|
|
|
|
things.""")
|
|
|
|
if yn('Would you like to set the prefix char(s) for your bot? ',
|
|
|
|
default=True):
|
|
|
|
output("""Enter any characters you want here, but be careful: they
|
|
|
|
should be rare enough that people don't accidentally address the bot
|
|
|
|
(simply because they'll probably be annoyed if they do address the bot
|
|
|
|
on accident). You can even have more than one. I (jemfinch) am quite
|
|
|
|
partial to @, but that's because I've been using it since my ocamlbot
|
|
|
|
days.""")
|
|
|
|
import supybot.callbacks as callbacks
|
|
|
|
c = ''
|
|
|
|
while not c:
|
|
|
|
try:
|
|
|
|
c = anything('What would you like your bot\'s prefix '
|
|
|
|
'character(s) to be?')
|
|
|
|
conf.supybot.reply.whenAddressedBy.chars.set(c)
|
2013-04-27 16:16:08 +02:00
|
|
|
except registry.InvalidRegistryValue as e:
|
2005-01-19 14:14:38 +01:00
|
|
|
output(str(e))
|
|
|
|
c = ''
|
|
|
|
else:
|
|
|
|
conf.supybot.reply.whenAddressedBy.chars.set('')
|
|
|
|
|
|
|
|
###
|
|
|
|
# logging variables.
|
|
|
|
###
|
|
|
|
|
|
|
|
if advanced:
|
2005-04-04 05:16:06 +02:00
|
|
|
# conf.supybot.log.stdout
|
|
|
|
output("""By default, your bot will log not only to files in the logs
|
|
|
|
directory you gave it, but also to stdout. We find this useful for
|
|
|
|
debugging, and also just for the pretty output (it's colored!)""")
|
|
|
|
stdout = not yn('Would you like to turn off this logging to stdout?',
|
|
|
|
default=False)
|
|
|
|
conf.supybot.log.stdout.setValue(stdout)
|
|
|
|
if conf.supybot.log.stdout():
|
|
|
|
# conf.something
|
|
|
|
output("""Some terminals may not be able to display the pretty
|
|
|
|
colors logged to stderr. By default, though, we turn the colors
|
|
|
|
off for Windows machines and leave it on for *nix machines.""")
|
|
|
|
if os.name is not 'nt':
|
|
|
|
conf.supybot.log.stdout.colorized.setValue(
|
|
|
|
not yn('Would you like to turn this colorization off?',
|
|
|
|
default=False))
|
2005-01-19 14:14:38 +01:00
|
|
|
|
|
|
|
# conf.supybot.log.level
|
|
|
|
output("""Your bot can handle debug messages at several priorities,
|
|
|
|
CRITICAL, ERROR, WARNING, INFO, and DEBUG, in decreasing order of
|
|
|
|
priority. By default, your bot will log all of these priorities except
|
|
|
|
DEBUG. You can, however, specify that it only log messages above a
|
|
|
|
certain priority level.""")
|
|
|
|
priority = str(conf.supybot.log.level)
|
|
|
|
logLevel = something('What would you like the minimum priority to be?'
|
|
|
|
' Just press enter to accept the default.',
|
|
|
|
default=priority).lower()
|
|
|
|
while logLevel not in ['debug','info','warning','error','critical']:
|
|
|
|
output("""That's not a valid priority. Valid priorities include
|
|
|
|
'DEBUG', 'INFO', 'WARNING', 'ERROR', and 'CRITICAL'""")
|
|
|
|
logLevel = something('What would you like the minimum priority to '
|
|
|
|
'be? Just press enter to accept the default.',
|
|
|
|
default=priority).lower()
|
|
|
|
conf.supybot.log.level.set(logLevel)
|
|
|
|
|
|
|
|
# conf.supybot.databases.plugins.channelSpecific
|
|
|
|
|
|
|
|
output("""Many plugins in Supybot are channel-specific. Their
|
|
|
|
databases, likewise, are specific to each channel the bot is in. Many
|
|
|
|
people don't want this, so we have one central location in which to
|
|
|
|
say that you would prefer all databases for all channels to be shared.
|
|
|
|
This variable, supybot.databases.plugins.channelSpecific, is that
|
|
|
|
place.""")
|
|
|
|
|
|
|
|
conf.supybot.databases.plugins.channelSpecific.setValue(
|
|
|
|
not yn('Would you like plugin databases to be shared by all '
|
|
|
|
'channels, rather than specific to each channel the '
|
|
|
|
'bot is in?'))
|
|
|
|
|
|
|
|
output("""There are a lot of options we didn't ask you about simply
|
|
|
|
because we'd rather you get up and running and have time
|
|
|
|
left to play around with your bot. But come back and see
|
|
|
|
us! When you've played around with your bot enough to
|
|
|
|
know what you like, what you don't like, what you'd like
|
|
|
|
to change, then take a look at your configuration file
|
|
|
|
when your bot isn't running and read the comments,
|
|
|
|
tweaking values to your heart's desire.""")
|
|
|
|
|
|
|
|
# Let's make sure that src/ plugins are loaded.
|
|
|
|
conf.registerPlugin('Admin', True)
|
2014-06-02 10:03:37 +02:00
|
|
|
conf.registerPlugin('AutoMode', True)
|
2005-01-19 14:14:38 +01:00
|
|
|
conf.registerPlugin('Channel', True)
|
|
|
|
conf.registerPlugin('Config', True)
|
|
|
|
conf.registerPlugin('Misc', True)
|
2014-10-22 12:29:03 +02:00
|
|
|
conf.registerPlugin('NickAuth', True)
|
2005-01-19 14:14:38 +01:00
|
|
|
conf.registerPlugin('User', True)
|
2014-02-22 00:55:41 +01:00
|
|
|
conf.registerPlugin('Utilities', True)
|
2005-01-19 14:14:38 +01:00
|
|
|
|
|
|
|
###
|
|
|
|
# Write the registry
|
|
|
|
###
|
2005-01-25 16:49:42 +01:00
|
|
|
|
|
|
|
# We're going to need to do a darcs predist thing here.
|
|
|
|
#conf.supybot.debug.generated.setValue('...')
|
|
|
|
|
2014-09-03 18:22:07 +02:00
|
|
|
filename = something("""In which file would you like to save
|
|
|
|
this config?""", default='%s.conf' % nick)
|
|
|
|
if not filename.endswith('.conf'):
|
|
|
|
filename += '.conf'
|
|
|
|
registry.close(conf.supybot, os.path.expanduser(filename))
|
2005-01-19 14:14:38 +01:00
|
|
|
|
|
|
|
# Done!
|
|
|
|
output("""All done! Your new bot configuration is %s. If you're running
|
|
|
|
a *nix based OS, you can probably start your bot with the command line
|
|
|
|
"supybot %s". If you're not running a *nix or similar machine, you'll
|
|
|
|
just have to start it like you start all your other Python scripts.""" % \
|
|
|
|
(filename, filename))
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
try:
|
|
|
|
main()
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
# We may still be using bold text when exiting during a prompt
|
|
|
|
if questions.useBold:
|
|
|
|
import supybot.ansi as ansi
|
2013-04-27 16:16:08 +02:00
|
|
|
print(ansi.RESET)
|
|
|
|
print()
|
|
|
|
print()
|
2005-01-19 14:14:38 +01:00
|
|
|
output("""Well, it looks like you canceled out of the wizard before
|
|
|
|
it was done. Unfortunately, I didn't get to write anything to file.
|
|
|
|
Please run the wizard again to completion.""")
|
2005-05-06 04:36:10 +02:00
|
|
|
|
2009-03-12 00:26:49 +01:00
|
|
|
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
|