Search in sources :

Example 1 with TextChannel

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

the class SendNudeCommand method request.

@Override
public void request(MessageCreateEvent event, Message message, Matcher m, Language lg) {
    if (message.getChannel().blockOptional().map(chan -> chan instanceof PrivateChannel).orElse(false) || message.getChannel().blockOptional().map(chan -> ((TextChannel) chan).isNsfw()).orElse(false)) {
        int position = RANDOM.nextInt(Nude.values().length);
        Nude nude = Nude.values()[position];
        message.getChannel().flatMap(chan -> chan.createEmbed(spec -> spec.setTitle(Translator.getLabel(lg, "sendnude.title")).setDescription(Translator.getLabel(lg, "sendnude.author").replace("{author}", nude.getAuthor()).replace("{url}", nude.getUrl())).setColor(discord4j.rest.util.Color.PINK).setFooter(Translator.getLabel(lg, "sendnude.footer").replace("{position}", String.valueOf(position + 1)).replace("{number}", String.valueOf(Nude.values().length)), null).setImage(nude.getImage()))).subscribe();
    } else
        // Exception NSFW
        BasicDiscordException.NO_NSFW_CHANNEL.throwException(message, this, lg);
}
Also used : PrivateChannel(discord4j.core.object.entity.channel.PrivateChannel) Language(enums.Language) java.awt(java.awt) MessageCreateEvent(discord4j.core.event.domain.message.MessageCreateEvent) AbstractCommand(commands.model.AbstractCommand) Matcher(java.util.regex.Matcher) Message(discord4j.core.object.entity.Message) TextChannel(discord4j.core.object.entity.channel.TextChannel) PrivateChannel(discord4j.core.object.entity.channel.PrivateChannel) Nude(enums.Nude) BasicDiscordException(exceptions.BasicDiscordException) Random(java.util.Random) Translator(util.Translator) Nude(enums.Nude)

Aggregations

AbstractCommand (commands.model.AbstractCommand)1 MessageCreateEvent (discord4j.core.event.domain.message.MessageCreateEvent)1 Message (discord4j.core.object.entity.Message)1 PrivateChannel (discord4j.core.object.entity.channel.PrivateChannel)1 TextChannel (discord4j.core.object.entity.channel.TextChannel)1 Language (enums.Language)1 Nude (enums.Nude)1 BasicDiscordException (exceptions.BasicDiscordException)1 java.awt (java.awt)1 Random (java.util.Random)1 Matcher (java.util.regex.Matcher)1 Translator (util.Translator)1