aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorluk3yx <luk3yx@users.noreply.github.com>2022-11-07 10:20:51 +1300
committerluk3yx <luk3yx@users.noreply.github.com>2022-11-07 10:20:51 +1300
commit3885b19161abef297f479c169c90fbd6b1072da0 (patch)
treeabe7c79282b01737684f5278f314c766256d561c
parentd05b369ccfa2bedf54bc3c4db11db9bf0f76f46e (diff)
downloadlurklite-commands-3885b19161abef297f479c169c90fbd6b1072da0.tar.gz
lurklite-commands-3885b19161abef297f479c169c90fbd6b1072da0.zip
Get character names of control characters
-rw-r--r--misc.py20
1 files changed, 14 insertions, 6 deletions
diff --git a/misc.py b/misc.py
index ffd0ed4..0447829 100644
--- a/misc.py
+++ b/misc.py
@@ -192,17 +192,25 @@ def coinflip_cmd(irc, hostmask, is_admin, args):
reply(irc, hostmask, args, msg)
+def get_char_name(char):
+ # Hack to get the name of control characters. U+2400 is "SYMBOL FOR NULL"
+ # and this function will remove the leading "SYMBOL FOR " prefix when a
+ # null byte is passed to it.
+ if char <= '\x1f':
+ char = chr(ord(char) + 0x2400)
+ return unicodedata.name(char)[11:]
+ return unicodedata.name(char, 'Unknown')
+
+
@register_command('chr', 'unicode', 'u')
def unicode_cmd(irc, hostmask, is_admin, args):
chars = args[1]
- if len(chars) > 5:
- msg = f'You must provide 1-5 characters, not {len(chars)}.'
+ if len(chars) > 10:
+ msg = f'You must provide 1-10 characters, not {len(chars)}.'
elif not chars:
msg = 'Usage: .unicode <character>'
else:
- msg = ', '.join(
- f'U+{ord(char):04X} - {unicodedata.name(char, "Unknown")}'
- for char in chars
- )
+ msg = ', '.join(f'U+{ord(char):04X} - {get_char_name(char)}'
+ for char in chars)
reply(irc, hostmask, args, msg)