-
Notifications
You must be signed in to change notification settings - Fork 24
delete blacklisted attachments from message and replace with webhook #520
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
delete blacklisted attachments from message and replace with webhook #520
Conversation
…e wonderful moderation of a given server marked as blacklisted
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please address the changes I wrote in the review comments.
Also, please use a proper/professional commit message. You can change the commit message of your existing commit using git commit --amend
(optionally with -m <message>
) and then force-pushing to your branch with git push --force-with-lease
.
@@ -54,6 +56,8 @@ public GuildConfig(Guild guild, Path file) { | |||
this.starboardConfig = new StarboardConfig(); | |||
this.messageCacheConfig = new MessageCacheConfig(); | |||
this.serverLockConfig = new ServerLockConfig(); | |||
this.blacklistedMessageExtensions = List.of("application/x-msdos-program", "application/java-archive", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason for the use of MIME types instead of extensions?
If you are using MIME types, why is the variable called "extensions"?
Message message = event.getMessage(); | ||
List<Message.Attachment> attachments = message.getAttachments(); | ||
List<Message.Attachment> allowedAttachments = new ArrayList<>(); | ||
attachments.forEach(attachment -> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be done nicely using the stream API, for example
List<Message.Attachment> allowedAttachments = attachments
.stream()
.filter(this::isAllowedAttachment)
.toList();
if (tc == null) { | ||
return; | ||
} | ||
long threadId = event.isFromThread() ? event.getChannel().getIdLong() : 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That can be merged with the previous event.isFromThread()
check by declaring the variable before (and initializing it with 0
).
} | ||
}); | ||
if (message.getAttachments().size() != allowedAttachments.size()) { | ||
IWebhookContainer tc = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tc
would imply TextChannel
. webhookContainer
(or something else if you have a better idea) would be a better name.
long threadId = event.isFromThread() ? event.getChannel().getIdLong() : 0; | ||
WebhookUtil.ensureWebhookExists( | ||
tc, | ||
wh -> WebhookUtil.replaceMemberMessageWithAttachments( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a small embed to the message saying that unwanted attachments were removed.
* @return a {@link CompletableFuture} representing the action of sending | ||
* the message | ||
*/ | ||
public static CompletableFuture<ReadonlyMessage> mirrorMessageToWebhookWithAttachments(@NotNull Webhook webhook, @NotNull Message originalMessage, String newMessageContent, long threadId, @Nullable List<LayoutComponent> components, List<Message.Attachment> attachments) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't duplicate code. Instead, you can add an attachments
parameter to the existing method and create a new overload with the old signature.
Please also fix the checkstyle errors. We use tabs for indentation. |
), | ||
e -> ExceptionLogger.capture( | ||
e, | ||
"Error creating webhook for UnformattedCodeListener" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This message is incorrect here.
new crazy amazing feature where if someone sends a message with a forbidden attachment then that attachment is removed and the whole message is replaced as a webhook with only the good attachments
works server wide
config in guild config