]>
Commit | Line | Data |
---|---|---|
be766737 | 1 | # Erebus IRC bot - Author: Erebus Team |
2 | # vim: fileencoding=utf-8 | |
3 | # simple module example | |
4 | # This file is released into the public domain; see http://unlicense.org/ | |
5 | ||
6 | # module info | |
7 | modinfo = { | |
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 | |
16 | import modlib | |
17 | lib = modlib.modlib(__name__) | |
18 | modstart = lib.modstart | |
19 | modstop = lib.modstop | |
20 | ||
21 | # module setup | |
22 | from 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.') | |
27 | def 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) |