Skip to content

Commit

Permalink
Merge pull request #167 from DMcP89/release/v0.4.2-Beta
Browse files Browse the repository at this point in the history
Release v0.4.2-Beta
  • Loading branch information
DMcP89 authored Sep 6, 2024
2 parents 255316f + b537514 commit 070ebb6
Show file tree
Hide file tree
Showing 6 changed files with 263 additions and 241 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Harambot
_An interactive Yahoo Fantasy sports bot for Discord._

![Python](https://img.shields.io/badge/python-3.8%20%7C%203.9%20%7C%203.10-blue) ![License](https://img.shields.io/badge/License-MIT-green) ![Build](https://img.shields.io/github/actions/workflow/status/DMcP89/harambot/unit-tests.yml?branch=main) ![Version](https://img.shields.io/badge/version-0.4.1--Beta-red)
![Python](https://img.shields.io/badge/python-3.8%20%7C%203.9%20%7C%203.10-blue) ![License](https://img.shields.io/badge/License-MIT-green) ![Build](https://img.shields.io/github/actions/workflow/status/DMcP89/harambot/unit-tests.yml?branch=main) ![Version](https://img.shields.io/badge/version-0.4.2--Beta-red)



Expand Down
36 changes: 20 additions & 16 deletions harambot/cogs/yahoo.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def __init__(self, bot, KEY, SECRET):
)
async def standings(self, interaction: discord.Interaction):
logger.info("Command:Standings called in %i", interaction.guild_id)
await interaction.response.defer()
embed = discord.Embed(
title="Standings",
description="Team Name\n W-L-T",
Expand All @@ -47,9 +48,9 @@ async def standings(self, interaction: discord.Interaction):
value=team["record"],
inline=False,
)
await interaction.response.send_message(embed=embed)
await interaction.followup.send(embed=embed)
else:
await interaction.response.send_message(self.error_message)
await interaction.followup.send(self.error_message)

async def roster_autocomplete(
self,
Expand Down Expand Up @@ -79,6 +80,7 @@ async def roster(self, interaction: discord.Interaction, team_name: str):
interaction.guild_id,
team_name,
)
await interaction.response.defer()
embed = discord.Embed(
title="{}'s Roster".format(team_name),
description="",
Expand All @@ -94,28 +96,29 @@ async def roster(self, interaction: discord.Interaction, team_name: str):
value=player["name"],
inline=False,
)
await interaction.response.send_message(embed=embed)
await interaction.followup.send(embed=embed)
else:
await interaction.response.send_message(self.error_message)
await interaction.followup.send(self.error_message)

@app_commands.command(
name="trade",
description="Create poll for latest trade for league approval",
)
async def trade(self, interaction: discord.Interaction):
logger.info("Command:Trade called in %i", interaction.guild_id)
await interaction.response.defer()
latest_trade = self.yahoo_api.get_latest_trade(
guild_id=interaction.guild_id
)
if latest_trade is None:
await interaction.response.send_message(
await interaction.followup.send(
"No trades up for approval at this time"
)
return

teams = self.yahoo_api.get_teams()
if teams is None:
await interaction.response.send_message(self.error_message)
await interaction.followup.send(self.error_message)
return
trader = teams[latest_trade["trader_team_key"]]
tradee = teams[latest_trade["tradee_team_key"]]
Expand All @@ -135,7 +138,7 @@ async def trade(self, interaction: discord.Interaction):
if api_details:
player_set0_details = player_set0_details + api_details
else:
await interaction.send(self.error_message)
await interaction.followup.send(self.error_message)
return

player_set1 = []
Expand All @@ -144,13 +147,13 @@ async def trade(self, interaction: discord.Interaction):
player_set1.append(player["name"])
player_details = self.yahoo_api.get_player_details(player["name"])
if player_details is None:
await interaction.send(self.error_message)
await interaction.followup.send(self.error_message)
return
api_details = self.get_player_text(player_details) + "\n"
if api_details:
player_set1_details = player_set1_details + api_details
else:
await interaction.response.send_message(self.error_message)
await interaction.followup.send(self.error_message)
return

confirm_trade_message = "{} sends {} to {} for {}".format(
Expand Down Expand Up @@ -180,10 +183,10 @@ async def trade(self, interaction: discord.Interaction):
value=" Click :white_check_mark: for yes,\
:no_entry_sign: for no",
)
await interaction.response.send_message(
response_message = await interaction.followup.send(
content=announcement, embed=embed
)
response_message = await interaction.original_response()
# response_message = await interaction.original_response()
yes_emoji = "\U00002705"
no_emoji = "\U0001F6AB"
await response_message.add_reaction(yes_emoji)
Expand Down Expand Up @@ -221,14 +224,15 @@ async def stats(self, interaction: discord.Interaction, player_name: str):
interaction.guild_id,
player_name,
)
await interaction.response.defer()
player = self.yahoo_api.get_player_details(
player_name, guild_id=interaction.guild_id
)
if player:
embed = self.get_player_embed(player)
await interaction.response.send_message(embed=embed)
await interaction.followup.send(embed=embed)
else:
await interaction.response.send_message("Player not found")
await interaction.followup.send("Player not found")

def get_player_embed(self, player):
embed = discord.Embed(
Expand Down Expand Up @@ -296,7 +300,7 @@ async def matchups(
interaction.guild_id, week
)
)

await interaction.response.defer()
week, details = self.yahoo_api.get_matchups(
guild_id=interaction.guild_id, week=week
)
Expand All @@ -310,9 +314,9 @@ async def matchups(
embed.add_field(
name=detail["name"], value=detail["value"], inline=False
)
await interaction.response.send_message(embed=embed)
await interaction.followup.send(embed=embed)
else:
await interaction.response.send_message(self.error_message)
await interaction.followup.send(self.error_message)

@app_commands.command(
name="waivers",
Expand Down
2 changes: 1 addition & 1 deletion harambot/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def create_drop_embed(transaction):


def create_add_drop_embed(transaction):
embed = Embed(title="Player Added/ Player Dropped")
embed = Embed(title="Player Added / Player Dropped")
embed.add_field(
name="Owner",
value=transaction["players"]["0"]["player"][1]["transaction_data"][0][
Expand Down
24 changes: 18 additions & 6 deletions harambot/yahoo_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class Yahoo:
scoring_type = None
league_id = None
league_type = None
current_league = None

def handle_oauth(f):
@functools.wraps(f)
Expand Down Expand Up @@ -59,23 +60,34 @@ def league(self):
)
return None

if (
self.current_league
and self.league_id == self.current_league.league_id
):
return self.current_league
try:
gm = game.Game(self.oauth, self.league_type)
try:
for id in gm.league_ids():
if self.league_id in id:
self.league_id = id
break
league = gm.to_league(self.league_id)
self.scoring_type = league.settings()["scoring_type"]
return league
self.current_league = gm.to_league(self.league_id)
self.scoring_type = self.current_league.settings()[
"scoring_type"
]
return self.current_league
except (RuntimeError, AssertionError):
logger.error(
"Error fetching league ids from Yahoo, trying with constructed league id"
)
league = gm.to_league(gm.game_id() + ".l." + self.league_id)
self.scoring_type = league.settings()["scoring_type"]
return league
self.current_league = gm.to_league(
gm.game_id() + ".l." + self.league_id
)
self.scoring_type = self.current_league.settings()[
"scoring_type"
]
return self.current_league
except Exception:
logger.exception(
"Error while fetching league details for league {}".format(
Expand Down
Loading

0 comments on commit 070ebb6

Please sign in to comment.