cleanup profiles
Some checks failed
Deploy to Dokku / docker (ubuntu-latest) (push) Failing after 16s

This commit is contained in:
Lee 2024-06-25 12:36:40 +01:00
parent 154eac28d1
commit 679143c331
16 changed files with 65 additions and 79 deletions

@ -27,7 +27,7 @@ public class PingCommand extends BatCommand {
public void execute(@NonNull BatGuild guild, @NonNull BatUser user, @NonNull TextChannel channel, @NonNull Member member, @NonNull SlashCommandInteraction interaction) {
long time = System.currentTimeMillis();
interaction.reply("Pinging...").queue(response -> {
response.editOriginal(("Gateway response time: `%sms`\nAPI response time `%sms`").formatted(
response.editOriginal("Gateway response time: `%sms`\nAPI response time `%sms`".formatted(
DiscordService.JDA.getGatewayPing(),
System.currentTimeMillis() - time
)).queue();

@ -0,0 +1,42 @@
package cc.fascinated.bat.common;
import lombok.Getter;
import java.util.HashMap;
import java.util.Map;
/**
* @author Fascinated (fascinated7)
*/
@Getter
public class ProfileHolder {
/**
* The profiles for the holder
*/
private Map<String, Profile> profiles;
/**
* Gets a profile for the holder
*
* @param clazz The class of the profile
* @param <T> The type of the profile
* @return The profile
*/
public <T extends Profile> T getProfile(Class<?> clazz) {
if (profiles == null) {
profiles = new HashMap<>();
}
Profile profile = profiles.values().stream().filter(p -> p.getClass().equals(clazz)).findFirst().orElse(null);
if (profile == null) {
try {
profile = (Profile) clazz.newInstance();
profiles.put(profile.getProfileKey(), profile);
} catch (InstantiationException | IllegalAccessException e) {
e.printStackTrace();
}
}
return (T) profile;
}
}

@ -1,8 +1,8 @@
package cc.fascinated.bat.event;
import cc.fascinated.bat.model.beatsaber.scoresaber.ScoreSaberLeaderboardToken;
import cc.fascinated.bat.model.beatsaber.scoresaber.ScoreSaberPlayerScoreToken;
import cc.fascinated.bat.model.beatsaber.scoresaber.ScoreSaberScoreToken;
import cc.fascinated.bat.model.token.beatsaber.scoresaber.ScoreSaberLeaderboardToken;
import cc.fascinated.bat.model.token.beatsaber.scoresaber.ScoreSaberPlayerScoreToken;
import cc.fascinated.bat.model.token.beatsaber.scoresaber.ScoreSaberScoreToken;
/**
* @author Fascinated (fascinated7)

@ -6,11 +6,10 @@ import cc.fascinated.bat.common.NumberUtils;
import cc.fascinated.bat.common.ScoreSaberUtils;
import cc.fascinated.bat.event.EventListener;
import cc.fascinated.bat.features.scoresaber.profiles.GuildNumberOneScoreFeedProfile;
import cc.fascinated.bat.features.scoresaber.profiles.GuildUserScoreFeedProfile;
import cc.fascinated.bat.model.BatGuild;
import cc.fascinated.bat.model.beatsaber.scoresaber.ScoreSaberLeaderboardToken;
import cc.fascinated.bat.model.beatsaber.scoresaber.ScoreSaberPlayerScoreToken;
import cc.fascinated.bat.model.beatsaber.scoresaber.ScoreSaberScoreToken;
import cc.fascinated.bat.model.token.beatsaber.scoresaber.ScoreSaberLeaderboardToken;
import cc.fascinated.bat.model.token.beatsaber.scoresaber.ScoreSaberPlayerScoreToken;
import cc.fascinated.bat.model.token.beatsaber.scoresaber.ScoreSaberScoreToken;
import cc.fascinated.bat.service.DiscordService;
import cc.fascinated.bat.service.GuildService;
import lombok.extern.log4j.Log4j2;

@ -6,9 +6,9 @@ import cc.fascinated.bat.common.NumberUtils;
import cc.fascinated.bat.common.ScoreSaberUtils;
import cc.fascinated.bat.event.EventListener;
import cc.fascinated.bat.features.scoresaber.profiles.GuildUserScoreFeedProfile;
import cc.fascinated.bat.model.beatsaber.scoresaber.ScoreSaberLeaderboardToken;
import cc.fascinated.bat.model.beatsaber.scoresaber.ScoreSaberPlayerScoreToken;
import cc.fascinated.bat.model.beatsaber.scoresaber.ScoreSaberScoreToken;
import cc.fascinated.bat.model.token.beatsaber.scoresaber.ScoreSaberLeaderboardToken;
import cc.fascinated.bat.model.token.beatsaber.scoresaber.ScoreSaberPlayerScoreToken;
import cc.fascinated.bat.model.token.beatsaber.scoresaber.ScoreSaberScoreToken;
import cc.fascinated.bat.model.BatGuild;
import cc.fascinated.bat.service.DiscordService;
import cc.fascinated.bat.service.GuildService;

@ -2,7 +2,7 @@ package cc.fascinated.bat.features.scoresaber.command.scoresaber;
import cc.fascinated.bat.command.BatSubCommand;
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.model.beatsaber.scoresaber.ScoreSaberAccountToken;
import cc.fascinated.bat.model.token.beatsaber.scoresaber.ScoreSaberAccountToken;
import cc.fascinated.bat.model.BatGuild;
import cc.fascinated.bat.model.BatUser;
import cc.fascinated.bat.features.scoresaber.profiles.UserScoreSaberProfile;

@ -5,7 +5,7 @@ import cc.fascinated.bat.common.Colors;
import cc.fascinated.bat.common.DateUtils;
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.common.NumberUtils;
import cc.fascinated.bat.model.beatsaber.scoresaber.ScoreSaberAccountToken;
import cc.fascinated.bat.model.token.beatsaber.scoresaber.ScoreSaberAccountToken;
import cc.fascinated.bat.model.BatGuild;
import cc.fascinated.bat.model.BatUser;
import cc.fascinated.bat.features.scoresaber.profiles.UserScoreSaberProfile;

@ -1,6 +1,7 @@
package cc.fascinated.bat.model;
import cc.fascinated.bat.common.Profile;
import cc.fascinated.bat.common.ProfileHolder;
import cc.fascinated.bat.service.DiscordService;
import lombok.Getter;
import lombok.NonNull;
@ -19,42 +20,13 @@ import java.util.Map;
@RequiredArgsConstructor
@Getter @Setter
@Document(collection = "guilds")
public class BatGuild {
public class BatGuild extends ProfileHolder {
/**
* The ID of the guild
*/
@NonNull @Id private final String id;
/**
* The profiles for this guild
*/
private Map<String, Profile> profiles;
/**
* Gets the profile for the guild
*
* @param clazz The class of the profile
* @param <T> The type of the profile
* @return The profile
*/
public <T extends Profile> T getProfile(Class<?> clazz) {
if (profiles == null) {
profiles = new HashMap<>();
}
Profile profile = profiles.values().stream().filter(p -> p.getClass().equals(clazz)).findFirst().orElse(null);
if (profile == null) {
try {
profile = (Profile) clazz.newInstance();
profiles.put(profile.getProfileKey(), profile);
} catch (InstantiationException | IllegalAccessException e) {
e.printStackTrace();
}
}
return (T) profile;
}
/**
* Gets the guild as the JDA Guild
*

@ -1,6 +1,7 @@
package cc.fascinated.bat.model;
import cc.fascinated.bat.common.Profile;
import cc.fascinated.bat.common.ProfileHolder;
import cc.fascinated.bat.service.DiscordService;
import lombok.Getter;
import lombok.NonNull;
@ -19,42 +20,13 @@ import java.util.Map;
@RequiredArgsConstructor
@Getter @Setter
@Document(collection = "users")
public class BatUser {
public class BatUser extends ProfileHolder {
/**
* The ID of the user
*/
@NonNull @Id private final String id;
/**
* The profiles for this user
*/
private Map<String, Profile> profiles;
/**
* Gets the profile for the user
*
* @param clazz The class of the profile
* @param <T> The type of the profile
* @return The profile
*/
public <T extends Profile> T getProfile(Class<?> clazz) {
if (profiles == null) {
profiles = new HashMap<>();
}
Profile profile = profiles.values().stream().filter(p -> p.getClass().equals(clazz)).findFirst().orElse(null);
if (profile == null) {
try {
profile = (Profile) clazz.newInstance();
profiles.put(profile.getProfileKey(), profile);
} catch (InstantiationException | IllegalAccessException e) {
e.printStackTrace();
}
}
return (T) profile;
}
/**
* Gets the guild as the JDA Guild
*

@ -1,4 +1,4 @@
package cc.fascinated.bat.model.beatsaber.scoresaber;
package cc.fascinated.bat.model.token.beatsaber.scoresaber;
import lombok.AllArgsConstructor;
import lombok.Getter;

@ -1,4 +1,4 @@
package cc.fascinated.bat.model.beatsaber.scoresaber;
package cc.fascinated.bat.model.token.beatsaber.scoresaber;
import lombok.Getter;
import lombok.ToString;

@ -1,4 +1,4 @@
package cc.fascinated.bat.model.beatsaber.scoresaber;
package cc.fascinated.bat.model.token.beatsaber.scoresaber;
import lombok.Getter;
import lombok.ToString;

@ -1,4 +1,4 @@
package cc.fascinated.bat.model.beatsaber.scoresaber;
package cc.fascinated.bat.model.token.beatsaber.scoresaber;
import lombok.Getter;
import lombok.ToString;

@ -1,4 +1,4 @@
package cc.fascinated.bat.model.beatsaber.scoresaber;
package cc.fascinated.bat.model.token.beatsaber.scoresaber;
import lombok.Getter;
import lombok.ToString;

@ -1,4 +1,4 @@
package cc.fascinated.bat.model.beatsaber.scoresaber;
package cc.fascinated.bat.model.token.beatsaber.scoresaber;
import lombok.Getter;
import lombok.Setter;

@ -8,6 +8,7 @@ import cc.fascinated.bat.exception.BadRequestException;
import cc.fascinated.bat.exception.ResourceNotFoundException;
import cc.fascinated.bat.model.beatsaber.scoresaber.*;
import cc.fascinated.bat.features.scoresaber.profiles.UserScoreSaberProfile;
import cc.fascinated.bat.model.token.beatsaber.scoresaber.*;
import com.google.gson.JsonObject;
import lombok.NonNull;
import lombok.SneakyThrows;