Skip to content

Commit

Permalink
Development -> Main update (#30)
Browse files Browse the repository at this point in the history
* Remove that "techstack" experiment
* Update dependency aiohttp to v3.9.1 (#22)
* Make install/update/run a little simpler if using local .venv (via some shell scripts for my own use)
* Add "r" alias (#28)
* Implement double impact for d10/d12 rolls >=10, closing #27 (#29)
  • Loading branch information
freiheit authored Nov 27, 2023
1 parent cf907fd commit d453aa2
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 172 deletions.
11 changes: 0 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
[![CodeQL](https://github.com/freiheit/MvKDiceBot/actions/workflows/github-code-scanning/codeql/badge.svg)](https://github.com/freiheit/MvKDiceBot/actions/workflows/github-code-scanning/codeql)
[![Pylint](https://github.com/freiheit/MvKDiceBot/actions/workflows/pylint.yml/badge.svg)](https://github.com/freiheit/MvKDiceBot/actions/workflows/pylint.yml)




# MvKDiceBot
Dice bot for MvK ruleset...

Expand All @@ -22,11 +19,3 @@ https://discord.com/api/oauth2/authorize?client_id=1168083075515826186&permissio
7. Generate an invite URL:
- Scopes: bot, applications.commands
- Bot Permissions: Read Messages/View Channels, Send Messages, Send Messages in Threads

## Tech Stack
freiheit/MvKDiceBot is built on the following main stack:
- <img width='25' height='25' src='https://img.stackshare.io/service/993/pUBY5pVj.png' alt='Python'/> [Python](https://www.python.org) – Languages
- <img width='25' height='25' src='https://img.stackshare.io/service/4837/py.jpg' alt='Pylint'/> [Pylint](https://www.pylint.org/) – Code Review
- <img width='25' height='25' src='https://img.stackshare.io/service/11563/actions.png' alt='GitHub Actions'/> [GitHub Actions](https://github.com/features/actions) – Continuous Integration

Full tech stack [here](/techstack.md)
9 changes: 9 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh

if which yum; then
sudo yum --skip-broken -y install python3.11 python3.11-devel python3.11-pip python3.11-pip-wheel python3.11-wheel
fi
# TODO: elif apt ...

python3.11 -m venv --symlinks --system-site-packages .venv
./.venv/bin/pip install -r requirements.txt
26 changes: 20 additions & 6 deletions mvkdicebot.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ async def on_ready():
logger.warning(f"Logged in as {bot.user} (ID: {bot.user.id})")


@bot.hybrid_command() # pylint: disable=no-member
@bot.hybrid_command(aliases=["r", "rolldice", "diceroll"]) # pylint: disable=no-member
async def roll(ctx, *, dicestr: str):
"""Rolls a pool of dice in NdN format.
Example: '?roll 1d20 2d10 d8 2d6'
Expand Down Expand Up @@ -93,7 +93,10 @@ async def roll(ctx, *, dicestr: str):
}

dicerolls = {}
flatdicerolls = []
flatdicerolls = [] # all dice
# dice d4-d12 are called "Character Dice" and the d20 is called the "Fortune Die"
characterdicerolls = [] # non-d20 dice
fortunedicerolls = [] # d20s

pattern_ndn = re.compile(r"([0-9]*) *[dD]([0-9]+)")

Expand All @@ -109,8 +112,6 @@ async def roll(ctx, *, dicestr: str):
else:
await ctx.send(f"Invalid dice size d{size}")

flatdicerolls = []

for size in dicecounts:
if dicecounts[size] > 0:
# logger.debug(f"rolling: d{size}={dicecounts[size]}")
Expand All @@ -123,8 +124,14 @@ async def roll(ctx, *, dicestr: str):
result = random.randint(1, size)
dicerolls[size].append(result)
flatdicerolls.append(result)
if size == 20:
fortunedicerolls.append(result)
else:
characterdicerolls.append(result)

flatdicerolls.sort(reverse=True)
fortunedicerolls.sort(reverse=True)
characterdicerolls.sort(reverse=True)

if len(dicerolls) > 0:
answer = ""
Expand Down Expand Up @@ -158,9 +165,16 @@ async def roll(ctx, *, dicestr: str):
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)
# die results of 10 or higher on a d10 or 12 give two impact. It doesn't happen on a d20.
fortuneimpact = sum(1 for p in fortunedicerolls if p >= 4)
doublecharacterimpact = sum(2 for p in characterdicerolls if p >= 10)
characterimpact = sum(1 for p in characterdicerolls if 4 <= p < 10)
impact = fortuneimpact + doublecharacterimpact + characterimpact
impact = max(impact, 1)
answer += f"**Impact:** {impact}"
answer += f"**Impact:** {impact} "
answer += (
f"(fortune={fortuneimpact} 2x={doublecharacterimpact} 1x={characterimpact})"
)

if cheat:
answer += "\n# Cheating"
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
aiohttp==3.9.0
aiohttp==3.9.1
aiosignal==1.3.1
astroid==3.0.1
async-timeout==4.0.3
Expand Down
3 changes: 3 additions & 0 deletions run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

./.venv/bin/python3 mvkdicebot.py
93 changes: 0 additions & 93 deletions techstack.md

This file was deleted.

61 changes: 0 additions & 61 deletions techstack.yml

This file was deleted.

3 changes: 3 additions & 0 deletions update.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

./.venv/bin/pip install -r requirements.txt

0 comments on commit d453aa2

Please sign in to comment.