Code Monkey home page Code Monkey logo

discord-sdk's Introduction

⚔️ discord-sdk

An (unofficial) open source Rust implementation of the Discord Game SDK.

Embark Embark Crates.io Docs dependency status Build status

Why not use this?

  • This project is not official and is using a largely undocumented protocol that Discord could change/break at any time in the future.
  • There is already a Rust wrapper for the official Game SDK.
  • Your project is not also in Rust. We may add a C API for this crate in the future, but for now this is a Rust only project.

Why use this?

  • You use Rust for your project and want to integrate features such as rich presence/activities provided by Discord.
  • You don't want to have a dependency on a closed source, shared library.
  • You like to live dangerously (though this library does also have some automated tests!).

Implemented Features

Commands

Events

Other

⚠️ Voice

Commands

Events

  • VOICE_SETTINGS_UPDATE_2 - Undocumented, but this event is fired for all voice settings changes, except for "Set Local Volume".

TODO: Images

⚠️ Lobbies

Commands

Events

Other

⚠️ Networking

NOTE: These are only tested insofar as the protocol is (probably) correct, however, the overlay is currently extremely limited, and so we were unable to test that the overlay commands actually function correctly since our primary project is Vulkan.

Note, there are a few other cases that overlay will not work with. The overlay is currently not supported for Mac, games with Vulkan support, and generally old games.

Also note, the SDK itself and its documentation uses the utterly confusing terminology of Un/Locked when talking about the overlay, this crate instead uses Visibility, as in Visible or Hidden.

Commands

Events

Commands

  • Get Relationships - NOTE: This command is not really exposed directly from the regular Game SDK, but is implicitly executed by the SDK during intialization.

Events

TODO: Storage

TODO?: Store

Commands

Events

⚠️ Deprecation

This hasn't been officially announced by Discord yet, but the Voice, Lobbies, and Networking functionality will be deprecated and removed sometime in the future. Since only the lobbies functionality has been implemented thus far, we will mark that functionality as deprecated once it is official.

Testing

Unfortunately Discord does not provide a convenient way to perform automated testing, as it requires an actual working Discord application to be running and logged in, which makes automated (particularly headless) testing...annoying.

For now, it's required that you manually spin up 2 different Discord applications (eg, Stable and Canary) and log in with separate accounts on the same machine, then run one test at a time.

Activities

cargo test --features local-testing test_activity

Lobbies

NOTE: This does not test the lobby search functionality as that command seems to be non-functioning and never returns results, even if the REST equivalent does return the expected results.

cargo test --features local-testing test_lobbies

Contribution

Contributor Covenant

We welcome community contributions to this project.

Please read our Contributor Guide for more information on how to get started. Please also read our Contributor Terms before you make any contributions.

Any contribution intentionally submitted for inclusion in an Embark Studios project, shall comply with the Rust standard licensing model (MIT OR Apache 2.0) and therefore be dual licensed as described below, without any additional terms or conditions:

License

This contribution is dual licensed under EITHER OF

at your option.

For clarity, "your" refers to Embark or any other licensee/user of the contribution.

discord-sdk's People

Contributors

ewpratten avatar jake-shadle avatar nehliin avatar nycodeghg avatar vojd avatar winrg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

discord-sdk's Issues

Box<dyn DiscordHandler> used for no reason

Describe the bug
The impl DiscordHandler trait object stored by Discord and its internal handler task is boxed in its current form. As far as I can tell, this is just an unnecessary(albeit minor) performance hit(introduces an unnecessary runtime vtable lookup), and converting it to impl DiscordHandler would only serve to improve performance. That being said, if there are legitimate reasons, please let me know!

Additional context
Relevant Discord ctor code
Relevant handler_task code

IO handler shutdown hangs tasks

Describe the bug
Alright, I've figured it out! This bug specifically occurs when anything .awaits a Discord request, and the IO handler restarts for whatever reason. The awaits hang perpetually.

To Reproduce
Steps to reproduce the behavior:

  1. Write some code which does the following:
    1. Connects to discord
    2. Sends a periodical request of some kind, I've been using activity updates.
    3. Make sure it logs when it does, or in some way shows that it's running
  2. Run it with Discord open
  3. Kill discord and reopen it
  4. Note how the logging suddenly pauses

