Search in sources :

Example 1 with GuildPropertyManager

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);
    });
}
Also used : GuildSpecification(net.robinfriedli.aiode.entities.GuildSpecification) GuildPropertyManager(net.robinfriedli.aiode.discord.property.GuildPropertyManager)

Example 2 with GuildPropertyManager

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);
    });
}
Also used : GuildSpecification(net.robinfriedli.aiode.entities.GuildSpecification) GuildPropertyManager(net.robinfriedli.aiode.discord.property.GuildPropertyManager)

Example 3 with GuildPropertyManager

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);
    }
}
Also used : AbstractGuildProperty(net.robinfriedli.aiode.discord.property.AbstractGuildProperty) AudioPlayer(com.sedmelluq.discord.lavaplayer.player.AudioPlayer) PlaylistItemTimestampInterceptor(net.robinfriedli.aiode.persist.interceptors.PlaylistItemTimestampInterceptor) PlaybackHistory(net.robinfriedli.aiode.entities.PlaybackHistory) JxpBackend(net.robinfriedli.jxp.api.JxpBackend) LoggerFactory(org.slf4j.LoggerFactory) Member(net.dv8tion.jda.api.entities.Member) TextChannel(net.dv8tion.jda.api.entities.TextChannel) HibernatePlaylistMigrator(net.robinfriedli.aiode.persist.tasks.HibernatePlaylistMigrator) ExecutionContext(net.robinfriedli.aiode.concurrent.ExecutionContext) Guild(net.dv8tion.jda.api.entities.Guild) GuildSpecification(net.robinfriedli.aiode.entities.GuildSpecification) Playlist(net.robinfriedli.aiode.entities.Playlist) Map(java.util.Map) Resource(org.springframework.core.io.Resource) EmbedDocumentContribution(net.robinfriedli.aiode.entities.xml.EmbedDocumentContribution) CommandManager(net.robinfriedli.aiode.command.CommandManager) AudioPlayback(net.robinfriedli.aiode.audio.AudioPlayback) SessionFactory(org.hibernate.SessionFactory) Set(java.util.Set) AudioManager(net.robinfriedli.aiode.audio.AudioManager) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) ZoneId(java.time.ZoneId) Sets(com.google.common.collect.Sets) List(java.util.List) AccessConfiguration(net.robinfriedli.aiode.entities.AccessConfiguration) SnowflakeMap(net.robinfriedli.aiode.util.SnowflakeMap) Optional(java.util.Optional) InterceptorChain(net.robinfriedli.aiode.persist.interceptors.InterceptorChain) HibernateComponent(net.robinfriedli.aiode.boot.configurations.HibernateComponent) PlaylistItem(net.robinfriedli.aiode.entities.PlaylistItem) MessageChannel(net.dv8tion.jda.api.entities.MessageChannel) AbstractGuildProperty(net.robinfriedli.aiode.discord.property.AbstractGuildProperty) LocalDateTime(java.time.LocalDateTime) Session(org.hibernate.Session) MutexSync(net.robinfriedli.exec.MutexSync) Value(org.springframework.beans.factory.annotation.Value) Strings(com.google.common.base.Strings) QueryBuilderFactory(net.robinfriedli.aiode.persist.qb.QueryBuilderFactory) GuildPropertyManager(net.robinfriedli.aiode.discord.property.GuildPropertyManager) SearchEngine(net.robinfriedli.aiode.util.SearchEngine) CommandContribution(net.robinfriedli.aiode.entities.xml.CommandContribution) Nullable(javax.annotation.Nullable) VerifyPlaylistInterceptor(net.robinfriedli.aiode.persist.interceptors.VerifyPlaylistInterceptor) Context(net.robinfriedli.jxp.persist.Context) Logger(org.slf4j.Logger) ShardManager(net.dv8tion.jda.api.sharding.ShardManager) CommandHistory(net.robinfriedli.aiode.entities.CommandHistory) IOException(java.io.IOException) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) Conditions(net.robinfriedli.jxp.queries.Conditions) HibernateInvoker(net.robinfriedli.aiode.function.HibernateInvoker) Aiode(net.robinfriedli.aiode.Aiode) SpotifyApi(se.michaelthelin.spotify.SpotifyApi) Component(org.springframework.stereotype.Component) TextChannel(net.dv8tion.jda.api.entities.TextChannel) MessageChannel(net.dv8tion.jda.api.entities.MessageChannel) GuildPropertyManager(net.robinfriedli.aiode.discord.property.GuildPropertyManager) Aiode(net.robinfriedli.aiode.Aiode) Member(net.dv8tion.jda.api.entities.Member)

Example 4 with GuildPropertyManager

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);
}
Also used : GuildSpecification(net.robinfriedli.aiode.entities.GuildSpecification) GuildPropertyManager(net.robinfriedli.aiode.discord.property.GuildPropertyManager)

Example 5 with GuildPropertyManager

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);
}
Also used : AbstractGuildProperty(net.robinfriedli.aiode.discord.property.AbstractGuildProperty) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) GuildSpecification(net.robinfriedli.aiode.entities.GuildSpecification) GuildPropertyManager(net.robinfriedli.aiode.discord.property.GuildPropertyManager) EmbedTable(net.robinfriedli.aiode.util.EmbedTable)

Aggregations

GuildPropertyManager (net.robinfriedli.aiode.discord.property.GuildPropertyManager)10 GuildSpecification (net.robinfriedli.aiode.entities.GuildSpecification)8 EmbedBuilder (net.dv8tion.jda.api.EmbedBuilder)3 AbstractGuildProperty (net.robinfriedli.aiode.discord.property.AbstractGuildProperty)3 Guild (net.dv8tion.jda.api.entities.Guild)2 Strings (com.google.common.base.Strings)1 Sets (com.google.common.collect.Sets)1 AudioPlayer (com.sedmelluq.discord.lavaplayer.player.AudioPlayer)1 IOException (java.io.IOException)1 Instant (java.time.Instant)1 LocalDateTime (java.time.LocalDateTime)1 ZoneId (java.time.ZoneId)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Nullable (javax.annotation.Nullable)1 Member (net.dv8tion.jda.api.entities.Member)1 MessageChannel (net.dv8tion.jda.api.entities.MessageChannel)1