From 60568f904bf9dfcfa4e3dfc8974529c788500c01 Mon Sep 17 00:00:00 2001 From: urlbot Date: Tue, 7 Jul 2015 00:02:17 +0200 Subject: [PATCH] decode: cleanup, decode multiple characters at once --- plugins.py | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/plugins.py b/plugins.py index 97074cb..bd643b9 100644 --- a/plugins.py +++ b/plugins.py @@ -472,21 +472,33 @@ def command_decode(argv, **args): 'msg': args['reply_user'] + ': usage: decode {single character}' } - char = argv[1] - char_esc = str(char.encode('unicode_escape'))[3:-1] - log.plugin('decode called for %s' % char) + log.plugin('decode called for %s' % argv[1]) - try: - uni_name = unicodedata.name(char) - except Exception as e: - log.plugin('decode(%s) failed: %s' % (char, str(e))) + out = [] + for i, char in enumerate(argv[1]): + if i > 9: + out.append('... limit reached.') + break + + char_esc = str(char.encode('unicode_escape'))[3:-1] + + try: + uni_name = unicodedata.name(char) + except Exception as e: + log.plugin('decode(%s) failed: %s' % (char, e)) + out.append("can't decode %s (%s): %s" % (char, char_esc, e)) + continue + + out.append('%s (%s) is called "%s"' % (char, char_esc, uni_name)) + + if 1 == len(out): return { - 'msg': args['reply_user'] + ": can't decode %s (%s): %s" % (char, char_esc, str(e)) + 'msg': args['reply_user'] + ': %s' % out[0] + } + else: + return { + 'msg': [args['reply_user'] + ': decoding %s:' % argv[1]] + out } - - return { - 'msg': args['reply_user'] + ': %s (%s) is called "%s"' % (char, char_esc, uni_name) - } @pluginfunction('show-blacklist', 'show the current URL blacklist, optionally filtered', ptypes_COMMAND) def command_show_blacklist(argv, **args):