]> jfr.im git - erebus.git/blame - modules/misc.py
update comments
[erebus.git] / modules / misc.py
CommitLineData
be766737 1# Erebus IRC bot - Author: Erebus Team
2# vim: fileencoding=utf-8
bac69af4 3# assorted simple functions
be766737 4# This file is released into the public domain; see http://unlicense.org/
5
6# module info
7modinfo = {
8 'author': 'Erebus Team',
9 'license': 'public domain',
10 'compatible': [0], # compatible module API versions
11 'depends': [], # other modules required to work properly?
12 'softdeps': ['help'], # modules which are preferred but not required
13}
14
15# preamble
16import modlib
17lib = modlib.modlib(__name__)
18modstart = lib.modstart
19modstop = lib.modstop
20
21# module setup
22from fractions import Fraction
23
24# module code
25@lib.hook(needchan=False, wantchan=True)
26@lib.help('<numerator>/<denominator>|<decimal>', 'reduces a fraction', 'you may supply a fraction in the form "1/2" or a decimal in the form ".5", "0.5", "5e-1", etc.')
27def reduce(bot, user, chan, realtarget, *args):
28 supplied_value = ''.join(args)
29 try:
30 frac = Fraction(supplied_value)
31 except ValueError:
32 return 'Invalid fraction supplied. You must supply a fraction in the form "1/2" or a decimal in the form ".5", "0.5", "5e-1", etc.'
33 return "%s = %s" % (supplied_value, frac)