forked from paqul/MinionBot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathformatters.py
More file actions
32 lines (22 loc) · 1.12 KB
/
formatters.py
File metadata and controls
32 lines (22 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from __future__ import annotations
from typing import Union
from rolls import RollResult, apologize_message
def _format_number(value: Union[int, float]) -> str:
if isinstance(value, float) and value.is_integer():
return str(int(value))
return str(value)
def format_roll_result(result: RollResult) -> str:
if result.error:
return result.error
if result.total is not None:
total_value = _format_number(result.total)
if result.equation is not None:
return f"({result.author_mention} k{result.dice}) | ***Wynik: {total_value}*** | **Rzuty: {result.rolls}**"
return f"({result.author_mention} k{result.dice}) | ***Suma: {total_value}*** | **Rzuty: {result.rolls}**"
if result.dice_type is not None:
if result.bonus in ("p", "k"):
return f"({result.author_mention} [k{result.dice}, *{result.dice_type}*]): **{result.rolls}**"
return f"({result.author_mention} [*{result.dice_type}*]): **{result.rolls}**"
if result.dice is not None:
return f"({result.author_mention} k{result.dice}): **{result.rolls}**"
return apologize_message