3
0
mirror of https://github.com/jlu5/PyLink.git synced 2025-01-12 05:02:33 +01:00

fantasy: rework to support service bots (#216)

This commit is contained in:
James Lu 2016-05-15 11:27:51 -07:00
parent 2877d7af4c
commit 96cefb5be0

View File

@ -4,6 +4,7 @@ import os
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import utils import utils
import world
from log import log from log import log
def handle_fantasy(irc, source, command, args): def handle_fantasy(irc, source, command, args):
@ -31,30 +32,27 @@ def handle_fantasy(irc, source, command, args):
return return
channel = args['target'] channel = args['target']
text = args['text'] orig_text = args['text']
for prefix in prefixes: # Cycle through the prefixes list we finished with.
if utils.isChannel(channel) and not irc.isInternalClient(source):
# The following conditions must be met for an incoming message for # The following conditions must be met for an incoming message for
# fantasy to trigger: # fantasy to trigger:
# 1) The message target is a channel. # 1) The message target is a channel.
# 2) The message starts with one of our fantasy prefixes. # 2) A PyLink service client exists in the channel.
# 3) The main PyLink client is in the channel where the command was # 3) The message starts with one of our fantasy prefixes.
# called.
# 4) The sender is NOT a PyLink client (this prevents infinite # 4) The sender is NOT a PyLink client (this prevents infinite
# message loops). # message loops).
if utils.isChannel(channel) and text.startswith(prefix) and \ for botname, sbot in world.services.items():
irc.pseudoclient.uid in irc.channels[channel].users and not \ log.debug('(%s) fantasy: checking bot %s', irc.name, botname)
irc.isInternalClient(source): if sbot.uids.get(irc.name) in irc.channels[channel].users:
for prefix in prefixes: # Cycle through the prefixes list we finished with.
if 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 = text[len(prefix):] text = orig_text[len(prefix):]
# Set the "place last command was called in" variable to the # Finally, call the bot command and loop to the next bot.
# channel in question, so that replies from fantasy-supporting sbot.call_cmd(irc, source, text, called_by=channel, notice=False)
# plugins get forwarded to it. continue
irc.called_by = channel
# Finally, call the bot command and break.
irc.callCommand(source, text)
break
utils.add_hook(handle_fantasy, 'PRIVMSG') utils.add_hook(handle_fantasy, 'PRIVMSG')