mirror of
https://github.com/jlu5/PyLink.git
synced 2025-01-26 04:04:22 +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.)
|
# Server description (shown in /links, /whois, etc.)
|
||||||
serverdesc: PyLink Server
|
serverdesc: PyLink Server
|
||||||
|
|
||||||
# Sets the fantasy command prefix for calling commands inside channels
|
# Options below this require the fantasy plugin to be loaded.
|
||||||
# (requires fantasy plugin).
|
|
||||||
prefix: "."
|
# Sets the default fantasy command prefix for calling commands inside channels
|
||||||
|
prefix: "&"
|
||||||
|
|
||||||
# Determines whether the bot will reply to commands prefixed with its nick
|
# Determines whether the bot will reply to commands prefixed with its nick
|
||||||
# (case sensitive and requires the fantasy plugin).
|
# (case sensitive and requires the fantasy plugin).
|
||||||
respondtonick: true
|
respondtonick: true
|
||||||
|
|
||||||
|
# Custom fantasy command prefixes for other service bots if they are loaded.
|
||||||
|
prefixes:
|
||||||
|
games: "@"
|
||||||
|
|
||||||
login:
|
login:
|
||||||
# PyLink administrative login - Change this, or the service will not start!
|
# PyLink administrative login - Change this, or the service will not start!
|
||||||
user: admin
|
user: admin
|
||||||
|
@ -14,22 +14,7 @@ def handle_fantasy(irc, source, command, args):
|
|||||||
# Break if the IRC network isn't ready.
|
# Break if the IRC network isn't ready.
|
||||||
return
|
return
|
||||||
|
|
||||||
try: # First, try to fetch the config-defined prefix.
|
respondtonick = irc.botdata.get("respondtonick")
|
||||||
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
|
|
||||||
|
|
||||||
channel = args['target']
|
channel = args['target']
|
||||||
orig_text = args['text']
|
orig_text = args['text']
|
||||||
@ -44,9 +29,30 @@ def handle_fantasy(irc, source, command, args):
|
|||||||
# message loops).
|
# message loops).
|
||||||
for botname, sbot in world.services.items():
|
for botname, sbot in world.services.items():
|
||||||
log.debug('(%s) fantasy: checking bot %s', irc.name, botname)
|
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.
|
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.
|
# Cut off the length of the prefix from the text.
|
||||||
text = orig_text[len(prefix):]
|
text = orig_text[len(prefix):]
|
||||||
|
Loading…
Reference in New Issue
Block a user