From 701a8b78d4b534843111b0b26c9433b1af720c65 Mon Sep 17 00:00:00 2001 From: Cal Corum Date: Sat, 5 Oct 2024 22:27:18 -0500 Subject: [PATCH] Update transactions.py Clean up transaction failures --- cogs/transactions.py | 354 ++++++++++++++++++++----------------------- 1 file changed, 163 insertions(+), 191 deletions(-) diff --git a/cogs/transactions.py b/cogs/transactions.py index f9f589c..9b6624d 100644 --- a/cogs/transactions.py +++ b/cogs/transactions.py @@ -817,9 +817,8 @@ class Transactions(commands.Cog): await trade.timed_delete() return else: - try: - next_team = await get_team_by_abbrev(resp, current['season']) - except ValueError: + next_team = await get_team_by_abbrev(resp, current['season']) + if next_team is None: await trade.send('Who the fuck even is that? Try again.') else: next_team_role = get_team_role(ctx, next_team) @@ -853,44 +852,41 @@ class Transactions(commands.Cog): current['season'], await fuzzy_player_search(ctx, trade.channel, self.bot, resp, player_cog.player_list.keys()) ) - except ValueError: - await trade.send(f'{await get_emoji(ctx, "squint")}') - 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.' - ) + except ValueError as e: + logging.error(f'Could not find player *{resp}*') else: - # Check that player is on one of the teams - # Check that the player hasn't been dropped (IL is okay) - if not trade.included_team(player['team']): - await trade.send(f'You know that {player["name"]} is on {player["team"]["abbrev"]}, right? ' - f'They\'re not part of this trade so...nah.') - elif await trade.not_available(player): - await trade.send(f'Ope. {player["name"]} is already one the move next week.') + if player is None: + await trade.send(f'{await get_emoji(ctx, "squint")}') + await trade.send('Who even is that? Try again.') else: - this_q.prompt = 'Where are they going? Please enter the destination team\'s abbreviation.' - resp = await this_q.ask(trade.get_gms(self.bot)) - - if resp is None: - await trade.send('RIP this move. Maybe next time.') - await trade.timed_delete() + # Check that player is on one of the teams + # Check that the player hasn't been dropped (IL is okay) + if not trade.included_team(player['team']): + await trade.send(f'You know that {player["name"]} is on {player["team"]["abbrev"]}, right? ' + f'They\'re not part of this trade so...nah.') + elif await trade.not_available(player): + await trade.send(f'Ope. {player["name"]} is already one the move next week.') else: - try: - dest_team = await get_team_by_abbrev(resp, current['season']) - except ValueError: - await trade.send(f'{await get_emoji(ctx, "facepalm")} They aren\'t even part of ' - f'this trade. Come on.') + this_q.prompt = 'Where are they going? Please enter the destination team\'s abbreviation.' + resp = await this_q.ask(trade.get_gms(self.bot)) + + if resp is None: + await trade.send('RIP this move. Maybe next time.') + await trade.timed_delete() else: - if player['team'] == dest_team: - await trade.send(f'{await get_emoji(ctx, "lolwhat")} {player["name"]} ' - f'is already on {dest_team["abbrev"]}.') - elif not trade.included_team(dest_team): - await trade.send(f'{await get_emoji(ctx, "lolwhat")} {dest_team["abbrev"]} ' - f'isn\'t even part of this trade.') + dest_team = await get_team_by_abbrev(resp, current['season']) + if dest_team is None: + await trade.send(f'{await get_emoji(ctx, "facepalm")} They aren\'t even part of ' + f'this trade. Come on.') else: - await trade.add_player(player, dest_team) + if player['team'] == dest_team: + await trade.send(f'{await get_emoji(ctx, "lolwhat")} {player["name"]} ' + f'is already on {dest_team["abbrev"]}.') + elif not trade.included_team(dest_team): + await trade.send(f'{await get_emoji(ctx, "lolwhat")} {dest_team["abbrev"]} ' + f'isn\'t even part of this trade.') + else: + await trade.add_player(player, dest_team) await trade.show_moves() @@ -1004,27 +1000,24 @@ class Transactions(commands.Cog): try: player = await get_player_by_name( current['season'], - await fuzzy_player_search(ctx, trade.channel, self.bot, resp, - player_cog.player_list.keys()) - ) - except ValueError: - await trade.send(f'{await get_emoji(ctx, "squint")}') - 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.' + await fuzzy_player_search(ctx, trade.channel, self.bot, resp, player_cog.player_list.keys()) ) + except ValueError as e: + logging.error(f'Could not find player *{resp}*') else: - if not trade.included_team(player['team']): - await t_channel.send(f'It looks like {player.name} is on {player.team.abbrev} ' - f'so I can\'t let you do that.') - # elif player['demotion_week'] > current['week']: - # await trade.send(f'Oof. {player["name"]} cannot be dropped until week ' - # f'{player["demotion_week"]}.') + if player is None: + await trade.send(f'{await get_emoji(ctx, "squint")}') + await trade.send('Who even is that? Try again.') else: - dest_team = await get_team_by_abbrev('FA', current['season']) - await trade.add_player(player, dest_team) + if not trade.included_team(player['team']): + await t_channel.send(f'It looks like {player.name} is on {player.team.abbrev} ' + f'so I can\'t let you do that.') + # elif player['demotion_week'] > current['week']: + # await trade.send(f'Oof. {player["name"]} cannot be dropped until week ' + # f'{player["demotion_week"]}.') + else: + dest_team = await get_team_by_abbrev('FA', current['season']) + await trade.add_player(player, dest_team) await trade.show_moves() @@ -1377,32 +1370,29 @@ class Transactions(commands.Cog): try: player = await get_player_by_name( current['season'], - await fuzzy_player_search(ctx, dropadd.channel, self.bot, resp, - player_cog.player_list.keys()) - ) - except ValueError: - await dropadd.send(f'{await get_emoji(ctx, "squint")}') - 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.' + await fuzzy_player_search(ctx, dropadd.channel, self.bot, resp, player_cog.player_list.keys()) ) + except ValueError as e: + logging.error(f'Could not find player *{resp}*') else: - fa_team = await get_team_by_abbrev('FA', current['season']) - dest_team = await get_team_by_abbrev(f'{team["abbrev"]}MiL', current['season']) - if not dropadd.included_team(player['team']) and player['team'] != fa_team: - await t_channel.send(f'It looks like {player["name"]} is on {player["team"]["abbrev"]} ' - f'so I can\'t let you do that.') - elif await dropadd.not_available(player): - await dropadd.send(f'Uh oh, looks like {player["name"]} is already on the move next week.') - elif player['demotion_week'] > current['week']: - await dropadd.send(f'Oof. {player["name"]} cannot be dropped until week ' - f'{player["demotion_week"]}.') + if player is None: + await dropadd.send(f'{await get_emoji(ctx, "squint")}') + await dropadd.send('Who even is that? Try again.') else: - if player['team'] == fa_team: - dropadd.avoid_freeze = False - await dropadd.add_player(player, dest_team) + fa_team = await get_team_by_abbrev('FA', current['season']) + dest_team = await get_team_by_abbrev(f'{team["abbrev"]}MiL', current['season']) + if not dropadd.included_team(player['team']) and player['team'] != fa_team: + await t_channel.send(f'It looks like {player["name"]} is on {player["team"]["abbrev"]} ' + f'so I can\'t let you do that.') + elif await dropadd.not_available(player): + await dropadd.send(f'Uh oh, looks like {player["name"]} is already on the move next week.') + elif player['demotion_week'] > current['week']: + await dropadd.send(f'Oof. {player["name"]} cannot be dropped until week ' + f'{player["demotion_week"]}.') + else: + if player['team'] == fa_team: + dropadd.avoid_freeze = False + await dropadd.add_player(player, dest_team) await dropadd.show_moves() @@ -1431,39 +1421,36 @@ class Transactions(commands.Cog): try: player = await get_player_by_name( current['season'], - await fuzzy_player_search(ctx, dropadd.channel, self.bot, resp, - player_cog.player_list.keys()) - ) - except ValueError: - await dropadd.send(f'{await get_emoji(ctx, "squint")}') - 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.' + await fuzzy_player_search(ctx, dropadd.channel, self.bot, resp, player_cog.player_list.keys()) ) + except ValueError as e: + logging.error(f'Could not find player *{resp}*') else: - if OFFSEASON_FLAG: - if not self.on_team_il(team, player): - await t_channel.send(f'It looks like {player["name"]} is on {player["team"]["abbrev"]} ' - f'so I can\'t let you do that.') - else: - await dropadd.add_player(player, team) + if player is None: + await dropadd.send(f'{await get_emoji(ctx, "squint")}') + await dropadd.send('Who even is that? Try again.') else: - fa_team = await get_team_by_abbrev('FA', current['season']) - if player['team'] != fa_team and not self.on_team_il(team, player): - await t_channel.send(f'It looks like {player["name"]} is on {player["team"]["abbrev"]} ' - f'so I can\'t let you do that.') - elif await dropadd.not_available(player): - await dropadd.send(f'Uh oh, looks like {player["name"]} is already on the move ' - f'next week.') - elif player['demotion_week'] > current['week']: - await dropadd.send(f'Oof. {player["name"]} cannot be dropped until week ' - f'{player["demotion_week"]}.') + if OFFSEASON_FLAG: + if not self.on_team_il(team, player): + await t_channel.send(f'It looks like {player["name"]} is on {player["team"]["abbrev"]} ' + f'so I can\'t let you do that.') + else: + await dropadd.add_player(player, team) else: - if player['team'] == fa_team: - dropadd.avoid_freeze = False - await dropadd.add_player(player, team) + fa_team = await get_team_by_abbrev('FA', current['season']) + if player['team'] != fa_team and not self.on_team_il(team, player): + await t_channel.send(f'It looks like {player["name"]} is on {player["team"]["abbrev"]} ' + f'so I can\'t let you do that.') + elif await dropadd.not_available(player): + await dropadd.send(f'Uh oh, looks like {player["name"]} is already on the move ' + f'next week.') + elif player['demotion_week'] > current['week']: + await dropadd.send(f'Oof. {player["name"]} cannot be dropped until week ' + f'{player["demotion_week"]}.') + else: + if player['team'] == fa_team: + dropadd.avoid_freeze = False + await dropadd.add_player(player, team) await dropadd.show_moves() @@ -1492,29 +1479,26 @@ class Transactions(commands.Cog): try: player = await get_player_by_name( current['season'], - await fuzzy_player_search(ctx, dropadd.channel, self.bot, resp, - player_cog.player_list.keys()) - ) - except ValueError: - await dropadd.send(f'{await get_emoji(ctx, "squint")}') - 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.' + await fuzzy_player_search(ctx, dropadd.channel, self.bot, resp, player_cog.player_list.keys()) ) + except ValueError as e: + logging.error(f'Could not find player *{resp}*') else: - if not dropadd.included_team(player['team']): - await t_channel.send(f'It looks like {player["name"]} is on {player["team"]["abbrev"]} ' - f'so I can\'t let you do that.') - elif await dropadd.not_available(player): - await dropadd.send(f'Uh oh, looks like {player["name"]} is already on the move next week.') - elif player['demotion_week'] > current['week']: - await dropadd.send(f'Oof. {player["name"]} cannot be dropped until week ' - f'{player["demotion_week"]}.') + if player is None: + await dropadd.send(f'{await get_emoji(ctx, "squint")}') + await dropadd.send('Who even is that? Try again.') else: - dest_team = await get_team_by_abbrev('FA', current['season']) - await dropadd.add_player(player, dest_team) + if not dropadd.included_team(player['team']): + await t_channel.send(f'It looks like {player["name"]} is on {player["team"]["abbrev"]} ' + f'so I can\'t let you do that.') + elif await dropadd.not_available(player): + await dropadd.send(f'Uh oh, looks like {player["name"]} is already on the move next week.') + elif player['demotion_week'] > current['week']: + await dropadd.send(f'Oof. {player["name"]} cannot be dropped until week ' + f'{player["demotion_week"]}.') + else: + dest_team = await get_team_by_abbrev('FA', current['season']) + await dropadd.add_player(player, dest_team) await dropadd.show_moves() @@ -1653,24 +1637,21 @@ class Transactions(commands.Cog): try: player = await get_player_by_name( current['season'], - await fuzzy_player_search(ctx, dropadd.channel, self.bot, resp, - player_cog.player_list.keys()) - ) - except ValueError: - await dropadd.send(f'{await get_emoji(ctx, "squint")}') - 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.' + await fuzzy_player_search(ctx, dropadd.channel, self.bot, resp, player_cog.player_list.keys()) ) + except ValueError as e: + logging.error(f'Could not find player *{resp}*') else: - if not dropadd.included_team(player['team']): - await t_channel.send(f'It looks like {player["name"]} is on {player["team"]["abbrev"]} ' - f'so I can\'t let you do that.') + if player is None: + await dropadd.send(f'{await get_emoji(ctx, "squint")}') + await dropadd.send('Who even is that? Try again.') else: - dest_team = await get_team_by_abbrev(f'{team["abbrev"]}IL', current['season']) - await dropadd.add_player(player, dest_team) + if not dropadd.included_team(player['team']): + await t_channel.send(f'It looks like {player["name"]} is on {player["team"]["abbrev"]} ' + f'so I can\'t let you do that.') + else: + dest_team = await get_team_by_abbrev(f'{team["abbrev"]}IL', current['season']) + await dropadd.add_player(player, dest_team) await dropadd.show_moves() @@ -1699,23 +1680,20 @@ class Transactions(commands.Cog): try: player = await get_player_by_name( current['season'], - await fuzzy_player_search(ctx, dropadd.channel, self.bot, resp, - player_cog.player_list.keys()) - ) - except ValueError: - await dropadd.send(f'{await get_emoji(ctx, "squint")}') - 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.' + await fuzzy_player_search(ctx, dropadd.channel, self.bot, resp, player_cog.player_list.keys()) ) + except ValueError as e: + logging.error(f'Could not find player *{resp}*') else: - if not self.on_team_il(team, player): - await t_channel.send(f'It looks like {player["name"]} is on {player["team"]["abbrev"]} ' - f'- you can only call up your MiL players mid-week.') + if player is None: + await dropadd.send(f'{await get_emoji(ctx, "squint")}') + await dropadd.send('Who even is that? Try again.') else: - await dropadd.add_player(player, team) + if not self.on_team_il(team, player): + await t_channel.send(f'It looks like {player["name"]} is on {player["team"]["abbrev"]} ' + f'- you can only call up your MiL players mid-week.') + else: + await dropadd.add_player(player, team) await dropadd.show_moves() @@ -1744,27 +1722,24 @@ class Transactions(commands.Cog): try: player = await get_player_by_name( current['season'], - await fuzzy_player_search(ctx, dropadd.channel, self.bot, resp, - player_cog.player_list.keys()) - ) - except ValueError: - await dropadd.send(f'{await get_emoji(ctx, "squint")}') - 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.' + await fuzzy_player_search(ctx, dropadd.channel, self.bot, resp, player_cog.player_list.keys()) ) + except ValueError as e: + logging.error(f'Could not find player *{resp}*') else: - if not dropadd.included_team(player['team']): - await t_channel.send(f'It looks like {player["name"]} is on {player["team"]["abbrev"]} ' - f'so I can\'t let you do that.') - # elif player['demotion_week'] > current['week']: - # await dropadd.send(f'Oof. {player["name"]} cannot be dropped until week ' - # f'{player["demotion_week"]}.') + if player is None: + await dropadd.send(f'{await get_emoji(ctx, "squint")}') + await dropadd.send('Who even is that? Try again.') else: - dest_team = await get_team_by_abbrev(f'{team["abbrev"]}MiL', current['season']) - await dropadd.add_player(player, dest_team) + if not dropadd.included_team(player['team']): + await t_channel.send(f'It looks like {player["name"]} is on {player["team"]["abbrev"]} ' + f'so I can\'t let you do that.') + # elif player['demotion_week'] > current['week']: + # await dropadd.send(f'Oof. {player["name"]} cannot be dropped until week ' + # f'{player["demotion_week"]}.') + else: + dest_team = await get_team_by_abbrev(f'{team["abbrev"]}MiL', current['season']) + await dropadd.add_player(player, dest_team) await dropadd.show_moves() @@ -1793,27 +1768,24 @@ class Transactions(commands.Cog): try: player = await get_player_by_name( current['season'], - await fuzzy_player_search(ctx, dropadd.channel, self.bot, resp, - player_cog.player_list.keys()) - ) - except ValueError: - await dropadd.send(f'{await get_emoji(ctx, "squint")}') - 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.' + await fuzzy_player_search(ctx, dropadd.channel, self.bot, resp, player_cog.player_list.keys()) ) + except ValueError as e: + logging.error(f'Could not find player *{resp}*') else: - if not dropadd.included_team(player['team']): - await t_channel.send(f'It looks like {player["name"]} is on {player["team"]["abbrev"]} ' - f'so I can\'t let you do that.') - # elif player['demotion_week'] > current['week']: - # await dropadd.send(f'Oof. {player["name"]} cannot be dropped until week ' - # f'{player["demotion_week"]}.') + if player is None: + await dropadd.send(f'{await get_emoji(ctx, "squint")}') + await dropadd.send('Who even is that? Try again.') else: - dest_team = await get_team_by_abbrev('FA', current['season']) - await dropadd.add_player(player, dest_team) + if not dropadd.included_team(player['team']): + await t_channel.send(f'It looks like {player["name"]} is on {player["team"]["abbrev"]} ' + f'so I can\'t let you do that.') + # elif player['demotion_week'] > current['week']: + # await dropadd.send(f'Oof. {player["name"]} cannot be dropped until week ' + # f'{player["demotion_week"]}.') + else: + dest_team = await get_team_by_abbrev('FA', current['season']) + await dropadd.add_player(player, dest_team) await dropadd.show_moves()