add scoresaber feed command and websocket impl

This commit is contained in:
Lee
2024-06-24 17:42:57 +01:00
parent 39cdab27ce
commit c0ae0fc596
19 changed files with 570 additions and 81 deletions

View File

@ -1,33 +0,0 @@
package cc.fascinated.bat.model;
import cc.fascinated.bat.service.DiscordService;
import lombok.Getter;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import net.dv8tion.jda.api.entities.Guild;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
/**
* @author Fascinated (fascinated7)
*/
@RequiredArgsConstructor
@Getter @Setter
@Document(collection = "guilds")
public class BatGuild {
/**
* The ID of the guild
*/
@NonNull @Id private final String id;
/**
* Gets the guild as the JDA Guild
*
* @return the guild
*/
private Guild getDiscordGuild() {
return DiscordService.JDA.getGuildById(id);
}
}

View File

@ -0,0 +1,66 @@
package cc.fascinated.bat.model.guild;
import cc.fascinated.bat.common.Profile;
import cc.fascinated.bat.service.DiscordService;
import lombok.Getter;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import net.dv8tion.jda.api.entities.Guild;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import java.util.HashMap;
import java.util.Map;
/**
* @author Fascinated (fascinated7)
*/
@RequiredArgsConstructor
@Getter @Setter
@Document(collection = "guilds")
public class BatGuild {
/**
* 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
*
* @return the guild
*/
public Guild getDiscordGuild() {
return DiscordService.JDA.getGuildById(id);
}
}

View File

@ -0,0 +1,75 @@
package cc.fascinated.bat.model.guild.profiles;
import cc.fascinated.bat.common.Profile;
import cc.fascinated.bat.service.DiscordService;
import lombok.Getter;
import lombok.Setter;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import java.util.ArrayList;
import java.util.List;
/**
* @author Fascinated (fascinated7)
*/
@Getter @Setter
public class ScoreSaberScoreFeedProfile extends Profile {
public ScoreSaberScoreFeedProfile() {
super("scoresaber-score-feed");
}
/**
* The channel ID of the score feed
*/
private String channelId;
/**
* The users that are being tracked
*/
private List<String> trackedUsers;
/**
* Gets the tracked users
*
* @return the tracked users
*/
public List<String> getTrackedUsers() {
if (this.trackedUsers == null) {
this.trackedUsers = new ArrayList<>();
}
return this.trackedUsers;
}
/**
* Adds a user to be tracked
*
* @param userId the user ID to add
*/
public void addTrackedUser(String userId) {
if (this.trackedUsers == null) {
this.trackedUsers = new ArrayList<>();
}
trackedUsers.add(userId);
}
/**
* Removes a user from being tracked
*
* @param userId the user ID to remove
*/
public void removeTrackedUser(String userId) {
if (this.trackedUsers == null) {
this.trackedUsers = new ArrayList<>();
}
trackedUsers.remove(userId);
}
/**
* Gets the channel as a TextChannel
*
* @return the channel as a TextChannel
*/
public TextChannel getAsTextChannel() {
return DiscordService.JDA.getTextChannelById(channelId);
}
}