Search in sources :

Example 1 with MessageBuilder

use of net.dv8tion.jda.core.MessageBuilder in project MantaroBot by Mantaro.

the class ActionCmds method meow.

@Command
public static void meow(CommandRegistry registry) {
    registry.register("meow", new SimpleCommand(Category.ACTION) {

        @Override
        protected void call(GuildMessageReceivedEvent event, String content, String[] args) {
            Message receivedMessage = event.getMessage();
            if (!receivedMessage.getMentionedUsers().isEmpty()) {
                String mew = event.getMessage().getMentionedUsers().stream().map(IMentionable::getAsMention).collect(Collectors.joining(" "));
                event.getChannel().sendFile(ImageActionCmd.CACHE.getInput("http://imgur.com/yFGHvVR.gif"), "mew.gif", new MessageBuilder().append(EmoteReference.TALKING).append(String.format("%s *is meowing at %s.*", event.getAuthor().getAsMention(), mew)).build()).queue();
            } else {
                event.getChannel().sendFile(ImageActionCmd.CACHE.getInput("http://imgur.com/yFGHvVR.gif"), "mew.gif", new MessageBuilder().append(":speech_balloon: Meow.").build()).queue();
            }
        }

        @Override
        public MessageEmbed help(GuildMessageReceivedEvent event) {
            return helpEmbed(event, "Meow command").setDescription("**Meow either to a person or the sky**.").setColor(Color.cyan).build();
        }
    });
    registry.registerAlias("meow", "mew");
}
Also used : MessageEmbed(net.dv8tion.jda.core.entities.MessageEmbed) SimpleCommand(net.kodehawa.mantarobot.modules.commands.SimpleCommand) Message(net.dv8tion.jda.core.entities.Message) IMentionable(net.dv8tion.jda.core.entities.IMentionable) MessageBuilder(net.dv8tion.jda.core.MessageBuilder) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent) SimpleCommand(net.kodehawa.mantarobot.modules.commands.SimpleCommand) Command(net.kodehawa.mantarobot.modules.Command)

Example 2 with MessageBuilder

use of net.dv8tion.jda.core.MessageBuilder in project MantaroBot by Mantaro.

the class ImageGame method sendEmbedImage.

protected RestAction<Message> sendEmbedImage(MessageChannel channel, String url, Consumer<EmbedBuilder> embedConfigurator) {
    EmbedBuilder eb = new EmbedBuilder();
    embedConfigurator.accept(eb);
    if (MantaroData.config().get().cacheGames) {
        eb.setImage("attachment://image.png");
        return channel.sendFile(cache.getInput(url), "image.png", new MessageBuilder().setEmbed(eb.build()).build());
    }
    eb.setImage(url);
    return channel.sendMessage(eb.build());
}
Also used : EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) MessageBuilder(net.dv8tion.jda.core.MessageBuilder)

Example 3 with MessageBuilder

use of net.dv8tion.jda.core.MessageBuilder in project MantaroBot by Mantaro.

the class ImageActionCmd method call.

@Override
protected void call(GuildMessageReceivedEvent event, String content) {
    String random = random(images);
    try {
        if (mentions(event).isEmpty()) {
            event.getChannel().sendMessage(EmoteReference.ERROR + "You need to mention a user").queue();
            return;
        }
        DBGuild dbGuild = MantaroData.db().getGuild(event.getGuild());
        GuildData guildData = dbGuild.getData();
        MessageBuilder toSend = new MessageBuilder().append(String.format(format, mentions(event), event.getAuthor().getAsMention()));
        if (!guildData.isNoMentionsAction() && swapNames) {
            toSend = new MessageBuilder().append(String.format(format, event.getAuthor().getAsMention(), mentions(event)));
        }
        if (guildData.isNoMentionsAction() && swapNames) {
            toSend = new MessageBuilder().append(String.format(format, "**" + noMentions(event) + "**", "**" + event.getMember().getEffectiveName() + "**"));
        }
        if (swapNames && guildData.isNoMentionsAction()) {
            toSend = new MessageBuilder().append(String.format(format, "**" + event.getMember().getEffectiveName() + "**", "**" + noMentions(event) + "**"));
        }
        if (isLonely(event)) {
            toSend = new MessageBuilder().append("**").append(lonelyLine).append("**");
        }
        event.getChannel().sendFile(CACHE.getInput(random), imageName, toSend.build()).queue();
    } catch (Exception e) {
        event.getChannel().sendMessage(EmoteReference.ERROR + "I'd like to know what happened, but I couldn't send the image.").queue();
        log.error("Error while performing Action Command ``" + name + "``. The image ``" + random + "`` threw an Exception.", e);
    }
}
Also used : GuildData(net.kodehawa.mantarobot.data.entities.helpers.GuildData) DBGuild(net.kodehawa.mantarobot.data.entities.DBGuild) MessageBuilder(net.dv8tion.jda.core.MessageBuilder)

