Search in sources :

Example 16 with Message

use of discord4j.core.object.entity.Message 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)

Example 17 with Message

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

the class AboutCommand method request.

@Override
public void request(MessageCreateEvent event, Message message, Matcher m, Language lg) {
    Optional<ApplicationInfo> appInfo = message.getClient().getApplicationInfo().blockOptional();
    if (appInfo.isPresent()) {
        message.getChannel().flatMap(chan -> chan.createEmbed(spec -> {
            spec.setTitle(Translator.getLabel(lg, "about.title").replace("{name}", Constants.name).replace("{version}", Constants.version)).setImage(Constants.changelog).setThumbnail(appInfo.get().getIconUrl(Image.Format.PNG).orElse(null)).addField(Translator.getLabel(lg, "about.invite.title"), Translator.getLabel(lg, "about.invite.desc").replace("{name}", Constants.name).replace("{invite}", Constants.invite), false).addField(Translator.getLabel(lg, "about.support.title"), Translator.getLabel(lg, "about.support.desc").replace("{name}", Constants.name).replace("{discordInvite}", Constants.discordInvite), false).addField(Translator.getLabel(lg, "about.twitter.title"), Translator.getLabel(lg, "about.twitter.desc").replace("{name}", Constants.name).replace("{twitter}", Constants.twitterAccount), false).addField(Translator.getLabel(lg, "about.opensource.title"), Translator.getLabel(lg, "about.opensource.desc").replace("{git}", Constants.git), false).addField(Translator.getLabel(lg, "about.free.title"), Translator.getLabel(lg, "about.free.desc").replace("{paypal}", Constants.paypal), false).addField(Translator.getLabel(lg, "about.privacy.title"), Translator.getLabel(lg, "about.privacy.desc").replace("{paypal}", Constants.paypal), false).addField(Translator.getLabel(lg, "about.graphist.title"), Translator.getLabel(lg, "about.graphist.desc").replace("{graphist}", Graphist.ELYCANN.toMarkdown()), false);
            StringBuilder st = new StringBuilder();
            for (Donator donator : Donator.values()) st.append(donator.getName()).append(", ");
            st.setLength(st.length() - 2);
            spec.addField(Translator.getLabel(lg, "about.donators.title"), st.toString() + ".", false);
        })).subscribe();
    }
}
Also used : User(discord4j.core.object.entity.User) Language(enums.Language) MessageCreateEvent(discord4j.core.event.domain.message.MessageCreateEvent) AbstractCommand(commands.model.AbstractCommand) Constants.authorName(data.Constants.authorName) Constants(data.Constants) ApplicationInfo(discord4j.core.object.entity.ApplicationInfo) Donator(enums.Donator) Image(discord4j.rest.util.Image) Matcher(java.util.regex.Matcher) Constants.authorAvatar(data.Constants.authorAvatar) Message(discord4j.core.object.entity.Message) Optional(java.util.Optional) Graphist(enums.Graphist) Translator(util.Translator) Donator(enums.Donator) ApplicationInfo(discord4j.core.object.entity.ApplicationInfo)

Example 18 with Message

use of discord4j.core.object.entity.Message in project S-argo by Expugn.

the class Sargo method sendEmbed.

public static Message sendEmbed(TextChannel tc, Consumer<EmbedCreateSpec> ecsTemplate, File image) {
    try {
        InputStream is = new FileInputStream(image);
        Message sentMessage = tc.createMessage(s -> s.setEmbed(ecsTemplate.andThen(es -> es.setImage("attachment://" + image.getName()))).addFile(image.getName(), is)).block();
        is.close();
        return sentMessage;
    } catch (FileNotFoundException e) {
        return tc.createMessage(ms -> ms.setEmbed(ecsTemplate.andThen(es -> es.addField("MISSING SCOUT RESULT", "Scout result image is missing.", true)))).block();
    } catch (IOException e) {
    // IGNORED
    }
    return null;
}
Also used : Reload(io.github.spugn.Sargo.Functions.Reload) MessageCreateEvent(discord4j.core.event.domain.message.MessageCreateEvent) Logger(org.slf4j.Logger) CommandSettingsParser(io.github.spugn.Sargo.XMLParsers.CommandSettingsParser) ReadyEvent(discord4j.core.event.domain.lifecycle.ReadyEvent) Update(io.github.spugn.Sargo.Functions.Update) DiscordClientBuilder(discord4j.core.DiscordClientBuilder) LoggerFactory(org.slf4j.LoggerFactory) DiscordClient(discord4j.core.DiscordClient) java.awt(java.awt) Consumer(java.util.function.Consumer) MessageListener(io.github.spugn.Sargo.Listeners.MessageListener) java.io(java.io) Message(discord4j.core.object.entity.Message) ScoutMasterParser(io.github.spugn.Sargo.XMLParsers.ScoutMasterParser) Activity(discord4j.core.object.presence.Activity) EmbedCreateSpec(discord4j.core.spec.EmbedCreateSpec) SystemData(io.github.spugn.Sargo.System.SystemData) LoginSettingsParser(io.github.spugn.Sargo.XMLParsers.LoginSettingsParser) GitHubImage(io.github.spugn.Sargo.Utilities.GitHubImage) TextChannel(discord4j.core.object.entity.TextChannel) Presence(discord4j.core.object.presence.Presence) Message(discord4j.core.object.entity.Message)

Example 19 with Message

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

the class TooMuchDiscordException method throwException.

