Search in sources :

Example 1 with AbstractSetting

use of me.shadorc.shadbot.command.admin.setting.core.AbstractSetting 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

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