-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
169 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package pw.chew.mlb.commands; | ||
|
||
import com.jagrosh.jdautilities.command.SlashCommand; | ||
import com.jagrosh.jdautilities.command.SlashCommandEvent; | ||
import net.dv8tion.jda.api.EmbedBuilder; | ||
import net.dv8tion.jda.api.interactions.DiscordLocale; | ||
import net.dv8tion.jda.api.interactions.commands.OptionType; | ||
import net.dv8tion.jda.api.interactions.commands.build.OptionData; | ||
import pw.chew.mlb.util.MLBAPIUtil; | ||
import pw.chew.mlb.util.TeamEmoji; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class StandingsCommand extends SlashCommand { | ||
|
||
public StandingsCommand() { | ||
this.name = "standings"; | ||
this.help = "Get the current standings."; | ||
this.guildOnly = false; | ||
this.options = List.of( | ||
new OptionData(OptionType.STRING, "division", "Select a division to view standings for!", true) | ||
// hardcode MLB for now. eventually milb will be added | ||
.addChoice("AL East", "American League East") | ||
.addChoice("AL Central", "American League Central") | ||
.addChoice("AL West", "American League West") | ||
.addChoice("NL East", "National League East") | ||
.addChoice("NL Central", "National League Central") | ||
.addChoice("NL West", "National League West") | ||
); | ||
|
||
// TODO: Future, make this installable in user contexts | ||
|
||
this.descriptionLocalization = Map.of( | ||
DiscordLocale.ENGLISH_US, "Get the current standings.", | ||
DiscordLocale.SPANISH, "Obtenga las posiciones actuales.", | ||
DiscordLocale.GERMAN, "Erhalten Sie die aktuellen Platzierungen." | ||
); | ||
} | ||
|
||
@Override | ||
protected void execute(SlashCommandEvent event) { | ||
String division = event.optString("division", "American League West"); | ||
|
||
// first we get standings | ||
var standings = MLBAPIUtil.getStandings().get(division); | ||
|
||
List<String> teams = new ArrayList<>(); | ||
for (MLBAPIUtil.Standing standing : standings) { | ||
teams.add( | ||
""" | ||
**%s) %s %s** | ||
**%s** W | **%s** L | **%s** pct | **%s** GB | **%s** Home | **%s** Away | **%s** L10 | ||
""".formatted( | ||
standing.rank(), TeamEmoji.fromName(standing.teamName()).getAsMention(), standing.teamName(), | ||
standing.wins(), standing.losses(), standing.winPct(), | ||
standing.gamesBack(), standing.homeRecord(), standing.awayRecord(), standing.lastTen() | ||
) | ||
); | ||
} | ||
|
||
// make a cute lil embed | ||
EmbedBuilder embed = new EmbedBuilder() | ||
.setTitle("Standings for " + division) | ||
.setDescription(String.join("\n", teams)); | ||
|
||
event.replyEmbeds(embed.build()).setEphemeral(true).queue(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters