[JDA] Fix User context resolution (#138)

When @ mentioning someone in Discord, if you manually click the user's name then the ID will be in the chat field as "<@!...>". However, one can _also_ mention a user like so "<@...>".

This PR handles both cases.
This commit is contained in:
simpleauthority
2018-06-03 12:47:21 -07:00
committed by Daniel Ennis
parent 0499f83e42
commit 3319ab78a2
@@ -68,7 +68,9 @@ public class JDACommandContexts extends CommandContexts<JDACommandExecutionConte
}
String arg = c.popFirstArg(); // we pop because we are only issuer aware if we are annotated
User user = null;
if (arg.startsWith("<@")) {
if (arg.startsWith("<@!")) { // for some reason a ! is added when @'ing and clicking their name.
user = jda.getUserById(arg.substring(3, arg.length() - 1));
} else if (arg.startsWith("<@")) { // users can /also/ be mentioned like this...
user = jda.getUserById(arg.substring(2, arg.length() - 1));
} else {
List<User> users = jda.getUsersByName(arg, true);