From c7d320ccaa351c383968330faf21dda696ac4958 Mon Sep 17 00:00:00 2001 From: bobloy Date: Tue, 29 Sep 2020 12:41:26 -0400 Subject: [PATCH] WIP Player converter --- werewolf/converters.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 werewolf/converters.py diff --git a/werewolf/converters.py b/werewolf/converters.py new file mode 100644 index 0000000..376749d --- /dev/null +++ b/werewolf/converters.py @@ -0,0 +1,28 @@ +from typing import TYPE_CHECKING, Union + +import discord +from discord.ext.commands import BadArgument, Converter +from redbot.core import commands + +from werewolf.player import Player + +if TYPE_CHECKING: + PlayerConverter = Union[int, discord.Member] + CronConverter = str +else: + + class PlayerConverter(Converter): + async def convert(self, ctx, argument) -> Player: + + try: + target = await commands.MemberConverter().convert(ctx, argument) + except BadArgument: + try: + target = int(argument) + assert target >= 0 + except (ValueError, AssertionError): + raise BadArgument + + # TODO: Get the game for context without making a new one + # TODO: Get player from game based on either ID or member object + return target \ No newline at end of file