3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-11-27 21:19:31 +01:00

Split fantasy prefix definitions into service-specific blocks

Closes #426.

This makes the pylink::prefix (aka bot::prefix) option only affect the main PyLink bot, and deprecates the pylink::prefixes::<...> options.
As the bot: config block is no longer checked, this commit depends on commit 45ed5b962e215763f7659631d1b98a5031dbab92 (ref #343) to alias it to conf::pylink.
This commit is contained in:
James Lu 2017-03-10 23:42:45 -08:00
parent fb626c8a97
commit bf42109d81
2 changed files with 27 additions and 18 deletions

View File

@ -15,18 +15,23 @@ pylink:
# Server description (shown in /links, /whois, etc.)
serverdesc: PyLink Server
# Sets the default fantasy command prefix for calling commands inside channels
# (requires fantasy plugin).
# Sets the fantasy command prefix for the main PyLink bot. To configure fantasy prefixes for
# other service bots, add or modify the "prefix:" option in the configuration section of each
# plugin.
# Note: prior to PyLink 1.2, defining a prefix here made it global for all service bots. This
# was removed because it called all bots in a channel at once (even if they have conflicting
# commands), which usually led to one successful reply and a string of "Command not found"
# errors.
prefix: "&"
# Determines whether the bot will reply to commands prefixed with its nick
# (case sensitive and requires the fantasy plugin).
# Whether service bots will respond to commands prefixes with their nick.
respondtonick: true
# Custom fantasy command prefixes for other service bots if they are loaded
# (requires fantasy plugin).
prefixes:
games: "@"
# Custom prefixes for other service bots if they are loaded. Note: this is deprecated
# since PyLink 1.2 in favour of adding prefixes into each plugin's configuration block
# itself (see the "prefix:" option in the "games:" block in this case).
#prefixes:
# games: "@"
# Determines whether hideoper modes should be respected in WHOIS replies.
# Defaults to true if not specified.
@ -638,10 +643,17 @@ automode:
# This option overrides the global "spawn_services" option defined in "pylink:".
#spawn_service: true
# Defines a fantasy prefix for the Automode bot (requires spawn_services to be set and the
# fantasy plugin to be loaded).
prefix: "@"
games:
# Sets the nick of the Games service, if you're using it. This defaults to "games" if not defined.
nick: Games
# Defines a fantasy prefix for the Games bot.
prefix: "./"
stats:
# Determines the time format that the Stats plugin should use for showing dates + times.
# Defaults to "%a, %d %b %Y %H:%M:%S +0000" (the RFC 2812 standard) if not specified.

View File

@ -29,11 +29,10 @@ def handle_fantasy(irc, source, command, args):
servuid = sbot.uids.get(irc.name)
if servuid in irc.channels[channel].users:
# Try to look up a prefix specific for this bot in
# bot: prefixes: <botname>, falling back to the default prefix if not
# specified.
prefixes = [conf.conf['bot'].get('prefixes', {}).get(botname) or
conf.conf['bot'].get('prefix')]
# Look up a string prefix for this bot in either its own configuration block, or
# in bot::prefixes::<botname>.
prefixes = [conf.conf.get(botname, {}).get('prefix',
conf.conf['bot'].get('prefixes', {}).get(botname))]
# If responding to nick is enabled, add variations of the current nick
# to the prefix list: "<nick>," and "<nick>:"
@ -43,14 +42,12 @@ def handle_fantasy(irc, source, command, args):
prefixes += [nick+',', nick+':']
if not any(prefixes):
# We finished with an empty prefixes list, meaning fantasy is misconfigured!
log.warning("(%s) Fantasy prefix for bot %s was not set in configuration - "
"fantasy commands will not work!", irc.name, botname)
# No prefixes were set, so skip.
continue
lowered_text = irc.toLower(orig_text)
for prefix in prefixes: # Cycle through the prefixes list we finished with.
if prefix and lowered_text.startswith(prefix):
for prefix in filter(None, prefixes): # Cycle through the prefixes list we finished with.
if lowered_text.startswith(prefix):
# Cut off the length of the prefix from the text.
text = orig_text[len(prefix):]