2020 */
2121package com .mcmoddev .mmdbot .watcher .event ;
2222
23+ import club .minnced .discord .webhook .send .AllowedMentions ;
24+ import com .mcmoddev .mmdbot .core .util .Utils ;
25+ import com .mcmoddev .mmdbot .core .util .webhook .WebhookManager ;
2326import com .mcmoddev .mmdbot .watcher .TheWatcher ;
2427import net .dv8tion .jda .api .EmbedBuilder ;
2528import net .dv8tion .jda .api .MessageBuilder ;
4245import java .time .Instant ;
4346import java .time .OffsetDateTime ;
4447import java .util .ArrayList ;
45- import java .util .Collections ;
4648import java .util .HashSet ;
4749import java .util .List ;
4850import java .util .Objects ;
5557 */
5658public final class EventReactionAdded extends ListenerAdapter {
5759
60+ private static final String WEBHOOK_NAME = "RequestLogs" ;
61+ public static final WebhookManager WEBHOOKS = WebhookManager .of (e -> e .trim ().equals (WEBHOOK_NAME ), WEBHOOK_NAME , AllowedMentions .none ());
62+
5863 /**
5964 * The Warned messages.
6065 */
6166 private final Set <Message > warnedMessages = new HashSet <>();
6267
6368 /**
6469 * The set of messages that have passed the reaction threshold required for request deletion, but are awaiting a
65- * staff member (a user with {@link Permission#KICK_MEMBERS }) to sign-off on the deletion by giving their own
70+ * staff member (a user with {@link Permission#MODERATE_MEMBERS }) to sign-off on the deletion by giving their own
6671 * reaction.
6772 *
6873 * <p>If a message has been added previously to this set, and the message falls back below the request deletion
@@ -93,8 +98,6 @@ public void onMessageReactionAdd(final MessageReactionAddEvent event) {
9398
9499 final var guild = event .getGuild ();
95100 final var guildId = guild .getIdLong ();
96- final var discussionChannel = guild .getTextChannelById (TheWatcher .getOldConfig ()
97- .getChannel ("requests.discussion" ));
98101 if (TheWatcher .getOldConfig ().getGuildID () == guildId && TheWatcher .getOldConfig ().getChannel ("requests.main" )
99102 == channel .getIdLong ()) {
100103
@@ -117,7 +120,7 @@ public void onMessageReactionAdd(final MessageReactionAddEvent event) {
117120 .flatMap (PaginationAction ::stream )
118121 .map (guild ::getMember )
119122 .filter (Objects ::nonNull )
120- .filter (member -> member .hasPermission (Permission .KICK_MEMBERS ))
123+ .filter (member -> member .hasPermission (Permission .MODERATE_MEMBERS ))
121124 .toList ();
122125 final var hasStaffSignoff = signedOffStaff .size () > 0 ;
123126
@@ -139,7 +142,6 @@ public void onMessageReactionAdd(final MessageReactionAddEvent event) {
139142 .getChannel ("events.requests_deletion" ));
140143 if (logChannel != null ) {
141144 final EmbedBuilder builder = new EmbedBuilder ();
142- builder .setAuthor (messageAuthor .getAsTag (), messageAuthor .getEffectiveAvatarUrl ());
143145 builder .setTitle ("Request awaiting moderator approval" );
144146 builder .appendDescription ("Request from " )
145147 .appendDescription (messageAuthor .getAsMention ())
@@ -153,9 +155,11 @@ public void onMessageReactionAdd(final MessageReactionAddEvent event) {
153155 builder .setColor (Color .YELLOW );
154156 builder .setFooter ("User ID: " + messageAuthor .getId ());
155157
156- logChannel .sendMessageEmbeds (builder .build ())
157- .allowedMentions (Collections .emptySet ())
158- .queue ();
158+ WEBHOOKS .getWebhook (logChannel )
159+ .send (Utils .webhookMessage (builder .build ())
160+ .setUsername (messageAuthor .getAsTag ())
161+ .setAvatarUrl (messageAuthor .getEffectiveAvatarUrl ())
162+ .build ());
159163 }
160164 }
161165 return ;
@@ -175,7 +179,6 @@ public void onMessageReactionAdd(final MessageReactionAddEvent event) {
175179 .getChannel ("events.requests_deletion" ));
176180 if (logChannel != null ) {
177181 final EmbedBuilder builder = new EmbedBuilder ();
178- builder .setAuthor (messageAuthor .getAsTag (), messageAuthor .getEffectiveAvatarUrl ());
179182 builder .setTitle ("Deleted request by community review" );
180183 builder .appendDescription ("Deleted request from " )
181184 .appendDescription (messageAuthor .getAsMention ())
@@ -192,25 +195,22 @@ public void onMessageReactionAdd(final MessageReactionAddEvent event) {
192195 builder .setColor (Color .RED );
193196 builder .setFooter ("User ID: " + messageAuthor .getId ());
194197
195- logChannel .sendMessage (message .getContentRaw ())
196- .setEmbeds (builder .build ())
197- .allowedMentions (Collections .emptySet ())
198- .queue ();
198+ WEBHOOKS .getWebhook (logChannel )
199+ .send (Utils .webhookMessage (builder .build ())
200+ .setContent (message .getContentRaw ())
201+ .setAvatarUrl (messageAuthor .getEffectiveAvatarUrl ())
202+ .setUsername (messageAuthor .getAsTag ())
203+ .build ());
199204 }
200205
201206 channel .deleteMessageById (event .getMessageId ())
202207 .reason (String .format (
203208 "Bad request: %d bad reactions, %d needs improvement reactions, %d good reactions" ,
204209 badReactionsCount , needsImprovementReactionsCount , goodReactionsCount ))
205- .flatMap (v -> {
206- RestAction <Message > action = messageAuthor .openPrivateChannel ()
207- .flatMap (privateChannel -> privateChannel .sendMessage (response ));
208- //If we can't DM the user, send it in the discussions channel instead.
209- if (discussionChannel != null ) {
210- action = action .onErrorFlatMap (throwable -> discussionChannel .sendMessage (response ));
211- }
212- return action ;
213- })
210+ .flatMap (v -> messageAuthor .openPrivateChannel ()
211+ .flatMap (privateChannel -> privateChannel .sendMessage (response ))
212+ // If we can't DM the user, send it in the thread.
213+ .onErrorFlatMap (throwable -> event .getGuild ().getThreadChannelById (event .getMessageIdLong ()).sendMessage (response )))
214214 .queue ();
215215
216216 } else if (!warnedMessages .contains (message ) && requestScore >= warningThreshold ) {
@@ -227,11 +227,9 @@ public void onMessageReactionAdd(final MessageReactionAddEvent event) {
227227 warnedMessages .add (message );
228228
229229 RestAction <Message > action = messageAuthor .openPrivateChannel ()
230- .flatMap (privateChannel -> privateChannel .sendMessage (response ));
231- //If we can't DM the user, send it in the thread.
232- if (discussionChannel != null ) {
233- action = action .onErrorFlatMap (throwable -> event .getGuild ().getThreadChannelById (event .getMessageIdLong ()).sendMessage (response ));
234- }
230+ .flatMap (privateChannel -> privateChannel .sendMessage (response ))
231+ // If we can't DM the user, send it in the thread.
232+ .onErrorFlatMap (throwable -> event .getGuild ().getThreadChannelById (event .getMessageIdLong ()).sendMessage (response ));
235233 action .queue ();
236234 }
237235 // Remove messages under the removal threshold from the awaiting sign-off set
0 commit comments