Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add kind to all interaction enum variants to fix interaction serde #3096

Open
wants to merge 1 commit into
base: next
Choose a base branch
from

Conversation

cheesycod
Copy link
Contributor

Currently, serializing an Interaction strips its type entirely making said interaction not only not deserializable but also need manual patching to confirm with discords own JSON structure (e.g. when serializing it for storage/use in other systems, the resulting JSON loses the type entirely)

Fix this issue the same way Components are implemented: by adding a kind to each interaction variant.

@github-actions github-actions bot added the model Related to the `model` module. label Jan 20, 2025
@jamesbt365
Copy link
Member

So this just increases model sizes... for what? The struct is the kind of interaction and there isn't really a reason to serialize these types? Not even sure why they even implement serialize tbh

@cheesycod
Copy link
Contributor Author

cheesycod commented Jan 22, 2025

So this just increases model sizes... for what? The struct is the kind of interaction and there isn't really a reason to serialize these types? Not even sure why they even implement serialize tbh

Right now, i have to manually inject type into Interaction before serializing them into serde_json::Value (and finally mlua::LuaValue (at the end of the day) and dumping it there. I actually rely heavily on the fact that you can serialize interactions throughout my bot

E.g:

                    // Inject in type
                    if let serde_json::Value::Object(ref mut map) = value {
                        let typ: u8 = interaction.kind().0;
                        map.insert("type".to_string(), serde_json::Value::Number(typ.into()));
                    }

                    serde_json::json!({
                        "InteractionCreate": {
                            "interaction": value
                        }
                    })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
model Related to the `model` module.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants