Skip to content

Commit

Permalink
Format/style fixups with black
Browse files Browse the repository at this point in the history
  • Loading branch information
freiheit committed Oct 30, 2023
1 parent 0710a7b commit 4821c91
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 deletions mvkdicebot.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
intents=intents,
)


@bot.event
async def on_ready():
logger.info(f"Logged in as {bot.user} (ID: {bot.user.id})")
Expand All @@ -57,25 +58,27 @@ async def roll(ctx, *, dicestr: str):
logger.debug(f"roll: {dicestr}")

# types of dice we're looking for:
dicecounts = { 20:0, 12:0,
10: 0,
8: 0,
6: 0,
4: 0,
dicecounts = {
20: 0,
12: 0,
10: 0,
8: 0,
6: 0,
4: 0,
}

dicerolls = {}
flatdicerolls = []

patternNdN = re.compile(r'([0-9]*)d([0-9]+)')
for (count, size) in re.findall(patternNdN, dicestr):
patternNdN = re.compile(r"([0-9]*)d([0-9]+)")

for count, size in re.findall(patternNdN, dicestr):
logger.debug(f"roll: count={count} size={size}")
size=int(size)
size = int(size)
if len(count) >= 1:
count=int(count)
count = int(count)
elif len(count) < 1 or int(count) < 1:
count=1
count = 1
if size in dicecounts:
dicecounts[size] += count
else:
Expand All @@ -85,10 +88,10 @@ async def roll(ctx, *, dicestr: str):

for size in dicecounts:
if dicecounts[size] > 0:
# logger.debug(f"rolling: d{size}={dicecounts[size]}")
# logger.debug(f"rolling: d{size}={dicecounts[size]}")
dicerolls[size] = []
for i in range(0, dicecounts[size]):
result = (random.randint(1,size))
result = random.randint(1, size)
dicerolls[size].append(result)
flatdicerolls.append(result)

Expand All @@ -98,22 +101,23 @@ async def roll(ctx, *, dicestr: str):
answer = "**Dice:** "

for size in dicerolls:
answer += f"{len(dicerolls[size])}d{size}{ str(dicerolls[size])} "
answer += f"{len(dicerolls[size])}d{size}{ str(dicerolls[size])} "
answer += "\n"

action_dice = flatdicerolls[:2]
action_total = sum(action_dice)
answer += f"**Action Total:** {str(action_total)} {str(action_dice)}\n"

impact = sum(1 for p in flatdicerolls if p >=4)
impact = sum(1 for p in flatdicerolls if p >= 4)
if impact < 1:
impact = 1
answer += f"**Impact:** {impact}"

await ctx.reply(answer)
else:
await ctx.reply(f"No valid NdNs found in '{dicestr}'")



# try:
# rolls, limit = map(int, dicestr.split("d"))
# except Exception:
Expand Down Expand Up @@ -171,6 +175,7 @@ def get_config():

return config, logger


config, logger = get_config()

bot.run(
Expand Down

0 comments on commit 4821c91

Please sign in to comment.