use of net.dv8tion.jda.core.entities.Message in project MantaroBot by Mantaro.
the class ReactionOperations method create.
public static Future<Void> create(Message message, long timeoutSeconds, ReactionOperation operation, String... defaultReactions) {
if (!message.getAuthor().equals(message.getJDA().getSelfUser()))
throw new IllegalArgumentException("Must provide a message sent by the bot");
Future<Void> f = create(message.getIdLong(), timeoutSeconds, operation);
if (defaultReactions.length > 0) {
AtomicInteger index = new AtomicInteger();
AtomicReference<Consumer<Void>> c = new AtomicReference<>();
Consumer<Throwable> ignore = (t) -> {
};
c.set(ignored -> {
// Ignore this if we already cancelled this operation.
if (f.isCancelled())
return;
int i = index.incrementAndGet();
if (i < defaultReactions.length) {
if (message.getGuild() != null && message.getGuild().getSelfMember() != null) {
message.addReaction(reaction(defaultReactions[i])).queue(c.get(), ignore);
}
}
});
message.addReaction(reaction(defaultReactions[0])).queue(c.get(), ignore);
}
return f;
}
use of net.dv8tion.jda.core.entities.Message in project MantaroBot by Mantaro.
the class DiscordUtils method listText.
public static Future<Void> listText(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());
}
if (embeds.size() == 1) {
event.getChannel().sendMessage(embeds.get(0)).queue();
return null;
}
AtomicInteger index = new AtomicInteger();
Message m = event.getChannel().sendMessage(embeds.get(0)).complete();
return InteractiveOperations.createOverriding(event.getChannel(), timeoutSeconds, e -> {
if (!canEveryoneUse && e.getAuthor().getIdLong() != event.getAuthor().getIdLong())
return Operation.IGNORED;
if (e.getChannel().getMessageById(m.getIdLong()) == null)
return Operation.IGNORED;
if (e.getMessage().getContentRaw().equals("&p <<") || e.getMessage().getContentRaw().equals("&page <<")) {
if (index.get() == 0)
return Operation.IGNORED;
m.editMessage(embeds.get(index.decrementAndGet())).queue();
} else if (e.getMessage().getContentRaw().equals("&p >>") || e.getMessage().getContentRaw().equals("&page >>")) {
if (index.get() + 1 >= embeds.size())
return Operation.IGNORED;
m.editMessage(embeds.get(index.incrementAndGet())).queue();
}
if (e.getMessage().getContentRaw().equals("&cancel")) {
m.delete().queue();
return Operation.COMPLETED;
}
return Operation.IGNORED;
});
}
use of net.dv8tion.jda.core.entities.Message in project MantaroBot by Mantaro.
the class DiscordUtils method listText.
public static Future<Void> listText(GuildMessageReceivedEvent event, int timeoutSeconds, boolean canEveryoneUse, List<String> parts) {
if (parts.size() == 0)
return null;
if (parts.size() == 1) {
event.getChannel().sendMessage(parts.get(0)).queue();
return null;
}
AtomicInteger index = new AtomicInteger();
Message m = event.getChannel().sendMessage(parts.get(0)).complete();
return InteractiveOperations.createOverriding(event.getChannel(), timeoutSeconds, e -> {
if (!canEveryoneUse && e.getAuthor().getIdLong() != event.getAuthor().getIdLong())
return Operation.IGNORED;
if (e.getChannel().getMessageById(m.getIdLong()) == null)
return Operation.IGNORED;
if (e.getMessage().getContentRaw().equals("&p <<") || e.getMessage().getContentRaw().equals("&page <<")) {
if (index.get() == 0)
return Operation.IGNORED;
m.editMessage(String.format("%s\n**Page: %d**", parts.get(index.decrementAndGet()), index.get() + 1)).queue();
} else if (e.getMessage().getContentRaw().equals("&p >>") || e.getMessage().getContentRaw().equals("&page >>")) {
if (index.get() + 1 >= parts.size())
return Operation.IGNORED;
m.editMessage(String.format("%s\n**Page: %d**", parts.get(index.incrementAndGet()), index.get() + 1)).queue();
}
if (e.getMessage().getContentRaw().equals("&cancel")) {
m.delete().queue();
return Operation.COMPLETED;
}
return Operation.IGNORED;
});
}
use of net.dv8tion.jda.core.entities.Message in project MantaroBot by Mantaro.
the class DiscordUtils method listText.
public static Future<Void> listText(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);
}
base.setDescription("**Total pages: " + parts.size() + ".**\nUse **&p>>** and **&p <<** to move across pages.\n**Reference " + EmoteReference.BUY + " Buy " + EmoteReference.SELL + " Sell.**");
if (parts.size() == 1) {
event.getChannel().sendMessage(base.build()).queue();
return null;
}
AtomicInteger index = new AtomicInteger();
Message m = event.getChannel().sendMessage(base.build()).complete();
return InteractiveOperations.createOverriding(event.getChannel(), timeoutSeconds, e -> {
if (!canEveryoneUse && e.getAuthor().getIdLong() != event.getAuthor().getIdLong())
return Operation.IGNORED;
if (e.getChannel().getMessageById(m.getIdLong()) == null)
return Operation.IGNORED;
if (e.getMessage().getContentRaw().equals("&p <<") || e.getMessage().getContentRaw().equals("&page <<")) {
if (index.get() == 0)
return Operation.IGNORED;
EmbedBuilder toSend = addAllFields(base, parts.get(index.decrementAndGet()));
toSend.setFooter("Current page: " + (index.get() + 1), null);
m.editMessage(toSend.build()).queue();
} else if (e.getMessage().getContentRaw().equals("&p >>") || e.getMessage().getContentRaw().equals("&page >>")) {
if (index.get() + 1 >= parts.size())
return Operation.IGNORED;
EmbedBuilder toSend = addAllFields(base, parts.get(index.incrementAndGet()));
toSend.setFooter("Current page: " + (index.get() + 1), null);
m.editMessage(toSend.build()).queue();
}
if (e.getMessage().getContentRaw().equals("&cancel")) {
m.delete().queue();
return Operation.COMPLETED;
}
return Operation.IGNORED;
});
}
use of net.dv8tion.jda.core.entities.Message in project FlareBot by FlareBot.
the class YouTubeExtractor method process.
@Override
public void process(String input, Player player, Message message, User user) throws Exception {
AudioItem item;
try {
item = GeneralUtils.resolveItem(player, input);
} catch (IllegalArgumentException e) {
MessageUtils.editMessage(null, MessageUtils.getEmbed(user).setDescription("Could not get that video/playlist! Make sure the URL is correct!").setColor(Color.RED), message);
return;
} catch (IllegalStateException e) {
if (e.getMessage().contains("Vevo")) {
MessageUtils.editMessage(null, MessageUtils.getEmbed(user).setDescription("We are blocked from playing this video as it is from Vevo! " + "Sorry for any inconvenience.").setColor(Color.RED), message);
return;
}
MessageUtils.editMessage(null, MessageUtils.getEmbed(user).setDescription("There was a problem with that video!\n" + "If the error continues, join our support discord: " + Constants.INVITE_URL + "\n" + "Input: " + input + "\n" + "Error Message: " + e.getMessage() + "\n" + "Stacktrace: " + MessageUtils.paste(GeneralUtils.getStackTrace(e))).setColor(Color.RED), message);
return;
}
List<AudioTrack> audioTracks = new ArrayList<>();
String name;
if (item instanceof AudioPlaylist) {
AudioPlaylist audioPlaylist = (AudioPlaylist) item;
audioTracks.addAll(audioPlaylist.getTracks());
name = audioPlaylist.getName();
} else {
AudioTrack track = (AudioTrack) item;
/*if (track.getInfo().length == 0 || track.getInfo().isStream) {
EmbedBuilder builder = MessageUtils.getEmbed(user).setDescription("Cannot queue a livestream!");
MessageUtils.editMessage(null, builder, message);
return;
}*/
audioTracks.add(track);
name = track.getInfo().title;
if (track.getInfo().identifier.equals("dQw4w9WgXcQ") && (random.nextInt(1000) + 1) == 1000) {
GeneralUtils.sendImage("https://flarebot.stream/img/rick_roll.jpg", "rick_roll.jpg", user);
Constants.logEG("You can't rick roll me!", null, message.getGuild(), user);
}
}
if (name != null) {
List<Track> tracks = audioTracks.stream().map(Track::new).peek(track -> {
track.getMeta().put("requester", user.getId());
track.getMeta().put("guildId", player.getGuildId());
}).collect(Collectors.toList());
if (tracks.size() > 1) {
// Double `if` https://giphy.com/gifs/ng1xAzwIkDgfm
Playlist p = new Playlist(tracks);
player.queue(p);
} else {
player.queue(tracks.get(0));
}
EmbedBuilder builder = MessageUtils.getEmbed(user);
builder.setDescription(String.format("%s added the %s [`%s`](%s)", user.getAsMention(), audioTracks.size() == 1 ? "song" : "playlist", name.replace("`", "'"), input));
if (audioTracks.size() > 1)
builder.addField("Song count:", String.valueOf(audioTracks.size()), true);
MessageUtils.editMessage(null, builder, message);
}
}
Aggregations