import random
import re

class ChooseModule:
	def __init__(self, circa):
		self.circa = circa

		self.listeners = {
			"cmd.choose": [self.choose],
			"cmd.roll": [self.roll],
		}

	def choose(self, fr, to, params):
		params = " ".join(params).strip()
		if len(params) == 0:
			self.circa.notice(fr, "choose <choice>, ... or <choice>")
		else:
			choices = re.split(r"\s*,\s*|\bor\b", " ".join(params))
			self.circa.say(to, "{0}: {1}".format(fr, random.choice(choices)))

	def roll(self, fr, to, params):
		dice = params[0]
		if dice.count("d") > 1:
			self.circa.notice(fr, "roll <n>d<n>")
		a, b = dice.split("d")[0], 6
		if "d" in dice:
			b = dice.split("d")[1]
		numdice, amtdice = 1, 6
		try:
			numdice = int(a)
		except ValueError:
			pass
		try:
			amtdice = int(b)
		except ValueError:
			pass
		self.circa.say(to, "{0}: {1}".format(fr, ", ".join(
			[str(random.randrange(1, amtdice)) for i in range(numdice)])))

module = ChooseModule

@@ -499,16 +499,61 @@
 arams):%0A
+%09%09numdice, amtdice = 1, 6%0A%09%09if len(params):%0A%09
 %09%09dice =
@@ -563,16 +563,17 @@
 rams%5B0%5D%0A
+%09
 %09%09if dic
@@ -590,16 +590,17 @@
 %22) %3E 1:%0A
+%09
 %09%09%09self.
@@ -632,16 +632,17 @@
 %3Ed%3Cn%3E%22)%0A
+%09
 %09%09a, b =
@@ -646,30 +646,14 @@
 b = 
-dice.split(%22d%22)%5B0%5D
+1
 , 6%0A
+%09
 %09%09if
@@ -669,16 +669,20 @@
 ice:%0A%09%09%09
+%09a, 
 b = dice
@@ -696,45 +696,18 @@
 %22d%22)
-%5B1%5D%0A%09%09numdice, amtdice = 1, 6
 %0A
+%09
 %09%09try:%0A
+%09
 %09%09%09n
@@ -720,24 +720,25 @@
  = int(a)%0A%09%09
+%09
 except Value
@@ -747,21 +747,23 @@
 ror:%0A%09%09%09
+%09
 pass%0A
+%09
 %09%09try:%0A%09
@@ -764,16 +764,17 @@
 try:%0A%09%09%09
+%09
 amtdice 
@@ -782,16 +782,17 @@
  int(b)%0A
+%09
 %09%09except
@@ -804,16 +804,17 @@
 eError:%0A
+%09
 %09%09%09pass%0A

fix roll command