1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-23 19:44:20 +00:00
royalnet/royalpack/commands/roll.py

50 lines
1.1 KiB
Python
Raw Normal View History

2022-08-13 14:29:18 +00:00
from email import message
import datetime
import random
import re
import royalnet.engineer as engi
import royalpack.bolts as rb
@rb.capture_errors
@engi.TeleportingConversation
2022-08-15 01:14:51 +00:00
async def roll(*, _msg: engi.Message, qty: int, die: int, mod: int, **__):
2022-08-13 14:29:18 +00:00
"""
2022-08-15 01:14:51 +00:00
Tira un dado nel formato di D&D: `1d20+1`, ad esempio.
2022-08-13 14:29:18 +00:00
"""
# modificatore supersegreto della fortuna. Ooooh! Questo è Top Secret!
2022-08-15 01:14:51 +00:00
# Steffo: hol up
2022-08-13 14:29:18 +00:00
r = random.Random(x=hash(datetime.date.today()))
luck = r.randrange(-100, 100)/100*die/3
2022-08-15 01:14:51 +00:00
2022-08-13 14:29:18 +00:00
random.seed(datetime.datetime.now())
# rolliamo i dadi richiesti
roll = []
for i in range(quantity):
extracted = random.randint(1, die)
result = int(round(extracted+luck, 0))
result = min(result, die)
result = max(result, 1)
roll.append(result)
# formuliamo una risposta da mostrare all'utente
2022-08-15 01:14:51 +00:00
answer = f"🎲 {qty}d{die}{mod:+} = {roll}"
if mod:
2022-08-13 14:29:18 +00:00
answer +=" "
2022-08-15 01:14:51 +00:00
if mod > 0:
2022-08-13 14:29:18 +00:00
answer += "+"
2022-08-15 01:14:51 +00:00
answer +=str(mod)
2022-08-13 14:29:18 +00:00
2022-08-15 01:14:51 +00:00
answer += " = "+str(sum(roll)+mod)
2022-08-13 14:29:18 +00:00
await _msg.reply(text=answer)
__all__ = ("roll",)