use of net.dv8tion.jda.core.EmbedBuilder in project MantaroBot by Mantaro.
the class PollLobby method startPoll.
public void startPoll() {
try {
if (!isCompilant) {
getChannel().sendMessage(EmoteReference.WARNING + "This poll cannot build. " + "**Remember that the maximum amount of options are 9, the minimum is 2 and that the maximum timeout is 10m and the minimum timeout is 30s.**\n" + "Options are separated with a comma, for example `1,2,3`. For spaced stuff use commas at the start and end of the sentence.").queue();
getRunningPolls().remove(getChannel());
return;
}
if (isPollAlreadyRunning(getChannel())) {
getChannel().sendMessage(EmoteReference.WARNING + "There seems to be another poll running here...").queue();
return;
}
if (!event.getGuild().getSelfMember().hasPermission(getChannel(), Permission.MESSAGE_ADD_REACTION)) {
event.getChannel().sendMessage(EmoteReference.ERROR + "Seems like I cannot add reactions here...").queue();
getRunningPolls().remove(getChannel());
return;
}
DBGuild dbGuild = MantaroData.db().getGuild(event.getGuild());
GuildData data = dbGuild.getData();
AtomicInteger at = new AtomicInteger();
data.setRanPolls(data.getRanPolls() + 1L);
dbGuild.save();
String toShow = Stream.of(options).map(opt -> String.format("#%01d.- %s", at.incrementAndGet(), opt)).collect(Collectors.joining("\n"));
EmbedBuilder builder = new EmbedBuilder().setAuthor(String.format("Poll #%1d created by %s", data.getRanPolls(), event.getAuthor().getName()), null, event.getAuthor().getAvatarUrl()).setDescription("**Poll started. React to the number to vote.**\n*" + name + "*").addField("Options", "```md\n" + toShow + "```", false).setColor(event.getMember().getColor()).setThumbnail("https://cdn.pixabay.com/photo/2012/04/14/16/26/question-34499_960_720.png").setFooter("You have " + Utils.getDurationMinutes(timeout) + " minutes to vote.", event.getAuthor().getAvatarUrl());
getChannel().sendMessage(builder.build()).queue(message -> ReactionOperations.create(message, TimeUnit.MILLISECONDS.toSeconds(timeout), new ReactionOperation() {
@Override
public boolean run(MessageReactionAddEvent e) {
int i = e.getReactionEmote().getName().charAt(0) - '0';
if (i < 1 || i > options.length)
return false;
return false;
}
@Override
public void onExpire() {
EmbedBuilder embedBuilder = new EmbedBuilder().setTitle("Poll results").setDescription("**Showing results for the poll started by " + event.getAuthor().getName() + "** with name: *" + name + "*").setFooter("Thanks for your vote", null);
AtomicInteger react = new AtomicInteger(0);
AtomicInteger counter = new AtomicInteger(0);
String votes = new ArrayList<>(getChannel().getMessageById(message.getIdLong()).complete().getReactions()).stream().filter(r -> react.getAndIncrement() <= options.length).map(r -> "+Registered " + (r.getCount() - 1) + " votes for option " + options[counter.getAndIncrement()]).collect(Collectors.joining("\n"));
embedBuilder.addField("Results", "```diff\n" + votes + "```", false);
event.getChannel().sendMessage(embedBuilder.build()).queue();
}
}, reactions(options.length)));
} catch (Exception e) {
getChannel().sendMessage(EmoteReference.ERROR + "An unknown error has occurred while setting up a poll. Maybe try again?").queue();
}
}
use of net.dv8tion.jda.core.EmbedBuilder in project MantaroBot by Mantaro.
the class ModLog method logUnban.
public static void logUnban(Member author, String target, String reason) {
DBGuild guildDB = MantaroData.db().getGuild(author.getGuild());
EmbedBuilder embedBuilder = new EmbedBuilder();
embedBuilder.addField("Responsible Moderator", author.getEffectiveName(), true);
embedBuilder.addField("Member ID", target, true);
embedBuilder.addField("Reason", reason, false);
embedBuilder.setAuthor("Unban", null, author.getUser().getEffectiveAvatarUrl());
if (guildDB.getData().getGuildLogChannel() != null) {
MantaroBot.getInstance().getTextChannelById(guildDB.getData().getGuildLogChannel()).sendMessage(embedBuilder.build()).queue();
}
}
use of net.dv8tion.jda.core.EmbedBuilder in project MantaroBot by Mantaro.
the class ModLog method log.
public static void log(Member author, User target, String reason, ModAction action, long caseN, String... time) {
DBGuild guildDB = MantaroData.db().getGuild(author.getGuild());
EmbedBuilder embedBuilder = new EmbedBuilder();
embedBuilder.addField("Responsible Moderator", author.getEffectiveName(), true);
embedBuilder.addField("Member", target.getName(), true);
embedBuilder.addField("Reason", reason, false);
embedBuilder.setThumbnail(target.getEffectiveAvatarUrl());
switch(action) {
case BAN:
embedBuilder.setAuthor("Ban | Case #" + caseN, null, author.getUser().getEffectiveAvatarUrl());
break;
case TEMP_BAN:
embedBuilder.setAuthor("Temp Ban | Case #" + caseN, null, author.getUser().getEffectiveAvatarUrl());
embedBuilder.addField("Time", time[0], true);
break;
case KICK:
embedBuilder.setAuthor("Kick | Case #" + caseN, null, author.getUser().getEffectiveAvatarUrl());
break;
case MUTE:
embedBuilder.setAuthor("Mute | Case #" + caseN, null, author.getUser().getEffectiveAvatarUrl());
break;
case UNMUTE:
embedBuilder.setAuthor("Un-mute | Case #" + caseN, null, author.getUser().getEffectiveAvatarUrl());
break;
}
if (guildDB.getData().getGuildLogChannel() != null) {
MantaroBot.getInstance().getTextChannelById(guildDB.getData().getGuildLogChannel()).sendMessage(embedBuilder.build()).queue();
}
}
use of net.dv8tion.jda.core.EmbedBuilder in project MantaroBot by Mantaro.
the class AudioCmdUtils method embedForQueue.
public static void embedForQueue(int page, GuildMessageReceivedEvent event, GuildMusicManager musicManager) {
String toSend = AudioUtils.getQueueList(musicManager.getTrackScheduler().getQueue());
Guild guild = event.getGuild();
if (toSend.isEmpty()) {
event.getChannel().sendMessage(new EmbedBuilder().setAuthor("Queue for server " + guild.getName(), null, guild.getIconUrl()).setColor(Color.CYAN).setDescription("Nothing here, just dust. Why don't you queue some songs?").setThumbnail("http://www.clipartbest.com/cliparts/jix/6zx/jix6zx4dT.png").build()).queue();
return;
}
String[] lines = NEWLINE_PATTERN.split(toSend);
if (!guild.getSelfMember().hasPermission(event.getChannel(), Permission.MESSAGE_ADD_REACTION)) {
String line = null;
StringBuilder sb = new StringBuilder();
int total;
{
int t = 0;
int c = 0;
for (String s : lines) {
if (s.length() + c + 1 > MessageEmbed.TEXT_MAX_LENGTH) {
t++;
c = 0;
}
c += s.length() + 1;
}
if (c > 0)
t++;
total = t;
}
int current = 0;
for (String s : lines) {
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) {
current++;
if (current == page) {
line = sb.toString();
break;
}
sb = new StringBuilder();
}
sb.append(s).append('\n');
}
if (sb.length() > 0 && current + 1 == page) {
line = sb.toString();
}
if (line == null || page > total) {
event.getChannel().sendMessage(new EmbedBuilder().setAuthor("Queue for server " + guild.getName(), null, guild.getIconUrl()).setColor(Color.CYAN).setDescription("Nothing here, just dust. Why don't you go back some pages?").setThumbnail("http://www.clipartbest.com/cliparts/jix/6zx/jix6zx4dT.png").build()).queue();
} else {
long length = musicManager.getTrackScheduler().getQueue().stream().mapToLong(value -> value.getInfo().length).sum();
EmbedBuilder builder = new EmbedBuilder().setAuthor("Queue for server " + guild.getName(), null, guild.getIconUrl()).setColor(Color.CYAN);
String nowPlaying = musicManager.getTrackScheduler().getAudioPlayer().getPlayingTrack() != null ? "**[" + musicManager.getTrackScheduler().getAudioPlayer().getPlayingTrack().getInfo().title + "](" + musicManager.getTrackScheduler().getAudioPlayer().getPlayingTrack().getInfo().uri + ")** (" + Utils.getDurationMinutes(musicManager.getTrackScheduler().getAudioPlayer().getPlayingTrack().getInfo().length) + ")" : "Nothing or title/duration not found";
VoiceChannel vch = guild.getSelfMember().getVoiceState().getChannel();
builder.addField("Currently playing", nowPlaying, false).setThumbnail("http://www.clipartbest.com/cliparts/jix/6zx/jix6zx4dT.png").addField("Total queue time", "`" + Utils.getReadableTime(length) + "`", true).addField("Total queue size", "`" + musicManager.getTrackScheduler().getQueue().size() + " songs`", true).addField("Repeat / Pause", "`" + (musicManager.getTrackScheduler().getRepeat() == null ? "false" : musicManager.getTrackScheduler().getRepeat()) + " / " + String.valueOf(musicManager.getTrackScheduler().getAudioPlayer().isPaused()) + "`", true).addField("Playing in", vch == null ? "No channel :<" : "`" + vch.getName() + "`", true).setFooter("Total pages: " + total + " -> Use ~>queue <page> to change pages. Currently in page " + page, guild.getIconUrl());
event.getChannel().sendMessage(builder.setDescription(line).build()).queue();
}
return;
}
DiscordUtils.list(event, 30, false, (p, total) -> {
long length = musicManager.getTrackScheduler().getQueue().stream().mapToLong(value -> value.getInfo().length).sum();
EmbedBuilder builder = new EmbedBuilder().setAuthor("Queue for server " + guild.getName(), null, guild.getIconUrl()).setColor(Color.CYAN);
String nowPlaying = musicManager.getTrackScheduler().getAudioPlayer().getPlayingTrack() != null ? "**[" + musicManager.getTrackScheduler().getAudioPlayer().getPlayingTrack().getInfo().title + "](" + musicManager.getTrackScheduler().getAudioPlayer().getPlayingTrack().getInfo().uri + ")** (" + Utils.getDurationMinutes(musicManager.getTrackScheduler().getAudioPlayer().getPlayingTrack().getInfo().length) + ")" : "Nothing or title/duration not found";
VoiceChannel vch = guild.getSelfMember().getVoiceState().getChannel();
builder.addField("Currently playing", nowPlaying, false).setThumbnail("http://www.clipartbest.com/cliparts/jix/6zx/jix6zx4dT.png").addField("Total queue time", "`" + Utils.getReadableTime(length) + "`", true).addField("Total queue size", "`" + musicManager.getTrackScheduler().getQueue().size() + " songs`", true).addField("Repeat / Pause", "`" + (musicManager.getTrackScheduler().getRepeat() == null ? "false" : musicManager.getTrackScheduler().getRepeat()) + " / " + String.valueOf(musicManager.getTrackScheduler().getAudioPlayer().isPaused()) + "`", true).addField("Playing in", vch == null ? "No channel :<" : "`" + vch.getName() + "`", true).setFooter("Total pages: " + total + " -> React to change pages. Currently in page " + p, guild.getIconUrl());
return builder;
}, lines);
}
use of net.dv8tion.jda.core.EmbedBuilder 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();
}
});
}
Aggregations