Skip to content

Commit

Permalink
housekeeping, updates, and log stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
benaclejames committed Jun 10, 2024
1 parent fc7ffa3 commit d4fdc8a
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 43 deletions.
28 changes: 13 additions & 15 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-bom</artifactId>
<version>1.12.372</version>
<version>1.12.739</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand All @@ -27,22 +27,28 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.12.3</version>
<version>2.17.1</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.12.3</version>
<version>2.17.1</version>
</dependency>
<dependency>
<groupId>net.dv8tion</groupId>
<artifactId>JDA</artifactId>
<version>5.0.0-alpha.18</version>
<version>5.0.0-beta.24</version>
<exclusions>
<exclusion>
<groupId>club.minnced</groupId>
<artifactId>opus-java</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk15on</artifactId>
<version>1.70</version>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.5.6</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
Expand All @@ -51,14 +57,6 @@
</dependency>
</dependencies>

<repositories>
<repository>
<id>dv8tion</id>
<name>m2-dv8tion</name>
<url>https://m2.dv8tion.net/releases</url>
</repository>
</repositories>

<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ private static void PrintError(IReplyCallback reply, String errorText, String ad
}

private static String ConstructUserIdentifier(User user) {
return "```" + user.getName() + "#" + user.getDiscriminator() + "```";
return "```" + user.getName() + "```";
}

