dice - annna - Annna the nice friendly bot.
HTML git clone git://bitreich.org/annna/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/annna/
DIR Log
DIR Files
DIR Refs
DIR Tags
DIR README
---
dice (995B)
---
1 #!/usr/bin/env python
2 # coding=utf-8
3
4 import os
5 import sys
6 import getopt
7 import xdice as dice
8
9 def usage(app):
10 app = os.path.basename(app)
11 print("usage: %s [-h] [dice_notation]" % (app), file=sys.stderr)
12 sys.exit(1)
13
14 def main(args):
15 doverbose = False
16 doshorten = False
17
18 try:
19 opts, largs = getopt.getopt(args[1:], "hvs")
20 except getopt.GetoptError as err:
21 print(str(err))
22 usage(args[0])
23
24 for o, a in opts:
25 if o == "-h":
26 usage(args[0])
27 elif o == "-s":
28 doshorten = True
29 elif o == "-v":
30 doverbose = True
31 else:
32 assert False, "unhandled option"
33
34 # six-sided dice once
35 if len(largs) < 1:
36 diceroll = "d6"
37 else:
38 diceroll = largs[0]
39
40 try:
41 score = dice.roll(diceroll)
42 except:
43 print("Invalid pattern.")
44 else:
45 if doshorten == True:
46 print("%s [%s]" \
47 % (score, "%s..." % (str(score.format(verbose=doverbose))[:32])))
48 else:
49 print("%s [%s]" % (score, score.format(verbose=doverbose)))
50
51 return 0
52
53 if __name__ == "__main__":
54 sys.exit(main(sys.argv))
55