Search in sources :

Example 6 with MessageChannel

use of discord4j.core.object.entity.channel.MessageChannel in project KaellyBot by Kaysoro.

the class AbstractCommand method request.

@Override
public final void request(MessageCreateEvent event, Message message) {
    Language lg = Translator.getLanguageFrom(message.getChannel().block());
    try {
        Matcher m = getMatcher(message);
        boolean isFound = m.find();
        // Caché si la fonction est désactivée/réservée aux admin et que l'auteur n'est pas super-admin
        if ((!isPublic() || isAdmin()) && message.getAuthor().map(user -> user.getId().asLong() != Constants.authorId).orElse(false))
            return;
        // S'il s'agit d'une demande d'aide...
        if (message.getContent().matches(Pattern.quote(getPrefix(message)) + getName() + "\\s+help")) {
            message.getChannel().flatMap(chan -> chan.createMessage(helpDetailed(lg, getPrefix(message)))).subscribe();
            return;
        }
        // La commande est trouvée
        if (isFound) {
            // Mais n'est pas utilisable en MP
            MessageChannel channel = message.getChannel().block();
            if (!isUsableInMP() && channel instanceof PrivateChannel) {
                BasicDiscordException.NOT_USABLE_IN_MP.throwException(message, this, lg);
                return;
            } else // Mais est désactivée par la guilde
            if (!(channel instanceof PrivateChannel) && message.getAuthor().map(user -> user.getId().asLong() != Constants.authorId).orElse(false) && isForbidden(Guild.getGuild(message.getGuild().block()))) {
                BasicDiscordException.COMMAND_FORBIDDEN.throwException(message, this, lg);
                return;
            }
        } else // Mais est mal utilisée
        if (message.getContent().startsWith(getPrefix(message) + getName())) {
            badUse.throwException(message, this, lg);
            return;
        }
        if (isFound)
            request(event, message, m, lg);
    } catch (Exception e) {
        BasicDiscordException.UNKNOWN_ERROR.throwException(message, this, lg);
        Reporter.report(e);
        LOG.error("request", e);
    }
}
Also used : Language(enums.Language) MessageCreateEvent(discord4j.core.event.domain.message.MessageCreateEvent) MessageChannel(discord4j.core.object.entity.channel.MessageChannel) Logger(org.slf4j.Logger) TextChannel(discord4j.core.object.entity.channel.TextChannel) LoggerFactory(org.slf4j.LoggerFactory) Permission(discord4j.rest.util.Permission) Constants(data.Constants) Snowflake(discord4j.common.util.Snowflake) Guild(data.Guild) PermissionSet(discord4j.rest.util.PermissionSet) Reporter(util.Reporter) GuildMessageChannel(discord4j.core.object.entity.channel.GuildMessageChannel) Matcher(java.util.regex.Matcher) BadUseCommandDiscordException(exceptions.BadUseCommandDiscordException) DiscordException(exceptions.DiscordException) PrivateChannel(discord4j.core.object.entity.channel.PrivateChannel) BasicDiscordException(exceptions.BasicDiscordException) Translator(util.Translator) Pattern(java.util.regex.Pattern) discord4j.core.object.entity(discord4j.core.object.entity) PrivateChannel(discord4j.core.object.entity.channel.PrivateChannel) Language(enums.Language) MessageChannel(discord4j.core.object.entity.channel.MessageChannel) GuildMessageChannel(discord4j.core.object.entity.channel.GuildMessageChannel) Matcher(java.util.regex.Matcher) BadUseCommandDiscordException(exceptions.BadUseCommandDiscordException) DiscordException(exceptions.DiscordException) BasicDiscordException(exceptions.BasicDiscordException)

Aggregations

MessageChannel (discord4j.core.object.entity.channel.MessageChannel)6 Language (enums.Language)5 MessageCreateEvent (discord4j.core.event.domain.message.MessageCreateEvent)4 Matcher (java.util.regex.Matcher)4 Translator (util.Translator)4 AbstractCommand (commands.model.AbstractCommand)3 Snowflake (discord4j.common.util.Snowflake)3 Message (discord4j.core.object.entity.Message)3 GuildMessageChannel (discord4j.core.object.entity.channel.GuildMessageChannel)3 Constants (data.Constants)2 Guild (data.Guild)2 Guild (discord4j.core.object.entity.Guild)2 exceptions (exceptions)2 BasicDiscordException (exceptions.BasicDiscordException)2 List (java.util.List)2 data (data)1 ChannelLanguage (data.ChannelLanguage)1 discord4j.core.object.entity (discord4j.core.object.entity)1 PrivateChannel (discord4j.core.object.entity.channel.PrivateChannel)1 TextChannel (discord4j.core.object.entity.channel.TextChannel)1