def dice(self, *, input : str = '6'):
'''
Roll dice
Inputs: Examples:
S | S - number of sides (default is 6) [6 | 12]
AdS | A - amount (default is 1) [5d6 | 2d10]
AdSt | t - return total [2d6t | 20d5t]
AdSs | s - return sorted [4d6s | 5d8s]
AdS^H | ^H - return highest H rolls [10d6^4 | 2d7^1]
AdSvL | vL - return lowest L rolls [15d7v2 | 8d9v2]
'''
# TODO: Add documentation on arithmetic/basic integer operations
if 'd' not in input:
input = 'd' + input
with multiprocessing.Pool(1) as pool:
async_result = pool.apply_async(dice.roll, (input,))
future = self.bot.loop.run_in_executor(None, async_result.get, 10.0)
try:
result = await asyncio.wait_for(future, 10.0, loop = self.bot.loop)
if type(result) is int:
await self.bot.embed_reply(result)
else:
await self.bot.embed_reply(", ".join(str(roll) for roll in result))
except discord.errors.HTTPException:
await self.bot.embed_reply(":no_entry: Output too long")
except pyparsing.ParseException:
await self.bot.embed_reply(":no_entry: Invalid input")
except (concurrent.futures.TimeoutError, multiprocessing.context.TimeoutError):
await self.bot.embed_reply(":no_entry: Execution exceeded time limit")
评论列表
文章目录