2
2
3
3
import com .jagrosh .jdautilities .command .SlashCommand ;
4
4
import com .jagrosh .jdautilities .command .SlashCommandEvent ;
5
+ import net .dv8tion .jda .api .EmbedBuilder ;
6
+ import net .dv8tion .jda .api .entities .MessageEmbed ;
7
+ import net .dv8tion .jda .api .entities .User ;
5
8
import net .dv8tion .jda .api .entities .channel .middleman .GuildMessageChannel ;
6
9
import net .dv8tion .jda .api .events .interaction .command .CommandAutoCompleteInteractionEvent ;
7
10
import net .dv8tion .jda .api .interactions .DiscordLocale ;
16
19
import pw .chew .mlb .listeners .GameFeedHandler ;
17
20
import pw .chew .mlb .objects .ActiveGame ;
18
21
import pw .chew .mlb .objects .GameState ;
22
+ import pw .chew .mlb .util .EmbedUtil ;
19
23
20
24
import java .time .OffsetDateTime ;
21
25
import java .time .format .DateTimeFormatter ;
@@ -45,14 +49,18 @@ public StartGameCommand() {
45
49
@ Override
46
50
protected void execute (SlashCommandEvent event ) {
47
51
String gamePk = event .getOption ("game" , "0" , OptionMapping ::getAsString );
48
- String startGame = startGame (gamePk , event .getGuildChannel ());
49
- event .reply (startGame ).setEphemeral (!startGame .contains ("Starting game" )).queue ();
52
+ try {
53
+ MessageEmbed startGame = startGame (gamePk , event .getGuildChannel (), event .getUser ());
54
+ event .replyEmbeds (startGame ).queue ();
55
+ } catch (IllegalStateException e ) {
56
+ event .replyEmbeds (EmbedUtil .failure (e .getMessage ())).setEphemeral (true ).queue ();
57
+ }
50
58
}
51
59
52
- public static String startGame (String gamePk , GuildMessageChannel channel ) {
60
+ public static MessageEmbed startGame (String gamePk , GuildMessageChannel channel , User invoker ) {
53
61
String currentGame = GameFeedHandler .currentGame (channel );
54
62
if (currentGame != null ) {
55
- return "This channel is already playing a game: " + currentGame + ". Please wait for it to finish, or stop it with `/stopgame`." ;
63
+ throw new IllegalStateException ( "This channel is already playing a game: " + currentGame + ". Please wait for it to finish, or stop it with `/stopgame`." ) ;
56
64
}
57
65
58
66
// Start a new thread
@@ -61,22 +69,30 @@ public static String startGame(String gamePk, GuildMessageChannel channel) {
61
69
62
70
// Refuse to start if the game is already over
63
71
if (currentState .isFinal ()) {
64
- return "This game is already over. Please start a different game." ;
72
+ throw new IllegalStateException ( "This game is already over. Please start a different game." ) ;
65
73
}
66
74
67
75
// We can only start games if the start time is less than 30 minutes away
68
76
// E.g. if game starts at 2:30, and the time is 1:59, we cannot start the game
69
77
// But, if it's 2:00, we can start the game
70
78
// We can also start it if it's like, 2:56, who cares, maybe we forgot to start it
71
79
if (OffsetDateTime .now ().isBefore (currentState .officialDate ().minusMinutes (30 ))) {
72
- return "This game is not yet ready to start. Please wait until the game is within 30 minutes of starting." ;
80
+ throw new IllegalStateException ( "This game is not yet ready to start. Please wait until the game is within 30 minutes of starting." ) ;
73
81
}
74
82
75
83
GameFeedHandler .addGame (activeGame );
76
84
77
- return "Starting game with gamePk: " + gamePk + "\n " +
78
- currentState .away ().clubName () + " @ " + currentState .home ().clubName () + " at " +
79
- TimeFormat .DATE_TIME_SHORT .format (currentState .officialDate ());
85
+ List <String > description = new ArrayList <>();
86
+ description .add ("First Pitch: %s" .formatted (TimeFormat .RELATIVE .format (currentState .officialDate ())));
87
+ description .add ("\n *Invoked by %s*" .formatted (invoker .getAsMention ()));
88
+
89
+ EmbedBuilder embed = new EmbedBuilder ()
90
+ .setTitle ("Starting Game **%s @ %s**" .formatted (currentState .away ().clubName (), currentState .home ().clubName ()))
91
+ .setDescription (String .join ("\n " , description ))
92
+ .setColor (0x4fc94f )
93
+ .setFooter ("Game PK: %s" .formatted (gamePk ));
94
+
95
+ return embed .build ();
80
96
}
81
97
82
98
@ Override
0 commit comments