package co.phoenixlab.discord.commands;

import co.phoenixlab.discord.MessageContext;
import co.phoenixlab.discord.api.entities.Channel;
import co.phoenixlab.discord.api.entities.Message;
import co.phoenixlab.discord.api.entities.User;

public class CommandUtil {

    public static User findUser(MessageContext context, String username) {
        return findUser(context, username, false);
    }

    public static User findUser(MessageContext context, String username, boolean global) {
        Message message = context.getMessage();
        User user;
        Channel channel = context.getApiClient().getChannelById(message.getChannelId());
        //  Attempt to find the given user
        //  If the user is @mentioned, try that first
        if (message.getMentions() != null && message.getMentions().length > 0) {
            user = message.getMentions()[0];
        } else {
            //  Try exact match, frontal match, ID match, and fuzzy match
            if (global) {
                user = context.getApiClient().findUser(username);
            } else {
                user = context.getApiClient().findUser(username, channel.getParent());
            }
        }
        return user;
    }
}

@@ -83,59 +83,8 @@
 xt;%0A
-import co.phoenixlab.discord.api.entities.Channel;%0A
 impo
@@ -130,16 +130,16 @@
 essage;%0A
+
 import c
@@ -502,97 +502,8 @@
 er;%0A
-        Channel channel = context.getApiClient().getChannelById(message.getChannelId());%0A
     
@@ -995,24 +995,24 @@
 e, c
-hannel.getParent
+ontext.getServer
 ());

Clean up findUser