Expected behavior
For an error to be returned, or, ideally, the request to be transparently resent in some way.

Device:
ArchLinux, kernel 6.1.19, rustc 1.66.0-nightly

Timestamps in presence info of `relationship_update` are strings instead of ints

"{"cmd":"DISPATCH","data":{"type":1,"user":{"id":"123414231424","username":"name","discriminator":"52","avatar":"f62f2a755cb18c94dc5cda94441024f1","bot":false,"flags":0,"premium_type":0},"presence":{"status":"dnd","activity":{"assets":{"large_image":"spotify:ab67616d0000b273d1e326d10706f3d8562d77f8","large_text":"To the Moon"},"created_at":"1628629162447","details":"To the Moon","flags":48,"id":"spotify:1","name":"Spotify","party":{"id":"spotify:216453179196440576"},"session_id":"6bb1ddaea510750e905615286709d632","state":"Rob Curly","sync_id":"2qZFCu2kYtAagNQA7NZfCq","timestamps":{"end":"1628629327961","start":"1628629161811"},"type":2}}},"evt":"RELATIONSHIP_UPDATE","nonce":null}"

Improper validation of image asset keys

Describe the bug
discord_sdk::activity::Assets::{large_image, small_image} don't properly validate what is passed in to them. The 32-char limit applies to keys, but not to proxied URLs, which have no such length limit.

Expected behavior
For it to not incorrectly discard data.

Add mock server

Since Discord themselves don't provide any kind of headless test server for RPCs, there's no good way to do automated testing in a normal headless environment since it requires installing the full Discord app, and logging into it, which, AFAICT, is impossible in a headless environment as Discord doesn't support command line arguments.

While testing locally in a regular desktop environment works, this is tedious and easy to miss stuff, especially from outside contributors, so I think it makes sense to make a unix domain socket/named pipe server that tests can fill out with preplanned responses/events to add a bit more sanity checking to CI.

Move off tokio fork

We're currently using a fork of tokio 1.7 to add some needed methods to NamedPipeClient as it is brand new in 1.7, this is necessary for us to be able to publish new releases.

Improper truncation of UTF-8 strings in `discord_sdk::activity::truncate`

thread 'main' panicked at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/alloc/src/string.rs:1396:13:
assertion failed: self.is_char_boundary(new_len)
stack backtrace:
   0: rust_begin_unwind
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panicking.rs:645:5
   1: core::panicking::panic_fmt
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/panicking.rs:72:14
   2: core::panicking::panic
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/panicking.rs:144:5
   3: discord_sdk::activity::truncate::{{closure}}
   4: discord_sdk::activity::ActivityBuilder::details

if text.len() > 128 {
tracing::warn!("{} '{}' is too long and will be truncated", name, text);
text.truncate(128);
}

To Reproduce
Steps to reproduce the behavior:

  1. Call discord_sdk::activity::ActivityBuilder::default().details("xäääääääääääääääääääääääääääääääääääääääääääääääääääääääääääääääää")

Support for new activity features

Is your feature request related to a problem? Please describe.
Not really

Describe the solution you'd like
Although the features aren't really new anymore, it would be great to still have the functionality within this library. The two features which i primarily have in mind are the following:

  • Asset keys being urls
  • Buttons

Describe alternatives you've considered
For url asset keys i can bypass the check by setting it not using the method eg:

let mut assets = Assets::default();
assets.large_image = Some(game_thumbnail.clone());
assets.large_text = Some(game_name.clone());

But to get buttons to work i would figure i need to do much more and alter the current source code.

Additional context
n/a

Add support for Voice

Even though Voice is being deprecated, we're hoping to use Lobbies in the short term to get voice chat support. This works well, but one missing piece is that when joined to a lobby voice channel, you hear everyone, and everyone can hear you, which is fine for internal playtests, but might be a bit tedious with real users. Adding support for the Voice API in the SDK would allow us to add support for self muting and un/muting of other players in the lobby.

Broken links in README.md

Describe the bug
The README does not correctly link back to multiple other markdown files. This leads to dead links on the docs.rs page.

To Reproduce
Steps to reproduce the behavior:

  1. Go to the docs.
  2. Click on 'Contributor Guide'
  3. See error

Expected behavior
I expect the links to work.

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.