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");
}
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());
}
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);
}
}
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();
}
}
}
}
}
Aggregations