@@ -25,6 +25,9 @@ public static void registerAll() {
2525 ButtonDispatcher .register ("unlinkModrinth" , GardenBotButtonHandlers ::unlinkModrinth );
2626 ButtonDispatcher .register ("linkMinecraft" , new ModalResponse (GardenBotModals .LINK_MINECRAFT ));
2727 ButtonDispatcher .register ("unlinkMinecraft?%s" , GardenBotButtonHandlers ::unlinkMinecraft );
28+
29+ ButtonDispatcher .register ("acceptInvite?%s" , GardenBotButtonHandlers ::acceptInvite );
30+ ButtonDispatcher .register ("declineInvite?%s" , GardenBotButtonHandlers ::declineInvite );
2831 }
2932
3033 public static Response unlinkModrinth (ButtonInteraction interaction ) {
@@ -47,13 +50,18 @@ public static Response unlinkModrinth(ButtonInteraction interaction) {
4750 json .getAsJsonObject ().getAsJsonPrimitive ("description" ).getAsString () :
4851 "Undefined Error." ;
4952 return new EmbedResponse ()
50- .setTitle ("Encountered an exception whilst attempting to unlink your Modrinth from your Mod Garden account." )
53+ .setTitle ("Encountered an exception whilst attempting to unlink your Modrinth account from your Mod Garden account." )
5154 .setDescription (stream .statusCode () + ": " + errorDescription + "\n Please report this to a team member." )
5255 .setColor (0xFF0000 )
5356 .markEphemeral ();
5457 }
5558 } catch (IOException | InterruptedException ex ) {
5659 GardenBot .LOG .error ("" , ex );
60+ return new EmbedResponse ()
61+ .setTitle ("Encountered an exception whilst attempting to unlink your Modrinth account from your Mod Garden account." )
62+ .setDescription (ex .getMessage () + "\n Please report this to a team member." )
63+ .setColor (0xFF0000 )
64+ .markEphemeral ();
5765 }
5866
5967 return new EmbedResponse ()
@@ -91,11 +99,16 @@ public static Response unlinkMinecraft(ButtonInteraction interaction) {
9199 }
92100 if (stream .statusCode () == 200 ) {
93101 return new MessageResponse ()
94- .setMessage ("You already ." )
102+ .setMessage ("You have already linked this Minecraft account to your Mod Garden account ." )
95103 .markEphemeral ();
96104 }
97105 } catch (IOException | InterruptedException ex ) {
98106 GardenBot .LOG .error ("" , ex );
107+ return new EmbedResponse ()
108+ .setTitle ("Encountered an exception whilst attempting to unlink your Minecraft account from your Mod Garden account." )
109+ .setDescription (ex .getMessage () + "\n Please report this to a team member." )
110+ .setColor (0xFF0000 )
111+ .markEphemeral ();
99112 }
100113
101114 String username = MinecraftAccountUtil .getMinecraftUsernameFromUuid (uuid );
@@ -107,6 +120,75 @@ public static Response unlinkMinecraft(ButtonInteraction interaction) {
107120 .setTitle ("Successfully unlinked your Minecraft account (" + username + ") from Mod Garden!" )
108121 .setColor (0xA9FFA7 )
109122 .markEphemeral ();
123+ }
124+
125+ public static Response acceptInvite (ButtonInteraction interaction ) {
126+ String inviteCode = interaction .arguments ()[0 ];
127+
128+ JsonObject publisher = new JsonObject ();
129+ publisher .addProperty ("invite_code" , inviteCode );
130+
131+ try {
132+ HttpResponse <Void > acceptResult = ModGardenAPIClient .post (
133+ "discord/project/user/accept" ,
134+ HttpRequest .BodyPublishers .ofString (publisher .toString ()),
135+ HttpResponse .BodyHandlers .discarding (),
136+ "Content-Type" , "application/json"
137+ );
138+ if (acceptResult .statusCode () != 201 ) {
139+ return new EmbedResponse ()
140+ .setTitle ("Could not accept invite to project." )
141+ .setDescription ("This invite is invalid or has expired." )
142+ .setColor (0x5D3E40 )
143+ .markEphemeral ();
144+ }
145+ } catch (IOException | InterruptedException ex ) {
146+ GardenBot .LOG .error ("" , ex );
147+ return new EmbedResponse ()
148+ .setTitle ("Encountered an exception whilst attempting to accept invite." )
149+ .setDescription (ex .getMessage () + "\n Please report this to a team member." )
150+ .setColor (0xFF0000 )
151+ .markEphemeral ();
152+ }
153+
154+ return new EmbedResponse ()
155+ .setTitle ("Successfully accepted invite to project!" )
156+ .setColor (0xA9FFA7 )
157+ .markEphemeral ();
158+ }
159+
160+ public static Response declineInvite (ButtonInteraction interaction ) {
161+ String inviteCode = interaction .arguments ()[0 ];
110162
163+ JsonObject publisher = new JsonObject ();
164+ publisher .addProperty ("invite_code" , inviteCode );
165+
166+ try {
167+ HttpResponse <Void > declineResult = ModGardenAPIClient .post (
168+ "discord/project/user/decline" ,
169+ HttpRequest .BodyPublishers .ofString (publisher .toString ()),
170+ HttpResponse .BodyHandlers .discarding (),
171+ "Content-Type" , "application/json"
172+ );
173+ if (declineResult .statusCode () != 201 ) {
174+ return new EmbedResponse ()
175+ .setTitle ("Could not decline invite to project." )
176+ .setDescription ("This invite is invalid or has expired." )
177+ .setColor (0x5D3E40 )
178+ .markEphemeral ();
179+ }
180+ } catch (IOException | InterruptedException ex ) {
181+ GardenBot .LOG .error ("" , ex );
182+ return new EmbedResponse ()
183+ .setTitle ("Encountered an exception whilst attempting to decline invite." )
184+ .setDescription (ex .getMessage () + "\n Please report this to a team member." )
185+ .setColor (0xFF0000 )
186+ .markEphemeral ();
187+ }
188+
189+ return new EmbedResponse ()
190+ .setTitle ("Successfully declined invite to project!" )
191+ .setColor (0xA9FFA7 )
192+ .markEphemeral ();
111193 }
112194}
0 commit comments