use of net.dv8tion.jda.core.EmbedBuilder in project MantaroBot by Mantaro.
the class DiscordUtils method list.
public static Future<Void> list(GuildMessageReceivedEvent event, int timeoutSeconds, boolean canEveryoneUse, EmbedBuilder base, List<List<MessageEmbed.Field>> parts) {
if (parts.size() == 0)
return null;
for (MessageEmbed.Field f : parts.get(0)) {
base.addField(f);
}
if (parts.size() == 1) {
event.getChannel().sendMessage(base.build()).queue();
return null;
}
// TODO move elsewhere
base.setDescription("**Total pages: " + parts.size() + ".**\nUse the message reactions to move between pages.\n**Reference " + EmoteReference.BUY + " Buy " + EmoteReference.SELL + " Sell.**");
AtomicInteger index = new AtomicInteger();
Message m = event.getChannel().sendMessage(base.build()).complete();
return ReactionOperations.create(m, timeoutSeconds, (e) -> {
if (!canEveryoneUse && e.getUser().getIdLong() != event.getAuthor().getIdLong())
return Operation.IGNORED;
if (e.getChannel().getMessageById(m.getIdLong()) == null)
return Operation.IGNORED;
switch(e.getReactionEmote().getName()) {
case // left arrow
"\u2b05":
if (index.get() == 0)
break;
EmbedBuilder toSend = addAllFields(base, parts.get(index.decrementAndGet()));
toSend.setFooter("Current page: " + (index.get() + 1), event.getAuthor().getEffectiveAvatarUrl());
m.editMessage(toSend.build()).queue();
break;
case // right arrow
"\u27a1":
if (index.get() + 1 >= parts.size())
break;
EmbedBuilder toSend1 = addAllFields(base, parts.get(index.incrementAndGet()));
toSend1.setFooter("Current page: " + (index.get() + 1), event.getAuthor().getEffectiveAvatarUrl());
m.editMessage(toSend1.build()).queue();
break;
}
if (event.getGuild().getSelfMember().hasPermission(e.getTextChannel(), Permission.MESSAGE_MANAGE)) {
e.getReaction().removeReaction(e.getUser()).queue();
}
return Operation.IGNORED;
}, "\u2b05", "\u27a1");
}
use of net.dv8tion.jda.core.EmbedBuilder in project FlareBot by FlareBot.
the class VoteUtil method sendVoteMessage.
public static void sendVoteMessage(UUID id, VoteGroup.VoteRunnable voteRunnable, VoteGroup group, long timeout, TextChannel channel, User user, String buttonGroupString, ButtonGroup.Button... optionalButtons) {
EmbedBuilder votesEmbed = new EmbedBuilder().setDescription("Vote to " + group.getMessageDesc()).addField("Yes", "0", true).addField("No", "0", true);
String messageDesc = group.getMessageDesc();
votesEmbed.setColor(ColorUtils.FLAREBOT_BLUE);
group.setVotesEmbed(votesEmbed);
ButtonGroup buttonGroup = new ButtonGroup(user.getIdLong(), buttonGroupString);
groupMap.put(id + channel.getGuild().getId(), group);
runnableMap.put(id + channel.getGuild().getId(), voteRunnable);
buttonGroup.addButton(new ButtonGroup.Button(355776056092917761L, (owner, user1, message) -> {
if (group.addVote(VoteGroup.Vote.YES, user1)) {
MessageUtils.sendAutoDeletedMessage(new EmbedBuilder().setDescription("You voted yes on " + messageDesc).build(), 2000, channel);
} else {
MessageUtils.sendAutoDeletedMessage(new EmbedBuilder().setDescription("You cannot vote on " + messageDesc).build(), 2000, channel);
}
}));
buttonGroup.addButton(new ButtonGroup.Button(355776081384570881L, (owner, user1, message) -> {
if (group.addVote(VoteGroup.Vote.NO, user1)) {
MessageUtils.sendAutoDeletedMessage(new EmbedBuilder().setDescription("You voted no on " + messageDesc).build(), 2000, channel);
} else {
MessageUtils.sendAutoDeletedMessage(new EmbedBuilder().setDescription("You cannot vote on " + messageDesc).build(), 2000, channel);
}
}));
for (ButtonGroup.Button button : optionalButtons) {
buttonGroup.addButton(button);
}
Message voteMessage = ButtonUtil.sendReturnedButtonedMessage(channel, votesEmbed.build(), buttonGroup);
group.setVoteMessage(voteMessage);
new FlareBotTask("Votes-" + voteMessage.getId()) {
@Override
public void run() {
voteRunnable.run(group.won());
groupMap.remove(group.getMessageDesc() + channel.getGuild().getId());
runnableMap.remove(group.getMessageDesc() + channel.getGuild().getId());
channel.deleteMessageById(voteMessage.getId()).queue();
}
}.delay(timeout);
}
use of net.dv8tion.jda.core.EmbedBuilder in project FlareBot by FlareBot.
the class GeneralUtils method handleMultiSelectionCommand.
/**
* This is to handle "multi-selection commands" for example the info and stats commands which take one or more
* arguments and get select data from an enum
*/
public static void handleMultiSelectionCommand(User sender, TextChannel channel, String[] args, MultiSelectionContent<String, String, Boolean>[] providedContent) {
String search = MessageUtils.getMessage(args);
String[] fields = search.split(",");
EmbedBuilder builder = MessageUtils.getEmbed(sender).setColor(Color.CYAN);
boolean valid = false;
for (String string : fields) {
String s = string.trim();
for (MultiSelectionContent<String, String, Boolean> content : providedContent) {
if (s.equalsIgnoreCase(content.getName()) || s.replaceAll("_", " ").equalsIgnoreCase(content.getName())) {
builder.addField(content.getName(), content.getReturn(), content.isAlign());
valid = true;
}
}
}
if (valid)
channel.sendMessage(builder.build()).queue();
else
MessageUtils.sendErrorMessage("That piece of information could not be found!", channel);
}
use of net.dv8tion.jda.core.EmbedBuilder in project FlareBot by FlareBot.
the class GeneralUtils method getReportEmbed.
/**
* Gets the {@link Report} embed with all of the info on the report.
*
* @param sender The {@link User} who requested the embed
* @param report The {@link Report} to get the embed of.
* @return an {@link EmbedBuilder} that contains all the report data
*/
public static EmbedBuilder getReportEmbed(User sender, Report report) {
EmbedBuilder eb = MessageUtils.getEmbed(sender);
User reporter = Getters.getUserById(report.getReporterId());
User reported = Getters.getUserById(report.getReportedId());
eb.addField("Report ID", String.valueOf(report.getId()), true);
eb.addField("Reporter", reporter != null ? MessageUtils.getTag(reporter) : "Unknown", true);
eb.addField("Reported", reported != null ? MessageUtils.getTag(reported) : "Unknown", true);
// eb.addField("Time", report.getTime().toLocalDateTime().atOffset(ZoneOffset.UTC).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")) + " GMT/BST", true);
eb.setTimestamp(report.getTime().toLocalDateTime());
eb.addField("Status", report.getStatus().getMessage(), true);
eb.addField("Message", "```" + report.getMessage() + "```", false);
StringBuilder builder = new StringBuilder("The last 5 messages by the reported user: ```\n");
for (ReportMessage m : report.getMessages()) {
builder.append("[").append(m.getTime().toLocalDateTime().format(DateTimeFormatter.ofPattern("HH:mm:ss"))).append(" GMT/BST] ").append(FormatUtils.truncate(100, m.getMessage())).append("\n");
}
builder.append("```");
eb.addField("Messages from reported user", builder.toString(), false);
return eb;
}
use of net.dv8tion.jda.core.EmbedBuilder in project FlareBot by FlareBot.
the class Constants method logEG.
public static void logEG(String eg, Command command, Guild guild, User user) {
EmbedBuilder builder = new EmbedBuilder().setTitle("Found `" + eg + "`").addField("Guild", guild.getId() + " (`" + guild.getName() + "`) ", true).addField("User", user.getAsMention() + " (`" + user.getName() + "#" + user.getDiscriminator() + "`)", true).setTimestamp(LocalDateTime.now(Clock.systemUTC()));
if (command != null)
builder.addField("Command", command.getCommand(), true);
Constants.getEGLogChannel().sendMessage(builder.build()).queue();
}
Aggregations