Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static UserWrapper tryGetUser(String from)
- {
- return tryGetUser(from, null);
- }
- public static UserWrapper tryGetUser(String from, JDA jda)
- {
- if(jda == null)
- {
- jda = Core.bot;
- }
- User usr = jda.getUserById(from);
- if (usr == null)
- {
- if (from.contains("#") && !from.startsWith("#"))
- {
- String[] str = from.split("#");
- usr = getUser(str[0], str[1]);
- if (usr != null)
- {
- return new UserWrapper(usr);
- }
- }
- else
- {
- if (from.startsWith("@"))
- {
- from = from.substring(1);
- }
- String f = from;
- if(f.startsWith("#"))
- {
- return new UserWrapper(jda.getUsers().parallelStream().filter(user -> user.getDiscriminator().equals(f.substring(1))).toArray(User[]::new));
- }
- else
- {
- return new UserWrapper(jda.getUsers().parallelStream().filter(user -> user.getUsername().equals(f)).toArray(User[]::new));
- }
- }
- }
- else
- {
- return new UserWrapper(usr);
- }
- return new UserWrapper();
- }
- public static class UserWrapper
- {
- public static enum WrapperState
- {
- SINGLE, MULTI, EMPTY;
- }
- public Optional<User> single;
- public Optional<User[]> multipile;
- public WrapperState state;
- public UserWrapper(User single)
- {
- single(single);
- }
- public UserWrapper(User[] multipile)
- {
- if (multipile.length == 0)
- {
- empty();
- }
- else if (multipile.length == 1)
- {
- single(multipile[0]);
- }
- else
- {
- multi(multipile);
- }
- }
- public UserWrapper()
- {
- empty();
- }
- private void single(User usr)
- {
- this.single = Optional.of(usr);
- this.multipile = Optional.empty();
- this.state = WrapperState.SINGLE;
- }
- private void multi(User[] usr)
- {
- this.single = Optional.empty();
- this.multipile = Optional.of(usr);
- this.state = WrapperState.MULTI;
- }
- private void empty()
- {
- this.single = Optional.empty();
- this.multipile = Optional.empty();
- state = WrapperState.EMPTY;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement