mirror of
https://github.com/Xevion/unbelievaselfbot.git
synced 2025-12-14 14:13:34 -06:00
begin working on blackjack automation, card processing
This commit is contained in:
@@ -44,6 +44,8 @@ class UnbelievaClient(discord.Client):
|
|||||||
self.last_deposit = -1
|
self.last_deposit = -1
|
||||||
self.last_user_deposit = -1
|
self.last_user_deposit = -1
|
||||||
|
|
||||||
|
self.current_blackjack: Optional[discord.Message] = None
|
||||||
|
|
||||||
async def on_ready(self):
|
async def on_ready(self):
|
||||||
await self.wait_until_ready()
|
await self.wait_until_ready()
|
||||||
self.channel: discord.TextChannel = self.get_channel(self.channel_id)
|
self.channel: discord.TextChannel = self.get_channel(self.channel_id)
|
||||||
@@ -51,6 +53,8 @@ class UnbelievaClient(discord.Client):
|
|||||||
self.check_task_available.start()
|
self.check_task_available.start()
|
||||||
logger.info(f'Connected to #{self.channel.name} in {self.channel.guild.name}')
|
logger.info(f'Connected to #{self.channel.name} in {self.channel.guild.name}')
|
||||||
|
|
||||||
|
def get_epoch(self, dt: datetime) -> float:
|
||||||
|
return (dt - datetime(1970, 1, 1)).total_seconds()
|
||||||
|
|
||||||
async def on_message(self, message: discord.Message):
|
async def on_message(self, message: discord.Message):
|
||||||
if message.channel == self.channel:
|
if message.channel == self.channel:
|
||||||
@@ -75,6 +79,56 @@ class UnbelievaClient(discord.Client):
|
|||||||
self.money += change
|
self.money += change
|
||||||
logger.info(f'Gained ${change}')
|
logger.info(f'Gained ${change}')
|
||||||
|
|
||||||
|
# Handling for blackjack
|
||||||
|
if embed.description.startswith('Type `hit` to draw another card'):
|
||||||
|
options = self.parse_options(embed.description)
|
||||||
|
my_cards = self.parse_cards(embed.fields[0])
|
||||||
|
dealer_cards = self.parse_cards(embed.fields[1])
|
||||||
|
print(options, my_cards, dealer_cards)
|
||||||
|
# self.current_blackjack = message
|
||||||
|
|
||||||
|
def parse_options(self, options_str: str) -> Tuple[bool, bool, bool, bool]:
|
||||||
|
"""
|
||||||
|
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
|
||||||
|
)
|
||||||
|
|
||||||
|
def parse_cards(self, card_str: discord.embeds.EmbedProxy) -> Tuple[str, Optional[str], Tuple[int, bool]]:
|
||||||
|
"""
|
||||||
|
Parses a Embed Proxy
|
||||||
|
|
||||||
|
:param card_str:
|
||||||
|
:return: [Card1, Card2?, [Value, isSoft]]
|
||||||
|
"""
|
||||||
|
emote_pattern = r'<:([A-z0-9]+):\d+>'
|
||||||
|
value_pattern = r'Value: (Soft )?(\d+)'
|
||||||
|
cards = list(re.finditer(emote_pattern, card_str.value))
|
||||||
|
value = re.search(value_pattern, card_str.value)
|
||||||
|
# pprint(card_str.value)
|
||||||
|
# print(cards, [card.groups() for card in cards])
|
||||||
|
# print(value, value.groups())
|
||||||
|
|
||||||
|
c1: str
|
||||||
|
c2: Optional[str]
|
||||||
|
c1, c2 = cards[0].group(1), cards[1].group(1)
|
||||||
|
c2 = c2 if c2 != 'cardBack' else None
|
||||||
|
|
||||||
|
return c1, c2, (int(value.group(2)), value.groups()[1] is None)
|
||||||
|
|
||||||
|
def handle_blackjack(self):
|
||||||
|
embed = self.current_blackjack.embeds[0]
|
||||||
|
options = self.parse_options(embed.description)
|
||||||
|
my_cards = self.parse_cards(embed.fields[0])
|
||||||
|
dealer_cards = self.parse_cards(embed.fields[1])
|
||||||
|
print(options, my_cards, dealer_cards)
|
||||||
|
pass
|
||||||
|
|
||||||
def handle_task_wait(self, match: re.Match):
|
def handle_task_wait(self, match: re.Match):
|
||||||
task_command = self.task_parsings[match.group(1)]
|
task_command = self.task_parsings[match.group(1)]
|
||||||
duration_match = re.match(
|
duration_match = re.match(
|
||||||
@@ -115,6 +169,9 @@ class UnbelievaClient(discord.Client):
|
|||||||
self.last_message = time.time()
|
self.last_message = time.time()
|
||||||
self.last_deposit = time.time()
|
self.last_deposit = time.time()
|
||||||
|
|
||||||
|
if self.current_blackjack is not None:
|
||||||
|
self.handle_blackjack()
|
||||||
|
|
||||||
async def command_sleep(self):
|
async def command_sleep(self):
|
||||||
"""Sleep right before sending a command."""
|
"""Sleep right before sending a command."""
|
||||||
now = time.time()
|
now = time.time()
|
||||||
|
|||||||
Reference in New Issue
Block a user