Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## Import and setup lines
- import random
- from operator import add, sub
- import re
- DICE_REGEX = re.compile('^(\d+)?\s*d\s*(\d+)(?:\s*(\+|-)\s*(\d+))?$')
- ## Function decleration
- def decide(phenny, input):
- """.decide - Deciding function."""
- msg = input.groups()[1]
- if msg is None:
- msg = '' # Hack
- if '|' in msg:
- msg = [i.strip() for i in msg.split('|')]
- if not all(msg):
- ret = "I'm sorry {}, but some of those options don't exist."
- ret = ret.format(input.nick)
- else:
- ret = '{}: {}'.format(input.nick, random.choice(msg))
- else:
- ret = "I'm sorry {}, but you haven't given me anything "
- ret += "to choose from there."
- ret = ret.format(input.nick)
- phenny.say(ret)
- decide.commands = ['decide', 'choose']
- decide.priority = "low"
- decide.example = ".decide option 1 | option 2"
- def roll(phenny, input):
- msg = input.groups()[1]
- if not msg: # Then there was no message.
- ret = "{}: {}".format(input.nick, random.randrange(1,7))
- phenny.say(ret)
- return
- # Otherwise, deal with a dnd roll.
- msg = msg.strip()
- match = DICE_REGEX.match(msg)
- if match:
- dice_no, sides, op, mod = match.groups() # Un-group the match
- sides = int(sides)
- dice_no = 1 if dice_no is None else int(dice_no) # Set optional params
- mod = 0 if mod is None else int(mod) # to default.
- op = add if op == '+' else sub
- if dice_no > 20: # You cannot be serious.
- phenny.say("There are way too many dice there for me to "
- "keep track of. What do you think I am, a robot?")
- return
- roll_list = []
- for i in range(dice_no):
- roll_list.append(random.randint(1,sides))
- total = op(sum(roll_list), mod)
- ret = "{}: You rolled {}".format(input.nick, total)
- if 1 < dice_no < 10:
- ret += " made from {}".format(str(roll_list))
- phenny.say(ret)
- return
- else:
- phenny.say("That doesn't appear to be a dnd roll. Try just .roll")
- roll.commands = ['roll']
- roll.priority = 'low'
- roll.example = '.roll or .roll 3d6 [or .roll d6 + 3 etc]'
Advertisement
Add Comment
Please, Sign In to add comment