use of net.dv8tion.jda.core.entities.MessageEmbed in project MantaroBot by Mantaro.
the class ImageCmds method rule34.
@Command
public static void rule34(CommandRegistry cr) {
cr.register("rule34", new SimpleCommand(Category.IMAGE) {
@Override
protected void call(GuildMessageReceivedEvent event, String content, String[] args) {
if (!nsfwCheck(event, true, true))
return;
String noArgs = content.split(" ")[0];
TextChannelGround.of(event).dropItemWithChance(13, 3);
switch(noArgs) {
case "get":
try {
String whole1 = content.replace("get ", "");
String[] wholeBeheaded = whole1.split(" ");
Rule34.get(60, image -> {
try {
int number;
try {
number = Integer.parseInt(wholeBeheaded[0]);
} catch (Exception e) {
number = r.nextInt(image.size());
}
String TAGS = image.get(number).getTags().replace(" ", " ,");
EmbedBuilder builder = new EmbedBuilder();
builder.setAuthor("Found image", null, "http:" + image.get(number - 1).getFile_url()).setImage("http:" + image.get(number - 1).getFile_url()).addField("Width", String.valueOf(image.get(number - 1).getWidth()), true).addField("Height", String.valueOf(image.get(number - 1).getHeight()), true).addField("Tags", "``" + (TAGS == null ? "None" : TAGS) + "``", false).setFooter("If the image doesn't load, click the title.", null);
event.getChannel().sendMessage(builder.build()).queue();
} catch (ArrayIndexOutOfBoundsException e) {
event.getChannel().sendMessage(EmoteReference.ERROR + "**There aren't more images or no results found**! Try with a lower number.").queue();
}
});
} catch (Exception exception) {
if (exception instanceof NumberFormatException)
event.getChannel().sendMessage(EmoteReference.ERROR + "Wrong argument type. Check ~>help rule34").queue(message -> message.delete().queueAfter(10, TimeUnit.SECONDS));
}
break;
case "tags":
try {
try {
boolean isOldFormat = args[1].matches("^[0-9]*$");
if (isOldFormat) {
event.getChannel().sendMessage(EmoteReference.WARNING + "Now you don't need to specify the page number. Please use ~>rule34 tags <tag>").queue();
return;
}
String sNoArgs = content.replace("tags ", "");
String[] expectedNumber = sNoArgs.split(" ");
String tags = expectedNumber[0];
Rule34.onSearch(60, tags, images -> {
try {
try {
number1 = Integer.parseInt(expectedNumber[2]);
} catch (Exception e) {
number1 = r.nextInt(images.size() > 0 ? images.size() - 1 : images.size());
}
String TAGS = images.get(number).getTags() == null ? tags : images.get(number).getTags().replace(" ", " ,");
EmbedBuilder builder = new EmbedBuilder();
builder.setAuthor("Found image", null, "http:" + images.get(number1 - 1).getFile_url()).setImage("http:" + images.get(number1 - 1).getFile_url()).addField("Width", String.valueOf(images.get(number1 - 1).getWidth()), true).addField("Height", String.valueOf(images.get(number1 - 1).getHeight()), true).addField("Tags", "``" + (TAGS == null ? "None" : TAGS) + "``", false).setFooter("If the image doesn't load, click the title.", null);
event.getChannel().sendMessage(builder.build()).queue();
} catch (Exception e) {
e.printStackTrace();
event.getChannel().sendMessage(EmoteReference.ERROR + "**There aren't more images or no results found**! Try with a lower number.").queue();
}
});
} catch (Exception exception) {
if (exception instanceof NumberFormatException)
event.getChannel().sendMessage(EmoteReference.ERROR + "Wrong argument type. Check ~>help rule34").queue(message -> message.delete().queueAfter(10, TimeUnit.SECONDS));
}
} catch (NullPointerException e) {
event.getChannel().sendMessage(EmoteReference.ERROR + "Rule34 decided to not fetch the image. Well, you can try with another number or tag.").queue();
}
break;
default:
onHelp(event);
break;
}
}
@Override
public MessageEmbed help(GuildMessageReceivedEvent event) {
return helpEmbed(event, "rule34.xxx commmand").setColor(Color.PINK).setDescription("**Retrieves images from the rule34 (hentai) image board.**").addField("Usage", "`~>rule34 get <imagenumber>` - **Gets an image based in parameters.**\n" + "`~>rule34 tags <tag> <imagenumber>` - **Gets an image based in the specified tag and parameters.**\n", false).addField("Parameters", "`page` - **Can be any value from 1 to the rule34 maximum page. Probably around 4000.**\n" + "`imagenumber` - **(OPTIONAL) Any number from 1 to the maximum possible images to get, specified by the first instance of the command.**\n" + "`tag` - **Any valid image tag. For example animal_ears or original.**", false).build();
}
});
}
use of net.dv8tion.jda.core.entities.MessageEmbed in project MantaroBot by Mantaro.
the class AssistedCommand method onHelp.
default default void onHelp(GuildMessageReceivedEvent event) {
MessageEmbed helpEmbed = help(event);
if (helpEmbed == null) {
event.getChannel().sendMessage(EmoteReference.ERROR + "There's no extended help set for this command.").queue(message -> message.delete().queueAfter(20, TimeUnit.SECONDS));
return;
}
event.getChannel().sendMessage(help(event)).queue();
}
use of net.dv8tion.jda.core.entities.MessageEmbed in project MantaroBot by Mantaro.
the class DiscordUtils method list.
public static Future<Void> list(GuildMessageReceivedEvent event, int timeoutSeconds, boolean canEveryoneUse, IntIntObjectFunction<EmbedBuilder> supplier, String... parts) {
if (parts.length == 0)
return null;
List<MessageEmbed> embeds = new ArrayList<>();
StringBuilder sb = new StringBuilder();
int total;
{
int t = 0;
int c = 0;
for (String s : parts) {
if (s.length() + c + 1 > MessageEmbed.TEXT_MAX_LENGTH) {
t++;
c = 0;
}
c += s.length() + 1;
}
if (c > 0)
t++;
total = t;
}
for (String s : parts) {
int l = s.length() + 1;
if (l > MessageEmbed.TEXT_MAX_LENGTH)
throw new IllegalArgumentException("Length for one of the pages is greater than the maximum");
if (sb.length() + l > MessageEmbed.TEXT_MAX_LENGTH) {
EmbedBuilder eb = supplier.apply(embeds.size() + 1, total);
eb.setDescription(sb.toString());
embeds.add(eb.build());
sb = new StringBuilder();
}
sb.append(s).append('\n');
}
if (sb.length() > 0) {
EmbedBuilder eb = supplier.apply(embeds.size() + 1, total);
eb.setDescription(sb.toString());
embeds.add(eb.build());
}
AtomicInteger index = new AtomicInteger();
Message m = event.getChannel().sendMessage(embeds.get(0)).complete();
return ReactionOperations.create(m, timeoutSeconds, (e) -> {
if (!canEveryoneUse && e.getUser().getIdLong() != event.getAuthor().getIdLong())
return false;
switch(e.getReactionEmote().getName()) {
case //left arrow
"⬅":
if (index.get() == 0)
break;
m.editMessage(embeds.get(index.decrementAndGet())).queue();
break;
case //right arrow
"➡":
if (index.get() + 1 >= embeds.size())
break;
m.editMessage(embeds.get(index.incrementAndGet())).queue();
break;
}
if (event.getGuild().getSelfMember().hasPermission(e.getTextChannel(), Permission.MESSAGE_MANAGE)) {
e.getReaction().removeReaction(e.getUser()).queue();
}
return false;
}, "⬅", "➡");
}
use of net.dv8tion.jda.core.entities.MessageEmbed in project MantaroBot by Mantaro.
the class MiscCmds method randomFact.
@Command
public static void randomFact(CommandRegistry cr) {
cr.register("randomfact", new SimpleCommand(Category.MISC) {
@Override
protected void call(GuildMessageReceivedEvent event, String content, String[] args) {
event.getChannel().sendMessage(EmoteReference.TALKING + facts.get().get(new Random().nextInt(facts.get().size() - 1))).queue();
}
@Override
public MessageEmbed help(GuildMessageReceivedEvent event) {
return helpEmbed(event, "Random Fact").setDescription("**Sends a random fact.**").build();
}
});
cr.registerAlias("randomfact", "rf");
}
use of net.dv8tion.jda.core.entities.MessageEmbed in project MantaroBot by Mantaro.
the class OwnerCmd method blacklist.
@Command
public static void blacklist(CommandRegistry cr) {
cr.register("blacklist", new SimpleCommand(Category.OWNER, CommandPermission.OWNER) {
@Override
protected void call(GuildMessageReceivedEvent event, String content, String[] args) {
MantaroObj obj = MantaroData.db().getMantaroData();
if (args[0].equals("guild")) {
if (args[1].equals("add")) {
if (MantaroBot.getInstance().getGuildById(args[2]) == null)
return;
obj.getBlackListedGuilds().add(args[2]);
event.getChannel().sendMessage(EmoteReference.CORRECT + "Blacklisted Guild: " + event.getJDA().getGuildById(args[2])).queue();
obj.save();
} else if (args[1].equals("remove")) {
if (!obj.getBlackListedGuilds().contains(args[2]))
return;
obj.getBlackListedGuilds().remove(args[2]);
event.getChannel().sendMessage(EmoteReference.CORRECT + "Unblacklisted Guild: " + args[2]).queue();
obj.save();
}
return;
}
if (args[0].equals("user")) {
if (args[1].equals("add")) {
if (MantaroBot.getInstance().getUserById(args[2]) == null)
return;
obj.getBlackListedUsers().add(args[2]);
event.getChannel().sendMessage(EmoteReference.CORRECT + "Blacklisted User: " + event.getJDA().getUserById(args[2])).queue();
obj.save();
} else if (args[1].equals("remove")) {
if (!obj.getBlackListedUsers().contains(args[2]))
return;
obj.getBlackListedUsers().remove(args[2]);
event.getChannel().sendMessage(EmoteReference.CORRECT + "Unblacklisted User: " + event.getJDA().getUserById(args[2])).queue();
obj.save();
}
}
}
@Override
public MessageEmbed help(GuildMessageReceivedEvent event) {
return helpEmbed(event, "Blacklist command").setDescription("**Blacklists a user (user argument) or a guild (guild argument) by id.**").setFooter("Examples", "~>blacklist user add/remove 293884638101897216\n" + "~>blacklist guild add/remove 305408763915927552").build();
}
});
}
Aggregations