Search in sources :

Example 1 with FrostDirectMessage

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);
}
Also used : EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) Timer(java.util.Timer) TimerTask(java.util.TimerTask) FrostDirectMessage(com.chill.projects.bot.messaging.FrostDirectMessage)

Example 2 with FrostDirectMessage

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);
        }
    }
}
Also used : java.util(java.util) RaidersList(com.chill.projects.bot.raiders.RaidersList) RolesID(com.chill.projects.bot.roles.RolesID) MessageHistory(net.dv8tion.jda.core.entities.MessageHistory) FrostRoles(com.chill.projects.bot.roles.FrostRoles) ListenerAdapter(net.dv8tion.jda.core.hooks.ListenerAdapter) Collectors(java.util.stream.Collectors) Message(net.dv8tion.jda.core.entities.Message) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent) DiscordSet(com.chill.projects.bot.container.DiscordSet) FrostGuildList(com.chill.projects.bot.guilds.FrostGuildList) RaidLimits(com.chill.projects.bot.raiders.RaidLimits) FrostDirectMessage(com.chill.projects.bot.messaging.FrostDirectMessage) Message(net.dv8tion.jda.core.entities.Message) FrostDirectMessage(com.chill.projects.bot.messaging.FrostDirectMessage) FrostDirectMessage(com.chill.projects.bot.messaging.FrostDirectMessage) MessageHistory(net.dv8tion.jda.core.entities.MessageHistory) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder)

Aggregations

FrostDirectMessage (com.chill.projects.bot.messaging.FrostDirectMessage)2 EmbedBuilder (net.dv8tion.jda.core.EmbedBuilder)2 DiscordSet (com.chill.projects.bot.container.DiscordSet)1 FrostGuildList (com.chill.projects.bot.guilds.FrostGuildList)1 RaidLimits (com.chill.projects.bot.raiders.RaidLimits)1 RaidersList (com.chill.projects.bot.raiders.RaidersList)1 FrostRoles (com.chill.projects.bot.roles.FrostRoles)1 RolesID (com.chill.projects.bot.roles.RolesID)1 java.util (java.util)1 Timer (java.util.Timer)1 TimerTask (java.util.TimerTask)1 Collectors (java.util.stream.Collectors)1 Message (net.dv8tion.jda.core.entities.Message)1 MessageHistory (net.dv8tion.jda.core.entities.MessageHistory)1 GuildMessageReceivedEvent (net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent)1 ListenerAdapter (net.dv8tion.jda.core.hooks.ListenerAdapter)1