From 8000d51453e09fb6434c89f7b9c7606ef8c5848e Mon Sep 17 00:00:00 2001 From: James Lu Date: Sun, 21 Jan 2018 13:50:37 -0800 Subject: [PATCH] Split the 'raw' command into a new plugin Closes #565. --- example-conf.yml | 4 ++++ plugins/exec.py | 20 -------------------- plugins/raw.py | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 20 deletions(-) create mode 100644 plugins/raw.py diff --git a/example-conf.yml b/example-conf.yml index 901ce82..489bc2c 100644 --- a/example-conf.yml +++ b/example-conf.yml @@ -508,6 +508,10 @@ plugins: # Servermaps plugin: displays network /map's from the PyLink server's perspective. #- servermaps + # Raw plugin: Provides a 'raw' command for sending raw text to IRC. + # Not supported outside Clientbot networks! + #- raw + logging: # This configuration block defines targets that PyLink should log commands, # errors, etc., to. diff --git a/plugins/exec.py b/plugins/exec.py index 9ffe8e8..38c68be 100644 --- a/plugins/exec.py +++ b/plugins/exec.py @@ -135,26 +135,6 @@ def pieval(irc, source, args): """ _eval(irc, source, args, locals_dict=exec_locals_dict, pretty_print=True) -@utils.add_cmd -def raw(irc, source, args): - """ - - Admin-only. Sends raw text to the uplink IRC server. - - \x02**WARNING: THIS CAN BREAK YOUR NETWORK IF USED IMPROPERLY!**\x02""" - permissions.check_permissions(irc, source, ['exec.raw']) - - args = ' '.join(args) - if not args.strip(): - irc.reply('No text entered!') - return - - log.debug('(%s) Sending raw text %r to IRC for %s', irc.name, args, - irc.get_hostmask(source)) - irc.send(args) - - irc.reply("Done.") - @utils.add_cmd def inject(irc, source, args): """ diff --git a/plugins/raw.py b/plugins/raw.py new file mode 100644 index 0000000..d44ab0a --- /dev/null +++ b/plugins/raw.py @@ -0,0 +1,35 @@ +""" +raw.py: Provides a 'raw' command for sending raw text to IRC. +""" +from pylinkirc.log import log +from pylinkirc.coremods import permissions +from pylinkirc import utils + +@utils.add_cmd +def raw(irc, source, args): + """ + + Sends raw text to the IRC server. + + This command is not officially supported on non-Clientbot networks, where it + requires a separate permission.""" + + if irc.protoname == 'clientbot': + # exec.raw is included for backwards compatibility with PyLink 1.x + perms = ['raw.raw', 'exec.raw'] + else: + perms = ['raw.raw.unsupported_network'] + permissions.check_permissions(irc, source, perms) + + args = ' '.join(args) + if not args.strip(): + irc.reply('No text entered!') + return + + # Note: This is loglevel debug so that we don't risk leaking things like + # NickServ passwords on Clientbot networks. + log.debug('(%s) Sending raw text %r to IRC for %s', irc.name, args, + irc.get_hostmask(source)) + irc.send(args) + + irc.reply("Done.")