dming 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- dming-0.1.0/LICENSE +21 -0
- dming-0.1.0/PKG-INFO +99 -0
- dming-0.1.0/README.md +81 -0
- dming-0.1.0/dming/__init__.py +3 -0
- dming-0.1.0/dming/cli.py +39 -0
- dming-0.1.0/dming/dice.py +40 -0
- dming-0.1.0/pyproject.toml +35 -0
dming-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Saúl Piña
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
dming-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: dming
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: DMing is a CLI (command-line interface) collection useful when running a TTRPG (tabletop role-playing games).
|
|
5
|
+
License: MIT
|
|
6
|
+
Author: Saúl Piña
|
|
7
|
+
Author-email: sauljabin@gmail.com
|
|
8
|
+
Requires-Python: >=3.13,<3.14
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Environment :: Console
|
|
11
|
+
Classifier: Operating System :: MacOS
|
|
12
|
+
Classifier: Operating System :: Unix
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
14
|
+
Requires-Dist: click (>=8.2.1,<9.0.0)
|
|
15
|
+
Requires-Dist: rich (>=14.1.0,<15.0.0)
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
|
|
18
|
+
# DMing
|
|
19
|
+
|
|
20
|
+
DMing is a CLI (command-line interface) collection useful when running a TTRPG (tabletop role-playing game).
|
|
21
|
+
|
|
22
|
+
> *[DMing](https://en.wiktionary.org/wiki/DMing)([Dungeon Mastering](https://en.wiktionary.org/wiki/Dungeon_Mastering#English)): Performing as a dungeon master, or running a tabletop role-playing game, especially Dungeons & Dragons.*
|
|
23
|
+
|
|
24
|
+
## Installation
|
|
25
|
+
|
|
26
|
+
```sh
|
|
27
|
+
pipx install dming
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Usage
|
|
31
|
+
|
|
32
|
+
### Roll Dice
|
|
33
|
+
|
|
34
|
+
> [!WARNING]
|
|
35
|
+
> DMing supports part of the [Roll20 Dice Specification](https://help.roll20.net/hc/en-us/articles/360037773133-Dice-Reference).
|
|
36
|
+
|
|
37
|
+
Use the command `roll <dice>`.
|
|
38
|
+
|
|
39
|
+
Examples:
|
|
40
|
+
|
|
41
|
+
* `roll 1d20`: roll a d20 die
|
|
42
|
+
* `roll 1d100`: roll a d100 die
|
|
43
|
+
* `roll 2d20kh1`: roll with advantage
|
|
44
|
+
* `roll 2d20kl1`: roll with disadvantage
|
|
45
|
+
* `roll 2d20dl1`: roll with advantage
|
|
46
|
+
* `roll 2d20dh1`: roll with disadvantage
|
|
47
|
+
* `roll 1d20+4`: roll a d20 die with a +4 modifier
|
|
48
|
+
* `roll 1d20-4`: roll a d20 die with a -4 modifier
|
|
49
|
+
|
|
50
|
+
> [!NOTE]
|
|
51
|
+
> `kh`: keep highest \
|
|
52
|
+
> `kl`: keep lowest \
|
|
53
|
+
> `dh`: drop highest \
|
|
54
|
+
> `dl`: drop lowest
|
|
55
|
+
|
|
56
|
+
### Using the Library
|
|
57
|
+
|
|
58
|
+
<a href="https://pypi.org/project/dming"><img alt="PyPI - Version" src="https://img.shields.io/pypi/v/dming?label=dming"></a>
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
```python
|
|
62
|
+
from dming.dice import roll
|
|
63
|
+
|
|
64
|
+
operation, result = roll("1d20+2")
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Alternatives
|
|
68
|
+
|
|
69
|
+
* JavaScript: [Dice Roller & Parser](https://www.npmjs.com/package/dice-roller-parser).
|
|
70
|
+
|
|
71
|
+
## Development
|
|
72
|
+
|
|
73
|
+
Installing poetry:
|
|
74
|
+
|
|
75
|
+
```shell
|
|
76
|
+
pipx install poetry
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Installing development dependencies:
|
|
80
|
+
|
|
81
|
+
```shell
|
|
82
|
+
poetry install
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Run:
|
|
86
|
+
|
|
87
|
+
```shell
|
|
88
|
+
poetry run roll <dice>
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Release a new version
|
|
92
|
+
|
|
93
|
+
> Check https://python-poetry.org/docs/cli/#version
|
|
94
|
+
|
|
95
|
+
```shell
|
|
96
|
+
poetry run python -m scripts.bump --help
|
|
97
|
+
poetry run python -m scripts.bump <major|minor|patch>
|
|
98
|
+
```
|
|
99
|
+
|
dming-0.1.0/README.md
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# DMing
|
|
2
|
+
|
|
3
|
+
DMing is a CLI (command-line interface) collection useful when running a TTRPG (tabletop role-playing game).
|
|
4
|
+
|
|
5
|
+
> *[DMing](https://en.wiktionary.org/wiki/DMing)([Dungeon Mastering](https://en.wiktionary.org/wiki/Dungeon_Mastering#English)): Performing as a dungeon master, or running a tabletop role-playing game, especially Dungeons & Dragons.*
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
pipx install dming
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
### Roll Dice
|
|
16
|
+
|
|
17
|
+
> [!WARNING]
|
|
18
|
+
> DMing supports part of the [Roll20 Dice Specification](https://help.roll20.net/hc/en-us/articles/360037773133-Dice-Reference).
|
|
19
|
+
|
|
20
|
+
Use the command `roll <dice>`.
|
|
21
|
+
|
|
22
|
+
Examples:
|
|
23
|
+
|
|
24
|
+
* `roll 1d20`: roll a d20 die
|
|
25
|
+
* `roll 1d100`: roll a d100 die
|
|
26
|
+
* `roll 2d20kh1`: roll with advantage
|
|
27
|
+
* `roll 2d20kl1`: roll with disadvantage
|
|
28
|
+
* `roll 2d20dl1`: roll with advantage
|
|
29
|
+
* `roll 2d20dh1`: roll with disadvantage
|
|
30
|
+
* `roll 1d20+4`: roll a d20 die with a +4 modifier
|
|
31
|
+
* `roll 1d20-4`: roll a d20 die with a -4 modifier
|
|
32
|
+
|
|
33
|
+
> [!NOTE]
|
|
34
|
+
> `kh`: keep highest \
|
|
35
|
+
> `kl`: keep lowest \
|
|
36
|
+
> `dh`: drop highest \
|
|
37
|
+
> `dl`: drop lowest
|
|
38
|
+
|
|
39
|
+
### Using the Library
|
|
40
|
+
|
|
41
|
+
<a href="https://pypi.org/project/dming"><img alt="PyPI - Version" src="https://img.shields.io/pypi/v/dming?label=dming"></a>
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
```python
|
|
45
|
+
from dming.dice import roll
|
|
46
|
+
|
|
47
|
+
operation, result = roll("1d20+2")
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Alternatives
|
|
51
|
+
|
|
52
|
+
* JavaScript: [Dice Roller & Parser](https://www.npmjs.com/package/dice-roller-parser).
|
|
53
|
+
|
|
54
|
+
## Development
|
|
55
|
+
|
|
56
|
+
Installing poetry:
|
|
57
|
+
|
|
58
|
+
```shell
|
|
59
|
+
pipx install poetry
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Installing development dependencies:
|
|
63
|
+
|
|
64
|
+
```shell
|
|
65
|
+
poetry install
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Run:
|
|
69
|
+
|
|
70
|
+
```shell
|
|
71
|
+
poetry run roll <dice>
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Release a new version
|
|
75
|
+
|
|
76
|
+
> Check https://python-poetry.org/docs/cli/#version
|
|
77
|
+
|
|
78
|
+
```shell
|
|
79
|
+
poetry run python -m scripts.bump --help
|
|
80
|
+
poetry run python -m scripts.bump <major|minor|patch>
|
|
81
|
+
```
|
dming-0.1.0/dming/cli.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import click
|
|
2
|
+
|
|
3
|
+
from dming.dice import roll
|
|
4
|
+
from dming import __version__
|
|
5
|
+
|
|
6
|
+
from rich.console import Console
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@click.command()
|
|
10
|
+
@click.argument("dice")
|
|
11
|
+
@click.option(
|
|
12
|
+
"-v", "verbose", help="Verbose output. Show the arithmetic operation.", is_flag=True
|
|
13
|
+
)
|
|
14
|
+
@click.version_option(__version__)
|
|
15
|
+
def _roll(dice: str, verbose: bool) -> None:
|
|
16
|
+
"""
|
|
17
|
+
Allows you to roll dice from your terminal.
|
|
18
|
+
|
|
19
|
+
\b
|
|
20
|
+
Examples:
|
|
21
|
+
roll 1d20 # roll a d20 die
|
|
22
|
+
roll 1d100 # roll a d100 die
|
|
23
|
+
roll 2d20kh1 # roll with advantage
|
|
24
|
+
roll 2d20kl1 # roll with disadvantage
|
|
25
|
+
roll 2d20dl1 # roll with advantage
|
|
26
|
+
roll 2d20dh1 # roll with disadvantage
|
|
27
|
+
roll 1d20+4 # roll a d20 die with a +4 modifier
|
|
28
|
+
roll 1d20-4 # roll a d20 die with a -4 modifier
|
|
29
|
+
"""
|
|
30
|
+
try:
|
|
31
|
+
operation, result = roll(dice)
|
|
32
|
+
if verbose:
|
|
33
|
+
console = Console()
|
|
34
|
+
console.print(f"{operation}={result}")
|
|
35
|
+
else:
|
|
36
|
+
print(f"{result}")
|
|
37
|
+
except Exception as e:
|
|
38
|
+
print(f"Invalid operation: {e}")
|
|
39
|
+
exit(-1)
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import re
|
|
2
|
+
import random
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def kh(n: int, dice: list[int]) -> list[int]:
|
|
6
|
+
return sorted(dice, reverse=True)[:n]
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def kl(n: int, dice: list[int]) -> list[int]:
|
|
10
|
+
return sorted(dice)[:n]
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def dh(n: int, dice: list[int]) -> list[int]:
|
|
14
|
+
return sorted(dice, reverse=True)[n:]
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def dl(n: int, dice: list[int]) -> list[int]:
|
|
18
|
+
return sorted(dice)[n:]
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
FILTERS = {"kh": kh, "kl": kl, "dh": dh, "dl": dl}
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def roll(dice: str) -> tuple[str, int]:
|
|
25
|
+
def replacer(expression: re.Match[str]):
|
|
26
|
+
total, die, filter, total_keep = expression.groups()
|
|
27
|
+
dice = [random.randint(1, int(die)) for _ in range(int(total) if total else 1)]
|
|
28
|
+
filtered_dice = (
|
|
29
|
+
FILTERS[filter](int(total_keep) if total_keep else 1, dice)
|
|
30
|
+
if filter
|
|
31
|
+
else dice
|
|
32
|
+
)
|
|
33
|
+
return str(sum(filtered_dice))
|
|
34
|
+
|
|
35
|
+
operation = re.sub(r"(\d+)?d(\d+)(kh|kl|dh|dl)?(\d+)?", replacer, dice)
|
|
36
|
+
|
|
37
|
+
if not re.match(r"^[0-9+-]+$", operation):
|
|
38
|
+
raise Exception("not allowed characters")
|
|
39
|
+
|
|
40
|
+
return operation, eval(operation)
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "dming"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "DMing is a CLI (command-line interface) collection useful when running a TTRPG (tabletop role-playing games)."
|
|
5
|
+
authors = [
|
|
6
|
+
{name = "Saúl Piña",email = "sauljabin@gmail.com"}
|
|
7
|
+
]
|
|
8
|
+
classifiers = [
|
|
9
|
+
"License :: OSI Approved :: MIT License",
|
|
10
|
+
"Environment :: Console",
|
|
11
|
+
"Operating System :: MacOS",
|
|
12
|
+
"Operating System :: Unix",
|
|
13
|
+
"Programming Language :: Python :: 3.13",
|
|
14
|
+
]
|
|
15
|
+
license = {text = "MIT"}
|
|
16
|
+
readme = "README.md"
|
|
17
|
+
requires-python = ">=3.13,<3.14"
|
|
18
|
+
dependencies = [
|
|
19
|
+
"click (>=8.2.1,<9.0.0)",
|
|
20
|
+
"rich (>=14.1.0,<15.0.0)"
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
[tool.ruff]
|
|
24
|
+
line-length = 88
|
|
25
|
+
indent-width = 4
|
|
26
|
+
|
|
27
|
+
[project.scripts]
|
|
28
|
+
roll = "dming.cli:_roll"
|
|
29
|
+
|
|
30
|
+
[build-system]
|
|
31
|
+
requires = ["poetry-core>=2.0.0,<3.0.0"]
|
|
32
|
+
build-backend = "poetry.core.masonry.api"
|
|
33
|
+
|
|
34
|
+
[tool.poetry.group.dev.dependencies]
|
|
35
|
+
faker = "*"
|