1717import net .dv8tion .jda .api .EmbedBuilder ;
1818import net .dv8tion .jda .api .entities .*;
1919import net .dv8tion .jda .api .entities .channel .Channel ;
20+ import net .dv8tion .jda .api .entities .channel .concrete .TextChannel ;
2021import net .dv8tion .jda .api .entities .channel .concrete .ThreadChannel ;
2122import net .dv8tion .jda .api .entities .channel .middleman .MessageChannel ;
2223import net .dv8tion .jda .api .events .interaction .ModalInteractionEvent ;
4344 */
4445@ Slf4j
4546@ RequiredArgsConstructor
46- @ AutoDetectableComponentHandler ({"resolve-report" ,"report" })
47+ @ AutoDetectableComponentHandler ({"resolve-report" , ReportManager . REPORT_INTERACTION_NAME })
4748public class ReportManager implements ButtonHandler , ModalHandler {
49+ static final String REPORT_INTERACTION_NAME = "report" ;
4850 private final BotConfig botConfig ;
4951
5052 @ Override
5153 public void handleButton (@ NotNull ButtonInteractionEvent event , Button button ) {
5254 event .deferReply (true ).queue ();
5355 String [] id = ComponentIdBuilder .split (event .getComponentId ());
56+ if ("resolve-report" .equals (id [0 ])) {
57+ handleResolveReportButton (event , id );
58+ } else if (REPORT_INTERACTION_NAME .equals (id [0 ])&&"create-thread" .equals (id [1 ])) {
59+ createReportUserThread (event , id );
60+ }else {
61+ Responses .error (event .getHook (), "Unexpected button" ).queue ();
62+ }
63+ }
64+
65+ private void createReportUserThread (ButtonInteractionEvent event , String [] id ) {
66+ TextChannel reportUserChannel = botConfig .get (event .getGuild ())
67+ .getModerationConfig ()
68+ .getReportUserThreadHolder ();
69+ ThreadChannel reportThread = event .getGuild ().getThreadChannelById (id [2 ]);
70+ List <MessageEmbed > reportEmbeds = event .getMessage ().getEmbeds ();
71+ String title ;
72+ if (reportEmbeds .isEmpty ()) {
73+ title = "report information" ;
74+ } else {
75+ title = reportEmbeds .get (0 ).getTitle ();
76+ }
77+ reportUserChannel
78+ .createThreadChannel (title , true )
79+ .queue (reporterThread -> {
80+ reporterThread .getManager ().setInvitable (false ).queue ();
81+ reporterThread
82+ .sendMessage (event .getUser ().getAsMention () +
83+ "\n You can provide additional information regarding your report here.\n "
84+ + "Messages sent in this thread can be seen by staff members but not other users." )
85+ .addEmbeds (reportEmbeds )
86+ .queue ();
87+ reportThread .addThreadMember (event .getUser ()).queue ();
88+ reportThread
89+ .sendMessageEmbeds (
90+ new EmbedBuilder ()
91+ .setTitle ("Additional information from reporter" )
92+ .setDescription ("The reporter created a thread for additional information: " + reporterThread .getAsMention () + "\n \n [thread link](" + reporterThread .getJumpUrl () + ")" )
93+ .build ())
94+ .queue ();
95+ Responses .info (event .getHook (), "Information thread created" , "The thread " +reporterThread .getAsMention ()+" has been created for you. You can provide additional details related to your report there." ).queue ();
96+ });
97+ }
98+
99+ private void handleResolveReportButton (ButtonInteractionEvent event , String [] id ) {
54100 ThreadChannel thread = event .getGuild ().getThreadChannelById (id [1 ]);
55101 if (thread == null ) {
56102 Responses .error (event .getHook (), "Could not find the corresponding thread channel." ).queue ();
@@ -64,7 +110,7 @@ public void handleButton(@NotNull ButtonInteractionEvent event, Button button) {
64110 /**
65111 * Resolves a report thread.
66112 * This closes the current thread.
67- * Tis method does not check whether the current thread is actually a report thread.
113+ * This method does not check whether the current thread is actually a report thread.
68114 * @param resolver the {@link User} responsible for resolving the report
69115 * @param reportThread the thread of the report to resolve
70116 */
@@ -99,7 +145,7 @@ protected Modal buildUserReportModal(@NotNull UserContextInteractionEvent event)
99145 .setMaxLength (MessageEmbed .VALUE_MAX_LENGTH )
100146 .build ();
101147 String title = "Report " + UserUtils .getUserTag (event .getTarget ());
102- return Modal .create (ComponentIdBuilder .build ("report" , "user" , event .getTarget ().getId ()), title .substring (0 , Math .min (title .length (), Modal .MAX_TITLE_LENGTH )))
148+ return Modal .create (ComponentIdBuilder .build (REPORT_INTERACTION_NAME , "user" , event .getTarget ().getId ()), title .substring (0 , Math .min (title .length (), Modal .MAX_TITLE_LENGTH )))
103149 .addActionRow (messageInput )
104150 .build ();
105151 }
@@ -120,7 +166,7 @@ protected Modal buildMessageReportModal(@NotNull MessageContextInteractionEvent
120166 TextInput messageInput = TextInput .create ("reason" , "Report Description" , TextInputStyle .PARAGRAPH )
121167 .setMaxLength (MessageEmbed .VALUE_MAX_LENGTH )
122168 .build ();
123- return Modal .create (ComponentIdBuilder .build ("report" , "message" , event .getTarget ().getId ()), title .substring (0 , Math .min (title .length (), Modal .MAX_TITLE_LENGTH )))
169+ return Modal .create (ComponentIdBuilder .build (REPORT_INTERACTION_NAME , "message" , event .getTarget ().getId ()), title .substring (0 , Math .min (title .length (), Modal .MAX_TITLE_LENGTH )))
124170 .addActionRow (messageInput )
125171 .build ();
126172 }
@@ -133,7 +179,7 @@ protected Modal buildMessageReportModal(@NotNull MessageContextInteractionEvent
133179 * @param targetId The targeted user's id.
134180 * @return The {@link WebhookMessageCreateAction}.
135181 */
136- protected WebhookMessageCreateAction <Message > handleUserReport (InteractionHook hook , @ NotNull String reason , String targetId ) {
182+ WebhookMessageCreateAction <Message > handleUserReport (InteractionHook hook , @ NotNull String reason , String targetId ) {
137183 if (reason .isBlank ()) {
138184 return Responses .error (hook , "No report reason was provided." );
139185 }
@@ -147,16 +193,26 @@ protected WebhookMessageCreateAction<Message> handleUserReport(InteractionHook h
147193 return ;
148194 }
149195 reportChannel .sendMessageEmbeds (embed .build ())
150- .queue (m -> this .createReportThread (m , target .getIdLong (), config .getModerationConfig ()));
151- embed .setDescription ("Successfully reported " + "`" + UserUtils .getUserTag (target ) + "`!\n Your report has been send to our Moderators" );
152- hook .sendMessageEmbeds (embed .build ()).queue ();
196+ .queue (m -> this .createReportThread (m , target .getIdLong (), config .getModerationConfig (),
197+ reportThread -> {
198+ sendReportResponse (hook , target , embed , reportThread );
199+ }));
153200 }, failure -> {
154201 Responses .error (hook , "The user to report seems not to exist any more." ).queue ();
155202 log .warn ("Cannot retrieve user {} when reporting them" , targetId , failure );
156203 });
157204 return null ;
158205 }
159206
207+ private void sendReportResponse (InteractionHook hook , User targetUser , EmbedBuilder reportEmbed , ThreadChannel reportThread ) {
208+ reportEmbed .setDescription ("Successfully reported " + "`" + UserUtils .getUserTag (targetUser ) + "`!\n Your report has been send to our Moderators.\n In case you want to supply additional details, please use the \" Create thread\" button below." );
209+ hook .sendMessageEmbeds (reportEmbed .build ())
210+ .addActionRow (Button .secondary (
211+ ComponentIdBuilder .build (REPORT_INTERACTION_NAME , "create-thread" ,reportThread .getId ()),
212+ "Create thread" ))
213+ .queue ();
214+ }
215+
160216 private void handleMessageReport (ModalInteractionEvent event , String messageId ) {
161217 String reason = event .getValue ("reason" ).getAsString ();
162218 if (reason .isBlank ()) {
@@ -170,12 +226,11 @@ private void handleMessageReport(ModalInteractionEvent event, String messageId)
170226 embed .addField ("Message" , String .format ("[Jump to Message](%s)" , target .getJumpUrl ()), false );
171227 MessageChannel reportChannel = config .getModerationConfig ().getReportChannel ();
172228 reportChannel .sendMessageEmbeds (embed .build ()).queue (m -> createReportThread (m , target .getAuthor ().getIdLong (), config .getModerationConfig (), thread ->{
229+ sendReportResponse (event .getHook (), target .getAuthor (), embed , thread );
173230 WebhookUtil .ensureWebhookExists (thread .getParentChannel ().asStandardGuildMessageChannel (), wh ->{
174231 WebhookUtil .mirrorMessageToWebhook (wh , target , target .getContentRaw (), thread .getIdLong (), null , null );
175232 });
176233 }));
177- embed .setDescription ("Successfully reported " + "`" + UserUtils .getUserTag (target .getAuthor ()) + "`!\n Your report has been send to our Moderators" );
178- event .getHook ().sendMessageEmbeds (embed .build ()).queue ();
179234 }, failure -> {
180235 Responses .error (event .getHook (), "The author of the message to report seems not to exist any more." ).queue ();
181236 log .info ("Cannot retrieve reported message {} in channel {} - the message might have been deleted" , messageId , event .getChannel (), failure );
0 commit comments