use of net.robinfriedli.aiode.entities.GuildSpecification in project aiode by robinfriedli.
the class GuildContext method setPrefix.
public void setPrefix(String prefix) {
StaticSessionProvider.consumeSession(session -> {
GuildSpecification guildSpecification = getSpecification(session);
guildSpecification.setPrefix(prefix);
});
}
use of net.robinfriedli.aiode.entities.GuildSpecification in project aiode by robinfriedli.
the class GuildContext method setBotName.
public void setBotName(String name) {
StaticSessionProvider.consumeSession(session -> {
GuildSpecification guildSpecification = getSpecification(session);
guildSpecification.setBotName(name);
});
}
use of net.robinfriedli.aiode.entities.GuildSpecification in project aiode by robinfriedli.
the class GuildManager method initializeGuild.
private GuildContext initializeGuild(Guild guild) {
GuildContext createdContext = hibernateComponent.invokeWithSession(session -> {
AudioPlayer player = audioManager.getPlayerManager().createPlayer();
Optional<Long> existingSpecification = queryBuilderFactory.select(GuildSpecification.class, "pk", Long.class).where((cb, root) -> cb.equal(root.get("guildId"), guild.getId())).build(session).uniqueResultOptional();
if (existingSpecification.isPresent()) {
return new GuildContext(guild, new AudioPlayback(player, guild), existingSpecification.get());
} else {
GuildSpecification newSpecification = new GuildSpecification(guild);
session.persist(newSpecification);
commandManager.getCommandContributionContext().query(attribute("restrictedAccess").is(true), CommandContribution.class).getResultStream().forEach(restrictedCommand -> {
AccessConfiguration permissionConfiguration = new AccessConfiguration(restrictedCommand, session);
session.persist(permissionConfiguration);
newSpecification.addAccessConfiguration(permissionConfiguration);
});
session.flush();
GuildContext guildContext = new GuildContext(guild, new AudioPlayback(player, guild), newSpecification.getPk());
handleNewGuild(guild, guildContext);
return guildContext;
}
});
guildContexts.put(guild, createdContext);
return createdContext;
}
use of net.robinfriedli.aiode.entities.GuildSpecification in project aiode by robinfriedli.
the class BotNameProperty method getForContext.
public static String getForContext(GuildContext guildContext, Session session) {
GuildSpecification specification = guildContext.getSpecification(session);
GuildPropertyManager guildPropertyManager = Aiode.get().getGuildPropertyManager();
return guildPropertyManager.getPropertyValueOptional("botName", String.class, specification).orElse(DEFAULT_FALLBACK);
}
use of net.robinfriedli.aiode.entities.GuildSpecification 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