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

37 lines
1.1 KiB
Python
Raw Normal View History

2019-11-11 09:34:05 +00:00
import re
from royalnet.commands import *
2020-09-16 00:37:31 +00:00
import royalnet.utils as ru
2019-11-11 09:34:05 +00:00
from .dndnew import DndnewCommand
2019-12-04 00:47:00 +00:00
from ..tables import DndCharacter
2020-02-18 13:48:21 +00:00
from ..utils import get_active_character
2019-11-11 09:34:05 +00:00
class DndeditCommand(DndnewCommand):
name: str = "dndedit"
description: str = "Edit the active DnD character."
aliases = ["de", "dnde", "edit", "dedit"]
async def run(self, args: CommandArgs, data: CommandData) -> None:
character_sheet = args.joined()
2020-09-16 00:37:31 +00:00
async with data.session_acm() as session:
active_character = await get_active_character(session=session, data=data)
2020-03-16 19:03:49 +00:00
2020-09-16 00:37:31 +00:00
if active_character is None:
raise CommandError("You don't have an active character.")
char: DndCharacter = active_character.character
2020-03-16 19:03:49 +00:00
2020-09-16 00:37:31 +00:00
if character_sheet == "":
await data.reply(char.to_edit_string())
return
2019-11-11 09:34:05 +00:00
2020-09-16 00:37:31 +00:00
arguments = self._parse(character_sheet)
for key in arguments:
char.__setattr__(key, arguments[key])
2019-11-11 09:34:05 +00:00
2020-09-16 00:37:31 +00:00
await ru.asyncify(session.commit)
2019-11-11 09:34:05 +00:00
2020-09-16 00:37:31 +00:00
await data.reply(f"✅ Edit successful!")