use of net.dv8tion.jda.api.EmbedBuilder in project MantaroBot by Mantaro.
the class Poll method createPoll.
private void createPoll(Context ctx, Message message, I18nContext languageContext) {
runningPoll = ReactionOperations.create(message, TimeUnit.MILLISECONDS.toSeconds(timeout), new ReactionOperation() {
@Override
public int add(MessageReactionAddEvent e) {
// always return false anyway lul
return Operation.IGNORED;
}
@Override
public void onExpire() {
if (getChannel() == null)
return;
var user = ctx.getAuthor();
var embedBuilder = new EmbedBuilder().setTitle(languageContext.get("commands.poll.result_header")).setDescription(String.format(languageContext.get("commands.poll.result_screen"), user.getName(), name)).setFooter(languageContext.get("commands.poll.thank_note"), null);
var react = new AtomicInteger(0);
var counter = new AtomicInteger(0);
getChannel().retrieveMessageById(message.getIdLong()).queue(message -> {
var votes = message.getReactions().stream().filter(r -> react.getAndIncrement() <= options.length).map(r -> String.format(languageContext.get("commands.poll.vote_results"), r.getCount() - 1, options[counter.getAndIncrement()])).collect(Collectors.joining("\n"));
embedBuilder.addField(languageContext.get("commands.poll.results"), "```diff\n" + votes + "```", false);
getChannel().sendMessageEmbeds(embedBuilder.build()).queue();
});
getRunningPolls().remove(getChannel().getId());
}
@Override
public void onCancel() {
getChannel().sendMessageFormat(languageContext.get("commands.poll.cancelled"), EmoteReference.CORRECT).queue();
onExpire();
}
}, reactions(options.length));
}
use of net.dv8tion.jda.api.EmbedBuilder in project MantaroBot by Mantaro.
the class EmbedJSON method gen.
public MessageEmbed gen(Member member) {
EmbedBuilder embedBuilder = new EmbedBuilder();
if (title != null)
embedBuilder.setTitle(title, titleUrl);
if (description != null)
embedBuilder.setDescription(description);
if (author != null)
embedBuilder.setAuthor(author, authorUrl, authorImg);
if (footer != null)
embedBuilder.setFooter(footer, footerImg);
if (image != null)
embedBuilder.setImage(image);
if (thumbnail != null)
embedBuilder.setThumbnail(thumbnail);
if (color != null) {
Color col = null;
try {
col = (Color) Color.class.getField(color).get(null);
} catch (Exception ignored) {
String colorLower = color.toLowerCase();
if (colorLower.equals("member")) {
if (member != null)
col = member.getColor();
} else if (colorLower.matches("#?(0x)?[0123456789abcdef]{1,6}")) {
try {
col = Color.decode(colorLower.startsWith("0x") ? colorLower : "0x" + colorLower);
} catch (Exception ignored2) {
}
}
}
if (col != null)
embedBuilder.setColor(col);
}
fields.forEach(f -> {
if (f == null) {
embedBuilder.addBlankField(false);
} else if (f.value == null) {
embedBuilder.addBlankField(f.inline);
} else {
embedBuilder.addField(f.name == null ? "" : f.name, f.value, f.inline);
}
});
return embedBuilder.build();
}
use of net.dv8tion.jda.api.EmbedBuilder in project c0debaseBot by Biospheere.
the class GuildMemberLeaveListener method onGuildMemberRemove.
@Override
public void onGuildMemberRemove(GuildMemberRemoveEvent event) {
event.getGuild().getTextChannelsByName("log", true).forEach(channel -> {
final EmbedBuilder embedBuilder = DiscordUtils.getDefaultEmbed(event.getMember());
embedBuilder.appendDescription(event.getMember().getEffectiveName() + " hat c0debase verlassen");
channel.sendMessage(embedBuilder.build()).queue();
});
}
use of net.dv8tion.jda.api.EmbedBuilder in project c0debaseBot by Biospheere.
the class MessageReceiveListener method checkMemeMessage.
/**
* @param message
* @return if the message has been deleted
*/
private boolean checkMemeMessage(final Message message) {
if (!message.getTextChannel().getName().contains("meme")) {
return false;
}
if (message.getTextChannel().getTopic() == null || !message.getTextChannel().getTopic().contains("test")) {
return false;
}
final boolean containsURL = StringUtils.containtsURL(message.getContentStripped());
final boolean containsAttachment = !message.getAttachments().isEmpty();
if (!containsURL && !containsAttachment) {
message.delete().queue(success -> {
final MessageEmbed messageEmbed = new EmbedBuilder().setDescription("Deine Nachricht wurde gelöscht da sie kein Bild/Video oder Link enthält.").setColor(message.getGuild().getSelfMember().getColor()).build();
message.getChannel().sendMessage(messageEmbed).delay(Duration.ofSeconds(10)).flatMap(Message::delete).queue();
});
return true;
}
return false;
}
use of net.dv8tion.jda.api.EmbedBuilder in project c0debaseBot by Biospheere.
the class MessageReceiveListener method updateXP.
private void updateXP(final Message message) {
final User user = bot.getDatabase().getUserDao().getOrCreateUser(message.getGuild().getId(), message.getAuthor().getId());
final float time = (System.currentTimeMillis() - user.getLastMessage()) / 1000;
if (time >= 50.0f) {
if (user.addXP(50)) {
final EmbedBuilder levelUpEmbed = DiscordUtils.getDefaultEmbed(message.getMember());
final int newLevel = user.getLevel();
levelUpEmbed.appendDescription(message.getAuthor().getAsMention() + " ist nun Level " + newLevel);
if (message.getIdLong() != DISCUSSION_CHANNEL_ID) {
levelUpEmbed.setImage(gifs.get(Constants.RANDOM.nextInt(gifs.size())));
}
message.getTextChannel().sendMessage(levelUpEmbed.build()).queue();
if (newLevel > 2 && !message.getMember().getRoles().contains(message.getJDA().getRoleById(PROJECT_ROLE_ID))) {
message.getGuild().addRoleToMember(message.getMember(), message.getJDA().getRoleById(PROJECT_ROLE_ID)).queue();
}
}
user.setLastMessage(System.currentTimeMillis());
bot.getDatabase().getUserDao().updateUser(user);
}
}
Aggregations