From 118d76fd5a8b401d1790fd4ac3b12054b726a148 Mon Sep 17 00:00:00 2001 From: James Lu Date: Sat, 14 May 2016 12:52:32 -0700 Subject: [PATCH] core: allow defining service bots with custom nicks/idents --- coreplugin.py | 12 ++++++++---- utils.py | 11 ++++++++++- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/coreplugin.py b/coreplugin.py index f1312f4..ea84f34 100644 --- a/coreplugin.py +++ b/coreplugin.py @@ -210,8 +210,11 @@ def spawn_service(irc, source, command, args): return name = args['name'] - ident = irc.botdata.get('ident') or 'pylink' + # TODO: make this configurable? host = irc.serverdata["hostname"] + + # Prefer spawning service clients with umode +io, plus hideoper and + # hidechans if supported. modes = [] for mode in ('oper', 'hideoper', 'hidechans', 'invisible'): mode = irc.umodes.get(mode) @@ -219,9 +222,10 @@ def spawn_service(irc, source, command, args): modes.append((mode, None)) # Track the service's UIDs on each network. - service = world.services[name] - service.uids[irc.name] = u = irc.proto.spawnClient(name, name, - irc.serverdata['hostname'], modes=modes, opertype="PyLink Service").uid + sbot = world.services[name] + sbot.uids[irc.name] = u = irc.proto.spawnClient(sbot.nick, sbot.ident, + host, modes=modes, opertype="PyLink Service", + manipulatable=sbot.manipulatable).uid # TODO: channels should be tracked in a central database, not hardcoded # in conf. diff --git a/utils.py b/utils.py index c02390f..4d447fb 100644 --- a/utils.py +++ b/utils.py @@ -151,9 +151,18 @@ def getDatabaseName(dbname): return dbname class ServiceBot(): - def __init__(self, name, default_help=True, default_request=True, default_list=True): + def __init__(self, name, default_help=True, default_request=True, default_list=True, + nick=None, ident=None, manipulatable=False): + # Service name self.name = name + # Nick/ident to take. Defaults to the same as the service name if not given. + self.nick = nick or name + self.ident = ident or name + + # Tracks whether the bot should be manipulatable by the 'bots' plugin and other commands. + self.manipulatable = manipulatable + # We make the command definitions a dict of lists of functions. Multiple # plugins are actually allowed to bind to one function name; this just causes # them to be called in the order that they are bound.