From 24c6eaa9df5f8ccd2689622cb8836fc305c1721e Mon Sep 17 00:00:00 2001 From: Jeremy Fincher Date: Sat, 15 Mar 2003 12:00:31 +0000 Subject: [PATCH] Fixed chr command to take hex/oct/binary literals and added a base command --- plugins/FunCommands.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/plugins/FunCommands.py b/plugins/FunCommands.py index 65a4e322e..df17953c4 100644 --- a/plugins/FunCommands.py +++ b/plugins/FunCommands.py @@ -103,11 +103,29 @@ class FunCommands(callbacks.Privmsg): Returns the character associated with the 8-bit value """ try: - i = int(privmsgs.getArgs(args)) + i = privmsgs.getArgs(args) + if i.startswith('0x'): + base = 16 + elif i.startswith('0b'): + base = 2 + i = i[2:] + elif i.startswith('0'): + base = 8 + else: + base = 10 + i = int(i, base) irc.reply(msg, chr(i)) except ValueError: irc.error(msg, 'That number doesn\'t map to an 8-bit character.') + def base(self, irc, msg, args): + """ + + Converts to base the number + """ + (base, number) = privmsgs.getArgs(args, needed=2) + irc.reply(msg, str(long(number, int(base)))) + def hexlify(self, irc, msg, args): "; turn string into a hexstring." text = privmsgs.getArgs(args)