<commit_before>package commands;

import bean.Santa;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.PrivateChannel;
import net.dv8tion.jda.api.entities.TextChannel;
import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.events.message.priv.PrivateMessageReceivedEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
import utils.Constants;
import utils.DiscordID;
import utils.SantaManager;

import java.awt.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

public class SecretSantaCommandListener extends ListenerAdapter {
    private final String santaAvatar = "http://up.makar.pw/H4ppmsVb.png";
    private final Map<String, PrivateAction> commands;
    private final SantaManager santas;

    public SecretSantaCommandListener() {
        commands = new HashMap<>();
        santas = SantaManager.loadSantas();
        addCommands();
    }

    @Override
    public void onPrivateMessageReceived(PrivateMessageReceivedEvent event) {
        String command = event.getMessage().getContentRaw().split(" ", 2)[0].toLowerCase();
        if (commands.containsKey(command))
            commands.get(command).run(event);
    }

    private void addCommands() {
        addSantaAddCommand();
        addSantaRemoveCommand();
        addSantaParticipantsCommand();
        addSantaGoCommand();
        addSantaStopCommand();
        addSantaSendSCommand();
        addSantaSendRCommand();
        addSantaSendACommand();
    }

    private PrivateAction addSantaAddCommand() {
        PrivateAction action = new PrivateAction() {
            public String getCommand() {
                return "addsanta";
            }

            public void run(PrivateMessageReceivedEvent event) {
                if (santas.started())
                    return;
                String invalidMessage = "Invalid format. Please use the format `!addsanta Your Name | Address | Message for your secret santa (what _not_ to buy & other notes)`";
                String[] command = event.getMessage().getContentRaw().split(" ", 2);
                if (command.length < 2) {
                    event.getChannel().sendMessage(invalidMessage).queue();
                    return;
                }
                String[] params = command[1].split("\\|");
                if (params.length < 3) {
                    event.getChannel().sendMessage(invalidMessage).queue();
                    return;
                }

                Santa santa = new Santa();
                santa.setDiscordID(event.getAuthor().getId());
                santa.setRealName(params[0].trim());
                santa.setAddress(params[1].trim());
                santa.setNotes(params[2].trim());

                EmbedBuilder msg = new EmbedBuilder();
                if (santas.add(santa)) {
                    msg.setAuthor(event.getAuthor().getName() + " was added as a secret Santa!", null,
                            event.getAuthor().getEffectiveAvatarUrl());
                    msg.setTitle("Details", null);
                    msg.setColor(Color.CYAN);
                    msg.setDescription(santa.toString());
                } else {
                    msg.setAuthor(event.getAuthor().getName() + " is already registered as a secret Santa.", null,
                            event.getAuthor().getEffectiveAvatarUrl());
                    msg.setTitle("Your information has been updated", null);
                    msg.setColor(Color.MAGENTA);
                    msg.setDescription(santa.toString());
                }
                event.getChannel().sendMessage(msg.build()).queue();
            }
        };
        commands.put(Constants.PREFIX + action.getCommand(), action);
        return action;
    }

    private PrivateAction addSantaRemoveCommand() {
        PrivateAction action = new PrivateAction() {
            public String getCommand() {
                return "removesanta";
            }

            public void run(PrivateMessageReceivedEvent event) {
                if (santas.started())
                    return;
                EmbedBuilder msg = new EmbedBuilder();
                if (santas.remove(event.getAuthor().getId())) {
                    msg.setAuthor(event.getAuthor().getName() + " has been removed as a secret Santa.", null,
                            event.getAuthor().getEffectiveAvatarUrl());
                    msg.setColor(Color.RED);
                } else {
                    msg.setAuthor(event.getAuthor().getName() + " is not registered as a secret Santa!", null,
                            event.getAuthor().getEffectiveAvatarUrl());
                    msg.setColor(Color.RED);
                    msg.setDescription(
                            "If you would like to register, use the format `!addsanta Your Name | Address | Message for your secret santa (what _not_ to buy & other notes)`");
                }
                event.getChannel().sendMessage(msg.build()).queue();
            }
        };
        commands.put(Constants.PREFIX + action.getCommand(), action);
        return action;
    }

