From 9a17c6e8dc93eeebfcc6b7f9c05b477e64d114ef Mon Sep 17 00:00:00 2001 From: luk3yx Date: Wed, 26 Oct 2022 14:20:43 +1300 Subject: Add .unicode command --- misc.py | 46 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/misc.py b/misc.py index 5d94381..40fae82 100644 --- a/misc.py +++ b/misc.py @@ -19,7 +19,8 @@ # along with this program. If not, see . # -import random, string, subprocess, time +import random, string, subprocess, time, unicodedata + # A quick "reply" function def reply(irc, hostmask, channel, *msg): @@ -30,11 +31,13 @@ def reply(irc, hostmask, channel, *msg): channel = channel[0] irc.msg(channel, mention, *map(str, msg)) + en_chars = string.ascii_uppercase + string.ascii_lowercase + \ '1234567890!@#$%^&*(),\'' alt_chars = 'ÅıÇδϩӈÔ˚Ò˜Ø∏Œ®Í†¨√∑≈ÁΩå∫ç∂´ƒ©˙ˆ∆˚¬µ˜øπœ®ß†¨√∑≈\Ω¡™£¢∞§¶•ªº' \ '⁄€‹›fifl‡°·‚≤æ' + @register_command('altcode', requires_admin = True) def altcode_cmd(irc, hostmask, is_admin, args): """ @@ -59,11 +62,13 @@ def altcode_cmd(irc, hostmask, is_admin, args): reply(irc, hostmask, args, res) + # Random capitalisation def randcaps(text): res = ''.join(random.choice((str.upper, str.lower))(i) for i in text) return res.replace('S', 'Z').replace('O', '0') + # .silly @register_command('silly', 'sillycaps') def silly_cmd(irc, hostmask, is_admin, args): @@ -74,6 +79,7 @@ def silly_cmd(irc, hostmask, is_admin, args): irc.msg(args[0], randcaps('{}nvalid syntax! Syntax:{}').format( 'I', ' .silly ')) + # .c0mmandz @register_command('c0mmandz') def bonkerzhelp(irc, hostmask, is_admin, args): @@ -81,17 +87,20 @@ def bonkerzhelp(irc, hostmask, is_admin, args): time.sleep(0.75) irc.msg(args[0], 'So snap out of it and do .commands.') + # .upper and .lower @register_command('upper', 'uppercase') def upper_cmd(irc, hostmask, is_admin, args): """ Makes a string uppercase. """ reply(irc, hostmask, args, args[1].upper().replace('.', '!')) + @register_command('lower', 'lowercase') def lower_cmd(irc, hostmask, is_admin, args): """ Makes a string lowercase. """ reply(irc, hostmask, args, args[1].lower().replace('!', '.')) + @register_command('rev', 'reverse') def rev_cmd(irc, hostmask, is_admin, args): """ Reverses a string. """ @@ -100,6 +109,7 @@ def rev_cmd(irc, hostmask, is_admin, args): else: reply(irc, hostmask, args, args[1][::-1]) + @register_command('ping') def ping(irc, hostmask, is_admin, args): if not random.randint(0, 9): @@ -107,9 +117,12 @@ def ping(irc, hostmask, is_admin, args): else: reply(irc, hostmask, args, 'pong') + # .roulette roulette_objs = ('trout', '... feather?', 'water molecule', 'troutgun', - 'anvil', 'sheet of paper') + 'anvil', 'sheet of paper') + + @register_command('roulette', 'r') def roulette_cmd(irc, hostmask, is_admin, args): """ A Russian roulette-style game. """ @@ -122,9 +135,10 @@ def roulette_cmd(irc, hostmask, is_admin, args): else: reply(irc, hostmask, args, '\x1dClick!\x1d') + # .choice def choice_cmd(irc, hostmask, is_admin, args): - choices = map(str.strip, args[-1].split(',')) + choices = map(str.strip, args[-1].split(',' if ',' in args[-1] else ' ')) # Deduplication choices = {choice.casefold(): choice for choice in choices} @@ -133,20 +147,22 @@ def choice_cmd(irc, hostmask, is_admin, args): if len(choices) < 2: if not choices or not choices[0]: reply(irc, hostmask, args, 'Invalid syntax! Usage: .choice ' - '') + '') else: reply(irc, hostmask, args, - 'I need more than one option to choose from!') + 'I need more than one option to choose from!') return choice = random.choice(choices) reply(irc, hostmask, args, 'Your options: ' + ', '.join(choices) - + '. My (random) choice: ' + choice) + + '. My (random) choice: ' + choice) + # Only register .choice on lurklite. if register_command.__module__.startswith('lurklite.'): register_command('choice', 'choose')(choice_cmd) + def get_fortune(): n = subprocess.check_output('/usr/games/fortune').decode('utf-8') # Avoid bad and possibly offensive fortunes @@ -159,10 +175,12 @@ def get_fortune(): assert i < 100 return n.strip().replace('\t', ' ') + @register_command('f', 'fortune') def fortune_cmd(irc, hostmask, is_admin, args): reply(irc, hostmask, args, get_fortune()) + @register_command('coin', 'coinflip') def coinflip_cmd(irc, hostmask, is_admin, args): if random.randint(0, 6000) == 0: @@ -172,3 +190,19 @@ def coinflip_cmd(irc, hostmask, is_admin, args): else: msg = 'Tails' reply(irc, hostmask, args, msg) + + +@register_command('chr', 'unicode') +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)}.' + elif not chars: + msg = 'Usage: .unicode ' + else: + msg = ', '.join( + f'U+{ord(char):04X} - {unicodedata.name(char, "Unknown")}' + for char in chars + ) + + reply(irc, hostmask, args, msg) -- cgit v1.2.3