EmbarkStudios / discord-sdk

An open implementation of the Discord Game SDK in Rust
Apache License 2.0
150 stars 10 forks source link

Implement buttons #24

Closed NyCodeGHG closed 1 year ago

NyCodeGHG commented 1 year ago

Checklist

Description of Changes

I implemented support for buttons. This is a breaking change, because it adds a new field to the Activity struct and changes how secrets are added. When both secrets and buttons are set, discord will respond with an error that the fields are exclusive. I've made some changes to represent that in the type system in ActivityBuilder via a generic.

The API for everything besides secrets and buttons stays the same. If a user wants to set the secrets they will have to call with_secrets() first and are only able to do that on the returned struct. The same behaviour is implemented for buttons but with with_buttons().

Discord responds with a different structure for the buttons than it expects in the request. I didn't want to duplicate the Activity struct, so I did that with being generic over the Button type. Because of a bug in rust I had to implement Default manually.

Related Issues

NyCodeGHG commented 1 year ago

I changed the implementation to now use enums, the user is not able to set just a label in the activity builder because this is only valid in the response. So this has the same type safety as the generics version, but much simpler :)