Skip to content

Conversation

@seailz
Copy link
Member

@seailz seailz commented Mar 30, 2024

PR Details

  • I have checked the PRs for upcoming features/bug fixes.

What you've changed

  • Developer-facing library
  • Internal Code
  • Documentation

Closes #0

Description

Added a new decoding and encoding system for discord.jar. This system is designed for better:

  • Readability
  • Consistency
  • DRY

The main difference here is the removal of existing #decompile and #compile methods. These are replaced by a system built with Java Reflection to prevent repeated code and errors.

Documentation

When creating an object, you must implement the DiscordObject interface. Then, for each of your fields, you must annotate them with @DiscordObjectParameter (you can customize the values to your liking). If you want one of your fields to automatically be filled with the DiscordJar instance, you can annotate it with @DiscordJarParameter, alongside the previous annotation. You must have a constructor annotated with @DiscordObjectConstructor with the same types as the fields, in the same order.

To assign custom values to a key, you may create a static method that takes a JSONObject and returns a HashMap<String, Object> that's annotated with @DiscordObjectCustomAssignations.

To decompile a JSON payload, use
discordJar.getParser().decompileObject(jsonObject, ExampleObject.class);

An example object might look like this, meaning there's no need for a decompile or compile method:

@ToString
public class PizzaObject implements DiscordObject {

    @Getter
    @DiscordObjectParameter(excludable = false, nullable = false)
    private final String name;

    @Getter
    @DiscordObjectParameter(excludable = false, nullable = false)
    private final int size;

    @DiscordObjectParameter(excludable = false, nullable = false)
    private final String[] labels;
    
    @DiscordObjectConstructor
    public PizzaObject(String name, int size, String[] labels) {
        this.name = name;
        this.size = size;
        this.labels = labels;
    }

    @DiscordObjectCustomAssignationsMethod
    public static HashMap<String, Object> customAssignations(JSONObject data) {
        return new HashMap<>(){{
            put("name", "hi im a pizza :)");
        }};
    }
}

Status

  • Create decompile system
  • Implement compile method
  • Implement into all existing model objects
  • HashMap implementation
  • Simple array decomplication

@seailz seailz added status: in progress PR or issue is currently in progress type: feature Issue or PR is a feature that should be implemented priority: high High priority LARGE PR or issue with a large amount of additions IMPORTANT Important PR or issue that is important to be added/implemented soon. labels Mar 30, 2024
@seailz seailz added this to the discord.jar 1.0 milestone Mar 30, 2024
@seailz seailz self-assigned this Mar 30, 2024
@github-actions
Copy link

Qodana Community for JVM

1 new problem were found

Inspection name Severity Problems
Unused assignment 🔶 Warning 1

💡 Qodana analysis was run in the pull request mode: only the changed files were checked
☁️ View the detailed Qodana report

Contact Qodana team

Contact us at qodana-support@jetbrains.com

@seailz
Copy link
Member Author

seailz commented Apr 2, 2025

oops forgot about this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

IMPORTANT Important PR or issue that is important to be added/implemented soon. LARGE PR or issue with a large amount of additions priority: high High priority status: in progress PR or issue is currently in progress type: feature Issue or PR is a feature that should be implemented

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants