mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-23 11:12:47 +01:00
Updated to allow different networks.
This commit is contained in:
parent
b88dd0f649
commit
aad1d2dc41
@ -123,18 +123,12 @@ if __name__ == '__main__':
|
||||
parser.add_option('-n', '--nick', action='store',
|
||||
dest='nick', default='',
|
||||
help='nick the bot should use')
|
||||
parser.add_option('-s', '--server', action='store',
|
||||
dest='server', default='',
|
||||
help='server to connect to')
|
||||
parser.add_option('-u', '--user', action='store',
|
||||
dest='user', default='',
|
||||
help='full username the bot should use')
|
||||
parser.add_option('-i', '--ident', action='store',
|
||||
dest='ident', default='',
|
||||
help='ident the bot should use')
|
||||
parser.add_option('-p', '--password', action='store',
|
||||
dest='password', default='',
|
||||
help='server password the bot should use')
|
||||
parser.add_option('-d', '--daemon', action='store_true',
|
||||
dest='daemon',
|
||||
help='Determines whether the bot will daemonize. '
|
||||
@ -209,9 +203,12 @@ if __name__ == '__main__':
|
||||
nick = options.nick or conf.supybot.nick()
|
||||
user = options.user or conf.supybot.user()
|
||||
ident = options.ident or conf.supybot.ident()
|
||||
password = options.password or conf.supybot.password()
|
||||
|
||||
server = options.server or conf.supybot.server()
|
||||
# We could add an option for this, but we'll wait until it's requested.
|
||||
defaultNetwork = conf.supybot.networks.default()
|
||||
network = conf.supybot.networks.get(defaultNetwork)
|
||||
server = network.server()
|
||||
password = network.password()
|
||||
if ':' in server:
|
||||
serverAndPort = server.split(':', 1)
|
||||
serverAndPort[1] = int(serverAndPort[1])
|
||||
@ -220,6 +217,7 @@ if __name__ == '__main__':
|
||||
server = (server, 6667)
|
||||
|
||||
if options.optimize:
|
||||
# This doesn't work anymore.
|
||||
__builtins__.__debug__ = False
|
||||
if options.optimize > 1:
|
||||
try:
|
||||
@ -253,7 +251,8 @@ if __name__ == '__main__':
|
||||
import callbacks
|
||||
import Owner
|
||||
|
||||
irc = irclib.Irc(nick, user=user, ident=ident, password=password)
|
||||
irc = irclib.Irc(nick, user=user, ident=ident,
|
||||
network=defaultNetwork, password=password)
|
||||
callback = Owner.Class()
|
||||
irc.addCallback(callback)
|
||||
driver = drivers.newDriver(server, irc)
|
||||
|
@ -257,13 +257,26 @@ def main():
|
||||
output("""Now we're going to ask you things that actually relate to the
|
||||
bot you'll be running.""")
|
||||
|
||||
# conf.supybot.server
|
||||
# Force the user into specifying a server if he didn't have one already
|
||||
try:
|
||||
defaultServer = registry._cache['supybot.server']
|
||||
defaultServer = utils.safeEval(defaultServer)
|
||||
defaultServer = defaultServer.split(':')[0]
|
||||
except KeyError:
|
||||
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 isValidRegistryName:
|
||||
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.default.set(network)
|
||||
network = conf.registerNetwork(network)
|
||||
|
||||
defaultServer = None
|
||||
server = None
|
||||
while not server:
|
||||
@ -274,8 +287,9 @@ def main():
|
||||
ip = socket.gethostbyname(serverString)
|
||||
except:
|
||||
output("""Sorry, I couldn't find that server. Perhaps you
|
||||
misspelled it?""")
|
||||
continue
|
||||
misspelled it? Also, be sure not to put the port in the server's
|
||||
name -- we'll ask you about that later.""")
|
||||
|
||||
output("""Found %s (%s).""" % (serverString, ip))
|
||||
output("""IRC Servers almost always accept connections on port
|
||||
6667. They can, however, accept connections anywhere their admin
|
||||
@ -294,8 +308,8 @@ def main():
|
||||
port = 0
|
||||
else:
|
||||
port = 6667
|
||||
server = ':'.join(map(str, [serverString, port]))
|
||||
conf.supybot.server.set(server)
|
||||
server = ':'.join([serverString, str(port)])
|
||||
network.server.setValue(server)
|
||||
|
||||
# conf.supybot.nick
|
||||
# Force the user into specifying a nick if he didn't have one already
|
||||
|
47
src/conf.py
47
src/conf.py
@ -51,10 +51,16 @@ _pluginsDir = os.path.join(installDir, 'plugins')
|
||||
###
|
||||
version ='0.77.2+cvs'
|
||||
|
||||
###
|
||||
# *** The following variables are affected by command-line options. They are
|
||||
# not registry variables for a specific reason. Do *not* change these to
|
||||
# registry variables without first consulting people smarter than yourself.
|
||||
###
|
||||
|
||||
###
|
||||
# daemonized: This determines whether or not the bot has been daemonized
|
||||
# (i.e., set to run in the background). Obviously, this defaults
|
||||
# to False.
|
||||
# to False. A command-line option for obvious reasons.
|
||||
###
|
||||
daemonized = False
|
||||
|
||||
@ -80,14 +86,14 @@ supybot = registry.Group()
|
||||
supybot.setName('supybot')
|
||||
|
||||
def registerGroup(Group, name, group=None):
|
||||
Group.register(name, group)
|
||||
return Group.register(name, group)
|
||||
|
||||
def registerGlobalValue(group, name, value):
|
||||
group.register(name, value)
|
||||
return group.register(name, value)
|
||||
|
||||
def registerChannelValue(group, name, value):
|
||||
value.supplyDefault = True
|
||||
group.register(name, value)
|
||||
return group.register(name, value)
|
||||
|
||||
def registerPlugin(name, currentValue=None):
|
||||
registerGlobalValue(supybot.plugins, name,
|
||||
@ -95,7 +101,7 @@ def registerPlugin(name, currentValue=None):
|
||||
default.""", showDefault=False))
|
||||
if currentValue is not None:
|
||||
supybot.plugins.get(name).setValue(currentValue)
|
||||
registerGroup(users.plugins, name)
|
||||
return registerGroup(users.plugins, name)
|
||||
|
||||
###
|
||||
# The user info registry.
|
||||
@ -130,8 +136,8 @@ class ValidChannel(registry.String):
|
||||
else:
|
||||
registry.String.setValue(self, v)
|
||||
|
||||
supybot.register('nick', ValidNick('supybot',
|
||||
"""Determines the bot's nick."""))
|
||||
registerGlobalValue(supybot, 'nick',
|
||||
ValidNick('supybot', """Determines the bot's nick."""))
|
||||
|
||||
registerGlobalValue(supybot, 'ident',
|
||||
ValidNick('supybot', """Determines the bot's ident string, if the server
|
||||
@ -142,11 +148,30 @@ registerGlobalValue(supybot, 'user',
|
||||
sends to the server."""))
|
||||
|
||||
# TODO: Make this check for validity.
|
||||
supybot.register('server', registry.String('irc.freenode.net', """Determines
|
||||
what server the bot connects to."""))
|
||||
registerGroup(supybot, 'networks')
|
||||
registerGlobalValue(supybot.networks, 'default', registry.String('',
|
||||
"""Determines what the default network joined by the bot will be."""))
|
||||
|
||||
def registerNetwork(name, password='', server=''):
|
||||
name = intern(name)
|
||||
network = registerGroup(supybot.networks, name)
|
||||
registerGlobalValue(network, 'password', registry.String(password,
|
||||
"""Determines what password will be used on %s. Yes, we know that
|
||||
technically passwords are server-specific and not network-specific,
|
||||
but this is the best we can do right now.""" % name))
|
||||
registerGlobalValue(network, 'server', registry.String(server,
|
||||
"""Determines what server the bot will connect to for %s.""" % name))
|
||||
return network
|
||||
|
||||
# Let's fill our networks.
|
||||
for (name, s) in registry._cache.iteritems():
|
||||
if name.startswith('supybot.networks.'):
|
||||
parts = name.split('.')
|
||||
print parts
|
||||
name = parts[2]
|
||||
if name != 'default':
|
||||
registerNetwork(name)
|
||||
|
||||
supybot.register('password', registry.String('', """Determines the password to
|
||||
be sent to the server if it requires one."""))
|
||||
|
||||
class SpaceSeparatedSetOfChannels(registry.SeparatedListOf):
|
||||
List = ircutils.IrcSet
|
||||
|
@ -440,11 +440,13 @@ class Irc(IrcCommandDispatcher):
|
||||
_nickSetters = sets.Set(['001', '002', '003', '004', '250', '251', '252',
|
||||
'254', '255', '265', '266', '372', '375', '376',
|
||||
'333', '353', '332', '366', '005'])
|
||||
def __init__(self, nick, user='', ident='', password='', callbacks=None):
|
||||
def __init__(self, nick, user='', ident='',
|
||||
network='unset', password='', callbacks=None):
|
||||
world.ircs.append(self)
|
||||
self.originalNick = intern(nick)
|
||||
self.originalNetwork = intern(network)
|
||||
self.nick = self.originalNick
|
||||
self.network = 'unset'
|
||||
self.network = self.originalNetwork
|
||||
self.nickmods = cycle(conf.supybot.nickmods())
|
||||
self.password = password
|
||||
self.user = intern(user or nick) # Default to nick
|
||||
@ -474,6 +476,7 @@ class Irc(IrcCommandDispatcher):
|
||||
def reset(self):
|
||||
"""Resets the Irc object. Called when the driver reconnects."""
|
||||
self.nick = self.originalNick
|
||||
self.network = self.originalNetwork
|
||||
self.prefix = '%s!%s@%s' % (self.nick, self.ident, 'unset.domain')
|
||||
self.state.reset()
|
||||
self.queue.reset()
|
||||
@ -570,6 +573,7 @@ class Irc(IrcCommandDispatcher):
|
||||
def do001(self, msg):
|
||||
"""Logs (and stores) the name of the network."""
|
||||
welcome = msg.args[1]
|
||||
if self.network == 'unset':
|
||||
if not welcome.startswith('Welcome to the '):
|
||||
log.info('Unexpected 001 welcome, guessing at network name.')
|
||||
self.network = msg.prefix
|
||||
|
Loading…
Reference in New Issue
Block a user