<commit_before>package com.bwfcwalshy.flarebot.commands.administrator;

import com.bwfcwalshy.flarebot.FlareBot;
import com.bwfcwalshy.flarebot.MessageUtils;
import com.bwfcwalshy.flarebot.commands.Command;
import com.bwfcwalshy.flarebot.commands.CommandType;
import com.bwfcwalshy.flarebot.scheduler.FlarebotTask;
import sx.blah.discord.handle.obj.IChannel;
import sx.blah.discord.handle.obj.IMessage;
import sx.blah.discord.handle.obj.IUser;
import sx.blah.discord.util.DiscordException;
import sx.blah.discord.util.MissingPermissionsException;
import sx.blah.discord.util.RequestBuffer;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Purge implements Command {
    private Map<String, Long> cooldowns = new HashMap<>();
    private static final long cooldown = 60000;

    @Override
    public void onCommand(IUser sender, IChannel channel, IMessage message, String[] args) {
        if (channel.isPrivate()) {
            MessageUtils.sendMessage(MessageUtils.getEmbed(sender).withDesc("Cannot purge in DMs!").build(), channel);
            return;
        }
        if (args.length == 1 && args[0].matches("\\d+")) {
            if(!FlareBot.getInstance().getPermissions(channel).hasPermission(sender, "flarebot.purge.bypass")) {
                long calmitdood = cooldowns.computeIfAbsent(channel.getGuild().getID(), n -> 0L);
                if (System.currentTimeMillis() - calmitdood < cooldown) {
                    MessageUtils.sendMessage(MessageUtils.getEmbed(sender)
                            .withDesc(String.format("You are on a cooldown! %s seconds left!",
                                    (cooldown - (System.currentTimeMillis() - calmitdood)) / 1000)).build(), channel);
                    return;
                }
            }
            int count = Integer.parseInt(args[0]) + 1;
            if (count < 2 || count > 200) {
                MessageUtils.sendMessage(MessageUtils
                        .getEmbed(sender).withDesc("Can't purge less than 2 messages or more than 200!").build(), channel);
                return;
            }
            cooldowns.put(channel.getGuild().getID(), System.currentTimeMillis());
            RequestBuffer.request(() -> {
                channel.getMessages().setCacheCapacity(count);
                boolean loaded = true;
                while (loaded && channel.getMessages().size() < count)
                    loaded = channel.getMessages().load(Math.min(count, 100));
                if (loaded) {
                    List<IMessage> list = new ArrayList<>(channel.getMessages());
                    List<IMessage> toDelete = new ArrayList<>();
                    for (IMessage msg : list) {
                        if (toDelete.size() > 99) {
                            bulk(toDelete, channel, sender);
                            toDelete.clear();
                        }
                        toDelete.add(msg);
                    }
                    bulk(toDelete, channel, sender);
                    channel.getMessages().setCacheCapacity(0);
                    IMessage msg = MessageUtils.sendMessage(MessageUtils
                            .getEmbed(sender).withDesc(":+1: Deleted!")
                            .appendField("Message Count: ", String.valueOf(count - 1), true).build(), channel);
                    new FlarebotTask("Delete message " + msg.getChannel().toString() + msg.getID()) {
                        @Override
                        public void run() {
                            RequestBuffer.request(() -> {
                                try {
                                    msg.delete();<commit_msg>* Tiny improvement to cooldown bypass<commit_after>package com.bwfcwalshy.flarebot.commands.administrator;

import com.bwfcwalshy.flarebot.FlareBot;
import com.bwfcwalshy.flarebot.MessageUtils;
import com.bwfcwalshy.flarebot.commands.Command;
import com.bwfcwalshy.flarebot.commands.CommandType;
import com.bwfcwalshy.flarebot.scheduler.FlarebotTask;
import sx.blah.discord.handle.obj.IChannel;
import sx.blah.discord.handle.obj.IMessage;
import sx.blah.discord.handle.obj.IUser;
import sx.blah.discord.util.DiscordException;
import sx.blah.discord.util.MissingPermissionsException;
import sx.blah.discord.util.RequestBuffer;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Purge implements Command {
    private Map<String, Long> cooldowns = new HashMap<>();
    private static final long cooldown = 60000;

    @Override
    public void onCommand(IUser sender, IChannel channel, IMessage message, String[] args) {
        if (channel.isPrivate()) {
            MessageUtils.sendMessage(MessageUtils.getEmbed(sender).withDesc("Cannot purge in DMs!").build(), channel);
            return;
        }
        if (args.length == 1 && args[0].matches("\\d+")) {
            if(!FlareBot.getInstance().getPermissions(channel).hasPermission(sender, "flarebot.purge.bypass")) {
                long calmitdood = cooldowns.computeIfAbsent(channel.getGuild().getID(), n -> 0L);
                if (System.currentTimeMillis() - calmitdood < cooldown) {
                    MessageUtils.sendMessage(MessageUtils.getEmbed(sender)
                            .withDesc(String.format("You are on a cooldown! %s seconds left!",
                                    (cooldown - (System.currentTimeMillis() - calmitdood)) / 1000)).build(), channel);
                    return;
                }
            }
            int count = Integer.parseInt(args[0]) + 1;
            if (count < 2 || count > 200) {
                MessageUtils.sendMessage(MessageUtils
                        .getEmbed(sender).withDesc("Can't purge less than 2 messages or more than 200!").build(), channel);
                return;
            }
            if(!FlareBot.getInstance().getPermissions(channel).hasPermission(sender, "flarebot.purge.bypass"))
                cooldowns.put(channel.getGuild().getID(), System.currentTimeMillis());
            RequestBuffer.request(() -> {
                channel.getMessages().setCacheCapacity(count);
                boolean loaded = true;
                while (loaded && channel.getMessages().size() < count)
                    loaded = channel.getMessages().load(Math.min(count, 100));
                if (loaded) {
                    List<IMessage> list = new ArrayList<>(channel.getMessages());
                    List<IMessage> toDelete = new ArrayList<>();
                    for (IMessage msg : list) {
                        if (toDelete.size() > 99) {
                            bulk(toDelete, channel, sender);
                            toDelete.clear();
                        }
                        toDelete.add(msg);
                    }
                    bulk(toDelete, channel, sender);
                    channel.getMessages().setCacheCapacity(0);
                    IMessage msg = MessageUtils.sendMessage(MessageUtils
                            .getEmbed(sender).withDesc(":+1: Deleted!")
                            .appendField("Message Count: ", String.valueOf(count - 1), true).build(), channel);
                    new FlarebotTask("Delete message " + msg.getChannel().toString() + msg.getID()) {
                        @Override
                        public void run() {
                            RequestBuffer.request(() -> {
                                try {
                                    msg.delete();
{'fraction_non_alphanumeric': 0.11619578193394349, 'fraction_numerical': 0.007958615200955034, 'mean_word_length': 1.8899961671138368, 'pattern_counts': {'":': 2, '<': 21, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5218895', 'n_tokens_mistral': 2080, 'n_tokens_neox': 1958, 'n_words': 372}