    private PrivateAction addSantaParticipantsCommand() {
        PrivateAction action = new PrivateAction() {
            public String getCommand() {
                return "santaparticipants";
            }

            public void run(PrivateMessageReceivedEvent event) {
                if (!event.getAuthor().getId().equals(DiscordID.ADMIN))
                    return;

                StringBuilder str = new StringBuilder();

                str.append("Current secret santa participants are:\n\n");
                santas.getAll().forEach(santa -> {
                    str.append(event.getJDA().getUserById(santa.getDiscordID()).getName());
                    str.append('\n');
                });

                event.getChannel().sendMessage(str.toString()).queue();
            }
        };
        commands.put(Constants.PREFIX + action.getCommand(), action);
        return action;
    }

    private PrivateAction addSantaGoCommand() {
        PrivateAction action = new PrivateAction() {
            public String getCommand() {
                return "gosanta";
            }

            public void run(PrivateMessageReceivedEvent event) {
                if (!event.getAuthor().getId().equals(DiscordID.ADMIN))
                    return;
                if (santas.size() <= 1) {<commit_msg>Add avatar adjustment command for SS<commit_after>package commands;

import bean.Santa;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.PrivateChannel;
import net.dv8tion.jda.api.entities.TextChannel;
import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.events.message.priv.PrivateMessageReceivedEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
import utils.Constants;
import utils.DiscordID;
import utils.SantaManager;

import java.awt.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

public class SecretSantaCommandListener extends ListenerAdapter {
    private String santaAvatar = "http://up.makar.pw/JgewAgnU.png";
    private final Map<String, PrivateAction> commands;
    private final SantaManager santas;

    public SecretSantaCommandListener() {
        commands = new HashMap<>();
        santas = SantaManager.loadSantas();
        addCommands();
    }

    @Override
    public void onPrivateMessageReceived(PrivateMessageReceivedEvent event) {
        String command = event.getMessage().getContentRaw().split(" ", 2)[0].toLowerCase();
        if (commands.containsKey(command))
            commands.get(command).run(event);
    }

    private void addCommands() {
        addSantaAddCommand();
        addSantaRemoveCommand();
        addSantaParticipantsCommand();
        addSantaGoCommand();
        addSantaStopCommand();
        addSantaSendSCommand();
        addSantaSendRCommand();
        addSantaSendACommand();
        addSantaAvatarCommand();
    }

    private PrivateAction addSantaAddCommand() {
        PrivateAction action = new PrivateAction() {
            public String getCommand() {
                return "addsanta";
            }

            public void run(PrivateMessageReceivedEvent event) {
                if (santas.started())
                    return;
                String invalidMessage = "Invalid format. Please use the format `!addsanta Your Name | Address | Message for your secret santa (what _not_ to buy & other notes)`";
                String[] command = event.getMessage().getContentRaw().split(" ", 2);
                if (command.length < 2) {
                    event.getChannel().sendMessage(invalidMessage).queue();
                    return;
                }
                String[] params = command[1].split("\\|");
                if (params.length < 3) {
                    event.getChannel().sendMessage(invalidMessage).queue();
                    return;
                }

                Santa santa = new Santa();
                santa.setDiscordID(event.getAuthor().getId());
                santa.setRealName(params[0].trim());
                santa.setAddress(params[1].trim());
                santa.setNotes(params[2].trim());

                EmbedBuilder msg = new EmbedBuilder();
                if (santas.add(santa)) {
                    msg.setAuthor(event.getAuthor().getName() + " was added as a secret Santa!", null,
                            event.getAuthor().getEffectiveAvatarUrl());
                    msg.setTitle("Details", null);
                    msg.setColor(Color.CYAN);
                    msg.setDescription(santa.toString());
                } else {
                    msg.setAuthor(event.getAuthor().getName() + " is already registered as a secret Santa.", null,
                            event.getAuthor().getEffectiveAvatarUrl());
                    msg.setTitle("Your information has been updated", null);
                    msg.setColor(Color.MAGENTA);
                    msg.setDescription(santa.toString());
                }
                event.getChannel().sendMessage(msg.build()).queue();
            }
        };
        commands.put(Constants.PREFIX + action.getCommand(), action);
        return action;
    }

    private PrivateAction addSantaRemoveCommand() {
        PrivateAction action = new PrivateAction() {
            public String getCommand() {
                return "removesanta";
            }

            public void run(PrivateMessageReceivedEvent event) {
                if (santas.started())
                    return;
                EmbedBuilder msg = new EmbedBuilder();
                if (santas.remove(event.getAuthor().getId())) {
                    msg.setAuthor(event.getAuthor().getName() + " has been removed as a secret Santa.", null,
                            event.getAuthor().getEffectiveAvatarUrl());
                    msg.setColor(Color.RED);
                } else {
                    msg.setAuthor(event.getAuthor().getName() + " is not registered as a secret Santa!", null,
                            event.getAuthor().getEffectiveAvatarUrl());
                    msg.setColor(Color.RED);
                    msg.setDescription(
                            "If you would like to register, use the format `!addsanta Your Name | Address | Message for your secret santa (what _not_ to buy & other notes)`");
                }
                event.getChannel().sendMessage(msg.build()).queue();
            }
        };
        commands.put(Constants.PREFIX + action.getCommand(), action);
        return action;
    }

    private PrivateAction addSantaParticipantsCommand() {
        PrivateAction action = new PrivateAction() {
            public String getCommand() {
                return "santaparticipants";
            }

            public void run(PrivateMessageReceivedEvent event) {
                if (!event.getAuthor().getId().equals(DiscordID.ADMIN))
                    return;

                StringBuilder str = new StringBuilder();

                str.append("Current secret santa participants are:\n\n");
                santas.getAll().forEach(santa -> {
                    str.append(event.getJDA().getUserById(santa.getDiscordID()).getName());
                    str.append('\n');
                });

                event.getChannel().sendMessage(str.toString()).queue();
            }
        };
        commands.put(Constants.PREFIX + action.getCommand(), action);
        return action;
    }

    private PrivateAction addSantaAvatarCommand() {
        PrivateAction action = new PrivateAction() {
            public String getCommand() {
                return "santaavatar";
            }

            public void run(PrivateMessageReceivedEvent event) {
                if (!event.getAuthor().getId().equals(DiscordID.ADMIN))
                    return;

                String[] command = event.getMessage().getContentRaw().split(" ", 2);
                if (command.length < 2)
                    return;

                santaAvatar = command[1];
                EmbedBuilder msg = new EmbedBuilder();
                msg.setAuthor("New Santa avatar set", santaAvatar, santaAvatar);
                event.getChannel().sendMessage(msg.build()).queue();
            }
        };
        commands.put(Constants.PREFIX + action.getCommand(), action);
        return action;
    }

    private PrivateAction addSantaGoCommand() {
        PrivateAction action = new PrivateAction() {
            public String getCommand() {
                return "gosanta";
            }

            public void run(PrivateMessageReceivedEvent event) {
                if (!event.getAuthor().getId().equals(DiscordID.ADMIN))
                    return;
                if (santas.size() <= 1) {
{'fraction_non_alphanumeric': 0.1098340636448531, 'fraction_numerical': 0.0027296889591264997, 'mean_word_length': 1.8657883902840675, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5040572', 'n_tokens_mistral': 3584, 'n_tokens_neox': 3378, 'n_words': 712}