<commit_before>package fredboat.command;

import fredboat.command.meta.ICommand;
import java.time.OffsetDateTime;
import net.dv8tion.jda.entities.Guild;
import net.dv8tion.jda.entities.Message;
import net.dv8tion.jda.entities.TextChannel;
import net.dv8tion.jda.entities.User;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import net.dv8tion.jda.JDA;
import net.dv8tion.jda.MessageBuilder;
import net.dv8tion.jda.MessageHistory;

public class FindCommand implements ICommand {

    @Override
    public void onInvoke(Guild guild, TextChannel channel, User invoker, Message message, String[] args) {
        JDA jda = guild.getJDA();

        String searchTerm = args[1].toLowerCase();
        TextChannel selected = channel;
        if (message.getMentionedChannels().isEmpty() == false) {
            selected = message.getMentionedChannels().get(0);
        }
        int toSearch = 1337;
        channel.sendTyping();

        Message startMsg = new MessageBuilder().appendMention(invoker)
                .appendString(" searching in ")
                .appendString(String.valueOf(toSearch), MessageBuilder.Formatting.BLOCK)
                .appendString(" messages from ")
                .appendString("#" + selected.getName(), MessageBuilder.Formatting.BLOCK)
                .appendString(" containing ")
                .appendString(searchTerm, MessageBuilder.Formatting.BLOCK)
                .appendString(".")
                .build();

        MessageHistory history = new MessageHistory(jda, selected);
        ArrayList<Message> msgs = new ArrayList<>();

        try {
            for (int i = 0; i < Math.ceil(toSearch / 100); i++) {
                msgs.addAll(history.retrieve(Math.min(100, toSearch - (i * 100))));
            }
        } catch (NullPointerException ex) {//End of chat - ignore
        }

        channel.sendMessage(startMsg);
        ArrayList<Message> matches = new ArrayList<>();

        for (Message msg : msgs) {
            if (msg.getContent().toLowerCase().contains(searchTerm) && !msg.equals(message)) {
                matches.add(msg);
            }
        }

        MessageBuilder endMsg = new MessageBuilder();
        endMsg.appendString("Found a total of ")
                .appendString(String.valueOf(matches.size()), MessageBuilder.Formatting.BLOCK)
                .appendString(" matches:");

        int i = 0;
        int truncated = 0;
        for (Message msg : matches) {
            i++;
            if (endMsg.getLength() > 1600 || msg.getContent().length() > 400) {
                truncated++;
            } else {
                endMsg.appendString("\n")
                        .appendString("[" + forceTwoDigits(i) + "] " + formatTimestamp(msg.getTime()), MessageBuilder.Formatting.BLOCK)
                        .appendString(" ")
                        .appendString(msg.getAuthor().getUsername(), MessageBuilder.Formatting.BLOCK)
                        .appendString(" ")
                        .appendString(msg.getContent());
            }
        }

        if (truncated > 0) {
            endMsg.appendString("\n[Truncated " + truncated + "]");
        }
        channel.sendMessage(endMsg.build());

    }
    
    private String forceTwoDigits(int i){
        String str = String.valueOf(i);
        
        if (str.length() == 1){
            str = "0" + str;
        }
        
        return str;
    }

    public String formatTimestamp(OffsetDateTime t) {
        String str = "[" + forceTwoDigits(t.getHour()) + ":" + forceTwoDigits(t.getMinute()) + "]";
        
        return str;
    }
}<commit_msg>More formatting<commit_after>package fredboat.command;

import fredboat.command.meta.ICommand;
import java.time.Clock;
import java.time.LocalDateTime;
import java.time.OffsetDateTime;
import net.dv8tion.jda.entities.Guild;
import net.dv8tion.jda.entities.Message;
import net.dv8tion.jda.entities.TextChannel;
import net.dv8tion.jda.entities.User;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import net.dv8tion.jda.JDA;
import net.dv8tion.jda.MessageBuilder;
import net.dv8tion.jda.MessageHistory;

public class FindCommand implements ICommand {

    @Override
    public void onInvoke(Guild guild, TextChannel channel, User invoker, Message message, String[] args) {
        JDA jda = guild.getJDA();

        String searchTerm = args[1].toLowerCase();
        TextChannel selected = channel;
        if (message.getMentionedChannels().isEmpty() == false) {
            selected = message.getMentionedChannels().get(0);
        }
        int toSearch = 1337;
        channel.sendTyping();

        Message startMsg = new MessageBuilder().appendMention(invoker)
                .appendString(" searching in ")
                .appendString(String.valueOf(toSearch), MessageBuilder.Formatting.BLOCK)
                .appendString(" messages from ")
                .appendString("#" + selected.getName(), MessageBuilder.Formatting.BLOCK)
                .appendString(" containing ")
                .appendString(searchTerm, MessageBuilder.Formatting.BLOCK)
                .appendString(".")
                .build();

        MessageHistory history = new MessageHistory(jda, selected);
        ArrayList<Message> msgs = new ArrayList<>();

        try {
            for (int i = 0; i < Math.ceil(toSearch / 100); i++) {
                msgs.addAll(history.retrieve(Math.min(100, toSearch - (i * 100))));
            }
        } catch (NullPointerException ex) {//End of chat - ignore
        }

        channel.sendMessage(startMsg);
        ArrayList<Message> matches = new ArrayList<>();

        for (Message msg : msgs) {
            if (msg.getContent().toLowerCase().contains(searchTerm) && !msg.equals(message)) {
                matches.add(msg);
            }
        }

        MessageBuilder endMsg = new MessageBuilder();
        endMsg.appendString("Found a total of ")
                .appendString(String.valueOf(matches.size()), MessageBuilder.Formatting.BLOCK)
                .appendString(" matches:");

        int i = 0;
        int truncated = 0;
        for (Message msg : matches) {
            i++;
            if (endMsg.getLength() > 1600 || msg.getContent().length() > 400) {
                truncated++;
            } else {
                endMsg.appendString("\n")
                        .appendString("[" + forceTwoDigits(i) + "] " + formatTimestamp(msg.getTime()), MessageBuilder.Formatting.BLOCK)
                        .appendString(" ")
                        .appendString(msg.getAuthor().getUsername(), MessageBuilder.Formatting.BLOCK)
                        .appendString(" ")
                        .appendString(msg.getContent());
            }
        }

        if (truncated > 0) {
            endMsg.appendString("\n[Truncated " + truncated + "]");
        }
        channel.sendMessage(endMsg.build());

    }
    
    private String forceTwoDigits(int i){
        String str = String.valueOf(i);
        
        if (str.length() == 1){
            str = "0" + str;
        }
        
        return str;
    }

    public String formatTimestamp(OffsetDateTime t) {
        String str;
        if(LocalDateTime.now(Clock.systemUTC()).getDayOfYear() != t.getDayOfYear()){
            str = "[" + t.getMonth().name().substring(0, 0) + t.getMonth().name().substring(1, 2).toLowerCase() + " " + t.getDayOfMonth() + " " + forceTwoDigits(t.getHour()) + ":" + forceTwoDigits(t.getMinute()) + "]";
        } else {
            str = "[" + forceTwoDigits(t.getHour()) + ":" + forceTwoDigits(t.getMinute()) + "]";
        }
        return str;
    }
}
{'fraction_non_alphanumeric': 0.12962720732504907, 'fraction_numerical': 0.009679529103989535, 'mean_word_length': 2.0905416329830233, 'pattern_counts': {'":': 3, '<': 13, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1077835', 'n_tokens_mistral': 2207, 'n_tokens_neox': 2090, 'n_words': 405}