diff options
author | Sean B. Palmer <http://inamidst.com/sbp/> | 2008-03-02 11:16:25 +0000 |
---|---|---|
committer | Sean B. Palmer <http://inamidst.com/sbp/> | 2008-03-02 11:16:25 +0000 |
commit | 23c1dffa101536889dd6bcef198233ee980add7f (patch) | |
tree | a60d4934705193bd282f002708c9e34c3b80191e /modules | |
parent | 1078791cb60d3ce4543d579fc07b9c0c145e8d10 (diff) | |
download | bot-23c1dffa101536889dd6bcef198233ee980add7f.tar.gz bot-23c1dffa101536889dd6bcef198233ee980add7f.tar.bz2 bot-23c1dffa101536889dd6bcef198233ee980add7f.zip |
Fixed some .u stuff, added .bytes, and made Ctrl+C work.
Diffstat (limited to 'modules')
-rwxr-xr-x | modules/codepoints.py | 46 |
1 files changed, 34 insertions, 12 deletions
diff --git a/modules/codepoints.py b/modules/codepoints.py index f2eb862..89ea078 100755 --- a/modules/codepoints.py +++ b/modules/codepoints.py @@ -11,7 +11,8 @@ import re, unicodedata from itertools import islice def about(u, cp=None, name=None): - if cp is None: cp = ord(u) + if cp is None: + cp = ord(u) if name is None: try: name = unicodedata.name(u) except ValueError: @@ -65,16 +66,27 @@ def codepoint_extended(arg): def u(phenny, input): arg = input.bytes[3:] - - ascii = True - for c in arg: - if ord(c) >= 0x80: - ascii = False - - if ascii: - if set(arg.upper()) - set('ABCDEFGHIJKLMNOPQRSTUVWXYZ '): - extended = True - else: extended = False + # phenny.msg('#inamidst', '%r' % arg) + if not arg: + return phenny.reply('You gave me zero length input.') + + # @@ space + if set(arg.upper()) - set( + 'ABCDEFGHIJKLMNOPQRSTUVWYXYZ0123456789- .?+*{}[]\\/^$'): + printable = False + else: printable = True + + if printable: + extended = False + for c in '.?+*{}[]\\/^$': + if c in arg: + extended = True + break + + if len(arg) == 4: + try: u = unichr(int(arg, 16)) + except ValueError: pass + else: return phenny.say(about(u)) if extended: # look up a codepoint with regexp @@ -84,6 +96,8 @@ def u(phenny, input): phenny.say(result) elif (i == 2) and (len(results) > 3): phenny.say(result + ' [...]') + if not results: + phenny.reply('Sorry, no results') else: # look up a codepoint freely result = codepoint_simple(arg) @@ -97,7 +111,15 @@ def u(phenny, input): for u in text: phenny.say(about(u)) # look up more than three podecoints - elif len(text) <= 8: + elif len(text) <= 10: phenny.reply(' '.join('U+%04X' % ord(c) for c in text)) else: phenny.reply('Sorry, your input is too long!') u.commands = ['u'] + +def bytes(phenny, input): + b = input.bytes + phenny.reply('%r' % b[b.find(' ') + 1:]) +bytes.commands = ['bytes'] + +if __name__ == '__main__': + print __doc__.strip() |