Search in sources :

Example 6 with GuildSpecification

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

Example 7 with GuildSpecification

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

Example 8 with GuildSpecification

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;
}
Also used : AudioPlayback(net.robinfriedli.aiode.audio.AudioPlayback) AudioPlayer(com.sedmelluq.discord.lavaplayer.player.AudioPlayer) GuildSpecification(net.robinfriedli.aiode.entities.GuildSpecification) AccessConfiguration(net.robinfriedli.aiode.entities.AccessConfiguration)

Example 9 with GuildSpecification

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

Example 10 with GuildSpecification

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));
        }
    }
}
Also used : AmbiguousCommandException(net.robinfriedli.aiode.exceptions.AmbiguousCommandException) Aiode(net.robinfriedli.aiode.Aiode) List(java.util.List) Guild(net.dv8tion.jda.api.entities.Guild) ShardManager(net.dv8tion.jda.api.sharding.ShardManager) AbstractGuildProperty(net.robinfriedli.aiode.discord.property.AbstractGuildProperty) GuildSpecification(net.robinfriedli.aiode.entities.GuildSpecification) TextChannel(net.dv8tion.jda.api.entities.TextChannel) GuildPropertyContribution(net.robinfriedli.aiode.entities.xml.GuildPropertyContribution) InvalidPropertyValueException(net.robinfriedli.aiode.exceptions.InvalidPropertyValueException) AmbiguousCommandException(net.robinfriedli.aiode.exceptions.AmbiguousCommandException) TextChannel(net.dv8tion.jda.api.entities.TextChannel) InvalidPropertyValueException(net.robinfriedli.aiode.exceptions.InvalidPropertyValueException) ShardManager(net.dv8tion.jda.api.sharding.ShardManager) Guild(net.dv8tion.jda.api.entities.Guild)

Aggregations

GuildSpecification (net.robinfriedli.aiode.entities.GuildSpecification)24 AccessConfiguration (net.robinfriedli.aiode.entities.AccessConfiguration)9 GuildPropertyManager (net.robinfriedli.aiode.discord.property.GuildPropertyManager)7 Session (org.hibernate.Session)7 Guild (net.dv8tion.jda.api.entities.Guild)6 EmbedBuilder (net.dv8tion.jda.api.EmbedBuilder)5 Role (net.dv8tion.jda.api.entities.Role)4 PermissionTarget (net.robinfriedli.aiode.command.PermissionTarget)4 GrantedRole (net.robinfriedli.aiode.entities.GrantedRole)4 Aiode (net.robinfriedli.aiode.Aiode)3 CommandContext (net.robinfriedli.aiode.command.CommandContext)3 SecurityManager (net.robinfriedli.aiode.command.SecurityManager)3 AbstractGuildProperty (net.robinfriedli.aiode.discord.property.AbstractGuildProperty)3 CustomPermissionTarget (net.robinfriedli.aiode.entities.CustomPermissionTarget)3 Color (java.awt.Color)2 ShardManager (net.dv8tion.jda.api.sharding.ShardManager)2 SpringPropertiesConfig (net.robinfriedli.aiode.boot.SpringPropertiesConfig)2 AbstractCommand (net.robinfriedli.aiode.command.AbstractCommand)2 ArgumentController (net.robinfriedli.aiode.command.argument.ArgumentController)2 InvalidCommandException (net.robinfriedli.aiode.exceptions.InvalidCommandException)2