use of sx.blah.discord.handle.obj.IGuild in project Shadbot by Shadorc.
the class DatabaseCmd method execute.
@Override
public void execute(Context context) throws MissingArgumentException, IllegalCmdArgumentException {
if (!context.hasArg()) {
throw new MissingArgumentException();
}
List<String> splitArgs = StringUtils.split(context.getArg());
if (splitArgs.size() > 2) {
throw new MissingArgumentException();
}
Long guildID = CastUtils.asPositiveLong(splitArgs.get(0));
if (guildID == null) {
throw new IllegalCmdArgumentException(String.format("`%s` is not a valid guild ID.", splitArgs.get(0)));
}
IGuild guild = context.getClient().getGuildByID(guildID);
if (guild == null) {
throw new IllegalCmdArgumentException("Guild not found.");
}
String json = null;
if (splitArgs.size() == 1) {
DBGuild dbGuild = Database.getDBGuild(guild);
json = dbGuild.toJSON().toString(Config.JSON_INDENT_FACTOR);
} else if (splitArgs.size() == 2) {
Long userID = CastUtils.asPositiveLong(splitArgs.get(1));
if (userID == null) {
throw new IllegalCmdArgumentException(String.format("`%s` is not a valid user ID.", splitArgs.get(0)));
}
DBUser dbUser = new DBUser(guild, userID);
json = dbUser.toJSON().toString(Config.JSON_INDENT_FACTOR);
}
if (json == null || json.length() == 2) {
BotUtils.sendMessage(Emoji.MAGNIFYING_GLASS + " Nothing found.", context.getChannel());
} else {
BotUtils.sendMessage(json, context.getChannel());
}
}
Aggregations