diff --git a/plugins/bots.py b/plugins/bots.py index b4158fd..e4cc95d 100644 --- a/plugins/bots.py +++ b/plugins/bots.py @@ -121,40 +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 mode(irc, source, args): - """ - - Admin-only. Sets modes on from , where is either the nick of a PyLink client, or the SID of a PyLink server. can be either a nick or a channel.""" - utils.checkAuthenticated(irc, source, allowOper=False) - try: - modesource, target, modes = args[0], args[1], args[2:] - except IndexError: - irc.reply('Error: Not enough arguments. Needs 3: source nick, target, modes to set.') - return - target = utils.nickToUid(irc, target) or target - extclient = target in irc.users and not utils.isInternalClient(irc, target) - parsedmodes = utils.parseModes(irc, target, modes) - ischannel = target in irc.channels - if not (target in irc.users or ischannel): - irc.reply("Error: Invalid channel or nick %r." % target) - return - elif not parsedmodes: - irc.reply("Error: No valid modes were given.") - return - elif not (ischannel or utils.isManipulatableClient(irc, target)): - irc.reply("Error: Can only set modes on channels or non-protected PyLink clients.") - return - if utils.isInternalServer(irc, modesource): - # Setting modes from a server. - irc.proto.modeServer(modesource, target, parsedmodes) - else: - # Setting modes from a client. - modesource = utils.nickToUid(irc, modesource) - irc.proto.modeClient(modesource, target, parsedmodes) - irc.callHooks([modesource, 'PYLINK_BOTSPLUGIN_MODE', - {'target': target, 'modes': parsedmodes, 'parse_as': 'MODE'}]) - @utils.add_cmd def msg(irc, source, args): """ diff --git a/plugins/opercmds.py b/plugins/opercmds.py new file mode 100644 index 0000000..961a40a --- /dev/null +++ b/plugins/opercmds.py @@ -0,0 +1,50 @@ +""" +opercmds.py: Provides a subset of network 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 mode(irc, source, args): + """ + + Oper-only, sets modes on the target channel.""" + + # Check that the caller is either opered or logged in as admin. + utils.checkAuthenticated(irc, source) + + try: + target, modes = args[0], args[1:] + except IndexError: + irc.reply('Error: Not enough arguments. Needs 2: target, modes to set.') + return + + if target not in irc.channels: + irc.reply("Error: Unknown channel '%s'." % target) + return + elif not modes: + # No modes were given before parsing (i.e. mode list was blank). + irc.reply("Error: No valid modes were given.") + return + + parsedmodes = utils.parseModes(irc, target, modes) + + if not parsedmodes: + # Modes were given but they failed to parse into anything meaningful. + # For example, "mode #somechan +o" would be erroneous because +o + # requires an argument! + irc.reply("Error: No valid modes were given.") + return + + irc.proto.modeClient(irc.pseudoclient.uid, target, parsedmodes) + + # Call the appropriate hooks for plugin like relay. + irc.callHooks([irc.pseudoclient.uid, 'OPERCMDS_MODEOVERRIDE', + {'target': target, 'modes': parsedmodes, 'parse_as': 'MODE'}]) +