From 370fcc43e825f0097e81dbb2f4c2d258c1b97a08 Mon Sep 17 00:00:00 2001 From: Bruce Cowan <bruce@bcowan.eu> Date: Sun, 11 Sep 2016 13:50:07 +0100 Subject: [PATCH] A couple more functions in Unicode plugin --- unicode.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/unicode.py b/unicode.py index 9c21684..2c04d34 100644 --- a/unicode.py +++ b/unicode.py @@ -1,3 +1,5 @@ +import unicodedata + from errbot import BotPlugin, botcmd @@ -21,4 +23,26 @@ class Unicode(BotPlugin): try: return ''.join([chr(int(i)) for i in args.split()]) except ValueError as e: - return "Error: {}".format(e) + return "**Error**: {}".format(e) + + @botcmd + def unicode_lookup(self, message, args): + """Looks up a character by name""" + if not args: + return "**Usage**: !unicode lookup <name>" + + try: + return "Character is {}".format(unicodedata.lookup(args)) + except KeyError: + return "**Error**: Character not found" + + @botcmd + def unicode_name(self, message, args): + """Looks up the name of a character""" + if len(args) != 1: + return "**Usage**: !unicode name <chr>" + + try: + return "Character's name is {}".format(unicodedata.name(args)) + except ValueError: + return "**Error**: Character not found" -- GitLab