1
1
Fork
You've already forked drocsid
0
A Discord compatible server for testing bots.
Rust 87.2%
C# 8.9%
Nix 3.9%
2024年10月31日 16:58:37 +01:00
.woodpecker Add a Woodpecker workflow 2024年09月24日 17:45:05 +02:00
dotnet store -> context and new endpoint for removing a context 2024年10月20日 18:21:19 +02:00
src Use the Id type from twilight_model instead of u64 2024年10月31日 16:58:37 +01:00
.gitignore Add a client for .NET 2024年10月17日 19:25:17 +02:00
Cargo.lock Graceful shutdown 2024年10月21日 01:54:46 +02:00
Cargo.toml Graceful shutdown 2024年10月21日 01:54:46 +02:00
flake.lock Add a client for .NET 2024年10月17日 19:25:17 +02:00
flake.nix The server now exposes multiple stores thanks to the meta store 2024年10月18日 23:27:21 +02:00
LICENSE.md Add LICENSE.md 2024年09月24日 16:45:02 +02:00
README.md store -> context and new endpoint for removing a context 2024年10月20日 18:21:19 +02:00
taplo.toml Drocsid now expose a REST API instead of a DSL 2024年10月17日 05:56:51 +02:00

Drocsid

NuGet Version

Drocsid is a server for testing Discord bots.

It acts as a server compatible with the Discord API.

In that way, Drocsid is similar to some really cool projects:

However, Drocsid is only used to test bots. Only the endpoints that are useful for this purpose are implemented. A Discord-compatible chat client won't be able to connect to it.

What's more, Drocsid doesn't use a persistent database; everything is stored in memory.

How to use it?

Drocsid expose three main services over HTTP with JSON:

  • Two Discord compatible services:
    • The bot API at /contexts/:context_id/bot/api.
    • The bot gateway (a WebSocket endpoint) at /contexts/:context_id/bot/gateway.
  • An API for writing tests at /contexts/:context_id.

This design allows any language with an HTTP client and a JSON library to be used to write tests.

Using a unique identifier from your test runner as the context identifier allows to isolate tests without running multiple instances of Drocsid.

Example

Here is an example that uses the API for testing a simple /ping command.

drocsid=localhost:3000/contexts/default
# Creation of the user Turtle,
# who happens to be the guild owner.
http POST $drocsid/users name=Turtle guild_owner=true
# Creation of the General channel.
http POST $drocsid/channels name=General
# The point of starting the bot now is to ensure that it
# doesn't receive events from Turtle joining the guild
# or from the #General channel being created.
bot start
# Get a snapshot of the state to see if
# the /ping command has been created.
# We repeat this request until it exists.
http GET $drocsid/state
# Turtle executes /ping in #General.
http POST $drocsid/interactions command=ping user=Turtle channel=General
# Get a snapshot of the state for asserting the response.
http GET $drocsid/state

For the moment, this example actually shows almost everything Drocsid is capable of.

API Endpoints

DELETE /contexts/:context_id

Removes a context. The next request trying to access this context will create a new one.

GET /contexts/:context_id/api/state

Returns a snapshot of the state.

POST /contexts/:context_id/api/users

interface CreateUserRequest {
 name: string;
 bot?: boolean;
 guild_owner?: boolean;
}

Creates an user.

POST /contexts/:context_id/api/channels

interface CreateChannelRequest {
 name: string;
}

Creates a channel.

POST /contexts/:context_id/api/interactions

interface CreateInteractionRequest {
 command: string;
 user: string;
 channel: string;
}

Creates an interaction.

Client for .NET

A client for .NET is published on nuget.

Hey that's cool!

Drocsid wants to be a common, so feel free to use it, contribute to it or discuss it. :3