Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
fdf5476
working on abstracting interactions
stuffyerface Jul 29, 2024
dc0d6e1
slash commands to interactionids
stuffyerface Aug 2, 2024
85b0808
parse interaction options, error handling,created InteractionExceptio…
stuffyerface Aug 2, 2024
a12c13a
command stats tracking
stuffyerface Aug 2, 2024
ec9dde4
removed onCommand and onButton from BaseCommand, handle it differentl…
stuffyerface Aug 4, 2024
425b145
removed command registering
stuffyerface Aug 4, 2024
65734d2
BaseCommand.java is now InteractionHandler.java, now handles commands…
stuffyerface Aug 4, 2024
03791cf
framework for future checks
stuffyerface Aug 4, 2024
a5135df
InteractionId is now a class, return Message Data instead of just embed,
stuffyerface Aug 4, 2024
3efb10a
random exception string
stuffyerface Aug 4, 2024
fa0f955
removed deprecated parseOptions
stuffyerface Aug 4, 2024
1b21d88
BaseCommand.java is now InteractionHandler.java
stuffyerface Aug 4, 2024
09f6beb
successful button presses edit message data
stuffyerface Aug 4, 2024
f487e98
button owners/permissions
stuffyerface Aug 4, 2024
ba0cf06
some error handling on bad InteractionId
stuffyerface Aug 4, 2024
1d2571c
assets?
stuffyerface Aug 4, 2024
cd770e7
more modals make more merry
stuffyerface Aug 5, 2024
9f9e78d
move modals
stuffyerface Aug 6, 2024
abe96c4
refactored to interactions package
stuffyerface Aug 19, 2024
92c9632
idek
stuffyerface Aug 19, 2024
ed11cdd
check if already verified
stuffyerface Aug 19, 2024
96b186a
no longer create Logger instance
stuffyerface Aug 19, 2024
7074f19
register commands on startup
stuffyerface Aug 19, 2024
fb50921
cleanup
stuffyerface Aug 19, 2024
bd44136
Make and handle exceptions for Hypixel and Mojang APIs
stuffyerface Aug 20, 2024
d1432de
Make options work in buttons
stuffyerface Aug 20, 2024
d5e7556
Pit command works!
stuffyerface Aug 20, 2024
2bcecc6
Rename InteractionManager for clarity
stuffyerface Aug 20, 2024
66f071c
Remove Test Command
stuffyerface Aug 20, 2024
b89979d
Create Stats Command
stuffyerface Aug 20, 2024
3c20fdc
remove redundant naming
stuffyerface Aug 20, 2024
e7c57ef
Add TKR Command
stuffyerface Aug 20, 2024
ee51514
Handle players that have never logged into Hypixel
stuffyerface Aug 20, 2024
30c0325
Add unique ids to command interactions, buttons decay after 30s unused.
stuffyerface Aug 21, 2024
44aa6fa
Make maxes command
stuffyerface Aug 21, 2024
6e5e483
deprecated class
stuffyerface Aug 21, 2024
fce58c2
add legacy achievement points, patch online status
stuffyerface Aug 21, 2024
e87f4c8
Add blitz command
stuffyerface Aug 22, 2024
27d9e6a
Fix Current Reward Streak
stuffyerface Aug 22, 2024
945aa18
fix hypixel empty array achievements
stuffyerface Aug 22, 2024
30e145d
Commands should never fail to give response now.
stuffyerface Aug 22, 2024
8470825
Remove button from tkr for now.
stuffyerface Aug 22, 2024
b84cb91
Add support for multiple columns and subtitles in embeds
stuffyerface Aug 22, 2024
eae3145
remove redundant code
stuffyerface Aug 22, 2024
5c2138e
convert string to json element
stuffyerface Aug 22, 2024
5df5222
add getOption and setOption to InteractionId
stuffyerface Aug 22, 2024
c27fd1f
add code for autocomplete
stuffyerface Aug 22, 2024
9940e6d
change ign optiondata
stuffyerface Aug 22, 2024
d6686fb
add MegaWallsCommand framework
stuffyerface Aug 22, 2024
b837489
convert to subtitle support
stuffyerface Aug 22, 2024
b2e0130
clear up button error
stuffyerface Aug 22, 2024
9a584ea
mw classes for api + schema
stuffyerface Aug 29, 2024
269addb
error message for invalid option
stuffyerface Aug 29, 2024
823a7ba
error message for invalid option
stuffyerface Aug 29, 2024
f1739d7
migrate to v2 hypixel endpoints
stuffyerface Aug 29, 2024
63e460b
full mw class data
stuffyerface Aug 29, 2024
3dd9b6c
remove responses
stuffyerface Aug 29, 2024
dc884a3
account for missing rank
stuffyerface Aug 29, 2024
6bc82e2
mwclass data, and schemas
stuffyerface Aug 29, 2024
4efb905
remove confusing suggestions
stuffyerface Aug 29, 2024
6f0f9be
limit user input to 30 characters
stuffyerface Aug 29, 2024
49614f2
add default string jsons
stuffyerface Aug 29, 2024
8e0488e
megawalls command "complete"
stuffyerface Aug 29, 2024
0b5254d
megawalls cleanup
stuffyerface Aug 29, 2024
7a4de95
support for integer defaults
stuffyerface Aug 29, 2024
75fbf33
add missing spider data
stuffyerface Aug 29, 2024
c2bdd40
fill out most recent tournament data
stuffyerface Aug 29, 2024
9cff11d
alert user to use new slash commands
stuffyerface Aug 29, 2024
3e248f5
mega walls class case-insensitive
stuffyerface Aug 29, 2024
965510e
fix getMegaWallsStat
stuffyerface Aug 31, 2024
eb421d0
add setOpion to InteractionId
stuffyerface Aug 31, 2024
f77c6fd
support for nested json with "." delimiter
stuffyerface Aug 31, 2024
b1f7afd
Populate tournaments.json
stuffyerface Aug 31, 2024
5bbc4ce
Working TournamentCommand
stuffyerface Aug 31, 2024
6a96c2f
cleanup
stuffyerface Aug 31, 2024
dcc99f7
Merge pull request #1 from stuffyerface/main
stuffyerface Aug 31, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .idea/jsonSchemas.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

