mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-27 13:34:28 +00:00
Create a new and better roll!
This commit is contained in:
parent
33a31b69a1
commit
df1c30eca8
2 changed files with 50 additions and 9 deletions
26
strings.py
26
strings.py
|
@ -1,4 +1,5 @@
|
|||
from db import MatchmakingStatus
|
||||
import dice
|
||||
import typing
|
||||
|
||||
|
||||
|
@ -151,8 +152,31 @@ class MATCHMAKING:
|
|||
class ROLL:
|
||||
SUCCESS = "🎲 {result}"
|
||||
|
||||
SYMBOLS = {
|
||||
dice.elements.Div: "/",
|
||||
dice.elements.Mul: "*",
|
||||
dice.elements.Sub: "-",
|
||||
dice.elements.Add: "+",
|
||||
dice.elements.Modulo: "%",
|
||||
dice.elements.AddEvenSubOdd: "+-",
|
||||
dice.elements.Highest: "h",
|
||||
dice.elements.Lowest: "l",
|
||||
dice.elements.Middle: "m",
|
||||
dice.elements.Again: "a",
|
||||
dice.elements.Successes: "e",
|
||||
dice.elements.SuccessFail: "f",
|
||||
dice.elements.ArrayAdd: ".+",
|
||||
dice.elements.ArraySub: ".-",
|
||||
dice.elements.Array: ",",
|
||||
dice.elements.Extend: "|",
|
||||
dice.elements.Reroll: "r",
|
||||
dice.elements.Explode: "x",
|
||||
dice.elements.ForceReroll: "rr"
|
||||
}
|
||||
|
||||
class ERRORS:
|
||||
INVALID_SYNTAX = "⚠ Il tiro dei dadi è fallito. Controlla la sintassi!"
|
||||
INVALID_SYNTAX = "⚠ Sintassi del tiro di dadi non valida."
|
||||
DICE_ERROR = "⚠ Il tiro di dadi è fallito."
|
||||
|
||||
|
||||
# Ship creator
|
||||
|
|
|
@ -85,9 +85,6 @@ def command(func: "function"):
|
|||
except TimedOut:
|
||||
logger.warning(f"Telegram timed out in {update}")
|
||||
except Exception:
|
||||
# noinspection PyUnreachableCode
|
||||
if __debug__:
|
||||
raise
|
||||
logger.error(f"Critical error: {sys.exc_info()}")
|
||||
# noinspection PyBroadException
|
||||
try:
|
||||
|
@ -117,9 +114,6 @@ def database_access(func: "function"):
|
|||
session = db.Session()
|
||||
return func(bot, update, session)
|
||||
except Exception:
|
||||
# noinspection PyUnreachableCode
|
||||
if __debug__:
|
||||
raise
|
||||
logger.error(f"Database error: {sys.exc_info()}")
|
||||
sentry.captureException()
|
||||
finally:
|
||||
|
@ -708,15 +702,38 @@ def cmd_markov(bot: telegram.Bot, update: telegram.Update):
|
|||
reply(bot, update, sentence)
|
||||
|
||||
|
||||
def exec_roll(roll) -> str:
|
||||
result = int(roll.evaluate())
|
||||
string = ""
|
||||
if isinstance(roll, dice.elements.Dice):
|
||||
string += f"<b>{result}</b>"
|
||||
else:
|
||||
for index, operand in enumerate(roll.original_operands):
|
||||
if operand != roll.operands[index]:
|
||||
string += f"<i>{roll.operands[index]}</i>"
|
||||
else:
|
||||
string += f"{operand}"
|
||||
if index + 1 != len(roll.original_operands):
|
||||
|
||||
string += strings.ROLL.SYMBOLS[roll.__class__]
|
||||
string += f"=<b>{result}</b>"
|
||||
return string
|
||||
|
||||
|
||||
@command
|
||||
def cmd_roll(bot: telegram.Bot, update: telegram.Update):
|
||||
dice_string = update.message.text.split(" ", 1)[1]
|
||||
try:
|
||||
result = dice.roll(f"{dice_string}t")
|
||||
roll = dice.roll(f"{dice_string}", raw=True)
|
||||
except dice.DiceBaseException:
|
||||
reply(bot, update, strings.ROLL.ERRORS.INVALID_SYNTAX)
|
||||
return
|
||||
reply(bot, update, strings.ROLL.SUCCESS, result=result)
|
||||
try:
|
||||
result = exec_roll(roll)
|
||||
except dice.DiceFatalException:
|
||||
reply(bot, update, strings.ROLL.ERRORS.DICE_ERROR)
|
||||
return
|
||||
reply(bot, update, strings.ROLL.SUCCESS, result=result, ignore_escaping=True)
|
||||
|
||||
|
||||
@command
|
||||
|
|
Loading…
Reference in a new issue