use of com.fredboat.backend.quarterdeck.parsing.RepeatModeParseException 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);
}
Aggregations