Search in sources :

Example 1 with SettingEnum

use of me.shadorc.shadbot.command.admin.setting.core.SettingEnum in project Shadbot by Shadorc.

the class DBGuild method toJSON.

public JSONObject toJSON() {
    JSONObject guildObj = new JSONObject();
    JSONObject settingsObj = new JSONObject();
    for (SettingEnum setting : settingsMap.keySet()) {
        settingsObj.put(setting.toString(), settingsMap.get(setting));
    }
    guildObj.put(SETTINGS_KEY, settingsObj);
    this.loadUsers();
    JSONObject usersObj = new JSONObject();
    for (Long userID : usersMap.keySet()) {
        usersObj.put(userID.toString(), usersMap.get(userID).toJSON());
    }
    guildObj.put(USERS_KEY, usersObj);
    return guildObj;
}
Also used : JSONObject(org.json.JSONObject) SettingEnum(me.shadorc.shadbot.command.admin.setting.core.SettingEnum)

Example 2 with SettingEnum

use of me.shadorc.shadbot.command.admin.setting.core.SettingEnum in project Shadbot by Shadorc.

the class SettingsCmd method execute.

@Override
public void execute(Context context) throws MissingArgumentException, IllegalCmdArgumentException {
    List<String> splitArgs = StringUtils.split(context.getArg(), 2);
    if (splitArgs.isEmpty()) {
        throw new MissingArgumentException();
    }
    SettingEnum settingEnum = Utils.getValueOrNull(SettingEnum.class, splitArgs.get(0));
    if (settingEnum == null || !SETTINGS_MAP.containsKey(settingEnum)) {
        throw new IllegalCmdArgumentException(String.format("Setting `%s` does not exist. Use `%shelp %s` to see all available settings.", splitArgs.get(0), context.getPrefix(), this.getName()));
    }
    AbstractSetting setting = SETTINGS_MAP.get(settingEnum);
    String arg = splitArgs.size() == 2 ? splitArgs.get(1) : null;
    if ("help".equals(arg)) {
        BotUtils.sendMessage(this.getHelp(context.getPrefix(), setting), context.getChannel());
        return;
    }
    try {
        setting.execute(context, arg);
    } catch (MissingArgumentException e) {
        BotUtils.sendMessage(new MessageBuilder(context.getClient()).withChannel(context.getChannel()).withContent(TextUtils.MISSING_ARG).withEmbed(this.getHelp(context.getPrefix(), setting)));
    }
}
Also used : IllegalCmdArgumentException(me.shadorc.shadbot.exception.IllegalCmdArgumentException) AbstractSetting(me.shadorc.shadbot.command.admin.setting.core.AbstractSetting) MessageBuilder(sx.blah.discord.util.MessageBuilder) MissingArgumentException(me.shadorc.shadbot.exception.MissingArgumentException) SettingEnum(me.shadorc.shadbot.command.admin.setting.core.SettingEnum)

Aggregations

SettingEnum (me.shadorc.shadbot.command.admin.setting.core.SettingEnum)2 AbstractSetting (me.shadorc.shadbot.command.admin.setting.core.AbstractSetting)1 IllegalCmdArgumentException (me.shadorc.shadbot.exception.IllegalCmdArgumentException)1 MissingArgumentException (me.shadorc.shadbot.exception.MissingArgumentException)1 JSONObject (org.json.JSONObject)1 MessageBuilder (sx.blah.discord.util.MessageBuilder)1