Tue, 01 Jul 2014 02:16:34 +0300
- added .convert with angle and temperature conversions
cobalt.py | file | annotate | diff | comparison | revisions |
--- a/cobalt.py Sun Jun 29 21:36:01 2014 +0000 +++ b/cobalt.py Tue Jul 01 02:16:34 2014 +0300 @@ -39,6 +39,7 @@ import hgapi import os import suds +import math try: uid = os.geteuid() @@ -532,11 +533,33 @@ elif command == 'die': check_admin (sender, ident, host, command) quit() - elif command == 'testlog': - check_admin (sender, ident, host, command) - if len(args) < 1: - raise logical_exception ("usage: .%s <message...>" % command) - chanlog (" ".join (args)) + elif command == 'convert': + if len(args) != 3 or args[1] != 'as': + raise logical_exception ("usage: .%s <value> as <valuetype>" % command) + + value = float (args[0]) + valuetype = args[2] + + if valuetype in ['radians', 'degrees']: + if valuetype == 'radians': + radvalue = value + degvalue = (value * 180.) / math.pi + else: + radvalue = (value * math.pi) / 180. + degvalue = value + + self.privmsg (replyto, '%s radians, %s degrees (%s)' %(radvalue, degvalue, degvalue % 360.)) + elif valuetype in ['celsius', 'fahrenheit']: + if valuetype == 'celsius': + celvalue = value + fahrvalue = value * 1.8 + 32 + else: + celvalue = (value - 32) / 1.8 + fahrvalue = value + + self.privmsg (replyto, '%s degrees celsius, %s degrees fahrenheit' %(celvalue, fahrvalue)) + else: + raise logical_exception ('unknown valuetype, expected one of: degrees, radians') # else: # raise logical_exception ("unknown command `.%s`" % command)