diff --git a/bot/client.py b/bot/client.py index 53be535..c4b6bd3 100644 --- a/bot/client.py +++ b/bot/client.py @@ -87,17 +87,14 @@ class UnbelievaClient(discord.Client): print(options, my_cards, dealer_cards) # self.current_blackjack = message - def parse_options(self, options_str: str) -> Tuple[bool, bool, bool, bool]: + def parse_options(self, options_str: str) -> PlayOptions: """ Return a tuple of booleans describing what the player can do. Tuple Options: [hit, stand, double_down, split] """ - return ( - '`hit`' in options_str, - '`stand`' in options_str, - '`double down`' in options_str, - '`split`' in options_str - ) + options = [f'`{sub}`' in options_str for sub in ['hit', 'stand', 'double down', 'split']] + # noinspection PyProtectedMember + return PlayOptions._make(options) def parse_cards(self, card_str: discord.embeds.EmbedProxy) -> Tuple[str, Optional[str], Tuple[int, bool]]: """ diff --git a/bot/constants.py b/bot/constants.py new file mode 100644 index 0000000..cc522e7 --- /dev/null +++ b/bot/constants.py @@ -0,0 +1,3 @@ +from collections import namedtuple + +PlayOptions = namedtuple('PlayOptions', ['hit', 'stand', 'double', 'split']) diff --git a/bot/exceptions.py b/bot/exceptions.py index c1ab4d1..2faf47b 100644 --- a/bot/exceptions.py +++ b/bot/exceptions.py @@ -12,3 +12,11 @@ class NoAceValue(BlackjackException): class IndetermineValue(BlackjackException): pass + + +class InvalidCard(BlackjackException): + pass + + +class CooldownRequired(UnbelievableException): + pass diff --git a/bot/parsers.py b/bot/parsers.py index 5611d96..2097c53 100644 --- a/bot/parsers.py +++ b/bot/parsers.py @@ -35,8 +35,8 @@ class EmbedMessage(BaseMessage, ABC): class TaskCooldownMessage(EmbedMessage): - COOLDOWN_REGEX = r'You cannot (work|be a slut|commit a crime) for ([\w\s]+)\.' - DURATION_REGEX = r'(\d+) (hour|minute|second)s?(?: and (\d+) (hour|minute|second)s?)?' + COOLDOWN_REGEX = re.compile(r'You cannot (work|be a slut|commit a crime) for ([\w\s]+)\.') + DURATION_REGEX = re.compile(r'(\d+) (hour|minute|second)s?(?: and (\d+) (hour|minute|second)s?)?') DELAY = 2 durations = {'hour': 3600, 'minute': 60, 'second': 1} @@ -60,16 +60,19 @@ class TaskCooldownMessage(EmbedMessage): class TaskResponse(EmbedMessage): + MONEY_REGEX = re.compile(r'\$([0-9,]+)') + def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) - self.change = 0 - money_match = re.search(r'\$([0-9,]+)', self.embed.description) + self.change = 0 + money_match = re.search(r'', self.embed.description) if money_match and 'deposited' not in self.embed.description.lower(): change = int(money_match.group(1).replace(',', '')) if self.embed.colour.value == 6732650: self.change += change - # logger.info(f'Gained ${change}') + logger.info(f'{self.message.author} Gained ${change}') if self.embed.colour.value == 15684432: self.change -= change + logger.info(f'{self.message.author} Lost ${change}') # logger.info(f'Lost ${change}')