[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added top half perc command and updated readme #2

Merged
merged 3 commits into from
Jan 15, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
added top-half-perc command and updated README
  • Loading branch information
coolbrett committed Jan 15, 2023
commit 5db5de43fd4f7fc6df25e8399b7126afbe28c690
10 changes: 2 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ This Discord bot is built with the pycord library and an espn-api specifically f

The goal is to build this bot so that it can handle all Discord servers that it is invited to with a single instance of itself

I want the bot to be able to display most things that you can find in the app as well as give insights through advanced statistics

PROCESS
-------

Expand All @@ -18,13 +20,7 @@ PROCESS

TO-DO
-----
- % of top (league roster size * (half number of teams in league)) players on roster -- avg and totals

BEGINNER TASKS
--------------
- Write a command that sends a saying based upon a random number
- Write a command that sends a message of a list of all the commands LeBot knows
- Write a basic README file using markdown that has a title, description, and authors listed
- Add descriptions to parameters of commands (https://github.com/Pycord-Development/pycord/discussions/1861)


Expand All @@ -49,7 +45,5 @@ NOTES

- the /standings command on NBA Bot shows the limit on mobile

- Once deployed, scaling vertically seems to be the better and cheaper way.
I want to each discord server to have their own instance of the bot
- Injury rate cannot be done using the espn_api -- the game_played field gets marked to 100 if
they play one game that week, not all
18 changes: 14 additions & 4 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,19 +298,29 @@ async def box_score(interaction: discord.Interaction, team_abbreviation: str, we

@bot.command(name="top-half-players-percentage", description="Gets the top half of all rostered players and gives percentage of how many top-half players a thas", guild_ids=[guild_id])
async def top_half_players_percentage(interaction: discord.Interaction, year: int = None, stat: str = None):
print("received top-half-players-percentage")

original_year = league_data.league.year
if year is not None:
league_data.set_year(year=year)

top_half_players = {}
if stat == "avg":
top_half_players = league_data.get_top_half_percentage_for_each_team(stat=stat)
else:
top_half_players = league_data.get_top_half_percentage_for_each_team()

embed = discord.Embed(title=f"Top Half Players of Rostered Players %")
embed = discord.Embed(title=f"Top Half of Rostered Players %")
description = "`TEAM".ljust(8) + "PERC%`\n"
for team_id, perc in top_half_players.items():
for team_id, percentage in top_half_players.items():
team = league_data.league.get_team_data(team_id=team_id)
perc = float("%.1f" % (perc * 100))
description += f"`{team.team_abbrev}".ljust(8) + f"{perc}%`\n"
percentage = float("%.1f" % (percentage * 100))
description += f"`{team.team_abbrev}".ljust(8) + f"{percentage}%`\n"
embed.add_field(name="", value=description)

# set year back to original year if it was changed
if league_data.league.year != original_year:
league_data.set_year(original_year)

await interaction.response.send_message(embed=embed)

Expand Down
1 change: 0 additions & 1 deletion tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,5 +138,4 @@ def get_top_half_percentage_for_each_team(league_data: LeagueData):
# percantage = float("%.3f" % percantage)
# print(f"{team.team_abbrev}:\t\t{percantage}%")
# print(f"total: {total}")

main()