<commit_before>package co.aikar.commands;

public class JDACommandContexts extends CommandContexts<JDACommandExecutionContext> {
    JDACommandContexts(CommandManager manager) {
        super(manager);
    }
}<commit_msg>provide some contexts for JDA<commit_after>package co.aikar.commands;

import co.aikar.commands.annotation.Optional;
import net.dv8tion.jda.core.JDA;
import net.dv8tion.jda.core.entities.ChannelType;
import net.dv8tion.jda.core.entities.Guild;
import net.dv8tion.jda.core.entities.Message;
import net.dv8tion.jda.core.entities.MessageChannel;
import net.dv8tion.jda.core.entities.User;
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;

public class JDACommandContexts extends CommandContexts<JDACommandExecutionContext> {
    public JDACommandContexts(JDACommandManager manager) {
        super(manager);
        this.registerIssuerOnlyContext(CommandEvent.class, CommandExecutionContext::getIssuer);
        this.registerIssuerOnlyContext(MessageReceivedEvent.class, c -> c.getIssuer().getIssuer());
        this.registerIssuerOnlyContext(Message.class, c -> {
            MessageReceivedEvent event = c.getIssuer().getIssuer();
            return event.getMessage();
        });
        this.registerIssuerOnlyContext(Guild.class, c -> {
            MessageReceivedEvent event = c.getIssuer().getIssuer();
            if (event.isFromType(ChannelType.PRIVATE) && c.getAnnotation(Optional.class) == null) {
                throw new InvalidCommandArgument("This command can only be executed in a Guild.", false); // TODO: Message Keys
            } else {
                return event.getGuild();
            }
        });
        this.registerIssuerOnlyContext(MessageChannel.class, c -> {
            MessageReceivedEvent event = c.getIssuer().getIssuer();
            return event.getChannel();
        });
        this.registerIssuerOnlyContext(ChannelType.class, c -> {
            MessageReceivedEvent event = c.getIssuer().getIssuer();
            return event.getChannelType();
        });
        this.registerIssuerOnlyContext(User.class, c -> {
            MessageReceivedEvent event = c.getIssuer().getIssuer();
            return event.getAuthor();
        });
        this.registerIssuerOnlyContext(JDA.class, c -> ((JDACommandManager) this.manager).getJDA());
    }

}
{'fraction_non_alphanumeric': 0.1107281344248169, 'fraction_numerical': 0.003015941404566997, 'mean_word_length': 3.2295081967213113, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 12, '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': '5525047', 'n_tokens_mistral': 658, 'n_tokens_neox': 660, 'n_words': 105}