use of net.robinfriedli.aiode.entities.GuildSpecification in project aiode by robinfriedli.
the class AccessConfigurationPartitionInterceptor method intercept.
@Override
public void intercept(QueryBuilder<?, ?, ?, ?> queryBuilder) {
Optional<ExecutionContext> executionContext = ExecutionContext.Current.optional();
if (executionContext.isPresent() || (session != null && guildId != null)) {
Session session = executionContext.map(ExecutionContext::getSession).orElse(this.session);
String id = executionContext.map(ctx -> ctx.getGuild().getId()).orElse(guildId);
queryBuilder.where((cb, root, subQueryFactory) -> cb.equal(root.get("guildSpecification"), subQueryFactory.createUncorrelatedSubQuery(GuildSpecification.class, "pk").where((cb1, root1, subQueryFactory1) -> cb1.equal(root1.get("guildId"), id)).build(session)));
}
}
use of net.robinfriedli.aiode.entities.GuildSpecification in project aiode by robinfriedli.
the class GuildPropertyInterceptor method onFlushDirty.
// use onFlushDirty instead of onFlushDirtyChained as exceptions should get thrown
@Override
public boolean onFlushDirty(Object entity, Serializable id, Object[] currentState, Object[] previousState, String[] propertyNames, Type[] types) {
if (entity instanceof GuildSpecification) {
for (int i = 0; i < currentState.length; i++) {
String propertyName = propertyNames[i];
Object current = currentState[i];
Object previous = previousState[i];
if (current != null && !current.equals(previous)) {
AbstractGuildProperty property = guildPropertyManager.getProperty(propertyName);
if (property != null) {
changedProperties.put(property, Pair.of(previous, current));
property.validate(current);
}
}
}
}
return next().onFlushDirty(entity, id, currentState, previousState, propertyNames, types);
}
use of net.robinfriedli.aiode.entities.GuildSpecification in project aiode by robinfriedli.
the class DeleteGrantedRolesForDeletedRolesTask method run.
@Override
protected void run(JobExecutionContext jobExecutionContext) {
Aiode aiode = Aiode.get();
ShardManager shardManager = aiode.getShardManager();
QueryBuilderFactory queryBuilderFactory = aiode.getQueryBuilderFactory();
StaticSessionProvider.consumeSession(session -> {
List<GuildSpecification> guildSpecifications = queryBuilderFactory.find(GuildSpecification.class).build(session).getResultList();
int deletionCounter = 0;
for (GuildSpecification guildSpecification : guildSpecifications) {
Guild guild = guildSpecification.getGuild(shardManager);
if (guild == null) {
continue;
}
for (AccessConfiguration accessConfiguration : guildSpecification.getAccessConfigurations()) {
Set<GrantedRole> grantedRoles = accessConfiguration.getRoles();
for (GrantedRole grantedRole : grantedRoles) {
Role guildRole = grantedRole.getRole(guild);
if (guildRole == null) {
// role has been deleted
accessConfiguration.removeRole(grantedRole);
session.delete(grantedRole);
++deletionCounter;
}
}
}
}
if (deletionCounter > 0) {
logger.info("Deleted " + deletionCounter + " GrantedRole entities for roles that no longer exist");
}
});
}
use of net.robinfriedli.aiode.entities.GuildSpecification in project aiode by robinfriedli.
the class GuildContext method getBotName.
public String getBotName() {
return StaticSessionProvider.invokeWithSession(session -> {
GuildPropertyManager guildPropertyManager = Aiode.get().getGuildPropertyManager();
GuildSpecification specification = getSpecification(session);
return guildPropertyManager.getPropertyValueOptional("botName", String.class, specification).orElse(BotNameProperty.DEFAULT_FALLBACK);
});
}
use of net.robinfriedli.aiode.entities.GuildSpecification in project aiode by robinfriedli.
the class GuildContext method getPrefix.
public String getPrefix() {
return StaticSessionProvider.invokeWithSession(session -> {
GuildPropertyManager guildPropertyManager = Aiode.get().getGuildPropertyManager();
GuildSpecification specification = getSpecification(session);
return guildPropertyManager.getPropertyValueOptional("prefix", String.class, specification).orElse(PrefixProperty.DEFAULT_FALLBACK);
});
}
Aggregations