much stuff

This commit is contained in:
Lee
2024-06-24 13:56:01 +01:00
parent eeb09ee1fd
commit 0b176c3b2a
36 changed files with 1493 additions and 69 deletions

View File

@ -0,0 +1,64 @@
package cc.fascinated.bat.command.impl.global.beatsaber.scoresaber;
import cc.fascinated.bat.command.BatSubCommand;
import cc.fascinated.bat.common.Profile;
import cc.fascinated.bat.model.BatGuild;
import cc.fascinated.bat.model.beatsaber.scoresaber.ScoreSaberAccountToken;
import cc.fascinated.bat.model.user.BatUser;
import cc.fascinated.bat.model.user.profiles.ScoreSaberProfile;
import cc.fascinated.bat.service.ScoreSaberService;
import cc.fascinated.bat.service.UserService;
import lombok.NonNull;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.interactions.commands.OptionMapping;
import net.dv8tion.jda.api.interactions.commands.SlashCommandInteraction;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Map;
/**
* @author Fascinated (fascinated7)
*/
@Component
public class LinkSubCommand extends BatSubCommand {
private final ScoreSaberService scoreSaberService;
private final UserService userService;
@Autowired
public LinkSubCommand(@NonNull ScoreSaberService scoreSaberService, @NonNull UserService userService) {
this.scoreSaberService = scoreSaberService;
this.userService = userService;
}
@Override
public void execute(@NonNull BatGuild guild, @NonNull BatUser user, @NonNull TextChannel channel, @NonNull Member member, @NonNull SlashCommandInteraction interaction, OptionMapping option) {
if (option == null) {
interaction.reply("You must provide a ScoreSaber profile link to link your profile").queue();
return;
}
String link = option.getAsString();
if (!link.contains("scoresaber.com/u/")) {
interaction.reply("Invalid ScoreSaber profile link").queue();
return;
}
String id = link.split("scoresaber.com/u/")[1];
if (id.contains("/")) {
id = id.split("/")[0];
}
ScoreSaberAccountToken account = scoreSaberService.getAccount(id);
if (account == null) {
interaction.reply("Invalid ScoreSaber profile link").queue();
return;
}
((ScoreSaberProfile) user.getProfile(ScoreSaberProfile.class)).setId(id);
userService.saveUser(user);
interaction.reply("Successfully linked your ScoreSaber profile").queue();
}
}

View File

@ -0,0 +1,72 @@
package cc.fascinated.bat.command.impl.global.beatsaber.scoresaber;
import cc.fascinated.bat.command.BatCommand;
import cc.fascinated.bat.model.BatGuild;
import cc.fascinated.bat.model.beatsaber.scoresaber.ScoreSaberAccountToken;
import cc.fascinated.bat.model.user.BatUser;
import cc.fascinated.bat.model.user.profiles.ScoreSaberProfile;
import cc.fascinated.bat.service.GuildService;
import cc.fascinated.bat.service.ScoreSaberService;
import cc.fascinated.bat.service.UserService;
import lombok.NonNull;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.MessageEmbed;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.interactions.commands.OptionMapping;
import net.dv8tion.jda.api.interactions.commands.OptionType;
import net.dv8tion.jda.api.interactions.commands.SlashCommandInteraction;
import net.dv8tion.jda.api.interactions.commands.build.OptionData;
import net.dv8tion.jda.internal.interactions.CommandDataImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* @author Fascinated (fascinated7)
*/
@Component
public class ScoreSaberCommand extends BatCommand {
private final ScoreSaberService scoreSaberService;
@Autowired
public ScoreSaberCommand(@NonNull ScoreSaberService scoreSaberService) {
super("scoresaber");
this.scoreSaberService = scoreSaberService;
super.setDescription("View a user's ScoreSaber profile");
super.setCommandData(new CommandDataImpl(this.getName(), this.getDescription())
.addOptions(new OptionData(OptionType.STRING, "link", "Link your ScoreSaber profile", false))
.addOptions(new OptionData(OptionType.USER, "user", "The user to view the ScoreSaber profile of", false))
);
}
@Override
public void execute(@NonNull BatGuild guild, @NonNull BatUser user, @NonNull TextChannel channel, @NonNull Member member, @NonNull SlashCommandInteraction interaction, OptionMapping option) {
ScoreSaberProfile profile = user.getProfile(ScoreSaberProfile.class);
if (profile.getId() == null) {
interaction.reply("You must link your ScoreSaber profile first").queue();
return;
}
// todo: handle rate limits
ScoreSaberAccountToken account = scoreSaberService.getAccount(profile.getId());
if (account == null) {
interaction.reply("Invalid ScoreSaber profile, please re-link your account.").queue();
return;
}
interaction.replyEmbeds(buildProfileEmbed(account)).queue();
}
/**
* Builds the profile embed for the ScoreSaber profile
*
* @param account The account to build the embed for
* @return The built embed
*/
public static MessageEmbed buildProfileEmbed(ScoreSaberAccountToken account) {
return new EmbedBuilder()
.addField("Name", account.getName(), true)
.build();
}
}

View File

@ -0,0 +1,25 @@
package cc.fascinated.bat.command.impl.global.beatsaber.scoresaber;
import cc.fascinated.bat.command.BatSubCommand;
import cc.fascinated.bat.model.BatGuild;
import cc.fascinated.bat.model.user.BatUser;
import cc.fascinated.bat.service.GuildService;
import cc.fascinated.bat.service.UserService;
import lombok.NonNull;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.interactions.commands.OptionMapping;
import net.dv8tion.jda.api.interactions.commands.SlashCommandInteraction;
import org.springframework.stereotype.Component;
/**
* @author Fascinated (fascinated7)
*/
@Component
public class UserSubCommand extends BatSubCommand {
@Override
public void execute(@NonNull BatGuild guild, @NonNull BatUser user, @NonNull TextChannel channel, @NonNull Member member, @NonNull SlashCommandInteraction interaction, OptionMapping option) {
interaction.reply("view someone elses profile").queue();
}
}