Search in sources :

Example 31 with IGuild

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());
    }
}
Also used : IllegalCmdArgumentException(me.shadorc.shadbot.exception.IllegalCmdArgumentException) DBGuild(me.shadorc.shadbot.data.db.DBGuild) MissingArgumentException(me.shadorc.shadbot.exception.MissingArgumentException) DBUser(me.shadorc.shadbot.data.db.DBUser) IGuild(sx.blah.discord.handle.obj.IGuild)

Aggregations

IGuild (sx.blah.discord.handle.obj.IGuild)31 IUser (sx.blah.discord.handle.obj.IUser)13 EmbedBuilder (sx.blah.discord.util.EmbedBuilder)9 IChannel (sx.blah.discord.handle.obj.IChannel)7 ArrayList (java.util.ArrayList)5 IRole (sx.blah.discord.handle.obj.IRole)5 EventSubscriber (sx.blah.discord.api.events.EventSubscriber)4 IMessage (sx.blah.discord.handle.obj.IMessage)4 DiscordException (sx.blah.discord.util.DiscordException)4 WebGuild (com.cloudcraftgaming.discal.api.object.web.WebGuild)3 HashMap (java.util.HashMap)3 List (java.util.List)3 MissingPermissionsException (sx.blah.discord.util.MissingPermissionsException)3 EventColor (com.cloudcraftgaming.discal.api.enums.event.EventColor)2 EventData (com.cloudcraftgaming.discal.api.object.event.EventData)2 Calendar (com.google.api.services.calendar.Calendar)2 Language (enums.Language)2 FileWriter (java.io.FileWriter)2 IOException (java.io.IOException)2 SimpleDateFormat (java.text.SimpleDateFormat)2