Skip to content

Commit

Permalink
Merge branch '106-dev' of github.com:freiheit/MvKDiceBot into 106-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
CJ Holmes committed Mar 26, 2024
2 parents b941d42 + a7a52cd commit f94b592
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pylint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11"]
python-version: ["3.12"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
Expand Down
24 changes: 24 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Test

on: [push]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install pylint
- name: Run tests
run: |
python test.py
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +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)
[![Tests](https://github.com/freiheit/MvKDiceBot/actions/workflows/test.yml/badge.svg)](https://github.com/freiheit/MvKDiceBot/actions/workflows/test.yml)

# MvKDiceBot
Dice bot for MvK ruleset...
Expand Down
20 changes: 4 additions & 16 deletions mvkroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def parse_dice(dicestr: str):
return dicecounts


def roll_dice(dicecounts, cheat=False):
def roll_dice(dicecounts):
"""Returns a dictionary of dieSize => rolls[]"""
dicerolls = {
20: [],
Expand All @@ -88,11 +88,7 @@ def roll_dice(dicecounts, cheat=False):
try:
for size, num in dicecounts.items():
if num > 0:
# pylint: disable=unused-variable
if cheat:
dicerolls[size] = [size for idx in range(0, num)]
else:
dicerolls[size] = [random.randint(1, size) for idx in range(0, num)]
dicerolls[size] = [random.randint(1, size) for idx in range(0, num)]
except Exception as exc:
raise RollError("Exception while rolling dice.") from exc

Expand Down Expand Up @@ -201,7 +197,6 @@ def mvkroll(dicestr: str):
logger.debug("Roll %s", {dicestr})

answer = ""
cheat = False
advantage = False
disadvantage = False

Expand All @@ -210,9 +205,6 @@ def mvkroll(dicestr: str):
elif re.search(r"advantage", dicestr, flags=re.IGNORECASE):
advantage = True

if re.search(r"cheat", dicestr, flags=re.IGNORECASE):
cheat = True

dicecounts = parse_dice(dicestr)

# advantage and disadvantage need _at least_ 2d20
Expand All @@ -225,7 +217,7 @@ def mvkroll(dicestr: str):
dicecounts[20] = 1
answer += "_No advantage/disadvantage, setting 1d20_\n"

dicerolls = roll_dice(dicecounts, cheat)
dicerolls = roll_dice(dicecounts)

# the d20 is called the "Fortune Die"
fortunedicerolls = dicerolls[20]
Expand Down Expand Up @@ -259,9 +251,6 @@ def mvkroll(dicestr: str):

answer += calc_impact(fortunedicerolls, characterdicerolls)

if cheat:
answer = "\n# Cheating #\n" + answer + "\n# Cheater #\n"

return answer


Expand All @@ -271,10 +260,9 @@ def plainroll(dicestr: str):
logger.debug("Roll %s", {dicestr})

answer = ""
cheat = False

dicecounts = parse_dice(dicestr)
dicerolls = roll_dice(dicecounts, cheat)
dicerolls = roll_dice(dicecounts)

answer += print_dice(dicerolls)

Expand Down
1 change: 1 addition & 0 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def test_parser_good(self):
"there are no matching dice strings here": {20:0, 12:0, 10:0, 8:0, 6:0, 4:0},
"messyd20what?": {20:1, 12:0, 10:0, 8:0, 6:0, 4:0},
"d20 3d6 5d10": {20:1, 12:0, 10:5, 8:0, 6:3, 4:0},
"d20 d6 d6 d6 4d10 d10": {20:1, 12:0, 10:5, 8:0, 6:3, 4:0},
"4d12 1d10 2d4": {20:0, 12:4, 10:1, 8:0, 6:0, 4:2},
" d4 d6 d8 d12 ": {20:0, 12:1, 10:0, 8:1, 6:1, 4:1},
"1024d20, 500d4": {20:1024, 12:0, 10:0, 8:0, 6:0, 4:500},
Expand Down
2 changes: 2 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
./.venv/bin/python test.py "$@"

0 comments on commit f94b592

Please sign in to comment.