Update transactions.py

Clean up transaction failures
This commit is contained in:
Cal Corum 2024-10-05 22:27:18 -05:00
parent e7d73470d1
commit 701a8b78d4

View File

@ -817,9 +817,8 @@ class Transactions(commands.Cog):
await trade.timed_delete() await trade.timed_delete()
return return
else: else:
try:
next_team = await get_team_by_abbrev(resp, current['season']) next_team = await get_team_by_abbrev(resp, current['season'])
except ValueError: if next_team is None:
await trade.send('Who the fuck even is that? Try again.') await trade.send('Who the fuck even is that? Try again.')
else: else:
next_team_role = get_team_role(ctx, next_team) next_team_role = get_team_role(ctx, next_team)
@ -853,14 +852,12 @@ class Transactions(commands.Cog):
current['season'], current['season'],
await fuzzy_player_search(ctx, trade.channel, self.bot, resp, player_cog.player_list.keys()) await fuzzy_player_search(ctx, trade.channel, self.bot, resp, player_cog.player_list.keys())
) )
except ValueError: except ValueError as e:
logging.error(f'Could not find player *{resp}*')
else:
if player is None:
await trade.send(f'{await get_emoji(ctx, "squint")}') await trade.send(f'{await get_emoji(ctx, "squint")}')
await trade.send('Who even is that? Try again.') await trade.send('Who even is that? Try again.')
except requests.ReadTimeout:
await trade.send(
f'I\'m dumb and couldn\'t read from the database fast enough. '
f'{await get_emoji(ctx, "dead")} Let\'s try that again.'
)
else: else:
# Check that player is on one of the teams # Check that player is on one of the teams
# Check that the player hasn't been dropped (IL is okay) # Check that the player hasn't been dropped (IL is okay)
@ -877,9 +874,8 @@ class Transactions(commands.Cog):
await trade.send('RIP this move. Maybe next time.') await trade.send('RIP this move. Maybe next time.')
await trade.timed_delete() await trade.timed_delete()
else: else:
try:
dest_team = await get_team_by_abbrev(resp, current['season']) dest_team = await get_team_by_abbrev(resp, current['season'])
except ValueError: if dest_team is None:
await trade.send(f'{await get_emoji(ctx, "facepalm")} They aren\'t even part of ' await trade.send(f'{await get_emoji(ctx, "facepalm")} They aren\'t even part of '
f'this trade. Come on.') f'this trade. Come on.')
else: else:
@ -1004,17 +1000,14 @@ class Transactions(commands.Cog):
try: try:
player = await get_player_by_name( player = await get_player_by_name(
current['season'], current['season'],
await fuzzy_player_search(ctx, trade.channel, self.bot, resp, await fuzzy_player_search(ctx, trade.channel, self.bot, resp, player_cog.player_list.keys())
player_cog.player_list.keys())
) )
except ValueError: except ValueError as e:
logging.error(f'Could not find player *{resp}*')
else:
if player is None:
await trade.send(f'{await get_emoji(ctx, "squint")}') await trade.send(f'{await get_emoji(ctx, "squint")}')
await trade.send('Who even is that? Try again.') await trade.send('Who even is that? Try again.')
except requests.ReadTimeout:
await trade.send(
f'I\'m dumb and couldn\'t read from the database fast enough. '
f'{await get_emoji(ctx, "dead")} Let\'s try that again.'
)
else: else:
if not trade.included_team(player['team']): if not trade.included_team(player['team']):
await t_channel.send(f'It looks like {player.name} is on {player.team.abbrev} ' await t_channel.send(f'It looks like {player.name} is on {player.team.abbrev} '
@ -1377,17 +1370,14 @@ class Transactions(commands.Cog):
try: try:
player = await get_player_by_name( player = await get_player_by_name(
current['season'], current['season'],
await fuzzy_player_search(ctx, dropadd.channel, self.bot, resp, await fuzzy_player_search(ctx, dropadd.channel, self.bot, resp, player_cog.player_list.keys())
player_cog.player_list.keys())
) )
except ValueError: except ValueError as e:
logging.error(f'Could not find player *{resp}*')
else:
if player is None:
await dropadd.send(f'{await get_emoji(ctx, "squint")}') await dropadd.send(f'{await get_emoji(ctx, "squint")}')
await dropadd.send('Who even is that? Try again.') await dropadd.send('Who even is that? Try again.')
except requests.ReadTimeout:
await dropadd.send(
f'I\'m dumb and couldn\'t read from the database fast enough. '
f'{await get_emoji(ctx, "dead")} Let\'s try that again.'
)
else: else:
fa_team = await get_team_by_abbrev('FA', current['season']) fa_team = await get_team_by_abbrev('FA', current['season'])
dest_team = await get_team_by_abbrev(f'{team["abbrev"]}MiL', current['season']) dest_team = await get_team_by_abbrev(f'{team["abbrev"]}MiL', current['season'])
@ -1431,17 +1421,14 @@ class Transactions(commands.Cog):
try: try:
player = await get_player_by_name( player = await get_player_by_name(
current['season'], current['season'],
await fuzzy_player_search(ctx, dropadd.channel, self.bot, resp, await fuzzy_player_search(ctx, dropadd.channel, self.bot, resp, player_cog.player_list.keys())
player_cog.player_list.keys())
) )
except ValueError: except ValueError as e:
logging.error(f'Could not find player *{resp}*')
else:
if player is None:
await dropadd.send(f'{await get_emoji(ctx, "squint")}') await dropadd.send(f'{await get_emoji(ctx, "squint")}')
await dropadd.send('Who even is that? Try again.') await dropadd.send('Who even is that? Try again.')
except requests.ReadTimeout:
await dropadd.send(
f'I\'m dumb and couldn\'t read from the database fast enough. '
f'{await get_emoji(ctx, "dead")} Let\'s try that again.'
)
else: else:
if OFFSEASON_FLAG: if OFFSEASON_FLAG:
if not self.on_team_il(team, player): if not self.on_team_il(team, player):
@ -1492,17 +1479,14 @@ class Transactions(commands.Cog):
try: try:
player = await get_player_by_name( player = await get_player_by_name(
current['season'], current['season'],
await fuzzy_player_search(ctx, dropadd.channel, self.bot, resp, await fuzzy_player_search(ctx, dropadd.channel, self.bot, resp, player_cog.player_list.keys())
player_cog.player_list.keys())
) )
except ValueError: except ValueError as e:
logging.error(f'Could not find player *{resp}*')
else:
if player is None:
await dropadd.send(f'{await get_emoji(ctx, "squint")}') await dropadd.send(f'{await get_emoji(ctx, "squint")}')
await dropadd.send('Who even is that? Try again.') await dropadd.send('Who even is that? Try again.')
except requests.ReadTimeout:
await dropadd.send(
f'I\'m dumb and couldn\'t read from the database fast enough. '
f'{await get_emoji(ctx, "dead")} Let\'s try that again.'
)
else: else:
if not dropadd.included_team(player['team']): if not dropadd.included_team(player['team']):
await t_channel.send(f'It looks like {player["name"]} is on {player["team"]["abbrev"]} ' await t_channel.send(f'It looks like {player["name"]} is on {player["team"]["abbrev"]} '
@ -1653,17 +1637,14 @@ class Transactions(commands.Cog):
try: try:
player = await get_player_by_name( player = await get_player_by_name(
current['season'], current['season'],
await fuzzy_player_search(ctx, dropadd.channel, self.bot, resp, await fuzzy_player_search(ctx, dropadd.channel, self.bot, resp, player_cog.player_list.keys())
player_cog.player_list.keys())
) )
except ValueError: except ValueError as e:
logging.error(f'Could not find player *{resp}*')
else:
if player is None:
await dropadd.send(f'{await get_emoji(ctx, "squint")}') await dropadd.send(f'{await get_emoji(ctx, "squint")}')
await dropadd.send('Who even is that? Try again.') await dropadd.send('Who even is that? Try again.')
except requests.ReadTimeout:
await dropadd.send(
f'I\'m dumb and couldn\'t read from the database fast enough. '
f'{await get_emoji(ctx, "dead")} Let\'s try that again.'
)
else: else:
if not dropadd.included_team(player['team']): if not dropadd.included_team(player['team']):
await t_channel.send(f'It looks like {player["name"]} is on {player["team"]["abbrev"]} ' await t_channel.send(f'It looks like {player["name"]} is on {player["team"]["abbrev"]} '
@ -1699,17 +1680,14 @@ class Transactions(commands.Cog):
try: try:
player = await get_player_by_name( player = await get_player_by_name(
current['season'], current['season'],
await fuzzy_player_search(ctx, dropadd.channel, self.bot, resp, await fuzzy_player_search(ctx, dropadd.channel, self.bot, resp, player_cog.player_list.keys())
player_cog.player_list.keys())
) )
except ValueError: except ValueError as e:
logging.error(f'Could not find player *{resp}*')
else:
if player is None:
await dropadd.send(f'{await get_emoji(ctx, "squint")}') await dropadd.send(f'{await get_emoji(ctx, "squint")}')
await dropadd.send('Who even is that? Try again.') await dropadd.send('Who even is that? Try again.')
except requests.ReadTimeout:
await dropadd.send(
f'I\'m dumb and couldn\'t read from the database fast enough. '
f'{await get_emoji(ctx, "dead")} Let\'s try that again.'
)
else: else:
if not self.on_team_il(team, player): if not self.on_team_il(team, player):
await t_channel.send(f'It looks like {player["name"]} is on {player["team"]["abbrev"]} ' await t_channel.send(f'It looks like {player["name"]} is on {player["team"]["abbrev"]} '
@ -1744,17 +1722,14 @@ class Transactions(commands.Cog):
try: try:
player = await get_player_by_name( player = await get_player_by_name(
current['season'], current['season'],
await fuzzy_player_search(ctx, dropadd.channel, self.bot, resp, await fuzzy_player_search(ctx, dropadd.channel, self.bot, resp, player_cog.player_list.keys())
player_cog.player_list.keys())
) )
except ValueError: except ValueError as e:
logging.error(f'Could not find player *{resp}*')
else:
if player is None:
await dropadd.send(f'{await get_emoji(ctx, "squint")}') await dropadd.send(f'{await get_emoji(ctx, "squint")}')
await dropadd.send('Who even is that? Try again.') await dropadd.send('Who even is that? Try again.')
except requests.ReadTimeout:
await dropadd.send(
f'I\'m dumb and couldn\'t read from the database fast enough. '
f'{await get_emoji(ctx, "dead")} Let\'s try that again.'
)
else: else:
if not dropadd.included_team(player['team']): if not dropadd.included_team(player['team']):
await t_channel.send(f'It looks like {player["name"]} is on {player["team"]["abbrev"]} ' await t_channel.send(f'It looks like {player["name"]} is on {player["team"]["abbrev"]} '
@ -1793,17 +1768,14 @@ class Transactions(commands.Cog):
try: try:
player = await get_player_by_name( player = await get_player_by_name(
current['season'], current['season'],
await fuzzy_player_search(ctx, dropadd.channel, self.bot, resp, await fuzzy_player_search(ctx, dropadd.channel, self.bot, resp, player_cog.player_list.keys())
player_cog.player_list.keys())
) )
except ValueError: except ValueError as e:
logging.error(f'Could not find player *{resp}*')
else:
if player is None:
await dropadd.send(f'{await get_emoji(ctx, "squint")}') await dropadd.send(f'{await get_emoji(ctx, "squint")}')
await dropadd.send('Who even is that? Try again.') await dropadd.send('Who even is that? Try again.')
except requests.ReadTimeout:
await dropadd.send(
f'I\'m dumb and couldn\'t read from the database fast enough. '
f'{await get_emoji(ctx, "dead")} Let\'s try that again.'
)
else: else:
if not dropadd.included_team(player['team']): if not dropadd.included_team(player['team']):
await t_channel.send(f'It looks like {player["name"]} is on {player["team"]["abbrev"]} ' await t_channel.send(f'It looks like {player["name"]} is on {player["team"]["abbrev"]} '