Closed Scyye closed 8 months ago
Please share the coresponding code of the command
it is terribly coded and theres a lot of stuff that doesnt need to be there, but here ya go
@SlashCommand(value = "package search")
public void onPackageGet(CommandEvent event,
@Param(name = "community", value = "The community to retrieve from") String community,
@Optional @Param(name = "search", value = "The search") String search) {
if (!ServerConfig.configs.get(event.getGuild().getId()).get("community").equals(""))
community = ServerConfig.configs.get(event.getGuild().getId()).get("community", String.class);
PackageListing[] result;
if (!TestCommands.checkExecute(event, e ->
!ServerConfig.configs.get(event.getGuild().getId()).get("disabledChannels", List.class).contains(e.getChannel().getId())
&& !ServerConfig.configs.get(event.getGuild().getId()).get("disabledUsers", List.class).contains(e.getUser().getId())))
return;
if (search!=null)
if (search.length()>100) {
event.reply("Search query too long.");
return;
}
if (community!=null)
if (community.length()>100) {
event.reply("Community name too long.");
return;
}
if (search!=null)
search = MarkdownSanitizer.sanitize(search).replace(" ", "_");
if (community!=null) {
community = community.toLowerCase().replace(" ", "-");
community = MarkdownSanitizer.sanitize(community);
boolean success = false;
for (var c : Bot.bot.tsja.getCommunities()) {
if (c.getIdentifier().equals(community)) {
success=true;
break;
}
}
if (!success) {
event.reply("Invalid Community. Do `/community all` for a list of valid communities.");
return;
}
} else {
community = "all";
}
if (search != null) {
result = new TSJAUtils().getPackagesByName(Bot.bot.tsja, community, search);
} else {
result = Bot.bot.tsja.getPackages(community, null);
}
PaginatedMenuHandler.Menu menu;
List<PaginatedMenuHandler.Page> pages = new ArrayList<>();
PaginatedMenuHandler.Page currentPage =
new PaginatedMenuHandler.Page(MessageCreateData.fromContent("# Mods\nSearch: " + search + "\n\n\n"));
StringBuilder builder = new StringBuilder();
for (PackageListing p : result) {
if (builder.length() > 1500) {
currentPage.append(builder.toString()); // Append builder to the current page
builder.setLength(0); // Clear the builder
pages.add(currentPage); // Add the current page to the list of pages
currentPage = new PaginatedMenuHandler.Page(MessageCreateData.fromContent("")); // Create a new page
}
String packageName = p.isDeprecated() ? "~~" + p.getName() + "~~" : p.getName();
String packageLink = MarkdownUtil.maskedLink(packageName, "<" + p.getPackageUrl() + ">");
String ownerLink = MarkdownUtil.maskedLink(p.getOwner(), "<" + TSJA.getTeamUrl(community, p.getOwner()) + ">");
String downloadLink = MarkdownUtil.maskedLink("here", "<" + p.getVersions()[0].getDownloadUrl() + ">");
String content = String.format("%s by %s, download %s (%s)\n", packageLink, ownerLink, downloadLink, p.getUniqueId());
builder.append(content);
}
currentPage.append(builder.toString());
pages.add(currentPage);
event.reply("MENU LOADING...", msg -> {
PaginatedMenuHandler.addMenu(PaginatedMenuHandler.buildMenu(msg, pages.stream().map(page -> page.content).toList().toArray(
MessageCreateData[]::new)));
});
}
If it helps, this has been happening for a while. Its not a new update thing.
Using the latest commit to the development and the following command class and logback config, I get perfectly fine error handling:
@Interaction
public class ExceptionTest {
@SlashCommand(value = "exception")
public void onCommand(CommandEvent event) {
throw new RuntimeException("test");
}
}
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<root level="info">
<appender-ref ref="STDOUT"/>
</root>
</configuration>
It's virtually impossible for me to reproduce this bug and I'm not even sure if it's related to jda-commands. Please consider the following steps to help me tackle down this bug:
using the same logback.xml as you, no log, yet theres an error in discord, see below.
@SlashCommand(value = "test")
public void onTest(CommandEvent event) {
throw new RuntimeException("Test");
}
as well as
@SlashCommand(value = "test")
public void onTest(CommandEvent event) throws RuntimeException {
throw new RuntimeException("Test");
}
No output to console
If this is needed, ill do it. although it doesnt seem like it, as even directly throwing a runtime exception doesnt print to the log
which version of jda-commands are you using?
4.0.0 beta.1
can you test if exceptions get logged when they are thrown outside of jda-commands?
logs perfectly.
I'm unable to reproduce the bug. Is your repository public?
looking at your pom.xml it seems like you haven't configured logback correctly. You also need to add the logback dependency:
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.8</version>
</dependency>
I've cloned your repo, added logback and exceptions were logged perfectly fine
I'm getting this response when running a command:
however, when doing as it suggests and checking the log console, theres nothing. any clue?