Skip to content

Commit

Permalink
Kick the user instead
Browse files Browse the repository at this point in the history
  • Loading branch information
rtm516 committed Jul 16, 2024
1 parent 856e80e commit 9fbdabe
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions src/main/java/org/geysermc/discordbot/listeners/AutoModHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.MessageEmbed;
import net.dv8tion.jda.api.entities.User;
Expand Down Expand Up @@ -70,35 +71,45 @@ public void onAutoModExecution(@Nonnull AutoModExecutionEvent event) {
Member member = event.getGuild().getMemberById(userId);
if (member == null || member.isTimedOut()) return;

event.getGuild().timeoutFor(member, 7, TimeUnit.DAYS).queue();
Guild guild = event.getGuild();
String reason = "Suspected account compromise";

User user = member.getUser();
user.openPrivateChannel().queue((channel) -> {
MessageEmbed embed = new EmbedBuilder()
.setTitle("You have been automatically timed out in " + event.getGuild().getName() + "!")
.addField("Reason", "Suspected account compromise", false)
.addField("Duration", "7 days", false)
.setTitle("You have been automatically kicked from " + guild.getName() + "!")
.addField("Reason", reason, false)
.addField("Recommended Actions", "Change your Discord password, enable 2FA, and scan your computer for malware. See [Discord's article](https://support.discord.com/hc/en-us/articles/24160905919511-My-Discord-Account-was-Hacked-or-Compromised) for more info.", false)
.setTimestamp(Instant.now())
.setColor(BotColors.WARNING.getColor())
.build();

channel.sendMessageEmbeds(embed).queue();

channel.sendMessageEmbeds(embed).queue(message -> {
// Kick user
guild.kick(user).reason(reason).queue();
}, throwable -> {
// Kick user
guild.kick(user).reason(reason).queue();
});
}, throwable -> {
// Kick user
guild.kick(member).reason(reason).queue();
});

Member selfMember = event.getGuild().getSelfMember();
int id = GeyserBot.storageManager.addLog(selfMember, "timeout", user, "Suspected account compromise");

Member selfMember = guild.getSelfMember();
int id = GeyserBot.storageManager.addLog(selfMember, "kick", user, reason);

MessageEmbed logEmbed = new EmbedBuilder()
.setTitle("Timed out user")
.setTitle("Kicked user")
.addField("User", user.getAsMention(), false)
.addField("Staff member", selfMember.getAsMention(), false)
.addField("Reason", "Suspected account compromise", false)
.addField("Reason", reason, false)
.setFooter("ID: " + id)
.setTimestamp(Instant.now())
.setColor(BotColors.WARNING.getColor())
.build();

ServerSettings.getLogChannel(event.getGuild()).sendMessageEmbeds(logEmbed).queue();
ServerSettings.getLogChannel(guild).sendMessageEmbeds(logEmbed).queue();
}
}

0 comments on commit 9fbdabe

Please sign in to comment.