@Override
public void throwException(Message message, Command command, Language lg, Object... arguments) {
    AnkamaBug bug = null;
    String gender = Translator.getLabel(lg, "exception.object." + objectKey + ".gender");
    StringBuilder st = new StringBuilder(Translator.getLabel(lg, "exception.toomuch.toomuch." + gender)).append(" ").append(Translator.getLabel(lg, "exception.object." + objectKey + ".plural")).append(" ").append(Translator.getLabel(lg, "exception.toomuch.found." + gender));
    if (arguments.length > 0) {
        List<Object> objects = (List<Object>) arguments[0];
        long similarOcc = objects.stream().collect(Collectors.groupingBy(e -> e, Collectors.counting())).values().stream().max(Long::compareTo).orElse(0L);
        if (similarOcc > 1) {
            if (command instanceof WhoisCommand)
                bug = AnkamaBug.GHOST_CHARACTER;
            else if (command instanceof GuildCommand)
                bug = AnkamaBug.GHOST_GUILD;
            else if (command instanceof AllianceCommand)
                bug = AnkamaBug.GHOST_ALLY;
        }
        if (objects.size() <= ITEM_LIMIT) {
            st.append(": ");
            for (Object object : objects) if (isTranslatable)
                st.append(Translator.getLabel(lg, object.toString())).append(", ");
            else
                st.append(object.toString()).append(", ");
            st.delete(st.length() - 2, st.length()).append(".");
        } else
            st.append(". ").append(Translator.getLabel(lg, "exception.toomuch.items"));
    } else {
        if (st.substring(st.length() - 1, st.length()).matches("\\s+"))
            st.delete(st.length() - 1, st.length());
        st.append(".");
    }
    if (bug != null) {
        final AnkamaBug BUG = bug;
        message.getChannel().flatMap(channel -> channel.createEmbed(BUG.decorateEmbed(st.toString(), lg))).subscribe();
    } else
        message.getChannel().flatMap(channel -> channel.createMessage(st.toString())).subscribe();
}
Also used : GuildCommand(commands.classic.GuildCommand) AnkamaBug(enums.AnkamaBug) Language(enums.Language) WhoisCommand(commands.classic.WhoisCommand) List(java.util.List) Message(discord4j.core.object.entity.Message) Command(commands.model.Command) Translator(util.Translator) Collectors(java.util.stream.Collectors) AllianceCommand(commands.classic.AllianceCommand) AnkamaBug(enums.AnkamaBug) WhoisCommand(commands.classic.WhoisCommand) GuildCommand(commands.classic.GuildCommand) AllianceCommand(commands.classic.AllianceCommand) List(java.util.List)

Example 20 with Message

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

the class NotFoundDiscordException method throwException.

@Override
public void throwException(Message message, Command command, Language lg, Object... arguments) {
    AnkamaBug bug = null;
    if (command instanceof WhoisCommand)
        bug = AnkamaBug.CHARACTER_NOT_FOUND;
    else if (command instanceof GuildCommand)
        bug = AnkamaBug.GUILD_NOT_FOUND;
    else if (command instanceof AllianceCommand)
        bug = AnkamaBug.ALLY_NOT_FOUND;
    else if (command instanceof ItemCommand)
        if (message.getContent().contains("'"))
            bug = AnkamaBug.ITEM_NOT_FOUND_APOSTROPHE;
        else if (message.getContent().toLowerCase().contains(Translator.getLabel(lg, "equip.muldo").toLowerCase()) || message.getContent().toLowerCase().contains(Translator.getLabel(lg, "equip.volkorne").toLowerCase()))
            bug = AnkamaBug.ITEM_PAGE_MULDO_VOLKORNE_NOT_FOUND;
    String gender = Translator.getLabel(lg, "exception.object." + objectKey + ".gender");
    String text = Translator.getLabel(lg, "exception.notfound.not." + gender) + " " + Translator.getLabel(lg, "exception.object." + objectKey + ".singular") + " " + Translator.getLabel(lg, "exception.notfound.found." + gender) + ".";
    if (bug != null) {
        final AnkamaBug BUG = bug;
        message.getChannel().flatMap(channel -> channel.createEmbed(BUG.decorateEmbed(text, lg))).subscribe();
    } else
        message.getChannel().flatMap(channel -> channel.createMessage(text)).subscribe();
}
Also used : GuildCommand(commands.classic.GuildCommand) AnkamaBug(enums.AnkamaBug) Language(enums.Language) WhoisCommand(commands.classic.WhoisCommand) ItemCommand(commands.classic.ItemCommand) Message(discord4j.core.object.entity.Message) Command(commands.model.Command) Translator(util.Translator) AllianceCommand(commands.classic.AllianceCommand) AnkamaBug(enums.AnkamaBug) WhoisCommand(commands.classic.WhoisCommand) GuildCommand(commands.classic.GuildCommand) ItemCommand(commands.classic.ItemCommand) AllianceCommand(commands.classic.AllianceCommand)

Aggregations

Message (discord4j.core.object.entity.Message)20 MessageCreateEvent (discord4j.core.event.domain.message.MessageCreateEvent)17 Language (enums.Language)17 Translator (util.Translator)17 Matcher (java.util.regex.Matcher)15 AbstractCommand (commands.model.AbstractCommand)14 List (java.util.List)9 exceptions (exceptions)7 EmbedCreateSpec (discord4j.core.spec.EmbedCreateSpec)5 ArrayList (java.util.ArrayList)5 Collectors (java.util.stream.Collectors)5 ServerUtils (util.ServerUtils)5 Command (commands.model.Command)4 Guild (data.Guild)4 Snowflake (discord4j.common.util.Snowflake)4 Pattern (java.util.regex.Pattern)4 Constants (data.Constants)3 ServerDofus (data.ServerDofus)3 MessageChannel (discord4j.core.object.entity.channel.MessageChannel)3 IOException (java.io.IOException)3