1111import net .dv8tion .jda .api .entities .emoji .EmojiUnion ;
1212import net .dv8tion .jda .api .events .interaction .command .SlashCommandInteractionEvent ;
1313import net .dv8tion .jda .api .events .interaction .component .ButtonInteractionEvent ;
14+ import net .dv8tion .jda .api .interactions .commands .OptionMapping ;
15+ import net .dv8tion .jda .api .interactions .commands .OptionType ;
1416import net .dv8tion .jda .api .interactions .commands .build .SubcommandData ;
1517import net .dv8tion .jda .api .interactions .components .buttons .Button ;
1618import net .dv8tion .jda .api .interactions .components .buttons .ButtonStyle ;
2123import net .javadiscord .javabot .data .config .guild .HelpConfig ;
2224import net .javadiscord .javabot .util .Pair ;
2325import net .javadiscord .javabot .util .Responses ;
26+ import net .javadiscord .javabot .util .StringUtils ;
27+
2428import org .jetbrains .annotations .NotNull ;
2529import xyz .dynxsty .dih4jda .interactions .commands .application .SlashCommand ;
2630import xyz .dynxsty .dih4jda .interactions .components .ButtonHandler ;
@@ -55,7 +59,8 @@ public class HelpPingSubcommand extends SlashCommand.Subcommand implements Butto
5559 * @param botConfig The main configuration of the bot
5660 */
5761 public HelpPingSubcommand (BotConfig botConfig , ScheduledExecutorService asyncPool ) {
58- setCommandData (new SubcommandData ("ping" , "Notify potential helpers that your question is urgent." ));
62+ setCommandData (new SubcommandData ("ping" , "Notify potential helpers that your question is urgent." )
63+ .addOption (OptionType .STRING , "comment" , "Optionally enter the reason you used this to be seen by helpers (e.g. 'no response')" , false ));
5964 lastPingTimes = new ConcurrentHashMap <>();
6065 this .botConfig = botConfig ;
6166 asyncPool .scheduleWithFixedDelay (this ::cleanTimeoutCache , CACHE_CLEANUP_DELAY , CACHE_CLEANUP_DELAY , TimeUnit .SECONDS );
@@ -92,29 +97,26 @@ public void execute(@NotNull SlashCommandInteractionEvent event) {
9297 if (isHelpPingTimeoutElapsed (member .getIdLong (), config )) {
9398 lastPingTimes .put (event .getMember ().getIdLong (), new Pair <>(System .currentTimeMillis (), config .getGuild ()));
9499 TextChannel notifChannel = config .getHelpConfig ().getHelpNotificationChannel ();
95- notifChannel .sendMessageEmbeds (new EmbedBuilder ().setDescription ("""
96- %s requested help in %s
97-
98- Tags:
99- %s
100-
101- [Click to view](%s)
102- """
103- .formatted (
104- event .getUser ().getAsMention (),
105- post .getAsMention (),
106- getTagString (post ),
107- post .getJumpUrl ()
108- ))
100+ EmbedBuilder eb = new EmbedBuilder ()
101+ .setDescription ("%s requested help in %s"
102+ .formatted (
103+ event .getUser ().getAsMention (),
104+ post .getAsMention ()
105+ ))
109106 .setAuthor (member .getEffectiveName (), null , member .getEffectiveAvatarUrl ())
110107 .setFooter (event .getUser ().getId ())
111- .setColor (Color .YELLOW )
112- .build ())
108+ .setColor (Color .YELLOW );
109+
110+ appendComment (eb , event .getOption ("comment" , null , OptionMapping ::getAsString ));
111+ appendTags (eb , post );
112+ eb .appendDescription ("\n \n [Click to view](" +post .getJumpUrl ()+")" );
113+
114+ notifChannel .sendMessageEmbeds (eb .build ())
113115 .addActionRow (createAcknowledgementButton ())
114116 .queue ();
115117 event .reply ("""
116118 Successfully requested help.
117-
119+
118120 Note that this does NOT gurantee that anybody here has the time and knowledge to help you.
119121 Abusing this command might result in moderative action taken against you.
120122 """ )
@@ -125,23 +127,31 @@ public void execute(@NotNull SlashCommandInteractionEvent event) {
125127 }
126128 }
127129
128- private String getTagString (ThreadChannel post ) {
129- String text = post
130- .getAppliedTags ()
131- .stream ()
132- .map (this ::getForumTagText )
133- .map (tag -> "- " + tag )
134- .collect (Collectors .joining ("\n " ));
135- if (text .isEmpty ()) {
136- text = "- <no tags>" ;
130+ private void appendTags (EmbedBuilder eb , ThreadChannel post ) {
131+ List <ForumTag > tags = post .getAppliedTags ();
132+ if (!tags .isEmpty ()) {
133+ String text = tags
134+ .stream ()
135+ .map (this ::getForumTagText )
136+ .map (tag -> "- " + tag )
137+ .collect (Collectors .joining ("\n " ));
138+ eb .appendDescription ("\n \n Tags:\n " )
139+ .appendDescription (text );
140+ }
141+ }
142+
143+ private void appendComment (EmbedBuilder eb , String comment ) {
144+ if (comment != null ) {
145+ eb
146+ .appendDescription ("\n \n comment:\n " )
147+ .appendDescription ("```\n " +StringUtils .standardSanitizer ().compute (comment ) + "\n ```" );
137148 }
138- return text ;
139149 }
140150
141151 private Button createAcknowledgementButton () {
142152 return Button .of (ButtonStyle .SECONDARY , ComponentIdBuilder .build ("help-ping" , "acknowledge" ), "Mark as acknowledged" );
143153 }
144-
154+
145155 private Button createUndoAcknowledgementButton () {
146156 return Button .of (ButtonStyle .SECONDARY , ComponentIdBuilder .build ("help-ping" , "unacknowledge" ), "Mark as unacknowledged" );
147157 }
@@ -202,11 +212,11 @@ public void handleButton(ButtonInteractionEvent event, Button button) {
202212 switch (id [1 ]) {
203213 case "acknowledge" ->
204214 acknowledgeChangeAction (event , true );
205- case "unacknowledge" ->
215+ case "unacknowledge" ->
206216 acknowledgeChangeAction (event , false );
207217 default -> event .reply ("Unknown button" ).setEphemeral (true ).queue ();
208218 }
209-
219+
210220 }
211221
212222 private void acknowledgeChangeAction (ButtonInteractionEvent event , boolean acknowledged ) {
@@ -224,7 +234,7 @@ private void acknowledgeChangeAction(ButtonInteractionEvent event, boolean ackno
224234 .setActionRow (acknowledged ?createUndoAcknowledgementButton ():createAcknowledgementButton ())
225235 .queue ();
226236 }
227-
237+
228238 private String getCurrentFormattedTimestamp () {
229239 return TimeFormat .RELATIVE .format (Instant .now ().toEpochMilli ());
230240 }
@@ -238,7 +248,7 @@ private String getForumTagText(ForumTag tag) {
238248 .append (" " );
239249 }
240250 sb .append (tag .getName ());
241-
251+
242252 return sb .toString ();
243253 }
244254
0 commit comments