2020-03-16 22:21:24 +00:00
|
|
|
import abc
|
|
|
|
from typing import *
|
|
|
|
import royalnet
|
|
|
|
import royalnet.commands as rc
|
|
|
|
import royalnet.utils as ru
|
|
|
|
from ...tables import DndBattleUnit
|
|
|
|
from ...utils import get_targets
|
|
|
|
|
|
|
|
|
|
|
|
class DndBattleTargetCommand(rc.Command, abc.ABC):
|
|
|
|
@abc.abstractmethod
|
|
|
|
async def _change(self, unit: DndBattleUnit, args: List[str]):
|
2020-09-16 00:37:31 +00:00
|
|
|
raise NotImplementedError()
|
2020-03-16 22:21:24 +00:00
|
|
|
|
|
|
|
async def run(self, args: rc.CommandArgs, data: rc.CommandData) -> None:
|
|
|
|
target = args[0]
|
|
|
|
|
2020-09-16 00:37:31 +00:00
|
|
|
async with data.session_acm() as session:
|
|
|
|
units = await get_targets(target, data=data, session=session)
|
|
|
|
if len(units) == 0:
|
|
|
|
raise rc.InvalidInputError(f"No targets found matching [c]{target}[/c].")
|
2020-03-16 22:21:24 +00:00
|
|
|
|
2020-09-16 00:37:31 +00:00
|
|
|
for unit in units:
|
|
|
|
await self._change(unit, args[1:])
|
2020-03-16 22:21:24 +00:00
|
|
|
|
2020-09-16 00:37:31 +00:00
|
|
|
await session.commit()
|
2020-03-16 22:21:24 +00:00
|
|
|
|
2020-09-16 00:37:31 +00:00
|
|
|
message = []
|
|
|
|
for unit in units:
|
|
|
|
message.append(f"{unit}")
|
|
|
|
|
|
|
|
await data.reply("\n\n".join(message))
|