Example #1
0
def main():
    import supybot.log as log
    import supybot.conf as conf
    log._stdoutHandler.setLevel(100)  # *Nothing* gets through this!
    parser = optparse.OptionParser(usage='Usage: %prog [options]',
                                   version='Supybot %s' % conf.version)
    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.')
    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:
            error('Please, don\'t run this as root.')

    filename = ''
    if args:
        parser.error('This program takes no non-option arguments.')
    output("""This is a wizard to help you start running supybot.  What it
    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 :)""")

    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)

    ### 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.
    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
        output("""Your bot will need to put his logs somewhere.  Do you have
        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)

        # 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)

        # conf.supybot.directories.conf
        output("""Your bot must know where to find his configuration files.
        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
        store his stuff. """)
        (confDir, basedir) = getDirectoryName('conf', basedir=basedir)
        conf.supybot.directories.conf.setValue(confDir)

        # 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
        store his stuff.""")
        (backupDir, basedir) = getDirectoryName('backup', basedir=basedir)
        conf.supybot.directories.backup.setValue(backupDir)

        # pluginDirs
        output("""Your bot will also need to know where to find his plugins at.
        Of course, he already knows where the plugins that he came with are,
        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:""")
        output(format('%L', pluginDirs + [plugin._pluginsDir]))
        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
        the various log, config, and data files.""")
        basedir = something("""Where would you like to create these
                            directories?""",
                            default=os.curdir)
        # conf.supybot.directories.log
        (logDir, basedir) = getDirectoryName('logs', prompt=False)
        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()
        (pluginDir, _) = getDirectoryName('plugins',
                                          basedir=basedir,
                                          prompt=False)
        if pluginDir not in pluginDirs:
            pluginDirs.append(pluginDir)
        conf.supybot.directories.plugins.setValue(pluginDirs)

    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
        network.  If you plan to connect to irc.freenode.net, for instance, you
        should answer this question with 'freenode' (without the quotes).""")
        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))
    output("""IRC Servers almost always accept connections on port
    6667.  They can, however, accept connections anywhere their admin
    feels like he wants to accept connections from.""")
    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):
                    raise ValueError
            except ValueError:
                output("""That's not a valid port.""")
                port = 0
    else:
        port = 6667
    server = ':'.join([serverString, str(port)])
    network.servers.setValue([server])

    # conf.supybot.nick
    # Force the user into specifying a nick if he didn't have one already
    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)
    defaultIdent = 'supybot'
    if advanced:
        output("""IRC servers also allow you to set your ident, which they
        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.""")
        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:
                output("""That was not a valid ident.  Go ahead and pick
                another.""")
    else:
        conf.supybot.ident.set(defaultIdent)

    if advanced:
        # conf.supybot.networks.<network>.ssl
        output("""Some servers allow you to use a secure connection via SSL.
        This requires having pyOpenSSL installed.  Currently, you also need
        Twisted installed as only the Twisted drivers supports SSL
        connections.""")
        if yn('Do you want to use an SSL connection?', default=False):
            network.ssl.setValue(True)

    # conf.supybot.networks.<network>.password
    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.""")
    if yn('Do you want your bot to join some channels when he connects?',
          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:
                  #supybot-bots #mychannel,mykey #otherchannel""")
        while True:
            channels = something('What channels?', default=defaultChannels)
            try:
                network.channels.set(channels)
                break
            except registry.InvalidRegistryValue, e:
                output(""""%s" is an invalid IRC channel.  Be sure to prefix
                the channel with # (or +, or !, or &, but no one uses those
                channels, really).  Be sure the channel key (if you are
                supplying one) does not contain a comma.""" % e.channel)
Example #2
0
def main():
    import supybot.log as log
    import supybot.conf as conf
    log._stdoutHandler.setLevel(100) # *Nothing* gets through this!
    parser = optparse.OptionParser(usage='Usage: %prog [options]',
                                   version='Supybot %s' % conf.version)
    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.')
    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:
            error('Please, don\'t run this as root.')

    filename = ''
    if args:
        parser.error('This program takes no non-option arguments.')
    output("""This is a wizard to help you start running supybot.  What it
    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 :)""")


    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)

    ### 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.
    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
        output("""Your bot will need to put his logs somewhere.  Do you have
        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)

        # 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)

        # conf.supybot.directories.conf
        output("""Your bot must know where to find his configuration files.
        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
        store his stuff. """)
        (confDir, basedir) = getDirectoryName('conf', basedir=basedir)
        conf.supybot.directories.conf.setValue(confDir)

        # 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
        store his stuff.""")
        (backupDir, basedir) = getDirectoryName('backup', basedir=basedir)
        conf.supybot.directories.backup.setValue(backupDir)

        # pluginDirs
        output("""Your bot will also need to know where to find his plugins at.
        Of course, he already knows where the plugins that he came with are,
        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:""")
        output(format('%L', pluginDirs + [plugin._pluginsDir]))
        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
        the various log, config, and data files.""")
        basedir = something("""Where would you like to create these
                            directories?""", default=os.curdir)
        # conf.supybot.directories.log
        (logDir, basedir) = getDirectoryName('logs', prompt=False)
        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()
        (pluginDir, _) = getDirectoryName('plugins',
                                          basedir=basedir, prompt=False)
        if pluginDir not in pluginDirs:
            pluginDirs.append(pluginDir)
        conf.supybot.directories.plugins.setValue(pluginDirs)

    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
        network.  If you plan to connect to irc.freenode.net, for instance, you
        should answer this question with 'freenode' (without the quotes).""")
        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))
    output("""IRC Servers almost always accept connections on port
    6667.  They can, however, accept connections anywhere their admin
    feels like he wants to accept connections from.""")
    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):
                    raise ValueError
            except ValueError:
                output("""That's not a valid port.""")
                port = 0
    else:
        port = 6667
    server = ':'.join([serverString, str(port)])
    network.servers.setValue([server])

    # conf.supybot.nick
    # Force the user into specifying a nick if he didn't have one already
    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)
    defaultIdent = 'supybot'
    if advanced:
        output("""IRC servers also allow you to set your ident, which they
        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.""")
        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:
                output("""That was not a valid ident.  Go ahead and pick
                another.""")
    else:
        conf.supybot.ident.set(defaultIdent)

    if advanced:
        # conf.supybot.networks.<network>.ssl
        output("""Some servers allow you to use a secure connection via SSL.
        This requires having pyOpenSSL installed.  Currently, you also need
        Twisted installed as only the Twisted drivers supports SSL
        connections.""")
        if yn('Do you want to use an SSL connection?', default=False):
            network.ssl.setValue(True)

    # conf.supybot.networks.<network>.password
    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.""")
    if yn('Do you want your bot to join some channels when he connects?',
          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:
                  #supybot-bots #mychannel,mykey #otherchannel""");
        while True:
            channels = something('What channels?', default=defaultChannels)
            try:
                network.channels.set(channels)
                break
            except registry.InvalidRegistryValue, e:
                output(""""%s" is an invalid IRC channel.  Be sure to prefix
                the channel with # (or +, or !, or &, but no one uses those
                channels, really).  Be sure the channel key (if you are
                supplying one) does not contain a comma.""" % e.channel)
Example #3
0
            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?  ',
Example #4
0
            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?  ',