messages = linkMap.get(event.getMessageIdLong());
if(messages.size()>1 && event.getGuild().getSelfMember()
- .hasPermission(event.getChannel(), Permission.MESSAGE_MANAGE))
- event.getChannel().deleteMessages(messages).queue(unused -> {}, ignored -> {});
+ .hasPermission(event.getChannel().asGuildMessageChannel(), Permission.MESSAGE_MANAGE))
+ event.getChannel().asGuildMessageChannel().deleteMessages(messages).queue(unused -> {}, ignored -> {});
else if(messages.size()>0)
messages.forEach(m -> m.delete().queue(unused -> {}, ignored -> {}));
}
diff --git a/commons/src/main/java/com/jagrosh/jdautilities/commons/utils/FinderUtil.java b/commons/src/main/java/com/jagrosh/jdautilities/commons/utils/FinderUtil.java
index 5d78084a..bc935747 100644
--- a/commons/src/main/java/com/jagrosh/jdautilities/commons/utils/FinderUtil.java
+++ b/commons/src/main/java/com/jagrosh/jdautilities/commons/utils/FinderUtil.java
@@ -15,6 +15,11 @@
*/
package com.jagrosh.jdautilities.commons.utils;
+import net.dv8tion.jda.api.entities.channel.concrete.Category;
+import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
+import net.dv8tion.jda.api.entities.channel.concrete.VoiceChannel;
+import net.dv8tion.jda.api.entities.emoji.Emoji;
+import net.dv8tion.jda.api.entities.emoji.RichCustomEmoji;
import net.dv8tion.jda.api.sharding.ShardManager;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.entities.*;
@@ -72,7 +77,7 @@ public final class FinderUtil
public final static Pattern USER_MENTION = Pattern.compile("<@!?(\\d{17,20})>"); // $1 -> ID
public final static Pattern CHANNEL_MENTION = Pattern.compile("<#(\\d{17,20})>"); // $1 -> ID
public final static Pattern ROLE_MENTION = Pattern.compile("<@&(\\d{17,20})>"); // $1 -> ID
- public final static Pattern EMOTE_MENTION = Pattern.compile("<:(.{2,32}):(\\d{17,20})>");
+ public final static Pattern EMOJI_MENTION = Pattern.compile("<:(.{2,32}):(\\d{17,20})>");
/**
* Queries a provided instance of {@link net.dv8tion.jda.api.JDA JDA} for {@link net.dv8tion.jda.api.entities.User User}s.
@@ -363,7 +368,7 @@ else if((name.toLowerCase().contains(lowerquery) || effName.toLowerCase().contai
/**
* Queries a provided instance of {@link net.dv8tion.jda.api.JDA JDA} for
- * {@link net.dv8tion.jda.api.entities.TextChannel TextChannel}s.
+ * {@link net.dv8tion.jda.api.entities.channel.concrete.TextChannel TextChannel}s.
*
* If a {@link net.dv8tion.jda.api.sharding.ShardManager ShardManager} is available this will query across that
* instead of the JDA instance.
@@ -387,7 +392,7 @@ public static List findTextChannels(String query, JDA jda)
/**
* Queries a provided instance of {@link net.dv8tion.jda.api.JDA JDA} for
- * {@link net.dv8tion.jda.api.entities.TextChannel TextChannel}s.
+ * {@link net.dv8tion.jda.api.entities.channel.concrete.TextChannel TextChannel}s.
*
* This only queries the instance of JDA, regardless of whether or not a
* {@link net.dv8tion.jda.api.sharding.ShardManager ShardManager} is available.
@@ -411,7 +416,7 @@ public static List findShardTextChannels(String query, JDA jda)
/**
* Queries a provided {@link net.dv8tion.jda.api.entities.Guild Guild} for
- * {@link net.dv8tion.jda.api.entities.TextChannel TextChannel}s.
+ * {@link net.dv8tion.jda.api.entities.channel.concrete.TextChannel TextChannel}s.
*
* The following special case is applied before the standard search is done:
*
@@ -496,7 +501,7 @@ else if(name.toLowerCase().contains(lowerquery) && startswith.isEmpty())
/**
* Queries a provided instance of {@link net.dv8tion.jda.api.JDA JDA} for
- * {@link net.dv8tion.jda.api.entities.VoiceChannel VoiceChannel}s.
+ * {@link net.dv8tion.jda.api.entities.channel.concrete.VoiceChannel VoiceChannel}s.
*
* If a {@link net.dv8tion.jda.api.sharding.ShardManager ShardManager} is available this will query across that
* instead of the JDA instance.
@@ -517,7 +522,7 @@ public static List findVoiceChannels(String query, JDA jda)
/**
* Queries a provided instance of {@link net.dv8tion.jda.api.JDA JDA} for
- * {@link net.dv8tion.jda.api.entities.VoiceChannel VoiceChannel}s.
+ * {@link net.dv8tion.jda.api.entities.channel.concrete.VoiceChannel VoiceChannel}s.
*
* This only queries the instance of JDA, regardless of whether or not a
* {@link net.dv8tion.jda.api.sharding.ShardManager ShardManager} is available.
@@ -538,7 +543,7 @@ public static List findShardVoiceChannels(String query, JDA jda)
/**
* Queries a provided {@link net.dv8tion.jda.api.entities.Guild Guild} for
- * {@link net.dv8tion.jda.api.entities.VoiceChannel VoiceChannel}s.
+ * {@link net.dv8tion.jda.api.entities.channel.concrete.VoiceChannel VoiceChannel}s.
*
* The standard search does not follow any special cases.
*
@@ -603,7 +608,7 @@ else if(name.toLowerCase().contains(lowerquery) && startswith.isEmpty())
/**
* Queries a provided instance of {@link net.dv8tion.jda.api.JDA JDA} for
- * {@link net.dv8tion.jda.api.entities.Category Categories}.
+ * {@link net.dv8tion.jda.api.entities.channel.concrete.Category Categories}.
*
* If a {@link net.dv8tion.jda.api.sharding.ShardManager ShardManager} is available this will query across that
* instead of the JDA instance.
@@ -624,7 +629,7 @@ public static List findCategories(String query, JDA jda)
/**
* Queries a provided instance of {@link net.dv8tion.jda.api.JDA JDA} for
- * {@link net.dv8tion.jda.api.entities.Category Categories}.
+ * {@link net.dv8tion.jda.api.entities.channel.concrete.Category Categories}.
*
* This only queries the instance of JDA, regardless of whether or not a
* {@link net.dv8tion.jda.api.sharding.ShardManager ShardManager} is available.
@@ -645,7 +650,7 @@ public static List findShardCategories(String query, JDA jda)
/**
* Queries a provided {@link net.dv8tion.jda.api.entities.Guild Guild} for
- * {@link net.dv8tion.jda.api.entities.Category Categories}.
+ * {@link net.dv8tion.jda.api.entities.channel.concrete.Category Categories}.
*
* The standard search does not follow any special cases.
*
@@ -766,16 +771,16 @@ else if(name.toLowerCase().contains(lowerquery) && startswith.isEmpty())
/**
* Queries a provided instance of {@link net.dv8tion.jda.api.JDA JDA} for
- * {@link net.dv8tion.jda.api.entities.Emote Emote}s.
+ * {@link net.dv8tion.jda.api.entities.emoji.Emoji Emoji}s.
*
* If a {@link net.dv8tion.jda.api.sharding.ShardManager ShardManager} is available this will query across that
* instead of the JDA instance.
*
*
The following special case is applied before the standard search is done:
*
- * - Emote Mention: Query provided matches a :emote: mention (more specifically {@literal <:emoteName:emoteID>}).
+ *
- Emoji Mention: Query provided matches a :emote: mention (more specifically {@literal <:emoteName:emoteID>}).
*
Note: This only returns here if the emote is valid. Validity being the ID retrieves a non-null
- * Emote and that the {@link net.dv8tion.jda.api.entities.Emote#getName() name} of the Emote is equal to the
+ * Emoji and that the {@link net.dv8tion.jda.api.entities.emoji.Emoji#getName() name} of the Emoji is equal to the
* name found in the query.
*
*
@@ -784,25 +789,25 @@ else if(name.toLowerCase().contains(lowerquery) && startswith.isEmpty())
* @param jda
* The instance of JDA to search from
*
- * @return A possibly-empty {@link java.util.List List} of Emotes found by the query from the provided JDA instance.
+ * @return A possibly-empty {@link java.util.List List} of Emojis found by the query from the provided JDA instance.
*/
- public static List findEmotes(String query, JDA jda)
+ public static List findEmojis(String query, JDA jda)
{
- return jdaFindEmotes(query, jda, true);
+ return jdaFindEmojis(query, jda, true);
}
/**
* Queries a provided instance of {@link net.dv8tion.jda.api.JDA JDA} for
- * {@link net.dv8tion.jda.api.entities.Emote Emote}s.
+ * {@link net.dv8tion.jda.api.entities.emoji.Emoji Emoji}s.
*
* This only queries the instance of JDA, regardless of whether or not a
* {@link net.dv8tion.jda.api.sharding.ShardManager ShardManager} is available.
*
*
The following special case is applied before the standard search is done:
*
- * - Emote Mention: Query provided matches a :emote: mention (more specifically {@literal <:emoteName:emoteID>}).
+ *
- Emoji Mention: Query provided matches a :emote: mention (more specifically {@literal <:emoteName:emoteID>}).
*
Note: This only returns here if the emote is valid. Validity being the ID retrieves a non-null
- * Emote and that the {@link net.dv8tion.jda.api.entities.Emote#getName() name} of the Emote is equal to the
+ * Emoji and that the {@link net.dv8tion.jda.api.entities.emoji.Emoji#getName() name} of the Emoji is equal to the
* name found in the query.
*
*
@@ -811,22 +816,22 @@ public static List findEmotes(String query, JDA jda)
* @param jda
* The instance of JDA to search from
*
- * @return A possibly-empty {@link java.util.List List} of Emotes found by the query from the provided JDA instance.
+ * @return A possibly-empty {@link java.util.List List} of Emojis found by the query from the provided JDA instance.
*/
- public static List findShardEmotes(String query, JDA jda)
+ public static List findShardEmojis(String query, JDA jda)
{
- return jdaFindEmotes(query, jda, false);
+ return jdaFindEmojis(query, jda, false);
}
/**
* Queries a provided {@link net.dv8tion.jda.api.entities.Guild Guild} for
- * {@link net.dv8tion.jda.api.entities.Emote Emote}s.
+ * {@link net.dv8tion.jda.api.entities.emoji.Emoji Emoji}s.
*
* The following special case is applied before the standard search is done:
*
- * - Emote Mention: Query provided matches a :emote: mention (more specifically {@literal <:emoteName:emoteID>}).
+ *
- Emoji Mention: Query provided matches a :emote: mention (more specifically {@literal <:emoteName:emoteID>}).
*
Note: This only returns here if the emote is valid. Validity being the ID retrieves a non-null
- * Emote and that the {@link net.dv8tion.jda.api.entities.Emote#getName() name} of the Emote is equal to the
+ * Emoji and that the {@link net.dv8tion.jda.api.entities.emoji.Emoji#getName() name} of the Emoji is equal to the
* name found in the query.
*
*
@@ -835,59 +840,59 @@ public static List findShardEmotes(String query, JDA jda)
* @param guild
* The Guild to search from
*
- * @return A possibly-empty {@link java.util.List List} of Emotes found by the query from the provided Guild.
+ * @return A possibly-empty {@link java.util.List List} of Emojis found by the query from the provided Guild.
*/
- public static List findEmotes(String query, Guild guild)
+ public static List findEmojis(String query, Guild guild)
{
- Matcher mentionMatcher = EMOTE_MENTION.matcher(query);
+ Matcher mentionMatcher = EMOJI_MENTION.matcher(query);
if(DISCORD_ID.matcher(query).matches())
{
- Emote emote = guild.getEmoteById(query);
- if(emote != null)
- return Collections.singletonList(emote);
+ Emoji Emoji = guild.getEmojiById(query);
+ if(Emoji != null)
+ return Collections.singletonList(Emoji);
}
else if(mentionMatcher.matches())
{
- String emoteName = mentionMatcher.group(1);
- String emoteId = mentionMatcher.group(2);
- Emote emote = guild.getEmoteById(emoteId);
- if(emote != null && emote.getName().equals(emoteName))
- return Collections.singletonList(emote);
+ String EmojiName = mentionMatcher.group(1);
+ String EmojiId = mentionMatcher.group(2);
+ Emoji Emoji = guild.getEmojiById(EmojiId);
+ if(Emoji != null && Emoji.getName().equals(EmojiName))
+ return Collections.singletonList(Emoji);
}
- return genericEmoteSearch(query, guild.getEmoteCache());
+ return genericEmojiSearch(query, guild.getEmojiCache());
}
- private static List jdaFindEmotes(String query, JDA jda, boolean useShardManager)
+ private static List jdaFindEmojis(String query, JDA jda, boolean useShardManager)
{
- Matcher mentionMatcher = EMOTE_MENTION.matcher(query);
+ Matcher mentionMatcher = EMOJI_MENTION.matcher(query);
ShardManager manager = useShardManager? jda.getShardManager() : null;
if(DISCORD_ID.matcher(query).matches())
{
- Emote emote = manager != null? manager.getEmoteById(query) : jda.getEmoteById(query);
- if(emote != null)
- return Collections.singletonList(emote);
+ Emoji Emoji = manager != null? manager.getEmojiById(query) : jda.getEmojiById(query);
+ if(Emoji != null)
+ return Collections.singletonList(Emoji);
}
else if(mentionMatcher.matches())
{
- String emoteName = mentionMatcher.group(1);
- String emoteId = mentionMatcher.group(2);
- Emote emote = manager != null? manager.getEmoteById(emoteId) : jda.getEmoteById(emoteId);
- if(emote != null && emote.getName().equals(emoteName))
- return Collections.singletonList(emote);
+ String EmojiName = mentionMatcher.group(1);
+ String EmojiId = mentionMatcher.group(2);
+ Emoji Emoji = manager != null? manager.getEmojiById(EmojiId) : jda.getEmojiById(EmojiId);
+ if(Emoji != null && Emoji.getName().equals(EmojiName))
+ return Collections.singletonList(Emoji);
}
- return genericEmoteSearch(query, jda.getEmoteCache());
+ return genericEmojiSearch(query, jda.getEmojiCache());
}
- private static List genericEmoteSearch(String query, SnowflakeCacheView cache)
+ private static List genericEmojiSearch(String query, SnowflakeCacheView cache)
{
- ArrayList exact = new ArrayList<>();
- ArrayList wrongcase = new ArrayList<>();
- ArrayList startswith = new ArrayList<>();
- ArrayList contains = new ArrayList<>();
+ ArrayList exact = new ArrayList<>();
+ ArrayList wrongcase = new ArrayList<>();
+ ArrayList startswith = new ArrayList<>();
+ ArrayList contains = new ArrayList<>();
String lowerquery = query.toLowerCase();
cache.forEach(emote -> {
String name = emote.getName();
diff --git a/commons/src/main/java/com/jagrosh/jdautilities/commons/waiter/EventWaiter.java b/commons/src/main/java/com/jagrosh/jdautilities/commons/waiter/EventWaiter.java
index ef8de743..11b9d8a3 100644
--- a/commons/src/main/java/com/jagrosh/jdautilities/commons/waiter/EventWaiter.java
+++ b/commons/src/main/java/com/jagrosh/jdautilities/commons/waiter/EventWaiter.java
@@ -17,7 +17,7 @@
import net.dv8tion.jda.api.events.Event;
import net.dv8tion.jda.api.events.GenericEvent;
-import net.dv8tion.jda.api.events.ShutdownEvent;
+import net.dv8tion.jda.api.events.session.ShutdownEvent;
import net.dv8tion.jda.api.hooks.EventListener;
import net.dv8tion.jda.api.hooks.SubscribeEvent;
import net.dv8tion.jda.internal.utils.Checks;
@@ -44,7 +44,7 @@
* {@link java.util.concurrent.ScheduledExecutorService Executor}, and thus a proper
* shutdown of said executor. The default constructor for an EventWaiter sets up a
* working, "live", EventWaiter whose shutdown is triggered via JDA firing a
- * {@link net.dv8tion.jda.api.events.ShutdownEvent ShutdownEvent}.
+ * {@link net.dv8tion.jda.api.events.session.ShutdownEvent ShutdownEvent}.
*
A more "shutdown adaptable" constructor allows the provision of a
* {@code ScheduledExecutorService} and a choice of how exactly shutdown will be handled
* (see {@link EventWaiter#EventWaiter(ScheduledExecutorService, boolean)} for more details).
@@ -81,7 +81,7 @@ public EventWaiter()
* {@code shutdownAutomatically} is required to be manually specified by developers as a way of
* verifying a contract that the developer will conform to the behavior of the newly generated EventWaiter:
*
- * - If {@code true}, shutdown is handled when a {@link net.dv8tion.jda.api.events.ShutdownEvent ShutdownEvent}
+ *
- If {@code true}, shutdown is handled when a {@link net.dv8tion.jda.api.events.session.ShutdownEvent ShutdownEvent}
* is fired. This means that any external functions of the provided Executor is now impossible and any externally
* queued tasks are lost if they have yet to be run.
* - If {@code false}, shutdown is now placed as a responsibility of the developer, and no attempt will be
@@ -97,7 +97,7 @@ public EventWaiter()
* The ScheduledExecutorService to use for this EventWaiter's threadpool.
* @param shutdownAutomatically
* Whether or not the {@code threadpool} will shutdown automatically when a
- * {@link net.dv8tion.jda.api.events.ShutdownEvent ShutdownEvent} is fired.
+ * {@link net.dv8tion.jda.api.events.session.ShutdownEvent ShutdownEvent} is fired.
*
* @throws java.lang.IllegalArgumentException
* If the threadpool provided is {@code null} or
diff --git a/examples/src/main/java/com/jagrosh/jdautilities/examples/command/AboutCommand.java b/examples/src/main/java/com/jagrosh/jdautilities/examples/command/AboutCommand.java
index cc6c04aa..97cbe1bc 100644
--- a/examples/src/main/java/com/jagrosh/jdautilities/examples/command/AboutCommand.java
+++ b/examples/src/main/java/com/jagrosh/jdautilities/examples/command/AboutCommand.java
@@ -21,7 +21,7 @@
import com.jagrosh.jdautilities.doc.standard.CommandInfo;
import com.jagrosh.jdautilities.examples.doc.Author;
import net.dv8tion.jda.api.entities.ApplicationInfo;
-import net.dv8tion.jda.api.entities.ChannelType;
+import net.dv8tion.jda.api.entities.channel.ChannelType;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.JDAInfo;
import net.dv8tion.jda.api.Permission;
diff --git a/examples/src/main/java/com/jagrosh/jdautilities/examples/command/GuildlistCommand.java b/examples/src/main/java/com/jagrosh/jdautilities/examples/command/GuildlistCommand.java
index 7297f510..78f857db 100644
--- a/examples/src/main/java/com/jagrosh/jdautilities/examples/command/GuildlistCommand.java
+++ b/examples/src/main/java/com/jagrosh/jdautilities/examples/command/GuildlistCommand.java
@@ -26,7 +26,7 @@
import com.jagrosh.jdautilities.menu.Paginator;
import com.jagrosh.jdautilities.commons.waiter.EventWaiter;
import net.dv8tion.jda.api.Permission;
-import net.dv8tion.jda.api.entities.ChannelType;
+import net.dv8tion.jda.api.entities.channel.ChannelType;
import net.dv8tion.jda.api.exceptions.PermissionException;
/**
diff --git a/examples/src/main/java/com/jagrosh/jdautilities/examples/command/RoleinfoCommand.java b/examples/src/main/java/com/jagrosh/jdautilities/examples/command/RoleinfoCommand.java
index fb0a2f07..0af1c8f4 100644
--- a/examples/src/main/java/com/jagrosh/jdautilities/examples/command/RoleinfoCommand.java
+++ b/examples/src/main/java/com/jagrosh/jdautilities/examples/command/RoleinfoCommand.java
@@ -22,10 +22,10 @@
import java.time.format.DateTimeFormatter;
import java.util.List;
import net.dv8tion.jda.api.EmbedBuilder;
-import net.dv8tion.jda.api.MessageBuilder;
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.Role;
+import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder;
/**
*
@@ -96,9 +96,9 @@ else if(found.size()>1)
if(list.size() * 24 <= 2048-desr.length())
list.forEach(m -> desr.append("<@").append(m.getUser().getId()).append("> "));
- event.reply(new MessageBuilder()
- .append(title)
- .setEmbed(new EmbedBuilder()
+ event.reply(new MessageCreateBuilder()
+ .setContent(title)
+ .setEmbeds(new EmbedBuilder()
.setDescription(desr.toString().trim())
.setColor(role.getColor()).build())
.build());
diff --git a/examples/src/main/java/com/jagrosh/jdautilities/examples/command/ServerinfoCommand.java b/examples/src/main/java/com/jagrosh/jdautilities/examples/command/ServerinfoCommand.java
index 9a4d70a4..f707ae11 100644
--- a/examples/src/main/java/com/jagrosh/jdautilities/examples/command/ServerinfoCommand.java
+++ b/examples/src/main/java/com/jagrosh/jdautilities/examples/command/ServerinfoCommand.java
@@ -21,6 +21,7 @@
import net.dv8tion.jda.api.*;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member;
+import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder;
/**
*
@@ -75,6 +76,6 @@ protected void execute(CommandEvent event)
builder.setThumbnail(guild.getIconUrl());
builder.setColor(owner == null ? null : owner.getColor());
builder.setDescription(str);
- event.reply(new MessageBuilder().append(title).setEmbed(builder.build()).build());
+ event.reply(new MessageCreateBuilder().setContent(title).setEmbeds(builder.build()).build());
}
}
diff --git a/menu/src/main/java/com/jagrosh/jdautilities/menu/ButtonMenu.java b/menu/src/main/java/com/jagrosh/jdautilities/menu/ButtonMenu.java
index ed2a768b..f3bbff31 100644
--- a/menu/src/main/java/com/jagrosh/jdautilities/menu/ButtonMenu.java
+++ b/menu/src/main/java/com/jagrosh/jdautilities/menu/ButtonMenu.java
@@ -24,15 +24,17 @@
import com.jagrosh.jdautilities.commons.waiter.EventWaiter;
import net.dv8tion.jda.api.EmbedBuilder;
-import net.dv8tion.jda.api.MessageBuilder;
-import net.dv8tion.jda.api.entities.Emote;
import net.dv8tion.jda.api.entities.Message;
-import net.dv8tion.jda.api.entities.MessageChannel;
-import net.dv8tion.jda.api.entities.MessageReaction.ReactionEmote;
+import net.dv8tion.jda.api.entities.channel.unions.MessageChannelUnion;
import net.dv8tion.jda.api.entities.Role;
import net.dv8tion.jda.api.entities.User;
+import net.dv8tion.jda.api.entities.emoji.Emoji;
import net.dv8tion.jda.api.events.message.react.MessageReactionAddEvent;
import net.dv8tion.jda.api.requests.RestAction;
+import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder;
+import net.dv8tion.jda.api.utils.messages.MessageCreateData;
+import net.dv8tion.jda.api.utils.messages.MessageEditBuilder;
+import net.dv8tion.jda.api.utils.messages.MessageEditData;
import net.dv8tion.jda.internal.utils.Checks;
/**
@@ -48,11 +50,11 @@ public class ButtonMenu extends Menu
private final String text;
private final String description;
private final List choices;
- private final Consumer action;
+ private final Consumer action;
private final Consumer finalAction;
ButtonMenu(EventWaiter waiter, Set users, Set roles, long timeout, TimeUnit unit,
- Color color, String text, String description, List choices, Consumer action, Consumer finalAction)
+ Color color, String text, String description, List choices, Consumer action, Consumer finalAction)
{
super(waiter, users, roles, timeout, unit);
this.color = color;
@@ -65,15 +67,15 @@ public class ButtonMenu extends Menu
/**
* Shows the ButtonMenu as a new {@link net.dv8tion.jda.api.entities.Message Message}
- * in the provided {@link net.dv8tion.jda.api.entities.MessageChannel MessageChannel}.
+ * in the provided {@link net.dv8tion.jda.api.entities.channel.unions.MessageChannelUnion MessageChannel}.
*
* @param channel
* The MessageChannel to send the new Message to
*/
@Override
- public void display(MessageChannel channel)
+ public void display(MessageChannelUnion channel)
{
- initialize(channel.sendMessage(getMessage()));
+ initialize(channel.sendMessage(getMessageCreate()));
}
/**
@@ -97,16 +99,16 @@ private void initialize(RestAction ra)
for(int i=0; i r = emote==null ? m.addReaction(choices.get(i)) : m.addReaction(emote);
+ RestAction r = emote==null ? m.addReaction(Emoji.fromFormatted(choices.get(i))) : m.addReaction(emote);
if(i+1 ra)
// If the reaction is an Emote we get the Snowflake,
// otherwise we get the unicode value.
- String re = event.getReaction().getReactionEmote().isEmote()
- ? event.getReaction().getReactionEmote().getId()
- : event.getReaction().getReactionEmote().getName();
+ String re = event.getReaction().getEmoji().getAsReactionCode();
// If the value we got is not registered as a button to
// the ButtonMenu being displayed we return false.
@@ -138,7 +138,7 @@ private void initialize(RestAction ra)
// is fired and processed above.
// Preform the specified action with the ReactionEmote
- action.accept(event.getReaction().getReactionEmote());
+ action.accept(event.getReaction().getEmoji());
finalAction.accept(m);
}, timeout, unit, () -> finalAction.accept(m));
});
@@ -148,13 +148,24 @@ private void initialize(RestAction ra)
}
// Generates a ButtonMenu message
- private Message getMessage()
+ private MessageCreateData getMessageCreate()
{
- MessageBuilder mbuilder = new MessageBuilder();
+ MessageCreateBuilder mbuilder = new MessageCreateBuilder();
if(text!=null)
- mbuilder.append(text);
+ mbuilder.setContent(text);
if(description!=null)
- mbuilder.setEmbed(new EmbedBuilder().setColor(color).setDescription(description).build());
+ mbuilder.setEmbeds(new EmbedBuilder().setColor(color).setDescription(description).build());
+ return mbuilder.build();
+ }
+
+ // Generates a ButtonMenu message
+ private MessageEditData getMessage()
+ {
+ MessageEditBuilder mbuilder = new MessageEditBuilder();
+ if(text!=null)
+ mbuilder.setContent(text);
+ if(description!=null)
+ mbuilder.setEmbeds(new EmbedBuilder().setColor(color).setDescription(description).build());
return mbuilder.build();
}
@@ -170,7 +181,7 @@ public static class Builder extends Menu.Builder
private String text;
private String description;
private final List choices = new LinkedList<>();
- private Consumer action;
+ private Consumer action;
private Consumer finalAction = (m) -> {};
/**
@@ -253,7 +264,7 @@ public Builder setDescription(String description)
*
* @return This builder
*/
- public Builder setAction(Consumer action)
+ public Builder setAction(Consumer action)
{
this.action = action;
return this;
@@ -280,8 +291,8 @@ public Builder setFinalAction(Consumer finalAction)
/**
* Adds a single String unicode emoji as a button choice.
*
- *
Any non-unicode {@link net.dv8tion.jda.api.entities.Emote Emote} should be
- * added using {@link ButtonMenu.Builder#addChoice(Emote)
+ *
Any non-unicode {@link net.dv8tion.jda.api.entities.emoji.Emoji Emote} should be
+ * added using {@link ButtonMenu.Builder#addChoice(Emoji)
* ButtonMenu.Builder#addChoice(Emote)}.
*
* @param emoji
@@ -296,7 +307,7 @@ public Builder addChoice(String emoji)
}
/**
- * Adds a single custom {@link net.dv8tion.jda.api.entities.Emote Emote} as button choices.
+ * Adds a single custom {@link net.dv8tion.jda.api.entities.emoji.Emoji Emote} as button choices.
*
*
Any regular unicode emojis should be added using {@link
* ButtonMenu.Builder#addChoice(String)
@@ -307,16 +318,16 @@ public Builder addChoice(String emoji)
*
* @return This builder
*/
- public Builder addChoice(Emote emote)
+ public Builder addChoice(Emoji emote)
{
- return addChoice(emote.getId());
+ return addChoice(emote.getFormatted());
}
/**
* Adds String unicode emojis as button choices.
*
- *
Any non-unicode {@link net.dv8tion.jda.api.entities.Emote Emote}s should be
- * added using {@link ButtonMenu.Builder#addChoices(Emote...)
+ *
Any non-unicode {@link net.dv8tion.jda.api.entities.emoji.Emoji Emote}s should be
+ * added using {@link ButtonMenu.Builder#addChoices(Emoji...)
* ButtonMenu.Builder#addChoices(Emote...)}.
*
* @param emojis
@@ -332,7 +343,7 @@ public Builder addChoices(String... emojis)
}
/**
- * Adds custom {@link net.dv8tion.jda.api.entities.Emote Emote}s as button choices.
+ * Adds custom {@link net.dv8tion.jda.api.entities.emoji.Emoji Emote}s as button choices.
*
*
Any regular unicode emojis should be added using {@link
* ButtonMenu.Builder#addChoices(String...)
@@ -343,9 +354,9 @@ public Builder addChoices(String... emojis)
*
* @return This builder
*/
- public Builder addChoices(Emote... emotes)
+ public Builder addChoices(Emoji... emotes)
{
- for(Emote emote : emotes)
+ for(Emoji emote : emotes)
addChoice(emote);
return this;
}
@@ -353,8 +364,8 @@ public Builder addChoices(Emote... emotes)
/**
* Sets the String unicode emojis as button choices.
*
- *
Any non-unicode {@link net.dv8tion.jda.api.entities.Emote Emote}s should be
- * set using {@link ButtonMenu.Builder#setChoices(Emote...)
+ *
Any non-unicode {@link net.dv8tion.jda.api.entities.emoji.Emoji Emote}s should be
+ * set using {@link ButtonMenu.Builder#setChoices(Emoji...)
* ButtonMenu.Builder#setChoices(Emote...)}.
*
* @param emojis
@@ -369,7 +380,7 @@ public Builder setChoices(String... emojis)
}
/**
- * Sets the {@link net.dv8tion.jda.api.entities.Emote Emote}s as button choices.
+ * Sets the {@link net.dv8tion.jda.api.entities.emoji.Emoji Emote}s as button choices.
*
*
Any regular unicode emojis should be set using {@link
* ButtonMenu.Builder#setChoices(String...)
@@ -380,7 +391,7 @@ public Builder setChoices(String... emojis)
*
* @return This builder
*/
- public Builder setChoices(Emote... emotes)
+ public Builder setChoices(Emoji... emotes)
{
this.choices.clear();
return addChoices(emotes);
diff --git a/menu/src/main/java/com/jagrosh/jdautilities/menu/Menu.java b/menu/src/main/java/com/jagrosh/jdautilities/menu/Menu.java
index 5fd8b39c..bb6f8600 100644
--- a/menu/src/main/java/com/jagrosh/jdautilities/menu/Menu.java
+++ b/menu/src/main/java/com/jagrosh/jdautilities/menu/Menu.java
@@ -22,6 +22,7 @@
import com.jagrosh.jdautilities.commons.waiter.EventWaiter;
import net.dv8tion.jda.api.entities.*;
+import net.dv8tion.jda.api.entities.channel.unions.MessageChannelUnion;
import javax.annotation.Nullable;
@@ -31,7 +32,7 @@
* or key-phrases.
*
*
Classes extending this are able to take a provided {@link net.dv8tion.jda.api.entities.Message Message}
- * or {@link net.dv8tion.jda.api.entities.MessageChannel MessageChannel} and display a visualized "Menu"
+ * or {@link net.dv8tion.jda.api.entities.channel.unions.MessageChannelUnion MessageChannel} and display a visualized "Menu"
* as or in it.
*
*
The JDA-Utilities default implementations of this superclass typically handle input through
@@ -71,12 +72,12 @@ protected Menu(EventWaiter waiter, Set users, Set roles, long timeou
}
/**
- * Displays this Menu in a {@link net.dv8tion.jda.api.entities.MessageChannel MessageChannel}.
+ * Displays this Menu in a {@link net.dv8tion.jda.api.entities.channel.unions.MessageChannelUnion MessageChannel}.
*
* @param channel
* The MessageChannel to display this Menu in
*/
- public abstract void display(MessageChannel channel);
+ public abstract void display(MessageChannelUnion channel);
/**
* Displays this Menu as a designated {@link net.dv8tion.jda.api.entities.Message Message}.
diff --git a/menu/src/main/java/com/jagrosh/jdautilities/menu/OrderedMenu.java b/menu/src/main/java/com/jagrosh/jdautilities/menu/OrderedMenu.java
index 52e138f7..1fc2655c 100644
--- a/menu/src/main/java/com/jagrosh/jdautilities/menu/OrderedMenu.java
+++ b/menu/src/main/java/com/jagrosh/jdautilities/menu/OrderedMenu.java
@@ -25,19 +25,23 @@
import com.jagrosh.jdautilities.commons.waiter.EventWaiter;
import net.dv8tion.jda.api.EmbedBuilder;
-import net.dv8tion.jda.api.MessageBuilder;
import net.dv8tion.jda.api.Permission;
-import net.dv8tion.jda.api.entities.ChannelType;
import net.dv8tion.jda.api.entities.Message;
-import net.dv8tion.jda.api.entities.MessageChannel;
import net.dv8tion.jda.api.entities.Role;
-import net.dv8tion.jda.api.entities.TextChannel;
import net.dv8tion.jda.api.entities.User;
+import net.dv8tion.jda.api.entities.channel.ChannelType;
+import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
+import net.dv8tion.jda.api.entities.channel.unions.MessageChannelUnion;
+import net.dv8tion.jda.api.entities.emoji.Emoji;
import net.dv8tion.jda.api.events.message.GenericMessageEvent;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import net.dv8tion.jda.api.events.message.react.MessageReactionAddEvent;
import net.dv8tion.jda.api.exceptions.PermissionException;
import net.dv8tion.jda.api.requests.RestAction;
+import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder;
+import net.dv8tion.jda.api.utils.messages.MessageCreateData;
+import net.dv8tion.jda.api.utils.messages.MessageEditBuilder;
+import net.dv8tion.jda.api.utils.messages.MessageEditData;
import net.dv8tion.jda.internal.utils.Checks;
/**
@@ -89,7 +93,7 @@ public class OrderedMenu extends Menu
/**
* Shows the OrderedMenu as a new {@link net.dv8tion.jda.api.entities.Message Message}
- * in the provided {@link net.dv8tion.jda.api.entities.MessageChannel MessageChannel}.
+ * in the provided {@link net.dv8tion.jda.api.entities.channel.unions.MessageChannelUnion MessageChannel}.
*
* @param channel
* The MessageChannel to send the new Message to
@@ -97,24 +101,24 @@ public class OrderedMenu extends Menu
* @throws java.lang.IllegalArgumentException
* If all of the following are violated simultaneously:
*
- * - Being sent to a {@link net.dv8tion.jda.api.entities.TextChannel TextChannel}.
+ * - Being sent to a {@link net.dv8tion.jda.api.entities.channel.concrete.TextChannel TextChannel}.
* - This OrderedMenu does not allow typed input.
* - The bot doesn't have {@link net.dv8tion.jda.api.Permission#MESSAGE_ADD_REACTION
* Permission.MESSAGE_ADD_REACTION} in the channel this menu is being sent to.
*
*/
@Override
- public void display(MessageChannel channel)
+ public void display(MessageChannelUnion channel)
{
// This check is basically for whether or not the menu can even display.
// Is from text channel
// Does not allow typed input
// Does not have permission to add reactions
- if(channel.getType()==ChannelType.TEXT
+ if(channel.getType()== ChannelType.TEXT
&& !allowTypedInput
&& !((TextChannel)channel).getGuild().getSelfMember().hasPermission((TextChannel) channel, Permission.MESSAGE_ADD_REACTION))
throw new PermissionException("Must be able to add reactions if not allowing typed input!");
- initialize(channel.sendMessage(getMessage()));
+ initialize(channel.sendMessage(getMessageCreate()));
}
/**
@@ -127,7 +131,7 @@ public void display(MessageChannel channel)
* @throws java.lang.IllegalArgumentException
* If all of the following are violated simultaneously:
*
- * - Being sent to a {@link net.dv8tion.jda.api.entities.TextChannel TextChannel}.
+ * - Being sent to a {@link net.dv8tion.jda.api.entities.channel.concrete.TextChannel TextChannel}.
* - This OrderedMenu does not allow typed input.
* - The bot doesn't have {@link net.dv8tion.jda.api.Permission#MESSAGE_ADD_REACTION
* Permission.MESSAGE_ADD_REACTION} in the channel this menu is being sent to.
@@ -142,7 +146,7 @@ public void display(Message message)
// Does not have permission to add reactions
if(message.getChannelType() == ChannelType.TEXT
&& !allowTypedInput
- && !message.getGuild().getSelfMember().hasPermission(message.getTextChannel(), Permission.MESSAGE_ADD_REACTION))
+ && !message.getGuild().getSelfMember().hasPermission(message.getGuildChannel(), Permission.MESSAGE_ADD_REACTION))
throw new PermissionException("Must be able to add reactions if not allowing typed input!");
initialize(message.editMessage(getMessage()));
}
@@ -163,11 +167,11 @@ private void initialize(RestAction ra)
{
// If this is not the last run of this loop
if(i < choices.size()-1)
- m.addReaction(getEmoji(i)).queue();
+ m.addReaction(Emoji.fromUnicode(getEmoji(i))).queue();
// If this is the last run of this loop
else
{
- RestAction re = m.addReaction(getEmoji(i));
+ RestAction re = m.addReaction(Emoji.fromUnicode(getEmoji(i)));
// If we're using the cancel function we want
// to add a "step" so we queue the last emoji being
// added and then make the RestAction to start waiting
@@ -175,7 +179,7 @@ private void initialize(RestAction ra)
if(useCancel)
{
re.queue(); // queue the last emoji
- re = m.addReaction(CANCEL);
+ re = m.addReaction(Emoji.fromUnicode(CANCEL));
}
// queue the last emoji or the cancel button
re.queue(v -> {
@@ -219,13 +223,13 @@ private void waitGeneric(Message m)
{
MessageReactionAddEvent event = (MessageReactionAddEvent)e;
// Process which reaction it is
- if(event.getReaction().getReactionEmote().getName().equals(CANCEL))
+ if(event.getReaction().getEmoji().getName().equals(CANCEL))
cancel.accept(m);
else
// The int provided in the success consumer is not indexed from 0 to number of choices - 1,
// but from 1 to number of choices. So the first choice will correspond to 1, the second
// choice to 2, etc.
- action.accept(m, getNumber(event.getReaction().getReactionEmote().getName()));
+ action.accept(m, getNumber(event.getReaction().getEmoji().getName()));
}
// If it's a valid MessageReceivedEvent
else if (e instanceof MessageReceivedEvent)
@@ -249,26 +253,39 @@ private void waitReactionOnly(Message m)
return isValidReaction(m, e);
}, e -> {
m.delete().queue();
- if(e.getReaction().getReactionEmote().getName().equals(CANCEL))
+ if(e.getReaction().getEmoji().getName().equals(CANCEL))
cancel.accept(m);
else
// The int provided in the success consumer is not indexed from 0 to number of choices - 1,
// but from 1 to number of choices. So the first choice will correspond to 1, the second
// choice to 2, etc.
- action.accept(m, getNumber(e.getReaction().getReactionEmote().getName()));
+ action.accept(m, getNumber(e.getReaction().getEmoji().getName()));
}, timeout, unit, () -> cancel.accept(m));
}
// This is where the displayed message for the OrderedMenu is built.
- private Message getMessage()
+ private MessageCreateData getMessageCreate()
{
- MessageBuilder mbuilder = new MessageBuilder();
+ MessageCreateBuilder mbuilder = new MessageCreateBuilder();
if(text!=null)
- mbuilder.append(text);
+ mbuilder.setContent(text);
StringBuilder sb = new StringBuilder();
for(int i=0; ichoices.size());
}
diff --git a/menu/src/main/java/com/jagrosh/jdautilities/menu/Paginator.java b/menu/src/main/java/com/jagrosh/jdautilities/menu/Paginator.java
index c6489ba8..ae8e4eb9 100644
--- a/menu/src/main/java/com/jagrosh/jdautilities/menu/Paginator.java
+++ b/menu/src/main/java/com/jagrosh/jdautilities/menu/Paginator.java
@@ -26,16 +26,17 @@
import com.jagrosh.jdautilities.commons.waiter.EventWaiter;
import net.dv8tion.jda.api.EmbedBuilder;
-import net.dv8tion.jda.api.MessageBuilder;
import net.dv8tion.jda.api.entities.Message;
-import net.dv8tion.jda.api.entities.MessageChannel;
+import net.dv8tion.jda.api.entities.channel.unions.MessageChannelUnion;
import net.dv8tion.jda.api.entities.Role;
import net.dv8tion.jda.api.entities.User;
+import net.dv8tion.jda.api.entities.emoji.Emoji;
import net.dv8tion.jda.api.events.message.GenericMessageEvent;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import net.dv8tion.jda.api.events.message.react.MessageReactionAddEvent;
import net.dv8tion.jda.api.exceptions.PermissionException;
import net.dv8tion.jda.api.requests.RestAction;
+import net.dv8tion.jda.api.utils.messages.*;
import net.dv8tion.jda.internal.utils.Checks;
/**
@@ -106,17 +107,17 @@ public class Paginator extends Menu
/**
* Begins pagination on page 1 as a new {@link net.dv8tion.jda.api.entities.Message Message}
- * in the provided {@link net.dv8tion.jda.api.entities.MessageChannel MessageChannel}.
+ * in the provided {@link net.dv8tion.jda.api.entities.channel.unions.MessageChannelUnion MessageChannel}.
*
* Starting on another page is available via {@link
- * Paginator#paginate(MessageChannel, int)
- * Paginator#paginate(MessageChannel, int)}.
+ * Paginator#paginate(MessageChannelUnion, int)
+ * Paginator#paginate(MessageChannelUnion, int)}.
*
* @param channel
* The MessageChannel to send the new Message to
*/
@Override
- public void display(MessageChannel channel)
+ public void display(MessageChannelUnion channel)
{
paginate(channel, 1);
}
@@ -139,7 +140,7 @@ public void display(Message message)
/**
* Begins pagination as a new {@link net.dv8tion.jda.api.entities.Message Message}
- * in the provided {@link net.dv8tion.jda.api.entities.MessageChannel MessageChannel}, starting
+ * in the provided {@link net.dv8tion.jda.api.entities.channel.unions.MessageChannelUnion MessageChannel}, starting
* on whatever page number is provided.
*
* @param channel
@@ -147,13 +148,13 @@ public void display(Message message)
* @param pageNum
* The page number to begin on
*/
- public void paginate(MessageChannel channel, int pageNum)
+ public void paginate(MessageChannelUnion channel, int pageNum)
{
if(pageNum<1)
pageNum = 1;
else if (pageNum>pages)
pageNum = pages;
- Message msg = renderPage(pageNum);
+ MessageCreateData msg = renderPageCreate(pageNum);
initialize(channel.sendMessage(msg), pageNum);
}
@@ -173,7 +174,7 @@ public void paginate(Message message, int pageNum)
pageNum = 1;
else if (pageNum>pages)
pageNum = pages;
- Message msg = renderPage(pageNum);
+ MessageEditData msg = renderPage(pageNum);
initialize(message.editMessage(msg), pageNum);
}
@@ -183,18 +184,18 @@ private void initialize(RestAction action, int pageNum)
if(pages > 1)
{
if(bulkSkipNumber > 1)
- m.addReaction(BIG_LEFT).queue();
- m.addReaction(LEFT).queue();
- m.addReaction(STOP).queue();
+ m.addReaction(Emoji.fromUnicode(BIG_LEFT)).queue();
+ m.addReaction(Emoji.fromUnicode(LEFT)).queue();
+ m.addReaction(Emoji.fromUnicode(STOP)).queue();
if(bulkSkipNumber > 1)
- m.addReaction(RIGHT).queue();
- m.addReaction(bulkSkipNumber > 1? BIG_RIGHT : RIGHT)
+ m.addReaction(Emoji.fromUnicode(RIGHT)).queue();
+ m.addReaction(bulkSkipNumber > 1? Emoji.fromUnicode(BIG_RIGHT) : Emoji.fromUnicode(RIGHT))
.queue(v -> pagination(m, pageNum), t -> pagination(m, pageNum));
}
else if(waitOnSinglePage)
{
// Go straight to without text-input because only one page is available
- m.addReaction(STOP).queue(
+ m.addReaction(Emoji.fromUnicode(STOP)).queue(
v -> paginationWithoutTextInput(m, pageNum),
t -> paginationWithoutTextInput(m, pageNum)
);
@@ -287,7 +288,7 @@ private boolean checkReaction(MessageReactionAddEvent event, long messageId)
{
if(event.getMessageIdLong() != messageId)
return false;
- switch(event.getReactionEmote().getName())
+ switch(event.getReaction().getEmoji().getName())
{
// LEFT, STOP, RIGHT, BIG_LEFT, BIG_RIGHT all fall-through to
// return if the User is valid or not. If none trip, this defaults
@@ -308,7 +309,7 @@ private boolean checkReaction(MessageReactionAddEvent event, long messageId)
private void handleMessageReactionAddAction(MessageReactionAddEvent event, Message message, int pageNum)
{
int newPageNum = pageNum;
- switch(event.getReaction().getReactionEmote().getName())
+ switch(event.getReaction().getEmoji().getName())
{
case LEFT:
if(newPageNum == 1 && wrapPageEnds)
@@ -356,10 +357,44 @@ private void handleMessageReactionAddAction(MessageReactionAddEvent event, Messa
int n = newPageNum;
message.editMessage(renderPage(newPageNum)).queue(m -> pagination(m, n));
}
-
- private Message renderPage(int pageNum)
+
+ private MessageEditData renderPage(int pageNum)
+ {
+ MessageEditBuilder mbuilder = new MessageEditBuilder();
+ EmbedBuilder ebuilder = new EmbedBuilder();
+ int start = (pageNum-1)*itemsPerPage;
+ int end = strings.size() < pageNum*itemsPerPage ? strings.size() : pageNum*itemsPerPage;
+ if(columns == 1)
+ {
+ StringBuilder sbuilder = new StringBuilder();
+ for(int i=start; ichoices.size())
selection = choices.size();
- Message msg = render(selection);
+ MessageCreateData msg = renderCreate(selection);
initialize(channel.sendMessage(msg), selection);
}
@@ -156,7 +160,7 @@ public void showDialog(Message message, int selection)
selection = 1;
else if(selection>choices.size())
selection = choices.size();
- Message msg = render(selection);
+ MessageEditData msg = render(selection);
initialize(message.editMessage(msg), selection);
}
@@ -165,15 +169,15 @@ private void initialize(RestAction action, int selection)
action.queue(m -> {
if(choices.size()>1)
{
- m.addReaction(UP).queue();
- m.addReaction(SELECT).queue();
- m.addReaction(CANCEL).queue();
- m.addReaction(DOWN).queue(v -> selectionDialog(m, selection), v -> selectionDialog(m, selection));
+ m.addReaction(Emoji.fromUnicode(UP)).queue();
+ m.addReaction(Emoji.fromUnicode(SELECT)).queue();
+ m.addReaction(Emoji.fromUnicode(CANCEL)).queue();
+ m.addReaction(Emoji.fromUnicode(DOWN)).queue(v -> selectionDialog(m, selection), v -> selectionDialog(m, selection));
}
else
{
- m.addReaction(SELECT).queue();
- m.addReaction(CANCEL).queue(v -> selectionDialog(m, selection), v -> selectionDialog(m, selection));
+ m.addReaction(Emoji.fromUnicode(SELECT)).queue();
+ m.addReaction(Emoji.fromUnicode(CANCEL)).queue(v -> selectionDialog(m, selection), v -> selectionDialog(m, selection));
}
});
}
@@ -183,15 +187,15 @@ private void selectionDialog(Message message, int selection)
waiter.waitForEvent(MessageReactionAddEvent.class, event -> {
if(!event.getMessageId().equals(message.getId()))
return false;
- if(!(UP.equals(event.getReaction().getReactionEmote().getName())
- || DOWN.equals(event.getReaction().getReactionEmote().getName())
- || CANCEL.equals(event.getReaction().getReactionEmote().getName())
- || SELECT.equals(event.getReaction().getReactionEmote().getName())))
+ if(!(UP.equals(event.getReaction().getEmoji().getName())
+ || DOWN.equals(event.getReaction().getEmoji().getName())
+ || CANCEL.equals(event.getReaction().getEmoji().getName())
+ || SELECT.equals(event.getReaction().getEmoji().getName())))
return false;
return isValidUser(event.getUser(), event.isFromGuild() ? event.getGuild() : null);
}, event -> {
int newSelection = selection;
- switch(event.getReaction().getReactionEmote().getName())
+ switch(event.getReaction().getEmoji().getName())
{
case UP:
if(newSelection>1)
@@ -223,7 +227,7 @@ else if(loop)
}, timeout, unit, () -> cancel.accept(message));
}
- private Message render(int selection)
+ private MessageCreateData renderCreate(int selection)
{
StringBuilder sbuilder = new StringBuilder();
for(int i=0; iurls.size())
pageNum = urls.size();
- Message msg = renderPage(pageNum);
+ MessageCreateData msg = renderPageCreate(pageNum);
initialize(channel.sendMessage(msg), pageNum);
}
@@ -154,7 +158,7 @@ public void paginate(Message message, int pageNum)
pageNum = 1;
else if (pageNum>urls.size())
pageNum = urls.size();
- Message msg = renderPage(pageNum);
+ MessageEditData msg = renderPage(pageNum);
initialize(message.editMessage(msg), pageNum);
}
@@ -164,17 +168,17 @@ private void initialize(RestAction action, int pageNum)
if(urls.size()>1)
{
if(bulkSkipNumber > 1)
- m.addReaction(BIG_LEFT).queue();
- m.addReaction(LEFT).queue();
- m.addReaction(STOP).queue();
+ m.addReaction(Emoji.fromUnicode(BIG_LEFT)).queue();
+ m.addReaction(Emoji.fromUnicode(LEFT)).queue();
+ m.addReaction(Emoji.fromUnicode(STOP)).queue();
if(bulkSkipNumber > 1)
- m.addReaction(RIGHT).queue();
- m.addReaction(bulkSkipNumber > 1? BIG_RIGHT : RIGHT)
+ m.addReaction(Emoji.fromUnicode(RIGHT)).queue();
+ m.addReaction(bulkSkipNumber > 1? Emoji.fromUnicode(BIG_RIGHT) : Emoji.fromUnicode(RIGHT))
.queue(v -> pagination(m, pageNum), t -> pagination(m, pageNum));
}
else if(waitOnSinglePage)
{
- m.addReaction(STOP).queue(v -> pagination(m, pageNum), t -> pagination(m, pageNum));
+ m.addReaction(Emoji.fromUnicode(STOP)).queue(v -> pagination(m, pageNum), t -> pagination(m, pageNum));
}
else
{
@@ -265,7 +269,7 @@ private boolean checkReaction(MessageReactionAddEvent event, long messageId)
{
if(event.getMessageIdLong() != messageId)
return false;
- switch(event.getReactionEmote().getName())
+ switch(event.getReaction().getEmoji().getName())
{
// LEFT, STOP, RIGHT, BIG_LEFT, BIG_RIGHT all fall-through to
// return if the User is valid or not. If none trip, this defaults
@@ -287,7 +291,7 @@ private void handleMessageReactionAddAction(MessageReactionAddEvent event, Messa
{
int newPageNum = pageNum;
int pages = urls.size();
- switch(event.getReaction().getReactionEmote().getName())
+ switch(event.getReaction().getEmoji().getName())
{
case LEFT:
if(newPageNum == 1 && wrapPageEnds)
@@ -336,18 +340,33 @@ private void handleMessageReactionAddAction(MessageReactionAddEvent event, Messa
message.editMessage(renderPage(newPageNum)).queue(m -> pagination(m, n));
}
- private Message renderPage(int pageNum)
+ private MessageCreateData renderPageCreate(int pageNum)
{
- MessageBuilder mbuilder = new MessageBuilder();
+ MessageCreateBuilder mbuilder = new MessageCreateBuilder();
EmbedBuilder ebuilder = new EmbedBuilder();
ebuilder.setImage(urls.get(pageNum-1));
ebuilder.setColor(color.apply(pageNum, urls.size()));
ebuilder.setDescription(description.apply(pageNum, urls.size()));
if(showPageNumbers)
ebuilder.setFooter("Image "+pageNum+"/"+urls.size(), null);
- mbuilder.setEmbed(ebuilder.build());
+ mbuilder.setEmbeds(ebuilder.build());
if(text!=null)
- mbuilder.append(text.apply(pageNum, urls.size()));
+ mbuilder.setContent(text.apply(pageNum, urls.size()));
+ return mbuilder.build();
+ }
+
+ private MessageEditData renderPage(int pageNum)
+ {
+ MessageEditBuilder mbuilder = new MessageEditBuilder();
+ EmbedBuilder ebuilder = new EmbedBuilder();
+ ebuilder.setImage(urls.get(pageNum-1));
+ ebuilder.setColor(color.apply(pageNum, urls.size()));
+ ebuilder.setDescription(description.apply(pageNum, urls.size()));
+ if(showPageNumbers)
+ ebuilder.setFooter("Image "+pageNum+"/"+urls.size(), null);
+ mbuilder.setEmbeds(ebuilder.build());
+ if(text!=null)
+ mbuilder.setContent(text.apply(pageNum, urls.size()));
return mbuilder.build();
}
@@ -626,7 +645,7 @@ public Builder allowTextInput(boolean allowTextInput)
/**
* Sets the {@link com.jagrosh.jdautilities.menu.Slideshow Slideshow} to traverse
* left or right when a provided text input is sent in the form of a Message to
- * the {@link net.dv8tion.jda.api.entities.GuildChannel GuildChannel} the menu is displayed in.
+ * the {@link net.dv8tion.jda.api.entities.channel.unions.GuildChannelUnion GuildChannel} the menu is displayed in.
*
* If one or both these parameters are provided {@code null} this resets
* both of them and they will no longer be available when the Slideshow is built.
diff --git a/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/OAuth2Client.java b/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/OAuth2Client.java
index 81a782de..8273b495 100644
--- a/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/OAuth2Client.java
+++ b/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/OAuth2Client.java
@@ -23,6 +23,7 @@
import com.jagrosh.jdautilities.oauth2.session.SessionController;
import com.jagrosh.jdautilities.oauth2.exceptions.InvalidStateException;
import com.jagrosh.jdautilities.oauth2.state.StateController;
+import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.internal.utils.Checks;
import okhttp3.OkHttpClient;
@@ -127,6 +128,28 @@ public interface OAuth2Client
@CheckReturnValue
OAuth2Action> getGuilds(Session session);
+ /**
+ * For the love of god and my sanity being broken, because I worked on this for 2 weeks. I am not going to document it now.
+ *
+ * @param user
+ * The User that should join the given Guild.
+ *
+ * @param guild
+ * The Guild the User should join.
+ *
+ * @param botAuthorizationToken
+ * The bot's authorization token.
+ *
+ * @return A {@link com.jagrosh.jdautilities.oauth2.requests.OAuth2Action OAuth2Action} for
+ * the OAuth2Guilds to be retrieved.
+ *
+ * @throws com.jagrosh.jdautilities.oauth2.exceptions.MissingScopeException
+ * If the provided Session does not have the 'guilds' scope.
+ */
+ @CheckReturnValue
+ OAuth2Action joinGuild(OAuth2User user, Guild guild, String botAuthorizationToken);
+
+
/**
* Gets the client ID for this OAuth2Client.
*
@@ -153,7 +176,7 @@ public interface OAuth2Client
*
* @return The client's SessionController.
*/
- SessionController getSessionController();
+ SessionController> getSessionController();
/**
* Builder for creating OAuth2Client instances.
@@ -165,7 +188,7 @@ class Builder
{
private long clientId = -1;
private String clientSecret;
- private SessionController sessionController;
+ private SessionController> sessionController;
private StateController stateController;
private OkHttpClient client;
@@ -225,7 +248,7 @@ public Builder setClientSecret(String clientSecret)
*
* @return This builder.
*/
- public Builder setSessionController(SessionController sessionController)
+ public Builder setSessionController(SessionController> sessionController)
{
this.sessionController = sessionController;
return this;
diff --git a/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/entities/OAuth2Guild.java b/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/entities/OAuth2Guild.java
index c763c1ce..d9a697e2 100644
--- a/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/entities/OAuth2Guild.java
+++ b/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/entities/OAuth2Guild.java
@@ -16,11 +16,12 @@
package com.jagrosh.jdautilities.oauth2.entities;
import com.jagrosh.jdautilities.oauth2.OAuth2Client;
+import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.ISnowflake;
+import net.dv8tion.jda.api.sharding.ShardManager;
import java.util.EnumSet;
-import java.util.List;
/**
* OAuth2 representation of a Discord Server/Guild.
@@ -33,6 +34,24 @@
*/
public interface OAuth2Guild extends ISnowflake
{
+ /**
+ * Check if the Bot is on the Guild.
+ *
+ * @param jda The {@link JDA} that should be used.
+ *
+ * @return true, if the bot is on the Guild | false, if not.
+ */
+ boolean botJoined(JDA jda);
+
+ /**
+ * Check if the Bot is on the Guild.
+ *
+ * @param shardManager The {@link ShardManager} that should be used.
+ *
+ * @return true, if the bot is on the Guild | false, if not.
+ */
+ boolean botJoined(ShardManager shardManager);
+
/**
* Gets the underlying {@link com.jagrosh.jdautilities.oauth2.OAuth2Client OAuth2Client}
* that created this OAuth2Guild.
@@ -67,7 +86,7 @@ public interface OAuth2Guild extends ISnowflake
*
* @return The Session User's raw permission value for the Guild.
*/
- int getPermissionsRaw();
+ long getPermissionsRaw();
/**
* Gets the Session User's {@link net.dv8tion.jda.api.Permission Permissions} for the Guild.
diff --git a/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/entities/OAuth2User.java b/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/entities/OAuth2User.java
index b9b26600..31720fb4 100644
--- a/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/entities/OAuth2User.java
+++ b/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/entities/OAuth2User.java
@@ -22,6 +22,7 @@
import net.dv8tion.jda.api.entities.IMentionable;
import net.dv8tion.jda.api.entities.ISnowflake;
import net.dv8tion.jda.api.entities.User;
+import org.jetbrains.annotations.NotNull;
/**
* OAuth2 representation of a Discord User.
@@ -54,7 +55,7 @@ public interface OAuth2User extends ISnowflake, IMentionable
*
* @return The user's Snowflake ID as a String.
*/
- String getId();
+ @NotNull @Override String getId();
/**
* Gets the user's Snowflake ID as a {@code long}.
@@ -146,35 +147,13 @@ public interface OAuth2User extends ISnowflake, IMentionable
*/
String getEffectiveAvatarUrl();
- /**
- * Gets whether or not this user is a bot.
- *
- * While, at the time of writing this documentation, bots cannot
- * authenticate applications, there may be a time in the future
- * where they have such an ability.
- *
- * @return {@code false}
- *
- * @deprecated
- * Due to the nature of OAuth2 at this moment, bots are not
- * allowed to use the various urls provided.
- *
This method is scheduled for removal upon merging it
- * with master
in JDA-Utilities 2.2
- */
- @Deprecated
- default boolean isBot()
- {
- // Note: the code here has not changed from it's implementation.
- return false;
- }
-
/**
* Gets the user as a discord formatted mention:
*
{@code <@SNOWFLAKE_ID> }
*
* @return A discord formatted mention of this user.
*/
- String getAsMention();
+ @NotNull String getAsMention();
/**
* Gets the corresponding {@link net.dv8tion.jda.api.entities.User JDA User}
diff --git a/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/entities/impl/OAuth2ClientImpl.java b/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/entities/impl/OAuth2ClientImpl.java
index d430ffe8..7e075cce 100644
--- a/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/entities/impl/OAuth2ClientImpl.java
+++ b/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/entities/impl/OAuth2ClientImpl.java
@@ -30,17 +30,16 @@
import com.jagrosh.jdautilities.oauth2.session.SessionData;
import com.jagrosh.jdautilities.oauth2.state.DefaultStateController;
import com.jagrosh.jdautilities.oauth2.state.StateController;
+import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.exceptions.HttpException;
-import net.dv8tion.jda.internal.requests.Method;
+import net.dv8tion.jda.api.requests.Method;
import net.dv8tion.jda.internal.utils.Checks;
import net.dv8tion.jda.internal.utils.EncodingUtil;
import net.dv8tion.jda.internal.utils.IOUtil;
-import net.dv8tion.jda.internal.utils.JDALogger;
import okhttp3.*;
import org.json.JSONArray;
import org.json.JSONObject;
import org.json.JSONTokener;
-import org.slf4j.Logger;
import java.io.IOException;
import java.io.InputStream;
@@ -54,16 +53,14 @@
*/
public class OAuth2ClientImpl implements OAuth2Client
{
- private static final Logger LOG = JDALogger.getLog(OAuth2Client.class);
-
private final long clientId;
private final String clientSecret;
- private final SessionController sessionController;
+ private final SessionController> sessionController;
private final StateController stateController;
private final OkHttpClient httpClient;
private final OAuth2Requester requester;
- public OAuth2ClientImpl(long clientId, String clientSecret, SessionController sessionController,
+ public OAuth2ClientImpl(long clientId, String clientSecret, SessionController> sessionController,
StateController stateController, OkHttpClient httpClient)
{
Checks.check(clientId >= 0, "Invalid Client ID");
@@ -188,13 +185,42 @@ protected List handle(Response response) throws IOException
obj = body.getJSONObject(i);
list.add(new OAuth2GuildImpl(OAuth2ClientImpl.this, obj.getLong("id"),
obj.getString("name"), obj.optString("icon", null), obj.getBoolean("owner"),
- obj.getInt("permissions")));
+ obj.getLong("permissions")));
}
return list;
}
};
}
+ @Override
+ public OAuth2Action joinGuild(OAuth2User user, Guild guild, String botAuthorizationToken)
+ {
+ if(!Scope.contains(user.getSession().getScopes(), Scope.GUILDS_JOIN))
+ throw new MissingScopeException("Join a Guild from a Session", Scope.GUILDS_JOIN);
+
+ return new OAuth2Action(this, Method.PUT, OAuth2URL.GUILD_JOIN.compile(guild.getId(), user.getId())) {
+ @Override
+ protected Headers getHeaders() {
+ return Headers.of("Authorization", "Bot " + botAuthorizationToken, "Content-Type", "application/json");
+ }
+
+ @Override
+ protected RequestBody getBody() {
+ return RequestBody.create(new JSONObject()
+ .append("access_token", user.getSession().getAccessToken()).toString(),
+ MediaType.parse("application/json"));
+ }
+
+ @Override
+ protected OAuth2User handle(Response response) throws IOException {
+ if (!response.isSuccessful())
+ throw failure(response);
+
+ return user;
+ }
+ };
+ }
+
@Override
public long getId()
{
diff --git a/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/entities/impl/OAuth2GuildImpl.java b/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/entities/impl/OAuth2GuildImpl.java
index f0dce737..d0c493e2 100644
--- a/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/entities/impl/OAuth2GuildImpl.java
+++ b/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/entities/impl/OAuth2GuildImpl.java
@@ -17,7 +17,9 @@
import com.jagrosh.jdautilities.oauth2.OAuth2Client;
import com.jagrosh.jdautilities.oauth2.entities.OAuth2Guild;
+import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.Permission;
+import net.dv8tion.jda.api.sharding.ShardManager;
import java.util.EnumSet;
@@ -28,12 +30,13 @@
public class OAuth2GuildImpl implements OAuth2Guild
{
private final OAuth2Client client;
- private final long id;
- private final String name, icon;
+ private final long id,
+ permissions;
+ private final String name,
+ icon;
private final boolean owner;
- private final int permissions;
- public OAuth2GuildImpl(OAuth2Client client, long id, String name, String icon, boolean owner, int permissions)
+ public OAuth2GuildImpl(OAuth2Client client, long id, String name, String icon, boolean owner, long permissions)
{
this.client = client;
this.id = id;
@@ -43,6 +46,12 @@ public OAuth2GuildImpl(OAuth2Client client, long id, String name, String icon, b
this.permissions = permissions;
}
+ @Override
+ public boolean botJoined(JDA jda) { return jda.getGuildById(getIdLong()) != null; }
+
+ @Override
+ public boolean botJoined(ShardManager shardManager) { return shardManager.getGuildById(getIdLong()) != null; }
+
@Override
public OAuth2Client getClient()
{
@@ -70,11 +79,11 @@ public String getIconId()
@Override
public String getIconUrl()
{
- return icon == null ? null : "https://cdn.discordapp.com/icons/" + id + "/" + icon + ".png";
+ return icon == null ? "https://i0.wp.com/www.alphr.com/wp-content/uploads/2019/02/Discord-Spoiler-Tag-Featured.jpg?resize=1200%2C1080&ssl=1" : "https://cdn.discordapp.com/icons/" + id + "/" + icon + ".png";
}
@Override
- public int getPermissionsRaw()
+ public long getPermissionsRaw()
{
return permissions;
}
@@ -98,13 +107,13 @@ public boolean hasPermission(Permission... perms)
return true;
long adminPermRaw = Permission.ADMINISTRATOR.getRawValue();
- int permissions = getPermissionsRaw();
+ long permissionsRaw = getPermissionsRaw();
- if ((permissions & adminPermRaw) == adminPermRaw)
+ if ((permissionsRaw & adminPermRaw) == adminPermRaw)
return true;
long checkPermsRaw = Permission.getRaw(perms);
- return (permissions & checkPermsRaw) == checkPermsRaw;
+ return (permissionsRaw & checkPermsRaw) == checkPermsRaw;
}
}
diff --git a/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/entities/impl/OAuth2UserImpl.java b/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/entities/impl/OAuth2UserImpl.java
index 80bf9316..301dc9af 100644
--- a/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/entities/impl/OAuth2UserImpl.java
+++ b/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/entities/impl/OAuth2UserImpl.java
@@ -23,22 +23,31 @@
import net.dv8tion.jda.api.sharding.ShardManager;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.entities.User;
+import org.jetbrains.annotations.NotNull;
/**
- *
* @author John Grosh (john.a.grosh@gmail.com)
*/
-public class OAuth2UserImpl implements OAuth2User
-{
+public class OAuth2UserImpl implements OAuth2User {
private final OAuth2Client client;
private final Session session;
private final long id;
- private final String name, discriminator, avatar, email;
- private final boolean verified, mfaEnabled;
-
- public OAuth2UserImpl(OAuth2Client client, Session session, long id, String name, String discriminator,
- String avatar, String email, boolean verified, boolean mfaEnabled)
- {
+ private final String name,
+ discriminator,
+ avatar,
+ email;
+ private final boolean verified,
+ mfaEnabled;
+
+ public OAuth2UserImpl(OAuth2Client client,
+ Session session,
+ long id,
+ String name,
+ String discriminator,
+ String avatar,
+ String email,
+ boolean verified,
+ boolean mfaEnabled) {
this.client = client;
this.session = session;
this.id = id;
@@ -51,136 +60,122 @@ public OAuth2UserImpl(OAuth2Client client, Session session, long id, String name
}
@Override
- public OAuth2Client getClient()
- {
+ public OAuth2Client getClient() {
return client;
}
@Override
- public Session getSession()
- {
+ public Session getSession() {
return session;
}
@Override
- public String getId()
- {
+ public @NotNull String getId() {
return Long.toUnsignedString(id);
}
@Override
- public long getIdLong()
- {
+ public long getIdLong() {
return id;
}
@Override
- public String getName()
- {
+ public String getName() {
return name;
}
@Override
- public String getEmail()
- {
- if(Scope.contains(getSession().getScopes(), Scope.EMAIL))
+ public String getEmail() {
+ if (Scope.contains(getSession().getScopes(), Scope.EMAIL))
throw new MissingScopeException("get email for user", Scope.EMAIL);
return email;
}
-
+
@Override
- public boolean isVerified()
- {
+ public boolean isVerified() {
return verified;
}
-
+
@Override
- public boolean isMfaEnabled()
- {
+ public boolean isMfaEnabled() {
return mfaEnabled;
}
@Override
- public String getDiscriminator()
- {
+ public String getDiscriminator() {
return discriminator;
}
@Override
- public String getAvatarId()
- {
+ public String getAvatarId() {
return avatar;
}
@Override
- public String getAvatarUrl()
- {
- return getAvatarId() == null ? null : "https://cdn.discordapp.com/avatars/" + getId() + "/" + getAvatarId()
- + (getAvatarId().startsWith("a_") ? ".gif" : ".png");
+ public String getAvatarUrl() {
+ if (getAvatarId() == null) {
+ return null;
+ }
+ if (getAvatarId().startsWith("a_")) {
+ return "https://cdn.discordapp.com/avatars/" + getId() + "/" + getAvatarId() + ".gif";
+ }
+
+ return "https://cdn.discordapp.com/avatars/" + getId() + "/" + getAvatarId() + ".png";
}
@Override
- public String getDefaultAvatarId()
- {
+ public String getDefaultAvatarId() {
return DEFAULT_AVATARS[Integer.parseInt(getDiscriminator()) % DEFAULT_AVATARS.length];
}
@Override
- public String getDefaultAvatarUrl()
- {
+ public String getDefaultAvatarUrl() {
return "https://discord.com/assets/" + getDefaultAvatarId() + ".png";
}
@Override
- public String getEffectiveAvatarUrl()
- {
+ public String getEffectiveAvatarUrl() {
return getAvatarUrl() == null ? getDefaultAvatarUrl() : getAvatarUrl();
}
@Override
- public String getAsMention()
- {
+ public @NotNull String getAsMention() {
return "<@" + id + '>';
}
-
+
@Override
- public User getJDAUser(JDA jda)
- {
+ public User getJDAUser(JDA jda) {
return jda.getUserById(id);
}
-
+
@Override
- public User getJDAUser(ShardManager shardManager)
- {
+ public User getJDAUser(ShardManager shardManager) {
return shardManager.getUserById(id);
}
-
+
@Override
- public boolean equals(Object o)
- {
+ public boolean equals(Object o) {
if (!(o instanceof OAuth2UserImpl))
return false;
OAuth2UserImpl oUser = (OAuth2UserImpl) o;
return this == oUser || this.id == oUser.id;
}
-
+
@Override
- public int hashCode()
- {
+ public int hashCode() {
return Long.hashCode(id);
}
@Override
- public String toString()
- {
+ public String toString() {
return "U:" + getName() + '(' + id + ')';
}
- private static final String[] DEFAULT_AVATARS = new String[] {
- "6debd47ed13483642cf09e832ed0bc1b",
- "322c936a8c8be1b803cd94861bdfa868",
- "dd4dbc0016779df1378e7812eabaa04d",
- "0e291f67c9274a1abdddeb3fd919cbaa",
- "1cbd08c76f8af6dddce02c5138971129"
+ private static final String[] DEFAULT_AVATARS = new String[]{
+ "6debd47ed13483642cf09e832ed0bc1b",
+ "322c936a8c8be1b803cd94861bdfa868",
+ "dd4dbc0016779df1378e7812eabaa04d",
+ "0e291f67c9274a1abdddeb3fd919cbaa",
+ "1cbd08c76f8af6dddce02c5138971129"
};
}
diff --git a/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/requests/OAuth2Action.java b/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/requests/OAuth2Action.java
index a5c3bec1..dfd761f2 100644
--- a/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/requests/OAuth2Action.java
+++ b/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/requests/OAuth2Action.java
@@ -16,7 +16,7 @@
package com.jagrosh.jdautilities.oauth2.requests;
import com.jagrosh.jdautilities.oauth2.entities.impl.OAuth2ClientImpl;
-import net.dv8tion.jda.internal.requests.Method;
+import net.dv8tion.jda.api.requests.Method;
import net.dv8tion.jda.internal.utils.Checks;
import okhttp3.Headers;
import okhttp3.Request;
@@ -39,16 +39,14 @@
*/
public abstract class OAuth2Action
{
- protected static final Consumer DEFAULT_SUCCESS = t -> {};
- protected static final Consumer DEFAULT_FAILURE = t -> {
- OAuth2Requester.LOGGER.error("Requester encountered an error while processing response!", t);
- };
+ protected final Consumer DEFAULT_SUCCESS = t -> {};
+ protected static final Consumer DEFAULT_FAILURE = t -> OAuth2Requester.LOGGER.error("Requester encountered an error while processing response!", t);
protected final OAuth2ClientImpl client;
protected final Method method;
protected final String url;
- public OAuth2Action(OAuth2ClientImpl client, Method method, String url)
+ protected OAuth2Action(OAuth2ClientImpl client, Method method, String url)
{
Checks.notNull(client, "OAuth2Client");
Checks.notNull(method, "Request method");
@@ -81,6 +79,9 @@ protected Request buildRequest()
case POST:
builder.post(getBody());
break;
+ case PUT:
+ builder.put(getBody());
+ break;
default:
throw new IllegalArgumentException(method.name() + " requests are not supported!");
}
diff --git a/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/requests/OAuth2Requester.java b/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/requests/OAuth2Requester.java
index 42a78cfc..d87d78c5 100644
--- a/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/requests/OAuth2Requester.java
+++ b/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/requests/OAuth2Requester.java
@@ -18,6 +18,7 @@
import com.jagrosh.jdautilities.commons.JDAUtilitiesInfo;
import net.dv8tion.jda.internal.utils.JDALogger;
import okhttp3.*;
+import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import java.io.IOException;
@@ -57,21 +58,21 @@ public void onResponse(Call call, Response response)
if(value != null)
success.accept(value);
}
- catch(Throwable t)
+ catch(Exception ex)
{
- LOGGER.error("OAuth2Action success callback threw an exception!", t);
+ LOGGER.error("OAuth2Action success callback threw an exception!", ex);
}
}
- catch(Throwable t)
+ catch(Exception ex)
{
// Handle end-user exception differently
try
{
- failure.accept(t);
+ failure.accept(ex);
}
- catch(Throwable t1)
+ catch(Exception ex1)
{
- LOGGER.error("OAuth2Action success callback threw an exception!", t1);
+ LOGGER.error("OAuth2Action success callback threw an exception!", ex1);
}
}
finally
@@ -81,7 +82,7 @@ public void onResponse(Call call, Response response)
}
@Override
- public void onFailure(Call call, IOException e)
+ public void onFailure(@NotNull Call call, @NotNull IOException e)
{
LOGGER.error("Requester encountered an error when submitting a request!", e);
}
@@ -98,7 +99,7 @@ T submitSync(OAuth2Action request) throws IOException
}
}
- private static void logSuccessfulRequest(OAuth2Action request)
+ private static void logSuccessfulRequest(OAuth2Action> request)
{
LOGGER.debug("Got a response for {} - {}\nHeaders: {}", request.getMethod(),
request.getUrl(), request.getHeaders());
diff --git a/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/requests/OAuth2URL.java b/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/requests/OAuth2URL.java
index 87314239..23d049f0 100644
--- a/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/requests/OAuth2URL.java
+++ b/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/requests/OAuth2URL.java
@@ -38,7 +38,8 @@ public enum OAuth2URL
"client_secret=%s",
"scope=%s"),
CURRENT_USER("/users/@me"),
- CURRENT_USER_GUILDS("/users/@me/guilds");
+ CURRENT_USER_GUILDS("/users/@me/guilds"),
+ GUILD_JOIN("/guilds/%guild_id%/members/%user_id%");
public static final String BASE_API_URL = String.format("https://discord.com/api/v%d", OAuth2Client.DISCORD_REST_VERSION);
@@ -62,7 +63,7 @@ public enum OAuth2URL
b.append(queryParams[i]);
}
- this.formattableRoute = route + b.toString();
+ this.formattableRoute = route + b;
this.queryParams = b.toString();
}
else
@@ -93,6 +94,22 @@ public String getRouteWithBaseUrl()
public String compile(Object... values)
{
- return BASE_API_URL + (hasQueryParams? String.format(formattableRoute, values) : formattableRoute);
+ if (hasQueryParams) {
+ return BASE_API_URL + String.format(formattableRoute, values);
+ } else {
+ String formatted = formattableRoute;
+
+ // TODO find a better way to do this.
+
+ if (formatted.contains("%guild_id%") && values.length >= 1) {
+ formatted = formatted.replace("%guild_id%", (String)values[0]);
+ }
+
+ if (formatted.contains("%user_id%") && values.length >= 2) {
+ formatted = formatted.replace("%user_id%", (String)values[1]);
+ }
+
+ return BASE_API_URL + formatted;
+ }
}
}
diff --git a/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/session/DefaultSessionController.java b/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/session/DefaultSessionController.java
index 1ff4ea1b..3ebcd474 100644
--- a/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/session/DefaultSessionController.java
+++ b/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/session/DefaultSessionController.java
@@ -43,9 +43,11 @@ public DefaultSession createSession(SessionData data)
return created;
}
- public class DefaultSession implements Session
+ public static class DefaultSession implements Session
{
- private final String accessToken, refreshToken, tokenType;
+ private final String accessToken,
+ refreshToken,
+ tokenType;
private final OffsetDateTime expiration;
private final Scope[] scopes;
diff --git a/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/session/SessionData.java b/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/session/SessionData.java
index 6a0fe93d..503c1034 100644
--- a/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/session/SessionData.java
+++ b/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/session/SessionData.java
@@ -28,7 +28,10 @@
*/
public class SessionData
{
- private final String identifier, accessToken, refreshToken, tokenType;
+ private final String identifier,
+ accessToken,
+ refreshToken,
+ tokenType;
private final OffsetDateTime expiration;
private final Scope[] scopes;
@@ -120,4 +123,9 @@ public String toString()
getIdentifier(), getAccessToken(), getRefreshToken(), getTokenType(),
getExpiration().format(DateTimeFormatter.RFC_1123_DATE_TIME));
}
+
+ @Override
+ public int hashCode() {
+ return super.hashCode();
+ }
}
diff --git a/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/state/DefaultStateController.java b/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/state/DefaultStateController.java
index ad4f4268..eb8f1814 100644
--- a/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/state/DefaultStateController.java
+++ b/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/state/DefaultStateController.java
@@ -15,6 +15,7 @@
*/
package com.jagrosh.jdautilities.oauth2.state;
+import java.security.SecureRandom;
import java.util.HashMap;
/**
@@ -24,8 +25,9 @@
*/
public class DefaultStateController implements StateController
{
- private final static String CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
+ private static final String CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
private final HashMap states = new HashMap<>();
+ private static final SecureRandom secureRandom = new SecureRandom();
@Override
public String generateNewState(String redirectUri)
@@ -45,7 +47,7 @@ private static String randomState()
{
StringBuilder sb = new StringBuilder();
for(int i = 0; i < 10; i++)
- sb.append(CHARACTERS.charAt((int)(Math.random()*CHARACTERS.length())));
+ sb.append(CHARACTERS.charAt(((int) (secureRandom.nextDouble() * CHARACTERS.length()))));
return sb.toString();
}
}