Example 4 with MessageBuilder

use of net.dv8tion.jda.core.MessageBuilder in project Ardent by adamint.

the class Eval method noArgs.

@Override
public void noArgs(Guild guild, MessageChannel channel, User user, Message message, String[] args) throws Exception {
    if (Ardent.developers.contains(user.getId())) {
        if (args.length == 1)
            channel.sendMessage("Use " + args[0] + " (code) to evaluate stuff").queue();
        else {
            String content = message.getContent().replace(GuildUtils.getPrefix(guild) + args[0] + " ", "");
            final MessageBuilder builder = new MessageBuilder();
            final Map<String, Object> shortcuts = new HashMap<>();
            shortcuts.put("api", message.getJDA());
            shortcuts.put("jda", message.getJDA());
            shortcuts.put("channel", channel);
            shortcuts.put("server", guild);
            shortcuts.put("guild", guild);
            shortcuts.put("connection", Database.connection);
            shortcuts.put("r", Database.r);
            shortcuts.put("message", message);
            shortcuts.put("msg", message);
            shortcuts.put("me", message.getAuthor());
            shortcuts.put("bot", message.getJDA().getSelfUser());
            shortcuts.put("shard", getShard());
            shortcuts.put("shards", ShardManager.getShards());
            final int timeout = 10;
            final Triple<Object, String, String> result = Engine.GROOVY.eval(shortcuts, Collections.emptyList(), Engine.DEFAULT_IMPORTS, timeout, content);
            if (result.getLeft() instanceof RestAction<?>) {
                ((RestAction<?>) result.getLeft()).queue();
            } else if (result.getLeft() != null) {
                builder.appendCodeBlock(result.getLeft().toString(), "");
            }
            if (!result.getMiddle().isEmpty()) {
                builder.append("\n").appendCodeBlock(result.getMiddle(), "");
            }
            if (!result.getRight().isEmpty()) {
                builder.append("\n").appendCodeBlock(result.getRight(), "");
            }
            if (builder.isEmpty()) {
                message.addReaction("✅").queue();
            } else {
                for (final Message m : builder.buildAll(MessageBuilder.SplitPolicy.NEWLINE, MessageBuilder.SplitPolicy.SPACE, MessageBuilder.SplitPolicy.ANYWHERE)) {
                    channel.sendMessage(m).queue();
                }
            }
        }
    }
}
Also used : MessageBuilder(net.dv8tion.jda.core.MessageBuilder) Message(net.dv8tion.jda.core.entities.Message) HashMap(java.util.HashMap) RestAction(net.dv8tion.jda.core.requests.RestAction)

Aggregations

MessageBuilder (net.dv8tion.jda.core.MessageBuilder)4 Message (net.dv8tion.jda.core.entities.Message)2 HashMap (java.util.HashMap)1 EmbedBuilder (net.dv8tion.jda.core.EmbedBuilder)1 IMentionable (net.dv8tion.jda.core.entities.IMentionable)1 MessageEmbed (net.dv8tion.jda.core.entities.MessageEmbed)1 GuildMessageReceivedEvent (net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent)1 RestAction (net.dv8tion.jda.core.requests.RestAction)1 DBGuild (net.kodehawa.mantarobot.data.entities.DBGuild)1 GuildData (net.kodehawa.mantarobot.data.entities.helpers.GuildData)1 Command (net.kodehawa.mantarobot.modules.Command)1 SimpleCommand (net.kodehawa.mantarobot.modules.commands.SimpleCommand)1