Skip to content

Commit 6852580

Browse files
committed
add custom notification for kicked users
1 parent 1dc8a34 commit 6852580

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

src/main/java/net/discordjug/javabot/data/config/guild/ModerationConfig.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,12 @@ public class ModerationConfig extends GuildConfigItem {
103103
/**
104104
* Text that is sent to users when they're banned.
105105
*/
106-
private String banMessageText = "Looks like you've been banned from the Java Discord. If you want to appeal this decision please fill out our form at <https://airtable.com/shrp5V4H1U5TYOXyC>.";
106+
private String banMessageText = "Looks like you've been banned from the Discord Java Community. If you want to appeal this decision please fill out our form at <https://airtable.com/shrp5V4H1U5TYOXyC>.";
107+
108+
/**
109+
* Text that is sent to users when they're banned.
110+
*/
111+
private String kickMessageText = "Looks like you've been kicked from the Discord Java Community. If you want to, you should be able to rejoin at <https://join.discordjug.net/> but please ensure you are following the rules if you do.";
107112

108113
/**
109114
* A list of rules that can result in a message being blocked or similar.

src/main/java/net/discordjug/javabot/systems/moderation/ModerationService.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -311,11 +311,14 @@ private boolean isBanned(@NotNull Guild guild, long userId) {
311311
*/
312312
public void kick(User user, String reason, Member kickedBy, MessageChannel channel, boolean quiet) {
313313
MessageEmbed kickEmbed = buildKickEmbed(user, kickedBy, reason);
314-
kickedBy.getGuild().kick(user).queue(s -> {
315-
notificationService.withUser(user).sendDirectMessage(c -> c.sendMessageEmbeds(kickEmbed));
316-
notificationService.withGuild(kickedBy.getGuild()).sendToModerationLog(c -> c.sendMessageEmbeds(kickEmbed));
317-
if (!quiet) channel.sendMessageEmbeds(kickEmbed).queue();
318-
}, ExceptionLogger::capture);
314+
user.openPrivateChannel()
315+
.flatMap(c -> c.sendMessageEmbeds(kickEmbed).setContent(getModerationConfig(kickedBy).getKickMessageText()))
316+
.mapToResult() // errors in sending DMs should still result in the kicking logic being executed
317+
.queue(_ -> {
318+
kickedBy.getGuild().kick(user).queue();
319+
notificationService.withGuild(kickedBy.getGuild()).sendToModerationLog(c -> c.sendMessageEmbeds(kickEmbed));
320+
if (!quiet) channel.sendMessageEmbeds(kickEmbed).queue();
321+
});
319322
}
320323

321324
public void sendKickGuildNotification(User user, String reason, Member moderator) {

0 commit comments

Comments
 (0)