Skip to content

Commit 299ac00

Browse files
authored
add Voice Channel Connection (#71)
* voice connection outline * implement Voice Session * code dump * update go dasgo * implement voice channel connection * update docs * update generators for requests coverage test rate limit map * update coverage test request order generator * update wrapper lint * update linters * update request test bot timeouts * refactor voice handlers * fix #70 * fix test references from contributing
1 parent 349d456 commit 299ac00

File tree

104 files changed

+21706
-13424
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

104 files changed

+21706
-13424
lines changed

.github/workflows/cache.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ jobs:
2727
- name: Run golangci-lint
2828
uses: golangci/golangci-lint-action@v3
2929
with:
30-
version: v1.53.3
30+
version: v1.64.5
3131
args: ./cache/...

.github/workflows/examples.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ jobs:
2828
- name: Run golangci-lint
2929
uses: golangci/golangci-lint-action@v3
3030
with:
31-
version: v1.53.3
31+
version: v1.64.5
3232
working-directory: ./_examples
3333
args: ./...

.github/workflows/gen.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@ jobs:
3030
- name: Run golangci-lint
3131
uses: golangci/golangci-lint-action@v3
3232
with:
33-
version: v1.53.3
33+
version: v1.64.5
3434
working-directory: ./_gen
3535
args: ./...

.github/workflows/shard.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
- name: Run golangci-lint
2828
uses: golangci/golangci-lint-action@v3
2929
with:
30-
version: v1.53.3
30+
version: v1.64.5
3131
args: ./shard/...
3232

3333
test-integration:
@@ -48,5 +48,4 @@ jobs:
4848
APPID: ${{ secrets.APPID }}
4949
COVERAGE_TEST_TOKEN: ${{ secrets.COVERAGE_TEST_TOKEN }}
5050
COVERAGE_TEST_GUILD: ${{ secrets.COVERAGE_TEST_GUILD }}
51-
COVERAGE_TEST_CATEGORY: ${{ secrets.COVERAGE_TEST_CATEGORY }}
5251
run: go test ./shard/tests/integration -race

.github/workflows/tools.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ jobs:
2727
- name: Run golangci-lint
2828
uses: golangci/golangci-lint-action@v3
2929
with:
30-
version: v1.53.3
30+
version: v1.64.5
3131
args: ./tools/...

.github/workflows/wrapper.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
- name: Run golangci-lint
4141
uses: golangci/golangci-lint-action@v3
4242
with:
43-
version: v1.53.3
43+
version: v1.64.5
4444
args: ./wrapper/...
4545

4646
test-unit:
@@ -80,4 +80,5 @@ jobs:
8080
COVERAGE_TEST_TOKEN: ${{ secrets.COVERAGE_TEST_TOKEN }}
8181
COVERAGE_TEST_GUILD: ${{ secrets.COVERAGE_TEST_GUILD }}
8282
COVERAGE_TEST_CATEGORY: ${{ secrets.COVERAGE_TEST_CATEGORY }}
83+
COVERAGE_TEST_VOICE_CHANNEL: ${{ secrets.COVERAGE_TEST_VOICE_CHANNEL }}
8384
run: go test ./wrapper/tests/integration -race

README.md

+33-22
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,34 @@
1-
# Create a Discord Bot in Go
1+
# Create a Discord Bot using Go
22

33
[![Go Doc](https://img.shields.io/badge/godoc-reference-5272B4.svg?style=for-the-badge&logo=appveyor&logo=appveyor)](https://pkg.go.dev/github.com/switchupcb/disgo)
44
[![License](https://img.shields.io/github/license/switchupcb/disgo.svg?style=for-the-badge)](https://github.com/switchupcb/disgo/blob/main/LICENSE)
55

6-
**Disgo** is a [Discord API](https://discord.com/developers/docs/reference) Wrapper designed to be flexible, performant, secure, and thread-safe. Disgo aims to provide every feature in the Discord API along with optional rate limiting, structured logging, shard management, and caching. Use the only Go module to provide a **100% one-to-one implementation** of the Discord API.
6+
**Disgo** helps you create a Discord Bot using the Go programming language.
77

8-
_This repository is STABLE. For more information, read the [roadmap](/_contribution/CONTRIBUTING.md#roadmap)._
8+
## What is Disgo?
99

10-
## A Next Generation Discord API Wrapper
10+
**Disgo** is a [Discord API](https://discord.com/developers/docs/reference) Wrapper designed to be flexible, performant, secure, and thread-safe. Disgo provides every feature in the Discord API along with optional rate limiting, structured logging, shard management, and caching.
1111

12-
High-quality code merits easy development.
12+
_This repository is STABLE. For more information, read the [roadmap](/_contribution/CONTRIBUTING.md#roadmap)._
1313

14-
Disgo uses developer operations to stay up-to-date with the ever-changing Discord API.
15-
- Code generation provides a clean implementation for every request and event.
16-
- Data race detection is run on an integration test _that covers the entire Discord API_ to ensure that Disgo is safe for concurrent usage.
14+
### A Next Generation Discord API Wrapper
1715

18-
In addition, **Disgo provides the following exclusive features**.
16+
Use the only Go module to provide a **100% one-to-one horizontally scalable implementation** of the Discord API.
17+
18+
Your development is also simplified with these exclusive features.
1919

2020
- [EVERY Rate Limit (Global, Per Route, Per Resource, Custom, Gateway)](_contribution/concepts/REQUESTS.md#what-is-a-rate-limit)
2121
- [Automatic Gateway Intent Calculation](_contribution/concepts/EVENTS.md#what-is-a-gateway-intent)
2222
- [Selective Event Processing](_contribution/concepts/EVENTS.md#selective-event-processing)
2323

2424
_Disgo uses [NO reflection or type assertion](_contribution/concepts/EVENTS.md#how-it-works)._
2525

26+
### A Next Generation Development Process
27+
28+
Disgo uses developer operations to stay up-to-date with the ever-changing Discord API.
29+
- Code generation provides an optimal implementation for every request and event.
30+
- Data race detection is run on _an integration test covering the entire Discord API_ to make Disgo safe for concurrent usage.
31+
2632
## Table of Contents
2733

2834
| Topic | Categories |
@@ -34,7 +40,7 @@ _Disgo uses [NO reflection or type assertion](_contribution/concepts/EVENTS.md#h
3440

3541
## Using the API
3642

37-
This breakdown provides you with a **full understanding** on how to use the API.
43+
Use this breakdown to learn how the Discord API works.
3844

3945
| Abstraction | Usecase | Example |
4046
| :----------- | :------------------------------------------------------------------------------------------------------------------------------------------------ | :---------------------------------------------------------------------------------- |
@@ -44,13 +50,17 @@ This breakdown provides you with a **full understanding** on how to use the API.
4450
| **Request** | Uses the Discord HTTP REST API to make one-time _requests_ for information. | Create an application command. <br> Request guild information. |
4551
| **Session** | Uses a Discord WebSocket Connection [(Gateway)](https://discord.com/developers/docs/topics/gateway) to receive _events_ that contain information. | Send a message when an application command is used or a user joins a voice channel. |
4652

47-
You create a **Client** that calls for **Resources** using **Requests** and handles **Events** from **Sessions** using event handlers.
53+
Here is an example.
54+
55+
You create a **Client** that **Requests** **Resources** and handles **Events** from **Sessions** using Event Handlers.
4856

4957
_For more information, please read [What is a Request?](/_contribution/concepts/REQUESTS.md) and [What is an Event?](/_contribution/concepts/EVENTS.md)._
5058

5159
### Flags
5260

53-
A flag is a [flag](https://discord.com/developers/docs/resources/application#application-object-application-flags), [type](https://discord.com/developers/docs/resources/channel#embed-object-embed-types), [key](https://discord.com/developers/docs/resources/audit-log#audit-log-change-object-audit-log-change-key), [level](https://discord.com/developers/docs/resources/guild#guild-object-verification-level) or any other option that Discord provides. All flags are denoted by `disgo.Flag` _(e.g., `disgo.FlagUserSTAFF`, `disgo.FlagVerificationLevelHIGH`, `disgo.FlagPremiumTierNONE`)_.
61+
All flags are denoted by `disgo.Flag` _(e.g., `disgo.FlagUserSTAFF`, `disgo.FlagVerificationLevelHIGH`, `disgo.FlagPremiumTierNONE`)_.
62+
63+
A flag is a [flag](https://discord.com/developers/docs/resources/application#application-object-application-flags), [type](https://discord.com/developers/docs/resources/channel#embed-object-embed-types), [key](https://discord.com/developers/docs/resources/audit-log#audit-log-change-object-audit-log-change-key), [level](https://discord.com/developers/docs/resources/guild#guild-object-verification-level) or any other option that Discord provides.
5464

5565
### Logging
5666

@@ -68,7 +78,7 @@ _Read [What is a Discord Shard](/_contribution/concepts/SHARD.md) for a simple y
6878

6979
The [Disgo Cache](/_contribution/concepts/CACHE.md#the-disgo-cache) is **optional** and **customizable**.
7080

71-
The **cache interface** allows you to replace the built-in cache with another store _(such as Redis or Memcached)_ or provide your own caching implementation.
81+
The **cache interface** lets you replace the built-in cache with another store _(such as Redis or Memcached)_ or provide your own caching implementation.
7282

7383
_Read [What is a Cache](/_contribution/concepts/CACHE.md) for a simple yet full understanding of the Disgo Cache._
7484

@@ -106,6 +116,7 @@ bot := &disgo.Client{
106116
Authorization: &disgo.Authorization{ ... },
107117
Config: disgo.DefaultConfig(),
108118
Handlers: new(disgo.Handlers),
119+
VoiceHandlers: new(disgo.VoiceHandlers),
109120
Sessions: disgo.NewSessionManager()
110121
}
111122
```
@@ -157,7 +168,7 @@ s := disgo.NewSession()
157168
if err := s.Connect(bot); err != nil {
158169
log.Printf("can't open websocket session to Discord Gateway: %v", err)
159170

160-
return
171+
return
161172
}
162173
```
163174

@@ -193,6 +204,7 @@ disgo.<Event>.SendEvent()
193204
disgo.Client.Handle(<event>, <handler>)
194205
disgo.Client.Remove(<event>, <index>)
195206
disgo.Client.Handlers.<Handler>
207+
disgo.Client.VoiceHandlers.<Handler>
196208

197209
// Use the client to manage the bot's settings.
198210
disgo.Client.ApplicationID
@@ -206,17 +218,16 @@ disgo.Client.Config.Gateway.<Settings>
206218

207219
### Why Go?
208220

209-
Go is a statically typed, compiled programming language _(with a garbage collector)_. So it performs computationally better compared to _most_ languages that provide [Discord API Wrappers](https://discord.com/developers/docs/topics/community-resources#libraries).
221+
**A Discord Bot is server-side software.**
210222

211-
Go maintains superior asynchronous handling due to the use of [Goroutines](https://gobyexample.com/goroutines) and [Channels](https://gobyexample.com/channels): This is helpful since **a Discord Bot is server-side software**.
223+
A server-side software uses asynchronous logic to operate.
224+
Go maintains superior asynchronous handling with [Goroutines](https://gobyexample.com/goroutines) and [Channels](https://gobyexample.com/channels).
212225

213-
### Comparison
226+
Go is a statically typed, compiled programming language _(with a garbage collector)_. So, it also performs better computationally compared to _most_ languages that provide [Discord API Wrappers](https://discord.com/developers/docs/topics/community-resources#libraries).
214227

215-
Disgo supports every feature in the Discord API and is **the most customizable Discord API Wrapper** due to its optional caching, shard management, rate limiting, and logging.
216-
- **DiscordGo** is not feature-complete.
217-
- **Disgord** is limiting.
228+
### How does Disgo compare to other Go Discord API Wrappers?
218229

219-
Look no further than the name. The word `disgo` contains 5 letters — while the others have 7+ — saving you precious keyboard strokes.
230+
Disgo supports every feature in the Discord API and is **the most customizable Discord API Wrapper** due to its optional caching, shard management, rate limiting, and logging.
220231

221232
Most important is Disgo's performance, which saves you money by reducing server costs.
222233

@@ -256,7 +267,7 @@ The [Apache License 2.0](#license) is permissive for commercial use. For more in
256267

257268
| Name | Contributions |
258269
| :---------------------------------------- | :----------------------------------------------------------------------- |
259-
| [SwitchUpCB](https://switchupcb.com) | Project Architecture, Generators, Dasgo, Requests, Events, Shard Manager |
270+
| [SwitchUpCB](https://switchupcb.com) | Project Architecture, Generators, Dasgo, Requests, Events, Voice Connection, Shard Manager |
260271
| [Thomas Rogers](https://github.com/t-rog) | Dasgo |
261272
| [Josh Dawe](https://github.com/joshdawe) | Dasgo |
262273

_contribution/CONTRIBUTING.md

+10-3
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Comments follow [Effective Go](https://golang.org/doc/effective_go#commentary) a
5252

5353
#### Static Code Analysis
5454

55-
Disgo uses [golangci-lint](https://github.com/golangci/golangci-lint) in order to statically analyze code. You can install golangci-lint with `go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.53.3`.
55+
Disgo uses [golangci-lint](https://github.com/golangci/golangci-lint) in order to statically analyze code. You can install golangci-lint with `go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.64.5`.
5656

5757
| Directory | Command | Description | GOWORK |
5858
| :------------ | :-------------------------------- | :------------------------------------------------- | :------ |
@@ -81,7 +81,14 @@ Unit tests are used to test logic.
8181

8282
#### Integration Tests
8383

84-
Integration tests are used to ensure functionality between the API Wrapper and Discord.
84+
Integration tests are used to prove functionality between the API Wrapper and Discord.
85+
86+
| Test | What feature is tested? |
87+
| :------------------ | :------------------------------------------------------- |
88+
| `coverage_test.go` | [Discord API Feature Coverage](/_gen/coverage/README.md) |
89+
| `ratelimit_test.go` | Global, Per-Route, Gateway Rate Limits |
90+
| `session_test.go` | Disgo Gateway Session |
91+
| `voice_test.go` | Disgo Voice Connection |
8592

8693
#### Running Tests
8794

@@ -92,7 +99,7 @@ Use `go test` to run the tests in the current directory. Use `go test ./<dir>` t
9299
Disgo is **STABLE**.
93100

94101
The following additional features are being implemented:
95-
1. Voice Connections ([UDP Decision](/_contribution/libraries/), [Audio Processing using Opus](https://discord.com/developers/docs/topics/voice-connections#encrypting-and-sending-voice))
102+
1. [Voice Audio Processing](https://github.com/switchupcb/disgo/issues/72))
96103
2. [Cache](https://github.com/switchupcb/disgo/issues/39)
97104

98105
[_Get assigned a feature or example now._](https://github.com/switchupcb/disgo/issues/45)

_contribution/concepts/CACHE.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ A [cache (computing)](https://en.wikipedia.org/wiki/Cache_(computing)) is a comp
44

55
## Why Cache?
66

7-
A cache is an alternative to sending redundant requests that take time to complete — to Discord: A cache stores data so that future requests for that data can be served immediately.
7+
A cache stores data so that future requests for that data can be served immediately. A cache is an alternative to sending redundant requests — which take time to complete — to Discord.
88

99
For example, retrieving _the amount of users in a guild_ requires a network request to be sent to Discord, and another network request to be returned from Discord. Without a cache, retrieving _the exact same information_ again requires two more network requests, even when the guild's condition remains unchanged.
1010

1111
## When to Use a Cache?
1212

13-
Caches are useful for storing costly requests or calculations relevant to the application's lifetime. In other words, a cache is **NOT** meant to be used for long-term storage.
13+
Use a cache to stop wasting time executing costly requests and calculations relevant to the application's lifetime. An application cache should **NOT** used for long-term storage because the cache resets when the application restarts.
1414

15-
**If you need data to persist when your bot restarts, use a database.**
15+
**Use a database when you need data to persist when your bot restarts.**
1616

1717
## How Does a Cache Work?
1818

@@ -29,4 +29,6 @@ _For more information, read [Cache Invalidation](https://en.wikipedia.org/wiki/C
2929

3030
## How Do I Cache?
3131

32-
Disgo provides an **optional** cache along with a **cache interface** for your Discord Bot. Read [The Disgo Cache](/cache/README.md) for information about its implementation.
32+
Disgo provides an **optional** cache along with a **cache interface** for your Discord Bot.
33+
34+
Read [The Disgo Cache](/cache/README.md) for information about its implementation.

0 commit comments

Comments
 (0)