75 changes: 61 additions & 14 deletions src/main/java/me/stuffy/stuffybot/Bot.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package me.stuffy.stuffybot;


import me.stuffy.stuffybot.commands.*;
import me.stuffy.stuffybot.events.ActiveEvents;
import me.stuffy.stuffybot.events.UpdateBotStatsEvent;
import me.stuffy.stuffybot.interactions.InteractionHandler;
import me.stuffy.stuffybot.utils.DiscordUtils;
import me.stuffy.stuffybot.utils.Logger;
import net.dv8tion.jda.api.JDA;
Expand All @@ -14,6 +14,12 @@
import net.dv8tion.jda.api.events.guild.GuildJoinEvent;
import net.dv8tion.jda.api.events.guild.GuildLeaveEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
import net.dv8tion.jda.api.interactions.commands.OptionType;
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
import net.dv8tion.jda.api.interactions.commands.build.Commands;
import net.dv8tion.jda.api.interactions.commands.build.OptionData;

import java.util.ArrayList;

public class Bot extends ListenerAdapter {
private static Bot INSTANCE;
Expand All @@ -33,29 +39,21 @@ public Bot() throws InterruptedException {

// Initialize home guild
this.homeGuild = jda.getGuildById("795108903733952562");
// this.homeGuild = jda.getGuildById("818238263110008863");
assert this.homeGuild != null : "Failed to find home guild";


// Log startup
String time = DiscordUtils.discordTimeNow();
String self = jda.getSelfUser().getAsMention();
Logger logger = new Logger();
logger.log("<Startup> Bot " + self + " started successfully " + time + ".");
Logger.log("<Startup> Bot " + self + " started successfully " + time + ".");

// Register commands
// Listen for interactions
jda.addEventListener(
new VerifyCommand("verify", "Links your discord account to your Minecraft account"),
new MaxedGamesCommand("maxes", "Find the games with all achievements unlocked"),
new TournamentCommand("tournament", "Shows tournament stats"),
new AchievementCommand("achievements", "Shows achievements progress for a user"),
new StatsCommand("stats", "Shows overall hypixel stats for a user"),
new PitCommand("pit", "Shows pit stats for a user"),
new TkrCommand("tkr", "Shows completed maps in TKR"),
new MegaWallsCommand("megawalls", "Shows Mega Walls stats for a user")
new InteractionHandler()
);


// Register commands "global"ly or "local"ly
registerCommands("local");

// Start events
new UpdateBotStatsEvent().startFixedRateEvent();
Expand Down Expand Up @@ -94,4 +92,53 @@ public void onGuildLeave(GuildLeaveEvent event) {
Guild leftGuild = event.getGuild();
Logger.log("<Guilds> Bot left guild: " + leftGuild.getName() + " (" + leftGuild.getId() + ")");
}

public void registerCommands(String scope) {
OptionData ignOption = new OptionData(OptionType.STRING, "ign", "The player's IGN", false);
// Create a list of commands first
ArrayList<CommandData> commandList = new ArrayList<>();
// commandList.add(Commands.slash("help", "*Should* show a help message"));
commandList.add(Commands.slash("pit", "Get Pit stats for a player")
.addOptions(ignOption));
commandList.add(Commands.slash("stats", "Get Hypixel stats for a player")
.addOptions(ignOption));
commandList.add(Commands.slash("tkr", "Get TKR stats for a player")
.addOptions(ignOption));
commandList.add(Commands.slash("maxes", "Get maxed games for a player")
.addOptions(ignOption));
commandList.add(Commands.slash("blitz", "Get Blitz Ultimate Kit xp for a player")
.addOptions(ignOption));
commandList.add(Commands.slash("megawalls", "Get Mega Walls skins for a player")
.addOptions(ignOption)
.addOptions(new OptionData(OptionType.STRING, "skins", "Which skins to look at", false).setAutoComplete(true)));
commandList.add(Commands.slash("tournament", "Get tournament stats for a player")
.addOptions(ignOption)
.addOptions(new OptionData(OptionType.INTEGER, "tournament", "Which tournament to look at (Leave empty for latest)", false).setAutoComplete(true)));


if (scope.equals("local")) {
//clearLocalCommands();
this.homeGuild.updateCommands().addCommands(
commandList
).queue();
Logger.log("<Commands> Successfully Registered commands in guild.");
} else if (scope.equals("global")){
jda.updateCommands().addCommands(
commandList
).queue();
Logger.log("<Commands> Successfully Registered commands globally.");
} else {
throw new IllegalArgumentException("Invalid scope: " + scope);
}
}

public void clearCommands() {
jda.updateCommands().queue();
Logger.log("<Commands> Successfully cleared commands.");
}

public void clearLocalCommands() {
this.homeGuild.updateCommands().queue();
Logger.log("<Commands> Successfully cleared local commands.");
}
}
41 changes: 0 additions & 41 deletions src/main/java/me/stuffy/stuffybot/commands/AchievementCommand.java

This file was deleted.

72 changes: 0 additions & 72 deletions src/main/java/me/stuffy/stuffybot/commands/BaseCommand.java

This file was deleted.

47 changes: 47 additions & 0 deletions src/main/java/me/stuffy/stuffybot/commands/BlitzCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package me.stuffy.stuffybot.commands;

import me.stuffy.stuffybot.interactions.InteractionId;
import me.stuffy.stuffybot.profiles.HypixelProfile;
import me.stuffy.stuffybot.utils.APIException;
import net.dv8tion.jda.api.entities.MessageEmbed;
import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder;
import net.dv8tion.jda.api.utils.messages.MessageCreateData;

import java.text.DecimalFormat;
import java.util.Map;

import static me.stuffy.stuffybot.utils.APIUtils.getHypixelProfile;
import static me.stuffy.stuffybot.utils.DiscordUtils.makeStatsEmbed;

public class BlitzCommand {
public static MessageCreateData blitz(InteractionId interactionId) throws APIException {
String ign = interactionId.getOptions().get("ign");
HypixelProfile hypixelProfile = getHypixelProfile(ign);
String username = hypixelProfile.getDisplayName();

Map<String, Integer> blitzStats = hypixelProfile.getBlitzStats();

DecimalFormat df = new DecimalFormat("#,###");
DecimalFormat df2 = new DecimalFormat("#,###.##");
StringBuilder embedContent = new StringBuilder();

for (Map.Entry<String, Integer> entry : blitzStats.entrySet()) {
String key = entry.getKey();
Integer value = entry.getValue();
if (value < 10000) {
embedContent.append(key).append(": **").append(df.format(value)).append("**/10,000 (").append(df2.format(value / 100)).append("%)\n");
} else {
embedContent.append("~~").append(key).append(": **").append(df.format(value)).append("**/10,000~~\n");
}
}

MessageEmbed blitzEmbed = makeStatsEmbed(
"Blitz Ultimate Kit Xp for " + username,
embedContent.toString()
);

return new MessageCreateBuilder()
.addEmbeds(blitzEmbed)
.build();
}
}
45 changes: 0 additions & 45 deletions src/main/java/me/stuffy/stuffybot/commands/MaxedGamesCommand.java

This file was deleted.

45 changes: 45 additions & 0 deletions src/main/java/me/stuffy/stuffybot/commands/MaxesCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package me.stuffy.stuffybot.commands;

import me.stuffy.stuffybot.interactions.InteractionId;
import me.stuffy.stuffybot.profiles.HypixelProfile;
import me.stuffy.stuffybot.utils.APIException;
import net.dv8tion.jda.api.entities.MessageEmbed;
import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder;
import net.dv8tion.jda.api.utils.messages.MessageCreateData;

import java.util.ArrayList;

import static me.stuffy.stuffybot.utils.APIUtils.getHypixelProfile;
import static me.stuffy.stuffybot.utils.DiscordUtils.makeStatsEmbed;
import static me.stuffy.stuffybot.utils.MiscUtils.toReadableName;

public class MaxesCommand {
public static MessageCreateData maxes(InteractionId interactionId) throws APIException {
String ign = interactionId.getOptions().get("ign");
HypixelProfile hypixelProfile = getHypixelProfile(ign);
String username = hypixelProfile.getDisplayName();

ArrayList<String> maxesArray = hypixelProfile.getMaxGames();

StringBuilder embedContent = new StringBuilder();
String subtitle = username + " has " + maxesArray.size() + " Maxed Games";
for (String game : maxesArray) {
embedContent.append(toReadableName(game)).append("\n");
}

if (maxesArray.isEmpty()) {
subtitle = "No Maxed Games found. :(";
}

MessageEmbed maxesEmbed = makeStatsEmbed(
"Maxed Games for " + username,
subtitle,
embedContent.toString()
);

return new MessageCreateBuilder()
.addEmbeds(maxesEmbed)
.build();

}
}
Loading