public static void VerifyLicense(IReplyCallback msg, String gumroadIdOrAlias, String token, GumServer guild) {

// Print our debug info
System.out.println("GuildID: " + guild.guild.getId());
System.out.println("User: " + msg.getUser().getName() + "#" + msg.getUser().getDiscriminator());
System.out.println("User: " + msg.getUser().getName());
System.out.println("Verifying license for " + gumroadIdOrAlias + " with token " + token);

// Check if we have an applicable alias
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@
import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;

import javax.annotation.Nonnull;
import java.util.List;

public class ButtonHandler extends ListenerAdapter {
@Override
public void onButtonInteraction(@Nonnull ButtonInteractionEvent event) {
public void onButtonInteraction(ButtonInteractionEvent event) {
// Ensure the button clicked has the id "verifybutton"
if (!event.getComponentId().equals("verifybutton")) return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@
import net.dv8tion.jda.api.entities.Role;
import net.dv8tion.jda.api.events.interaction.ModalInteractionEvent;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import net.dv8tion.jda.api.events.interaction.component.SelectMenuInteractionEvent;

import net.dv8tion.jda.api.events.interaction.component.StringSelectInteractionEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
import net.dv8tion.jda.api.interactions.components.ActionRow;
import net.dv8tion.jda.api.interactions.components.Modal;
import net.dv8tion.jda.api.interactions.components.buttons.Button;
import net.dv8tion.jda.api.interactions.components.selections.SelectMenu;
import net.dv8tion.jda.api.interactions.components.selections.StringSelectMenu;
import net.dv8tion.jda.api.interactions.components.text.TextInput;
import net.dv8tion.jda.api.interactions.components.text.TextInputStyle;
import net.dv8tion.jda.api.interactions.modals.Modal;

import javax.annotation.Nonnull;
import java.awt.*;
import java.util.ArrayList;
import java.util.HashSet;
Expand All @@ -31,8 +31,8 @@

public class InteractionHandler extends ListenerAdapter {
@Override
public void onSlashCommandInteraction(@Nonnull SlashCommandInteractionEvent event) {
switch (event.getCommandPath()) {
public void onSlashCommandInteraction(SlashCommandInteractionEvent event) {
switch (event.getFullCommandName()) {
case "spawnverify":
{
// Create a button
Expand Down Expand Up @@ -139,16 +139,16 @@ private Modal createVerifyWindow(String productId, String productName) {
.build();

return Modal.create("verifymodal_" + productId, "Verify License Key for " + productName)
.addActionRows(ActionRow.of(subject))
.addComponents(ActionRow.of(subject))
.build();
}

private String getNameFromIdDropdown(SelectMenu selectDropdown, String id) {
private String getNameFromIdDropdown(StringSelectMenu selectDropdown, String id) {
return selectDropdown.getOptions().stream().filter(option -> option.getValue().equals(id)).findFirst().get().getLabel();
}

@Override
public void onSelectMenuInteraction(SelectMenuInteractionEvent event) {
public void onStringSelectInteraction(StringSelectInteractionEvent event) {
if (!event.getComponentId().startsWith("verifyselector"))
return;

Expand All @@ -159,7 +159,7 @@ public void onSelectMenuInteraction(SelectMenuInteractionEvent event) {
}

@Override
public void onModalInteraction(@Nonnull ModalInteractionEvent event) {
public void onModalInteraction(ModalInteractionEvent event) {
if (event.getModalId().startsWith("verifymodal_")) {
String id = event.getModalId().replace("verifymodal_", "");
String licenseKey = event.getValue("key").getAsString();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package com.benaclejames.gumcord.Interactions.Modal;

import net.dv8tion.jda.api.interactions.components.ActionRow;
import net.dv8tion.jda.api.interactions.components.LayoutComponent;
import net.dv8tion.jda.api.interactions.components.text.TextInput;
import net.dv8tion.jda.api.interactions.components.text.TextInputStyle;
import net.dv8tion.jda.internal.interactions.component.ModalImpl;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Unmodifiable;
import net.dv8tion.jda.internal.interactions.modal.ModalImpl;

import java.util.Collections;
import java.util.List;
Expand All @@ -16,7 +15,7 @@ public VerifyModal(String id, String title) {
super("verifymodal_" + id, ComputeTitle(title), ConstructModalComponents());
}

private static String ComputeTitle(@NotNull String productName) {
private static String ComputeTitle(String productName) {
String computedName = productName;

// If the productname is longer than 45 characters, add an ellipsis
Expand All @@ -30,7 +29,7 @@ private static String ComputeTitle(@NotNull String productName) {
return computedName;
}

private static @NotNull @Unmodifiable List<ActionRow> ConstructModalComponents() {
private static List<LayoutComponent> ConstructModalComponents() {
TextInput subject = TextInput.create("key", "License Key", TextInputStyle.SHORT)
.setPlaceholder("12345678-12345678-12345678-12345678")
.setRequiredRange(35, 35)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import net.dv8tion.jda.api.interactions.components.ActionRow;
import net.dv8tion.jda.api.interactions.components.LayoutComponent;
import net.dv8tion.jda.api.interactions.components.buttons.Button;
import net.dv8tion.jda.api.interactions.components.selections.SelectMenu;
import net.dv8tion.jda.api.interactions.components.selections.StringSelectMenu;
import net.dv8tion.jda.api.utils.messages.MessageEditBuilder;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -55,7 +55,7 @@ public Collection<? extends LayoutComponent> build() {
int offset = this.page * 25;

// First, fill our list with as many elements as we can before hitting the 25 item limit
SelectMenu.Builder selectMenu = SelectMenu.create(this.id).setMaxValues(1);
StringSelectMenu.Builder selectMenu = StringSelectMenu.create(this.id).setMaxValues(1);

int i;
for (i = 0; i < Math.min(25, this.items.size() - offset); i++) {
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/benaclejames/gumcord/SetupHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.benaclejames.gumcord.Dynamo.TableTypes.GumServer;
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.events.ReadyEvent;
import net.dv8tion.jda.api.events.session.ReadyEvent;
import net.dv8tion.jda.api.events.guild.GuildJoinEvent;
import net.dv8tion.jda.api.events.guild.GuildLeaveEvent;
import net.dv8tion.jda.api.events.guild.GuildReadyEvent;
Expand All @@ -14,19 +14,19 @@
import net.dv8tion.jda.api.interactions.commands.OptionType;
import net.dv8tion.jda.api.interactions.commands.build.Commands;
import net.dv8tion.jda.api.interactions.commands.build.OptionData;
import org.jetbrains.annotations.NotNull;

import javax.annotation.Nonnull;
import java.util.Map;

public final class SetupHandler extends ListenerAdapter {
@Override
public void onGuildJoin(@Nonnull GuildJoinEvent event) {
public void onGuildJoin(GuildJoinEvent event) {
DynamoHelper.GetServer(event.getGuild());
System.out.println("Joined " + event.getGuild().getName());
}

@Override
public void onGuildLeave(@Nonnull GuildLeaveEvent event) {
public void onGuildLeave(@NotNull GuildLeaveEvent event) {

}

Expand Down Expand Up @@ -86,7 +86,7 @@ public void onGuildReady(GuildReadyEvent event) {
}

@Override
public void onReady(@Nonnull ReadyEvent event) {
public void onReady(@NotNull ReadyEvent event) {
var spawnVerify = Commands.slash("spawnverify", "Spawns a button to allow user to verify their purchases")
.setDefaultPermissions(DefaultMemberPermissions.enabledFor(Permission.MANAGE_CHANNEL, Permission.MODERATE_MEMBERS))
.setGuildOnly(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.GuildChannel;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.MessageChannel;
import net.dv8tion.jda.api.entities.channel.middleman.GuildChannel;
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;

import java.awt.*;
import java.time.Duration;
Expand Down
12 changes: 12 additions & 0 deletions src/main/resources/logback.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} %boldCyan(%-34.-34thread) %red(%10.10X{jda.shard}) %boldGreen(%-15.-15logger{0}) %highlight(%-6level) %msg%n</pattern>
</encoder>
</appender>

<root level="info">
<appender-ref ref="STDOUT" />
</root>
</configuration>

0 comments on commit d4fdc8a

Please sign in to comment.