diff --git a/SupyMisc/plugin.py b/SupyMisc/plugin.py index e495a09..01948a0 100644 --- a/SupyMisc/plugin.py +++ b/SupyMisc/plugin.py @@ -129,6 +129,43 @@ class SupyMisc(callbacks.Plugin): nick = msg.nick irc.reply(ircutils.hostFromHostmask(irc.state.nickToHostmask(nick))) gethost = wrap(gethost, [(additional('nick'))]) + + ### Access to python built-in functions + def int2bin(self, irc, msg, args, num): + """ + Returns the binary representation of . + """ + out = bin(int(num)) + irc.reply(out) + int2bin = wrap(int2bin, ['int']) + + def int2hex(self, irc, msg, args, num): + """ + Returns the hexadecimal representation of . + """ + out = hex(int(num)) + irc.reply(out) + int2hex = wrap(int2hex, ['int']) + + def bin2int(self, irc, msg, args, num): + """ + Returns the decimal representation of . + """ + try: + irc.reply(int(num, base=2)) + except ValueError: + irc.error("Invalid input: {}.".format(num)) + bin2int = wrap(bin2int, ['somethingWithoutSpaces']) + + def hex2int(self, irc, msg, args, num): + """ + Returns the decimal representation of . + """ + try: + irc.reply(int(num, base=16)) + except ValueError: + irc.error("Invalid input: {}.".format(num)) + hex2int = wrap(hex2int, ['somethingWithoutSpaces']) Class = SupyMisc