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
2019-12-04 01:47:00 +01:00

33 lines
954 B
Python

import re
from royalnet.commands import *
from .dndnew import DndnewCommand
from ..tables import DndCharacter
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()
if character_sheet == "":
await data.reply(self._syntax())
return
author = await data.get_author(error_if_none=True)
if author.dnd_active_character is None:
raise CommandError("You don't have an active character.")
char: DndCharacter = author.dnd_active_character.character
arguments = self._parse(character_sheet)
for key in arguments:
char.__setattr__(key, arguments[key])
await data.session_commit()
await data.reply(f"✅ Edit successful!")