1919 * downloadable file, then posts it as one or more ordered code-block messages that each respect
2020 * Discord's 2000-character limit.
2121 */
22- public class FormatCodeDispatcher {
22+ class FormatCodeDispatcher {
2323
2424 /**
2525 * Acknowledges the interaction by replying with the full code as a file, then posts the code as
@@ -32,10 +32,10 @@ public class FormatCodeDispatcher {
3232 */
3333 public static void sendCode (Code code , @ Nonnull CommandInteraction event , Message target ){
3434 if (code .getContent ().isBlank ()) {
35- Responses .error (event . getHook () , "There is no code to format in that message." ).queue ();
35+ Responses .error (event , "There is no code to format in that message." ).queue ();
3636 return ;
3737 }
38- // Currently we always format as Java. A language dropdown will be added in the future.
38+
3939 List <String > messages = code .toDiscordMessages ();
4040
4141 // The reply both acknowledges the interaction and hands users the full,
@@ -49,7 +49,7 @@ public static void sendCode(Code code, @Nonnull CommandInteraction event, Messag
4949
5050 event .replyFiles (file )
5151 .setAllowedMentions (List .of ())
52- .setComponents (FormatCodeCommand . buildActionRow (target , event .getUser ().getIdLong ()))
52+ .setComponents (buildActionRow (target , event .getUser ().getIdLong ()))
5353 .queue (success -> sendChunksInOrder (channel , messages , 0 , target ,event ));
5454 }
5555
@@ -62,7 +62,11 @@ private static void sendChunksInOrder(MessageChannel channel, List<String> messa
6262 .setAllowedMentions (List .of ());
6363
6464 if (index == messages .size () - 1 ) {
65- action .setComponents (buildActionRow (target , event .getUser ().getIdLong ()));
65+ if (index == 0 ){
66+ action .setComponents (buildActionRow (target , event .getUser ().getIdLong ()));
67+ } else {
68+ action .setComponents (buildActionRow (target ));
69+ }
6670 }
6771
6872 action .queue (success ->
@@ -73,11 +77,23 @@ private static void sendChunksInOrder(MessageChannel channel, List<String> messa
7377 * Builds the action row placed on the last code-block message.
7478 *
7579 * @param target the original message linked by the "View Original" button
76- * @param requesterId the id of the requesting user
7780 * @return an action row containing the "View Original" link button
7881 */
7982 @ Contract ("_ -> new" )
80- static @ NotNull ActionRow buildActionRow (@ NotNull Message target , long requesterId ) {
83+ static @ NotNull ActionRow buildActionRow (@ NotNull Message target ) {
8184 return ActionRow .of (Button .link (target .getJumpUrl (), "View Original" ));
8285 }
86+
87+ /**
88+ * Builds the action row placed on the file-upload message: a delete button and a "View Original" link.
89+ *
90+ * @param target the original message linked by the "View Original" button
91+ * @param requesterId the id of the user permitted to delete the message
92+ * @return an action row containing the delete and "View Original" buttons
93+ */
94+ @ Contract ("_ -> new" )
95+ static @ NotNull ActionRow buildActionRow (@ NotNull Message target , long requesterId ) {
96+ return ActionRow .of (InteractionUtils .createDeleteButton (requesterId ),
97+ Button .link (target .getJumpUrl (), "View Original" ));
98+ }
8399}
0 commit comments