<commit_before>package be.isach.samaritan.listener;

import net.dv8tion.jda.JDA;
import net.dv8tion.jda.MessageHistory;
import net.dv8tion.jda.entities.Message;
import net.dv8tion.jda.entities.MessageChannel;
import net.dv8tion.jda.entities.TextChannel;
import net.dv8tion.jda.events.Event;
import net.dv8tion.jda.events.message.MessageReceivedEvent;
import net.dv8tion.jda.hooks.EventListener;
import net.dv8tion.jda.hooks.ListenerAdapter;
import org.luaj.vm2.ast.Str;

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

public class QuoteHandler extends Thread implements EventListener {

    private Map<MessageChannel, List<Message>> messageChannelListMap;
    private JDA jda;

    public QuoteHandler(JDA jda) {
        this.jda = jda;
        this.messageChannelListMap = new HashMap<>();

        this.jda.addEventListener(this);
    }

    @Override
    public synchronized void start() {
        super.start();
        loadData();
    }

    public void loadData() {
        System.out.println("[Quote Handler]: Loading channel histories...");
        for (TextChannel messageChannel : jda.getTextChannels()) {
            try {
                List<Message> messages = new ArrayList<>();
                MessageHistory messageHistory = new MessageHistory(messageChannel);
                messageHistory.retrieve(1000);
                messages.addAll(messageHistory.getRecent());
                messageChannelListMap.put(messageChannel, messages);
                System.out.println("[Quote Handler]: Loaded 1000 messages in channel: " + messageChannel.getName());
            } catch (Exception exc) {
                continue;
            }
        }
    }

    public Message searchForQuote(String str, MessageChannel messageChannel) {
        if (!messageChannelListMap.containsKey(messageChannel) || messageChannelListMap.get(messageChannel) == null)
            return null;

        for (Message message : messageChannelListMap.get(messageChannel)) {
            if (message.getContent().toLowerCase().contains(str.toLowerCase())
                    && !message.getContent().startsWith("-")
                    && !message.getAuthor().isBot()) {
                return message;
            }
        }
        return null;
    }<commit_msg>Quote Improvement<commit_after>package be.isach.samaritan.listener;

import net.dv8tion.jda.JDA;
import net.dv8tion.jda.MessageHistory;
import net.dv8tion.jda.entities.Message;
import net.dv8tion.jda.entities.MessageChannel;
import net.dv8tion.jda.entities.TextChannel;
import net.dv8tion.jda.events.Event;
import net.dv8tion.jda.events.message.MessageReceivedEvent;
import net.dv8tion.jda.hooks.EventListener;
import net.dv8tion.jda.hooks.ListenerAdapter;
import org.luaj.vm2.ast.Str;

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

public class QuoteHandler extends Thread implements EventListener {

    private Map<MessageChannel, List<Message>> messageChannelListMap;
    private JDA jda;

    public QuoteHandler(JDA jda) {
        this.jda = jda;
        this.messageChannelListMap = new HashMap<>();

        this.jda.addEventListener(this);
    }

    @Override
    public synchronized void start() {
        super.start();
        loadData();
    }

    public void loadData() {
        System.out.println("[Quote Handler]: Loading channel histories...");
        for (TextChannel messageChannel : jda.getTextChannels()) {
            try {
                List<Message> messages = new ArrayList<>();
                MessageHistory messageHistory = new MessageHistory(messageChannel);
                messageHistory.retrieve(2000);
                messages.addAll(messageHistory.getRecent());
                messageChannelListMap.put(messageChannel, messages);
                System.out.println("[Quote Handler]: Loaded 1000 messages in channel: " + messageChannel.getName());
            } catch (Exception exc) {
                continue;
            }
        }
    }

    public Message searchForQuote(String str, MessageChannel messageChannel) {
        if (!messageChannelListMap.containsKey(messageChannel) || messageChannelListMap.get(messageChannel) == null)
            return null;

        for (Message message : messageChannelListMap.get(messageChannel)) {
            if (message.getContent().toLowerCase().contains(str.toLowerCase())
                    && !message.getContent().startsWith("-")
                    && !message.getAuthor().isBot()) {
                return message;
            }
        }
        return null;
    }
{'fraction_non_alphanumeric': 0.10735930735930736, 'fraction_numerical': 0.007792207792207792, 'mean_word_length': 2.714630225080386, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '6718359', 'n_tokens_mistral': 1298, 'n_tokens_neox': 1240, 'n_words': 243}