use of net.robinfriedli.aiode.discord.property.GuildPropertyManager 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.discord.property.GuildPropertyManager 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);
});
}
use of net.robinfriedli.aiode.discord.property.GuildPropertyManager in project aiode by robinfriedli.
the class GuildManager method getDefaultTextChannelForGuild.
private TextChannel getDefaultTextChannelForGuild(Guild guild, GuildContext guildContext) {
Aiode aiode = Aiode.get();
Member selfMember = guild.getSelfMember();
// fetch the default text channel from the customised property
GuildPropertyManager guildPropertyManager = aiode.getGuildPropertyManager();
AbstractGuildProperty defaultTextChannelProperty = guildPropertyManager.getProperty("defaultTextChannelId");
if (defaultTextChannelProperty != null) {
String defaultTextChannelId;
try {
defaultTextChannelId = (String) hibernateComponent.invokeWithSession(session -> defaultTextChannelProperty.get(guildContext.getSpecification(session)));
} catch (NullPointerException e) {
throw new RuntimeException(e);
}
if (!Strings.isNullOrEmpty(defaultTextChannelId)) {
TextChannel textChannelById = guild.getTextChannelById(defaultTextChannelId);
if (textChannelById != null && selfMember.hasAccess(textChannelById) && textChannelById.canTalk(selfMember)) {
return textChannelById;
}
}
}
// check if the guild's playback has a current communication text channel
MessageChannel playbackCommunicationChannel = guildContext.getPlayback().getCommunicationChannel();
if (playbackCommunicationChannel instanceof TextChannel) {
TextChannel textChannelFromPlayback = (TextChannel) playbackCommunicationChannel;
if (selfMember.hasAccess(textChannelFromPlayback) && textChannelFromPlayback.canTalk(selfMember)) {
return textChannelFromPlayback;
}
}
// use guild default defined by discord
TextChannel defaultChannel = guild.getDefaultChannel();
if (defaultChannel != null && selfMember.hasAccess(defaultChannel) && defaultChannel.canTalk(selfMember)) {
return defaultChannel;
} else {
TextChannel systemChannel = guild.getSystemChannel();
if (systemChannel != null && selfMember.hasAccess(systemChannel) && systemChannel.canTalk()) {
return systemChannel;
}
}
List<TextChannel> availableChannels = guild.getTextChannels().stream().filter(channel -> selfMember.hasAccess(channel) && channel.canTalk(selfMember)).collect(Collectors.toList());
if (availableChannels.isEmpty()) {
return null;
} else {
return availableChannels.get(0);
}
}
use of net.robinfriedli.aiode.discord.property.GuildPropertyManager 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.discord.property.GuildPropertyManager in project aiode by robinfriedli.
the class PropertyCommand method listProperties.
private void listProperties() {
GuildPropertyManager guildPropertyManager = Aiode.get().getGuildPropertyManager();
List<AbstractGuildProperty> properties = guildPropertyManager.getProperties();
GuildSpecification specification = getContext().getGuildContext().getSpecification();
EmbedBuilder embedBuilder = new EmbedBuilder();
EmbedTable table = new EmbedTable(embedBuilder);
table.addColumn("Name", properties, AbstractGuildProperty::getName);
table.addColumn("Default Value", properties, AbstractGuildProperty::getDefaultValue);
table.addColumn("Set Value", properties, property -> property.display(specification));
table.build();
sendMessage(embedBuilder);
}
Aggregations