From 1f2b99ca26792a568d916073deb372d6b6978e89 Mon Sep 17 00:00:00 2001 From: James Lu Date: Fri, 18 Dec 2015 21:35:41 -0800 Subject: [PATCH] Move "KICK" from bots.py to a new plugin, chancmds Also, add more sanity checks to make sure the things we're kicking are actually valid. --- plugins/bots.py | 25 --------------------- plugins/chancmds.py | 55 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 25 deletions(-) create mode 100644 plugins/chancmds.py diff --git a/plugins/bots.py b/plugins/bots.py index 4c07d3b..b4158fd 100644 --- a/plugins/bots.py +++ b/plugins/bots.py @@ -121,31 +121,6 @@ def part(irc, source, args): irc.proto.partClient(u, channel, reason) irc.callHooks([u, 'PYLINK_BOTSPLUGIN_PART', {'channels': clist, 'text': reason, 'parse_as': 'PART'}]) -@utils.add_cmd -def kick(irc, source, args): - """ [] - - Admin-only. Kicks from via , where is the nick of a PyLink client.""" - utils.checkAuthenticated(irc, source, allowOper=False) - try: - nick = args[0] - channel = args[1] - target = args[2] - reason = ' '.join(args[3:]) - except IndexError: - irc.reply("Error: Not enough arguments. Needs 3-4: source nick, channel, target, reason (optional).") - return - u = utils.nickToUid(irc, nick) or nick - targetu = utils.nickToUid(irc, target) - if not utils.isChannel(channel): - irc.reply("Error: Invalid channel name %r." % channel) - return - if utils.isInternalServer(irc, u): - irc.proto.kickServer(u, channel, targetu, reason) - else: - irc.proto.kickClient(u, channel, targetu, reason) - irc.callHooks([u, 'PYLINK_BOTSPLUGIN_KICK', {'channel': channel, 'target': targetu, 'text': reason, 'parse_as': 'KICK'}]) - @utils.add_cmd def mode(irc, source, args): """ diff --git a/plugins/chancmds.py b/plugins/chancmds.py new file mode 100644 index 0000000..3821106 --- /dev/null +++ b/plugins/chancmds.py @@ -0,0 +1,55 @@ +""" +chancmds.py: Provides a subset of channel management commands. +""" + +import sys +import os +# Add the base PyLink folder to path, so we can import utils and log. +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) + +import utils +from log import log + +@utils.add_cmd +def kick(irc, source, args): + """ [] + + Oper only. Kicks from via , where is either the nick of a PyLink client or the SID of a PyLink server.""" + utils.checkAuthenticated(irc, source, allowOper=False) + try: + sourcenick = args[0] + channel = args[1] + target = args[2] + reason = ' '.join(args[3:]) + except IndexError: + irc.reply("Error: Not enough arguments. Needs 3-4: source nick, channel, target, reason (optional).") + return + + # Convert the source and target nicks to UIDs. + u = utils.nickToUid(irc, sourcenick) or sourcenick + targetu = utils.nickToUid(irc, target) + + if channel not in irc.channels: # KICK only works on channels that exist. + irc.reply("Error: Unknown channel %r." % channel) + return + + if utils.isInternalServer(irc, u): + # Send kick from server if the given kicker is a SID + irc.proto.kickServer(u, channel, targetu, reason) + elif u not in irc.users: + # Whatever we were told to send the kick from wasn't valid; try to be + # somewhat user friendly in the error. message + irc.reply("Error: No such PyLink client '%s'. The first argument to " + "KICK should be the name of a PyLink client (e.g. '%s'; see " + "'help kick' for details." % (sourcenick, + irc.pseudoclient.nick)) + return + elif targetu not in irc.users: + # Whatever we were told to kick doesn't exist! + irc.reply("Error: No such nick '%s'." % target) + return + else: + irc.proto.kickClient(u, channel, targetu, reason) + + irc.callHooks([u, 'CHANCMDS_KICK', {'channel': channel, 'target': targetu, + 'text': reason, 'parse_as': 'KICK'}])