1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-23 03:24:20 +00:00

Royalnetify a bit the code

This commit is contained in:
Steffo 2022-08-15 01:14:51 +00:00 committed by Stefano Pigozzi
parent fb5ee419b7
commit 7e704dd6b9
2 changed files with 10 additions and 33 deletions

View file

@ -111,7 +111,7 @@ register_telegram(tg_router, commands.fiorygi_bury, ["bury"],
register_telegram(tg_router, commands.version, ["version"]) register_telegram(tg_router, commands.version, ["version"])
register_telegram(tg_router, commands.cv, ["cv", "civù"]) register_telegram(tg_router, commands.cv, ["cv", "civù"])
register_telegram(tg_router, commands.rocoinflip, ["rocoinflip"], r'"(?P<teama>[^"]+)"\s+"(?P<teamb>[^"]+)"') register_telegram(tg_router, commands.rocoinflip, ["rocoinflip"], r'"(?P<teama>[^"]+)"\s+"(?P<teamb>[^"]+)"')
register_telegram(tg_router, commands.roll, ["roll"], r"(?P<message>.+)") register_telegram(tg_router, commands.roll, ["roll"], r"(?P<qty>[0-9]*)d(?P<die>[0-9]+)(?P<mod>[+-][0-9]+)")
register_telegram(tg_router, commands.diobot, ["diobot", "phrase"]) register_telegram(tg_router, commands.diobot, ["diobot", "phrase"])
register_telegram(tg_router, commands.loginprogress, ["loginprogress"]) register_telegram(tg_router, commands.loginprogress, ["loginprogress"])

View file

@ -10,38 +10,16 @@ import royalpack.bolts as rb
@rb.capture_errors @rb.capture_errors
@engi.TeleportingConversation @engi.TeleportingConversation
async def roll(*, _msg: engi.Message, message: str, **__): async def roll(*, _msg: engi.Message, qty: int, die: int, mod: int, **__):
""" """
Tira un dado Tira un dado nel formato di D&D: `1d20+1`, ad esempio.
""" """
if not re.match("[0-9]*d[0-9]+(\+[0-9])?(\-[0-9])?", message):
await _msg.reply(text="❗️ Errore: la stringa deve rispettare il pattern [quantity]d[die][modifier]")
# quantità di dadi
quantity, die = message.split('d')
if(message[0] =='d'):
quantity = 1
# modificatore
if '+' in message or '-' in message:
if '+' in message:
die, modifier = die.split('+')
else:
die, modifier = die.split('-')
modifier = '-'+ modifier
else:
modifier = 0
# rendiamo tutto un int, se non lo è già
quantity = int(quantity)
die = int(die)
modifier = int(modifier)
# modificatore supersegreto della fortuna. Ooooh! Questo è Top Secret! # modificatore supersegreto della fortuna. Ooooh! Questo è Top Secret!
# Steffo: hol up
r = random.Random(x=hash(datetime.date.today())) r = random.Random(x=hash(datetime.date.today()))
luck = r.randrange(-100, 100)/100*die/3 luck = r.randrange(-100, 100)/100*die/3
random.seed(datetime.datetime.now()) random.seed(datetime.datetime.now())
# rolliamo i dadi richiesti # rolliamo i dadi richiesti
@ -56,15 +34,14 @@ async def roll(*, _msg: engi.Message, message: str, **__):
roll.append(result) roll.append(result)
# formuliamo una risposta da mostrare all'utente # formuliamo una risposta da mostrare all'utente
answer = "🎲 " + message + " = " answer = f"🎲 {qty}d{die}{mod:+} = {roll}"
answer += str(roll) if mod:
if modifier:
answer +=" " answer +=" "
if modifier > 0: if mod > 0:
answer += "+" answer += "+"
answer +=str(modifier) answer +=str(mod)
answer += " = "+str(sum(roll)+modifier) answer += " = "+str(sum(roll)+mod)
await _msg.reply(text=answer) await _msg.reply(text=answer)