Search in sources :

Example 1 with GuildMessageEvent

use of com.freya02.botcommands.api.application.context.message.GuildMessageEvent in project BotCommands by freya022.

the class ContextQuote method execute.

@JDAMessageCommand(name = "Quote message")
public void execute(GuildMessageEvent event) {
    final Message targetMessage = event.getTarget();
    event.reply("> " + targetMessage.getContentRaw()).queue();
}
Also used : Message(net.dv8tion.jda.api.entities.Message) JDAMessageCommand(com.freya02.botcommands.api.application.context.annotations.JDAMessageCommand)

Example 2 with GuildMessageEvent

use of com.freya02.botcommands.api.application.context.message.GuildMessageEvent in project BotCommands by freya022.

the class ApplicationCommandsBuilder method processMessageCommand.

private void processMessageCommand(ApplicationCommand applicationCommand, Method method) {
    if (method.getAnnotation(JDAMessageCommand.class).guildOnly()) {
        if (!ReflectionUtils.hasFirstParameter(method, GlobalMessageEvent.class) && !ReflectionUtils.hasFirstParameter(method, GuildMessageEvent.class))
            throw new IllegalArgumentException("Message command at " + Utils.formatMethodShort(method) + " must have a GuildMessageEvent or GlobalMessageEvent as first parameter");
        if (!ReflectionUtils.hasFirstParameter(method, GuildMessageEvent.class)) {
            // If type is correct but guild specialization isn't used
            LOGGER.warn("Guild-only message command {} uses GlobalMessageEvent, consider using GuildMessageEvent to remove warnings related to guild stuff's nullability", Utils.formatMethodShort(method));
        }
    } else {
        if (!ReflectionUtils.hasFirstParameter(method, GlobalMessageEvent.class))
            throw new IllegalArgumentException("Message command at " + Utils.formatMethodShort(method) + " must have a GlobalMessageEvent as first parameter");
    }
    final MessageCommandInfo info = new MessageCommandInfo(context, applicationCommand, method);
    LOGGER.debug("Adding message command {} for method {}", info.getPath().getName(), Utils.formatMethodShort(method));
    context.addMessageCommand(info);
}
Also used : MessageCommandInfo(com.freya02.botcommands.internal.application.context.message.MessageCommandInfo) GlobalMessageEvent(com.freya02.botcommands.api.application.context.message.GlobalMessageEvent) JDAMessageCommand(com.freya02.botcommands.api.application.context.annotations.JDAMessageCommand) GuildMessageEvent(com.freya02.botcommands.api.application.context.message.GuildMessageEvent)

Example 3 with GuildMessageEvent

use of com.freya02.botcommands.api.application.context.message.GuildMessageEvent in project BotCommands by freya022.

the class MessageCommandInfo method execute.

public boolean execute(BContext context, MessageContextInteractionEvent event, Consumer<Throwable> throwableConsumer) throws Exception {
    final Object[] objects = new Object[commandParameters.size() + 1];
    if (guildOnly) {
        objects[0] = new GuildMessageEvent(context, event);
    } else {
        objects[0] = new GlobalMessageEvent(context, event);
    }
    for (int i = 0, commandParametersLength = commandParameters.size(); i < commandParametersLength; i++) {
        ContextCommandParameter<MessageContextParameterResolver> parameter = commandParameters.get(i);
        if (parameter.isOption()) {
            objects[i + 1] = parameter.getResolver().resolve(context, this, event);
        // no need to check for unresolved parameters,
        // it is impossible to have other arg types other than Message (and custom resolvers)
        } else {
            objects[i + 1] = parameter.getCustomResolver().resolve(context, this, event);
        }
    }
    applyCooldown(event);
    getMethodRunner().invoke(objects, throwableConsumer);
    return true;
}
Also used : MessageContextParameterResolver(com.freya02.botcommands.api.parameters.MessageContextParameterResolver) GlobalMessageEvent(com.freya02.botcommands.api.application.context.message.GlobalMessageEvent) GuildMessageEvent(com.freya02.botcommands.api.application.context.message.GuildMessageEvent)

Aggregations

JDAMessageCommand (com.freya02.botcommands.api.application.context.annotations.JDAMessageCommand)2 GlobalMessageEvent (com.freya02.botcommands.api.application.context.message.GlobalMessageEvent)2 GuildMessageEvent (com.freya02.botcommands.api.application.context.message.GuildMessageEvent)2 MessageContextParameterResolver (com.freya02.botcommands.api.parameters.MessageContextParameterResolver)1 MessageCommandInfo (com.freya02.botcommands.internal.application.context.message.MessageCommandInfo)1 Message (net.dv8tion.jda.api.entities.Message)1