mirror of
https://github.com/jlu5/PyLink.git
synced 2024-11-30 14:49:28 +01:00
Services API rework
- Move nick/ident/host/gecos fetching from services_support into functions - Remove the unused 'ident' argument from ServiceBot - Rename the 'nick' argument in ServiceBot to 'default_nick' - Define default nicks for the PyLink, Automode, and Games services
This commit is contained in:
parent
3e150d8514
commit
89699051d5
@ -22,21 +22,10 @@ def spawn_service(irc, source, command, args):
|
|||||||
# Get the ServiceBot object.
|
# Get the ServiceBot object.
|
||||||
sbot = world.services[name]
|
sbot = world.services[name]
|
||||||
|
|
||||||
# Look up the nick or ident in the following order:
|
nick = sbot.get_nick(irc)
|
||||||
# 1) Network specific nick/ident settings for this service (servers::irc.name::servicename_nick)
|
ident = sbot.get_ident(irc)
|
||||||
# 2) Global settings for this service (servicename::nick)
|
host = sbot.get_host(irc)
|
||||||
# 3) The preferred nick/ident combination defined by the plugin (sbot.nick / sbot.ident)
|
realname = sbot.get_realname(irc)
|
||||||
# 4) The literal service name.
|
|
||||||
# settings, and then falling back to the literal service name.
|
|
||||||
sbconf = conf.conf.get(name, {})
|
|
||||||
nick = irc.serverdata.get("%s_nick" % name) or sbconf.get('nick') or sbot.nick or name
|
|
||||||
ident = irc.serverdata.get("%s_ident" % name) or sbconf.get('ident') or sbot.ident or name
|
|
||||||
|
|
||||||
# Determine host the same way as above, except fall back to server hostname.
|
|
||||||
host = irc.serverdata.get("%s_host" % name) or sbconf.get('host') or irc.hostname()
|
|
||||||
|
|
||||||
# Determine realname the same way as above, except fall back to pylink:realname (and if that fails, the service name).
|
|
||||||
realname = irc.serverdata.get("%s_realname" % name) or sbconf.get('realname') or conf.conf['pylink'].get('realname') or name
|
|
||||||
|
|
||||||
# Spawning service clients with these umodes where supported. servprotect usage is a
|
# Spawning service clients with these umodes where supported. servprotect usage is a
|
||||||
# configuration option.
|
# configuration option.
|
||||||
@ -143,4 +132,4 @@ utils.add_hook(handle_commands, 'PRIVMSG')
|
|||||||
# TODO: be more specific, and possibly allow plugins to modify this to mention
|
# TODO: be more specific, and possibly allow plugins to modify this to mention
|
||||||
# their features?
|
# their features?
|
||||||
mydesc = "\x02PyLink\x02 provides extended network services for IRC."
|
mydesc = "\x02PyLink\x02 provides extended network services for IRC."
|
||||||
utils.registerService('pylink', desc=mydesc, manipulatable=True)
|
utils.registerService('pylink', default_nick="PyLink", desc=mydesc, manipulatable=True)
|
||||||
|
@ -24,7 +24,7 @@ myservice = utils.registerService("myservice", desc=desc)
|
|||||||
- **`name`** - defines the service name (mandatory)
|
- **`name`** - defines the service name (mandatory)
|
||||||
- `default_help` - Determines whether the default HELP command should be used for the service. Defaults to True.
|
- `default_help` - Determines whether the default HELP command should be used for the service. Defaults to True.
|
||||||
- `default_list` - Determines whether the default LIST command should be used for the service. Defaults to True.
|
- `default_list` - Determines whether the default LIST command should be used for the service. Defaults to True.
|
||||||
- `nick`, `ident` - Sets the default nick and ident for the service bot. If not given, these simply default to the service name.
|
- `default_nick` - Sets the default nick this service should use if the user doesn't provide it. Defaults to the same as the service name.
|
||||||
- `manipulatable` - Determines whether the bot is marked manipulatable. Only manipulatable clients can be force joined, etc. using PyLink commands. Defaults to False.
|
- `manipulatable` - Determines whether the bot is marked manipulatable. Only manipulatable clients can be force joined, etc. using PyLink commands. Defaults to False.
|
||||||
- `desc` - Sets the command description of the service. This is shown in the default HELP command if enabled.
|
- `desc` - Sets the command description of the service. This is shown in the default HELP command if enabled.
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ mydesc = ("The \x02Automode\x02 plugin provides simple channel ACL management by
|
|||||||
"to users matching hostmasks or exttargets.")
|
"to users matching hostmasks or exttargets.")
|
||||||
|
|
||||||
# Register ourselves as a service.
|
# Register ourselves as a service.
|
||||||
modebot = utils.registerService("automode", desc=mydesc)
|
modebot = utils.registerService("automode", default_nick="Automode", desc=mydesc)
|
||||||
reply = modebot.reply
|
reply = modebot.reply
|
||||||
error = modebot.error
|
error = modebot.error
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ from pylinkirc.log import log
|
|||||||
|
|
||||||
mydesc = "The \x02Games\x02 plugin provides simple games for IRC."
|
mydesc = "The \x02Games\x02 plugin provides simple games for IRC."
|
||||||
|
|
||||||
gameclient = utils.registerService("Games", manipulatable=True, desc=mydesc)
|
gameclient = utils.registerService("Games", default_nick="Games", manipulatable=True, desc=mydesc)
|
||||||
reply = gameclient.reply # TODO find a better syntax for ServiceBot.reply()
|
reply = gameclient.reply # TODO find a better syntax for ServiceBot.reply()
|
||||||
error = gameclient.error # TODO find a better syntax for ServiceBot.error()
|
error = gameclient.error # TODO find a better syntax for ServiceBot.error()
|
||||||
# commands
|
# commands
|
||||||
|
53
utils.py
53
utils.py
@ -183,18 +183,14 @@ class ServiceBot():
|
|||||||
PyLink IRC Service class.
|
PyLink IRC Service class.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, name, default_help=True, default_list=True,
|
def __init__(self, name, default_help=True, default_list=True, manipulatable=False, default_nick=None, desc=None):
|
||||||
nick=None, ident=None, manipulatable=False, desc=None):
|
# Service name and default nick
|
||||||
# Service name
|
|
||||||
self.name = name
|
self.name = name
|
||||||
|
self.default_nick = default_nick
|
||||||
|
|
||||||
# TODO: validate nick, ident, etc. on runtime as well
|
# TODO: validate nick, ident, etc. on runtime as well
|
||||||
assert isNick(name), "Invalid service name %r" % name
|
assert isNick(name), "Invalid service name %r" % name
|
||||||
|
|
||||||
# Nick/ident to take. Defaults to the same as the service name if not given.
|
|
||||||
self.nick = nick
|
|
||||||
self.ident = ident
|
|
||||||
|
|
||||||
# Tracks whether the bot should be manipulatable by the 'bots' plugin and other commands.
|
# Tracks whether the bot should be manipulatable by the 'bots' plugin and other commands.
|
||||||
self.manipulatable = manipulatable
|
self.manipulatable = manipulatable
|
||||||
|
|
||||||
@ -363,6 +359,49 @@ class ServiceBot():
|
|||||||
self.commands[name].append(func)
|
self.commands[name].append(func)
|
||||||
return func
|
return func
|
||||||
|
|
||||||
|
def get_nick(self, irc):
|
||||||
|
"""
|
||||||
|
Returns the preferred nick for this service bot on the given network. The following fields are checked in the given order:
|
||||||
|
# 1) Network specific nick settings for this service (servers:<netname>:servicename_nick)
|
||||||
|
# 2) Global settings for this service (servicename:nick)
|
||||||
|
# 3) The service's hardcoded default nick.
|
||||||
|
# 4) The literal service name.
|
||||||
|
"""
|
||||||
|
sbconf = conf.conf.get(self.name, {})
|
||||||
|
return irc.serverdata.get("%s_nick" % self.name) or sbconf.get('nick') or self.default_nick or self.name
|
||||||
|
|
||||||
|
def get_ident(self, irc):
|
||||||
|
"""
|
||||||
|
Returns the preferred ident for this service bot on the given network. The following fields are checked in the given order:
|
||||||
|
# 1) Network specific ident settings for this service (servers:<netname>:servicename_ident)
|
||||||
|
# 2) Global settings for this service (servicename:ident)
|
||||||
|
# 3) The service's hardcoded default nick.
|
||||||
|
# 4) The literal service name.
|
||||||
|
"""
|
||||||
|
sbconf = conf.conf.get(self.name, {})
|
||||||
|
return irc.serverdata.get("%s_ident" % self.name) or sbconf.get('ident') or self.default_nick or self.name
|
||||||
|
|
||||||
|
def get_host(self, irc):
|
||||||
|
"""
|
||||||
|
Returns the preferred hostname for this service bot on the given network. The following fields are checked in the given order:
|
||||||
|
# 1) Network specific hostname settings for this service (servers:<netname>:servicename_host)
|
||||||
|
# 2) Global settings for this service (servicename:host)
|
||||||
|
# 3) The PyLink server hostname.
|
||||||
|
"""
|
||||||
|
sbconf = conf.conf.get(self.name, {})
|
||||||
|
return irc.serverdata.get("%s_host" % self.name) or sbconf.get('host') or irc.hostname()
|
||||||
|
|
||||||
|
def get_realname(self, irc):
|
||||||
|
"""
|
||||||
|
Returns the preferred real name for this service bot on the given network. The following fields are checked in the given order:
|
||||||
|
# 1) Network specific realname settings for this service (servers:<netname>:servicename_realname)
|
||||||
|
# 2) Global settings for this service (servicename:realname)
|
||||||
|
# 3) The globally configured real name (pylink:realname).
|
||||||
|
# 4) The literal service name.
|
||||||
|
"""
|
||||||
|
sbconf = conf.conf.get(self.name, {})
|
||||||
|
return irc.serverdata.get("%s_realname" % self.name) or sbconf.get('realname') or conf.conf['pylink'].get('realname') or self.name
|
||||||
|
|
||||||
def _show_command_help(self, irc, command, private=False, shortform=False):
|
def _show_command_help(self, irc, command, private=False, shortform=False):
|
||||||
"""
|
"""
|
||||||
Shows help for the given command.
|
Shows help for the given command.
|
||||||
|
Loading…
Reference in New Issue
Block a user