A rust library for interacting with multiple Spacebar-compatible Instances at once.
Go to file
kozabrada123 7a878d03ac Revert "Mess w/ the tests to see if it really works"
This reverts commit 7b975e3c95.
2024-01-19 16:05:34 +01:00
.cargo initial wasm32 'support' (#443) 2023-11-20 13:40:55 +01:00
.github/workflows wasm-safari CI seems to be bugged - disabling for now 2023-12-03 15:57:03 +01:00
chorus-macros Add source url field trait 2023-09-03 21:00:48 +02:00
examples feat: switch safina_timer for tokio, fix sleep duration overflow in examples 2024-01-19 15:48:59 +01:00
src Revert "Mess w/ the tests to see if it really works" 2024-01-19 16:05:34 +01:00
tests Revert "Mess w/ the tests to see if it really works" 2024-01-19 16:05:34 +01:00
.gitignore Exclude all Target dirs 2023-08-01 21:21:00 +02:00
.rusty-hook.toml Change rusty-hook to be pre-commit 2023-05-28 11:43:03 +02:00
Cargo.lock Revert "Mess w/ the tests to see if it really works" 2024-01-19 16:05:34 +01:00
Cargo.toml Revert "Mess w/ the tests to see if it really works" 2024-01-19 16:05:34 +01:00
LICENSE Initial commit 2023-04-03 22:19:25 +02:00
README.md Update documentation and examples 2023-12-10 18:40:03 +01:00
SECURITY.md Create SECURITY.md 2023-06-04 22:17:56 +02:00

README.md

Chorus is a Rust library which poses as an API wrapper for Spacebar Chat and Discord. It is designed to be easy to use, and to be compatible with both Discord and Spacebar Chat.

You can establish as many connections to as many servers as you want, and you can use them all at the same time.

A Tour of Chorus

Chorus combines all the required functionalities of a user-centric Spacebar library into one package. The library handles various aspects on your behalf, such as rate limiting, authentication and maintaining a WebSocket connection to the Gateway. This means that you can focus on building your application, instead of worrying about the underlying implementation details.

To get started with Chorus, import it into your project by adding the following to your Cargo.toml file:

[dependencies]
chorus = "0.13.0"

Establishing a Connection

To connect to a Spacebar compatible server, you need to create an Instance like this:

use chorus::instance::Instance;
use chorus::UrlBundle;

#[tokio::main]
async fn main() {
    let bundle = UrlBundle::new(
        "https://example.com/api".to_string(),
        "wss://example.com/".to_string(),
        "https://example.com/cdn".to_string(),
    );
    let instance = Instance::new(bundle)
        .await
        .expect("Failed to connect to the Spacebar server");
    // You can create as many instances of `Instance` as you want, but each `Instance` should likely be unique.
    dbg!(instance.instance_info);
    dbg!(instance.limits_information);
}

This Instance can now be used to log in, register and from there on, interact with the server in all sorts of ways.

Logging In

Logging in correctly provides you with an instance of ChorusUser, with which you can interact with the server and manipulate the account. Assuming you already have an account on the server, you can log in like this:

use chorus::types::LoginSchema;
// Assume, you already have an account created on this instance. Registering an account works
// the same way, but you'd use the Register-specific Structs and methods instead.
let login_schema = LoginSchema {
    login: "user@example.com".to_string(),
    password: "Correct-Horse-Battery-Staple".to_string(),
    ..Default::default()
};
// Each user connects to the Gateway. The Gateway connection lives on a seperate thread. Depending on
// the runtime feature you choose, this can potentially take advantage of all of your computers' threads.
let user = instance
    .login_account(login_schema)
    .await
    .expect("An error occurred during the login process");
dbg!(user.belongs_to);
dbg!(&user.object.read().unwrap().username);

Supported Platforms

All major desktop operating systems (Windows, macOS (aarch64/x86_64), Linux (aarch64/x86_64)) are supported. wasm32-unknown-unknown is a supported compilation target on versions 0.12.0 and up. This allows you to use Chorus in your browser, or in any other environment that supports WebAssembly.

We recommend checking out the examples directory, as well as the documentation for more information.

MSRV (Minimum Supported Rust Version)

Rust 1.67.1. This number might change at any point while Chorus is not yet at version 1.0.0.

Development Setup

Make sure that you have at least Rust 1.67.1 installed. You can check your Rust version by running cargo --version in your terminal. To compile for wasm32-unknown-unknown, you need to install the wasm32-unknown-unknown target. You can do this by running rustup target add wasm32-unknown-unknown.

Testing

In general, the tests will require you to run a local instance of the Spacebar server. You can find instructions on how to do that here. You can find a pre-configured version of the server here. It is recommended to use the pre-configured version, as certain things like "proxy connection checking" are already disabled on this version, which otherwise might break tests.

wasm

To test for wasm, you will need to cargo install wasm-pack. You can then run wasm-pack test --<chrome/firefox/safari> --headless -- --target wasm32-unknown-unknown --features="rt, client" --no-default-features to run the tests for wasm.

Versioning

This crate uses Semantic Versioning 2.0.0 as its versioning scheme. You can read the specification here.

Contributing

Chorus is currently missing voice support and a lot of API endpoints, many of which should be trivial to implement, ever since we streamlined the process of doing so.

If you'd like to contribute new functionality, check out The 'Meta'-issues. They contain a comprehensive list of all features which are yet missing for full Discord.com compatibility. Please feel free to open an Issue with the idea you have, or a Pull Request. Please keep our contribution guidelines in mind. Your contribution might not be accepted if it violates these guidelines or our Code of Conduct.

Progress Tracker/Roadmap

Core Functionality

Messaging

User Management

Additional Features

  • Server discovery
  • Server templates

Voice and Video

Permissions and Roles

Guild Management

Moderation

  • Channel moderation (slow mode, etc.)
  • User sanctions (mute, kick, ban)
  • Audit logs

Embeds and Rich Content

  • Sending rich content in messages (links, images, videos)
  • Customizing embed appearance (title, description, color, fields)

Webhooks

  • Webhook creation and management
  • Handling incoming webhook events

Documentation and Examples

  • Comprehensive documentation
  • Example usage and code snippets
  • Tutorials and guides