mirror of
https://github.com/jlu5/PyLink.git
synced 2025-01-11 20:52:42 +01:00
fantasy: fixes to respondtonick, allow configuring custom per-bot prefixes
This commit is contained in:
parent
96cefb5be0
commit
e4d42bf551
@ -13,14 +13,19 @@ bot:
|
||||
# Server description (shown in /links, /whois, etc.)
|
||||
serverdesc: PyLink Server
|
||||
|
||||
# Sets the fantasy command prefix for calling commands inside channels
|
||||
# (requires fantasy plugin).
|
||||
prefix: "."
|
||||
# Options below this require the fantasy plugin to be loaded.
|
||||
|
||||
# Sets the default fantasy command prefix for calling commands inside channels
|
||||
prefix: "&"
|
||||
|
||||
# Determines whether the bot will reply to commands prefixed with its nick
|
||||
# (case sensitive and requires the fantasy plugin).
|
||||
respondtonick: true
|
||||
|
||||
# Custom fantasy command prefixes for other service bots if they are loaded.
|
||||
prefixes:
|
||||
games: "@"
|
||||
|
||||
login:
|
||||
# PyLink administrative login - Change this, or the service will not start!
|
||||
user: admin
|
||||
|
@ -14,22 +14,7 @@ def handle_fantasy(irc, source, command, args):
|
||||
# Break if the IRC network isn't ready.
|
||||
return
|
||||
|
||||
try: # First, try to fetch the config-defined prefix.
|
||||
prefixes = [irc.botdata["prefix"]]
|
||||
except KeyError: # Config option is missing.
|
||||
prefixes = []
|
||||
|
||||
if irc.botdata.get("respondtonick"):
|
||||
# If responding to nick is enabled, add variations of the current nick
|
||||
# to the prefix list: "<nick>," and "<nick>:"
|
||||
nick = irc.pseudoclient.nick
|
||||
prefixes += [nick+',', nick+':']
|
||||
|
||||
if not prefixes:
|
||||
# We finished with an empty prefixes list, meaning fantasy is misconfigured!
|
||||
log.warning("(%s) Fantasy prefix was not set in configuration - "
|
||||
"fantasy commands will not work!", irc.name)
|
||||
return
|
||||
respondtonick = irc.botdata.get("respondtonick")
|
||||
|
||||
channel = args['target']
|
||||
orig_text = args['text']
|
||||
@ -44,9 +29,30 @@ def handle_fantasy(irc, source, command, args):
|
||||
# message loops).
|
||||
for botname, sbot in world.services.items():
|
||||
log.debug('(%s) fantasy: checking bot %s', irc.name, botname)
|
||||
if sbot.uids.get(irc.name) in irc.channels[channel].users:
|
||||
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 = [irc.botdata.get('prefixes', {}).get(botname) or
|
||||
irc.botdata.get('prefix')]
|
||||
|
||||
# If responding to nick is enabled, add variations of the current nick
|
||||
# to the prefix list: "<nick>," and "<nick>:"
|
||||
nick = irc.users[servuid].nick
|
||||
|
||||
if respondtonick:
|
||||
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)
|
||||
continue
|
||||
|
||||
for prefix in prefixes: # Cycle through the prefixes list we finished with.
|
||||
if orig_text.startswith(prefix):
|
||||
if prefix and orig_text.startswith(prefix):
|
||||
|
||||
# Cut off the length of the prefix from the text.
|
||||
text = orig_text[len(prefix):]
|
||||
|
Loading…
Reference in New Issue
Block a user