Search in sources :

Example 1 with GuildPlayer

use of com.fredboat.backend.quarterdeck.db.entities.main.GuildPlayer in project Backend by FredBoat.

the class SqlSauceGuildPlayerRepo method patch.

@Override
public GuildPlayer patch(Long id, Map<String, Object> partialUpdate) {
    Function<GuildPlayer, GuildPlayer> update = guildPlayer -> guildPlayer;
    // voice channel id
    if (partialUpdate.containsKey("voiceChannelId")) {
        DiscordSnowflake voiceChannelId = PatchParseUtil.parseDiscordSnowflake("voiceChannelId", partialUpdate);
        update = update.andThen(guildPlayer -> guildPlayer.setVoiceChannelId(voiceChannelId.longValue()));
    }
    // active text channel id
    if (partialUpdate.containsKey("activeTextChannelId")) {
        DiscordSnowflake activeTextChannelId = PatchParseUtil.parseDiscordSnowflake("activeTextChannelId", partialUpdate);
        update = update.andThen(guildPlayer -> guildPlayer.setActiveTextChannelId(activeTextChannelId.longValue()));
    }
    // is paused
    if (partialUpdate.containsKey("isPaused")) {
        boolean isPaused = PatchParseUtil.parseBoolean("isPaused", partialUpdate);
        update = update.andThen(guildPlayer -> guildPlayer.setPaused(isPaused));
    }
    // volume
    if (partialUpdate.containsKey("volume")) {
        int volume = PatchParseUtil.parseInt("volume", partialUpdate);
        update = update.andThen(guildPlayer -> guildPlayer.setVolume(volume));
    }
    // repeat mode
    if (partialUpdate.containsKey("repeatMode")) {
        String repeatModeRaw = PatchParseUtil.cast("repeatMode", partialUpdate, String.class);
        Optional<RepeatMode> parse = RepeatMode.parse(repeatModeRaw);
        if (parse.isPresent()) {
            update = update.andThen(guildPlayer -> guildPlayer.setRepeatMode(parse.get()));
        } else {
            throw new RepeatModeParseException(repeatModeRaw);
        }
    }
    // is shuffled
    if (partialUpdate.containsKey("isShuffled")) {
        boolean isShuffled = PatchParseUtil.parseBoolean("isShuffled", partialUpdate);
        update = update.andThen(guildPlayer -> guildPlayer.setShuffled(isShuffled));
    }
    return this.dbWrapper.findApplyAndMerge(GuildPlayer.key(id), update);
}
Also used : RepeatMode(fredboat.definitions.RepeatMode) Component(org.springframework.stereotype.Component) PatchParseUtil(com.fredboat.backend.quarterdeck.parsing.PatchParseUtil) RepeatModeParseException(com.fredboat.backend.quarterdeck.parsing.RepeatModeParseException) Map(java.util.Map) GuildPlayer(com.fredboat.backend.quarterdeck.db.entities.main.GuildPlayer) Optional(java.util.Optional) GuildPlayerRepo(com.fredboat.backend.quarterdeck.db.repositories.api.GuildPlayerRepo) DatabaseWrapper(space.npstr.sqlsauce.DatabaseWrapper) Function(java.util.function.Function) DiscordSnowflake(com.fredboat.backend.quarterdeck.rest.v1.transfer.DiscordSnowflake) RepeatMode(fredboat.definitions.RepeatMode) RepeatModeParseException(com.fredboat.backend.quarterdeck.parsing.RepeatModeParseException) GuildPlayer(com.fredboat.backend.quarterdeck.db.entities.main.GuildPlayer) DiscordSnowflake(com.fredboat.backend.quarterdeck.rest.v1.transfer.DiscordSnowflake)

Aggregations

GuildPlayer (com.fredboat.backend.quarterdeck.db.entities.main.GuildPlayer)1 GuildPlayerRepo (com.fredboat.backend.quarterdeck.db.repositories.api.GuildPlayerRepo)1 PatchParseUtil (com.fredboat.backend.quarterdeck.parsing.PatchParseUtil)1 RepeatModeParseException (com.fredboat.backend.quarterdeck.parsing.RepeatModeParseException)1 DiscordSnowflake (com.fredboat.backend.quarterdeck.rest.v1.transfer.DiscordSnowflake)1 RepeatMode (fredboat.definitions.RepeatMode)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Function (java.util.function.Function)1 Component (org.springframework.stereotype.Component)1 DatabaseWrapper (space.npstr.sqlsauce.DatabaseWrapper)1