use of net.robinfriedli.aiode.exceptions.InvalidPropertyValueException in project aiode by robinfriedli.
the class SanitizingEntityInterceptor method onSave.
@Override
public boolean onSave(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types) {
if (entity instanceof SanitizedEntity) {
SanitizedEntity sanitizedEntity = (SanitizedEntity) entity;
Set<SanitizedEntity.IdentifierFormattingRule> identifierFormattingRules = sanitizedEntity.getIdentifierFormattingRules();
for (SanitizedEntity.IdentifierFormattingRule identifierFormattingRule : identifierFormattingRules) {
String identifier = sanitizedEntity.getIdentifier();
if (!identifierFormattingRule.getPredicate().test(identifier)) {
String errorMessage = String.format(identifierFormattingRule.getErrorMessage(), identifier);
throw new InvalidPropertyValueException(errorMessage);
}
}
}
return super.onSave(entity, id, state, propertyNames, types);
}
use of net.robinfriedli.aiode.exceptions.InvalidPropertyValueException in project aiode by robinfriedli.
the class DefaultTextChannelProperty method setValue.
@Override
public void setValue(String value, GuildSpecification guildSpecification) {
ShardManager shardManager = Aiode.get().getShardManager();
Guild guild = guildSpecification.getGuild(shardManager);
TextChannel textChannelById = null;
try {
textChannelById = guild.getTextChannelById(value);
} catch (NumberFormatException ignored) {
}
if (textChannelById != null) {
guildSpecification.setDefaultTextChannelId(value);
} else {
List<TextChannel> textChannelsByName = guild.getTextChannelsByName(value, true);
if (textChannelsByName.size() == 1) {
guildSpecification.setDefaultTextChannelId(textChannelsByName.get(0).getId());
} else if (textChannelsByName.size() > 1) {
throw new AmbiguousCommandException(textChannelsByName, c -> {
TextChannel channel = (TextChannel) c;
return channel.getName() + " (" + channel.getId() + ")";
});
} else {
throw new InvalidPropertyValueException(String.format("No text channel found for '%s'. Either copy the id of the channel or its name.", value));
}
}
}
Aggregations