added /pop command
This commit is contained in:
54
bot.py
54
bot.py
@@ -107,6 +107,20 @@ def roll_traditional_dice(count: int, sides: int) -> List[int]:
|
||||
"""Roll traditional dice."""
|
||||
return [random.randint(1, sides) for _ in range(count)]
|
||||
|
||||
def roll_popping_dice(count: int, sides: int) -> List[List[int]]:
|
||||
"""Roll dice that spawn a d4 on rolling 1.
|
||||
Returns a list of lists, where each inner list represents the chain of rolls from one initial die."""
|
||||
results = []
|
||||
for _ in range(count):
|
||||
chain = []
|
||||
roll = random.randint(1, sides)
|
||||
chain.append(roll)
|
||||
while roll == 1: # Keep rolling d4s as long as we get 1s
|
||||
roll = random.randint(1, 4)
|
||||
chain.append(roll)
|
||||
results.append(chain)
|
||||
return results
|
||||
|
||||
def roll_genesys_die(die_type: str) -> Tuple[str, str]:
|
||||
"""Roll a single Genesys die and return its result."""
|
||||
return random.choice(GENESYS_DICE[die_type])
|
||||
@@ -216,6 +230,46 @@ async def genesys(interaction: discord.Interaction, dice: str):
|
||||
except Exception as e:
|
||||
await interaction.response.send_message(f"Error: {str(e)}")
|
||||
|
||||
@client.tree.command(name="pop", description="Roll dice that spawn 1d4 on rolling 1 (e.g., 2d6 + 1d8)")
|
||||
async def pop(interaction: discord.Interaction, dice: str):
|
||||
try:
|
||||
dice_sets = parse_dice_notation(dice)
|
||||
if not dice_sets:
|
||||
await interaction.response.send_message("Invalid dice notation. Use format like '2d6 + 1d8'")
|
||||
return
|
||||
|
||||
results = []
|
||||
total = 0
|
||||
|
||||
for count, die in dice_sets:
|
||||
if not die.isdigit():
|
||||
await interaction.response.send_message(f"Invalid die type: {die} did you include +? Use format like '2d6 + 1d8'")
|
||||
return
|
||||
|
||||
sides = int(die)
|
||||
rolls = roll_popping_dice(count, sides)
|
||||
|
||||
# Format the output for this dice set
|
||||
roll_strs = []
|
||||
set_total = 0
|
||||
for chain in rolls:
|
||||
chain_str = str(chain[0])
|
||||
if len(chain) > 1:
|
||||
chain_str += f" → {' → '.join(map(str, chain[1:]))}"
|
||||
roll_strs.append(chain_str)
|
||||
set_total += sum(chain)
|
||||
|
||||
results.append(f"{count}d{sides}: [{', '.join(roll_strs)}] = {set_total}")
|
||||
total += set_total
|
||||
|
||||
response = "\n".join(results)
|
||||
if len(dice_sets) > 1:
|
||||
response += f"\nTotal: {total}"
|
||||
|
||||
await interaction.response.send_message(response)
|
||||
except Exception as e:
|
||||
await interaction.response.send_message(f"Error: {str(e)}")
|
||||
|
||||
@client.event
|
||||
async def on_ready():
|
||||
print(f'{client.user} has connected to Discord!')
|
||||
|
||||
Reference in New Issue
Block a user