|
5 | 5 | <p><a href="https://discord.gg/CH9ubGPMV6">Discord Server</a> • <a href="https://github.com/lavaclient/lavadeno">Github</a></p> |
6 | 6 | </blockquote> |
7 | 7 |
|
8 | | -- **Flexible**: Lavadeno is not restricted to a specific discord library. Meaning you only need a connection to the discord gateway for it to work. |
| 8 | +- **Flexible:** Lavadeno is a generic library, meaning you can use it with just a connection to the discord gateway, no library restriction. |
9 | 9 | - **Easy-to-Use**: Lavadeno has a neat and user-friendly promise-based api. |
10 | | -- **Lightweight**: Designed to be small and performant, it's a great choice for any sized project. |
11 | | - |
| 10 | +- **Lightweight:** Designed to be small and performant, it's a great choice for any sized project. |
12 | 11 |
|
13 | 12 | <h2 align="center">Setup</h2> |
14 | 13 |
|
15 | | -- Deno 1.3.x |
| 14 | +- Deno Runtime |
16 | 15 | - Lavalink |
17 | 16 | - [Official](https://github.com/freyacodes/lavalink) |
18 | 17 | - [With Filters (Unofficial)](https://github.com/melike2d/lavalink/) |
19 | 18 | - Connection to the Discord Gateway. |
20 | 19 |
|
| 20 | +#### Single Node |
| 21 | + |
| 22 | +```ts |
| 23 | +import { Node } from "https://deno.land/x/lavadeno/mod.ts"; |
| 24 | + |
| 25 | +const node = new Node({ |
| 26 | + connection: { |
| 27 | + host: "localhost", |
| 28 | + port: 2333, |
| 29 | + password: "youshallnotpass", |
| 30 | + }, |
| 31 | + sendGatewayPayload: (id, payload) => sendPayloadToDiscord(), |
| 32 | +}); |
| 33 | + |
| 34 | +node.on("connect", node => console.log(`now connected...`)); |
| 35 | + |
| 36 | +node.connect(870267613635309618n); |
| 37 | +``` |
| 38 | +#### Multiple Nodes |
| 39 | + |
21 | 40 | ```ts |
22 | | -import { Manager } from "https://deno.land/x/lavadeno/mod.ts"; |
23 | | - |
24 | | -const nodes = [ |
25 | | - { |
26 | | - id: "main", |
27 | | - host: "localhost", |
28 | | - port: 2333, |
29 | | - password: "youshallnotpass" |
30 | | - } |
31 | | -] |
32 | | - |
33 | | -const manager = new Manager(nodes, { |
34 | | - send(id, payload) { |
35 | | - sendPayloadToDiscord(); |
36 | | - } |
| 41 | +import { Cluster } from "https://deno.land/x/lavadeno/mod.ts"; |
| 42 | + |
| 43 | +const cluster = new Cluster({ |
| 44 | + nodes: [ |
| 45 | + { |
| 46 | + id: "main", |
| 47 | + host: "localhost", |
| 48 | + port: 2333, |
| 49 | + password: "youshallnotpass", |
| 50 | + }, |
| 51 | + ], |
| 52 | + sendGatewayPayload: (id, payload) => sendPayloadToDiscord(), |
37 | 53 | }); |
| 54 | + |
| 55 | +cluster.on("nodeConnect", node => console.log(`node "${node.id}" is now connected...`)); |
| 56 | + |
| 57 | +cluster.init(870267613635309618n); |
| 58 | +``` |
| 59 | + |
| 60 | +### Resuming / Reconnecting |
| 61 | + |
| 62 | +LavaDeno supports exponential backoff and basic reconnection types, along with *manual* reconnecting as reconnecting isn't automatic. |
| 63 | + |
| 64 | +```ts |
| 65 | +const node = new Node({ |
| 66 | + connection: { |
| 67 | + // resuming, a key must be supplied or else it wont work. |
| 68 | + resuming: { |
| 69 | + key: "lavad3n0ftw" |
| 70 | + }, |
| 71 | + |
| 72 | + // exponential backoff |
| 73 | + reconnect: { |
| 74 | + type: "exponential", |
| 75 | + maxDelay: 15000, |
| 76 | + initialDelay: 1000, |
| 77 | + tries: -1 // unlimited |
| 78 | + }, |
| 79 | + |
| 80 | + // basic |
| 81 | + reconnect: { |
| 82 | + type: "basic", |
| 83 | + delay: 5000. |
| 84 | + tries: 5 |
| 85 | + }, |
| 86 | + } |
| 87 | +}) |
38 | 88 | ``` |
39 | 89 |
|
40 | 90 | --- |
41 | 91 |
|
42 | | -<p align="center"><a href="https://dimensional.fun">melike2d</a> © 2020</p> |
| 92 | +<p align="center"><a href="https://dimensional.fun">melike2d</a> © 2018 - 2021</p> |
0 commit comments