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)));
}
}
Aggregations