use of com.chill.projects.bot.messaging.FrostDirectMessage in project Frost by woojiahao.
the class ModerationCommands method muteCommand.
private void muteCommand(DiscordSet set, String duration, String targetID) {
Member target = set.getGuild().getMemberById(targetID);
Role mutedRole = set.getGuild().getRolesByName("Muted", true).get(0);
String muteSuccess = String.format("User: %s#%s is muted now for %s minutes", target.getEffectiveName(), set.getGuild().getJDA().getUserById(targetID).getDiscriminator(), duration);
set.getFrom().sendMessage(muteSuccess).queue();
set.getFrom().sendMessage("Timer started").queue();
set.getGuild().getController().addSingleRoleToMember(target, mutedRole).complete();
new FrostDirectMessage().sendPrivateMessage(target.getUser(), new EmbedBuilder().addField("Mute", "You have been muted for " + String.valueOf(Long.parseLong(duration) / 60000), true).build());
Timer t = new Timer();
t.schedule(new TimerTask() {
@Override
public void run() {
set.getFrom().sendMessage("Timer ended").queue();
set.getGuild().getController().removeSingleRoleFromMember(target, mutedRole).complete();
new FrostDirectMessage().sendPrivateMessage(target.getUser(), new EmbedBuilder().addField("Unmute", "You have been unmuted", true).build());
}
}, Long.parseLong(duration) * 60000);
}
use of com.chill.projects.bot.messaging.FrostDirectMessage in project Frost by woojiahao.
the class SpamDetector method updateMap.
private void updateMap(DiscordSet set) {
String user = set.getUser().getId();
String guild = set.getGuild().getId();
int guildPos = 0;
if ((guildPos = hasGuildEntry(guild)) == -1) {
messageCount.add(new AbstractMap.SimpleEntry<>(guild, new HashMap<>()));
messageTimer.add(new AbstractMap.SimpleEntry<>(guild, new HashMap<>()));
guildPos = messageCount.size() - 1;
}
if (!hasUserEntry(user, guildPos)) {
messageCount.get(guildPos).getValue().put(user, 1L);
messageTimer.get(guildPos).getValue().put(user, System.currentTimeMillis());
int finalGuildPos = guildPos;
new Timer().schedule(new TimerTask() {
@Override
public void run() {
messageCount.get(finalGuildPos).getValue().remove(user);
messageTimer.get(finalGuildPos).getValue().remove(user);
}
}, RaidLimits.MESSAGE.getDuration());
return;
}
long currentMessageCount = messageCount.get(guildPos).getValue().get(user);
messageCount.get(guildPos).getValue().replace(user, currentMessageCount + 1);
if (messageCount.get(guildPos).getValue().get(user) > RaidLimits.MESSAGE.getMessageCount()) {
long firstMessageTime = messageTimer.get(guildPos).getValue().get(user);
long currentTime = System.currentTimeMillis();
if (currentTime - firstMessageTime <= RaidLimits.MESSAGE.getDuration()) {
FrostRoles.assignRole(set, RolesID.MUTED);
String loggingID = FrostGuildList.getFrostGuildByID(set.getGuild().getId()).getLoggingChannel();
set.getGuild().getTextChannelById(loggingID).sendMessage(set.getUser().getAsMention() + " was muted due " + "to spam").queue();
new FrostDirectMessage().sendPrivateMessage(set.getUser(), new EmbedBuilder().addField("Auto spam detection", "You have been muted for spam", false).build());
List<Message> toDelete = new MessageHistory(set.getFrom()).retrievePast(50).complete().stream().filter(m -> m.getAuthor().getId().equals(set.getUser().getId())).collect(Collectors.toList());
if (toDelete != null || toDelete.size() > 0) {
set.getGuild().getTextChannelById(set.getFrom().getId()).deleteMessages(toDelete).queue();
}
RaidersList.add(user, guild);
}
}
}
Aggregations