Commit dd52f81f authored by Bruce Cowan's avatar Bruce Cowan

Add unit definition

Fixes #1
parent 708e6d7c
Pipeline #1836 passed with stage
in 18 seconds
......@@ -9,6 +9,10 @@ class Unit(BotPlugin):
super().activate()
self.ureg = UnitRegistry()
self.definitions = self.get('definitions', list())
for d in self.definitions:
Please register or sign in to reply
self.ureg.define(d)
@botcmd
def convert(self, message, args):
......@@ -36,3 +40,18 @@ class Unit(BotPlugin):
return str(e)
else:
return res
@botcmd
def unit_define(self, message, args):
"""Define a new unit"""
if not args or '=' not in args:
return "**Usage**: !unit define <lhs> = <rhs>"
try:
self.ureg.define(args)
except Exception as e:
return str(e)
else:
self.definitions.append(args)
return "Added definition"
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment