Giter Site home page Giter Site logo

Comments (12)

Kaktushose avatar Kaktushose commented on June 2, 2024

Please share the coresponding code of the command

from jda-commands.

Scyye avatar Scyye commented on June 2, 2024

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)));
        });
    }

from jda-commands.

Scyye avatar Scyye commented on June 2, 2024

If it helps, this has been happening for a while.
Its not a new update thing.

from jda-commands.

Kaktushose avatar Kaktushose commented on June 2, 2024

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:

  1. Check and preferably share your logging configuration
  2. Create a test command that directly throws an exception like I did and see if it's logged correctly
  3. Execute your command code outside of a jda-commands environment so we can find the spot where the NPE occurs. This would help me with trying to reproduce the bug

from jda-commands.

Scyye avatar Scyye commented on June 2, 2024

using the same logback.xml as you, no log, yet theres an error in discord, see below.

image

@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

from jda-commands.

Kaktushose avatar Kaktushose commented on June 2, 2024

which version of jda-commands are you using?

from jda-commands.

Scyye avatar Scyye commented on June 2, 2024

4.0.0 beta.1

from jda-commands.

Kaktushose avatar Kaktushose commented on June 2, 2024

can you test if exceptions get logged when they are thrown outside of jda-commands?

from jda-commands.

Scyye avatar Scyye commented on June 2, 2024

logs perfectly.

from jda-commands.

Kaktushose avatar Kaktushose commented on June 2, 2024

I'm unable to reproduce the bug. Is your repository public?

from jda-commands.

Scyye avatar Scyye commented on June 2, 2024

https://github.com/Scyye/ThunderstoreBrowser/blob/main/src/main/java/dev/scyye/thunderstorebot/commands/APICommands.java

from jda-commands.

Kaktushose avatar Kaktushose commented on June 2, 2024

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

from jda-commands.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.