lavacord 1.1.9 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -186,7 +186,7 @@
186
186
  same "printed page" as the copyright notice for easier
187
187
  identification within third-party archives.
188
188
 
189
- Copyright 2019-2020 Jacz
189
+ Copyright 2019-2022 Jacz
190
190
 
191
191
  Licensed under the Apache License, Version 2.0 (the "License");
192
192
  you may not use this file except in compliance with the License.
package/README.md CHANGED
@@ -1,12 +1,9 @@
1
1
  [![Discord](https://discordapp.com/api/guilds/323779330033319941/embed.png)](https://discord.gg/wXrjZmV)
2
- [![npm](https://img.shields.io/npm/v/npm.svg)](https://www.npmjs.com/package/lavacord)
3
- [![npm downloads](https://img.shields.io/npm/dt/lavacord.svg?maxAge=3600)](https://www.npmjs.com/package/lavacord)
4
- [![NPM version](https://badge.fury.io/js/lavacord.svg)](http://badge.fury.io/js/lavacord)
5
- [![Codacy Badge](https://api.codacy.com/project/badge/Grade/b50839d781c24a94a4e1c17342a147bd)](https://www.codacy.com/app/lavacord/lavacord?utm_source=github.com&utm_medium=referral&utm_content=lavacord/lavacord&utm_campaign=Badge_Grade)
6
- [![Open Source Love](https://badges.frapsoft.com/os/mit/mit.svg?v=102)](https://github.com/ellerbrock/open-source-badge/)
7
- [![dependencies Status](https://david-dm.org/lavacord/lavacord/status.svg)](https://david-dm.org/lavacord/lavacord)
8
- [![devDependencies Status](https://david-dm.org/lavacord/lavacord/dev-status.svg)](https://david-dm.org/lavacord/lavacord?type=dev)
9
- [![NPM](https://nodei.co/npm/lavacord.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/lavacord/)
2
+ [![npm (scoped)](https://img.shields.io/npm/v/lavacord?label=npm%20version)](https://www.npmjs.com/package/lavacord)
3
+ [![npm downloads](https://img.shields.io/npm/dt/lavacord.svg?label=total%20downloads)](https://www.npmjs.com/package/lavacord)
4
+ [![GitHub](https://img.shields.io/github/license/lavacord/lavacord)](https://github.com/lavacord/lavacord/)
5
+ [![Depfu](https://badges.depfu.com/badges/70051aad57dddc0c44a990d26b1f6e23/overview.svg)](https://depfu.com/github/lavacord/Lavacord?project_id=11810)
6
+ [![Codacy Badge](https://api.codacy.com/project/badge/Grade/b50839d781c24a94a4e1c17342a147bd)](https://www.codacy.com/app/lavacord/lavacord)
10
7
 
11
8
  # LavaCord
12
9
  A simple and easy to use lavalink wrapper.
@@ -37,7 +34,7 @@ npm install lavacord/lavacord
37
34
  ## LavaLink configuration
38
35
  Download from [the CI server](https://ci.fredboat.com/viewLog.html?buildId=lastSuccessful&buildTypeId=Lavalink_Build&tab=artifacts&guest=1)
39
36
 
40
- Put an `application.yml` file in your working directory. [Example](https://github.com/Frederikam/Lavalink/blob/master/LavalinkServer/application.yml.example)
37
+ Put an `application.yml` file in your working directory. [Example](https://github.com/freyacodes/Lavalink/blob/master/LavalinkServer/application.yml.example)
41
38
 
42
39
  Run with `java -jar Lavalink.jar`
43
40
 
@@ -45,7 +42,7 @@ Run with `java -jar Lavalink.jar`
45
42
  If you're having a problem with the module contact us in the [**Discord Server**](https://discord.gg/wXrjZmV)
46
43
 
47
44
  # Implementation
48
- Start by creating a new `Manager` passing an array of nodes and an object with `user` the client's user id and `shards` The total number of shards your bot is operating on.
45
+ Start by creating a new `Manager` passing an array of nodes and an object with `user` the client's user id.
49
46
 
50
47
  ```javascript
51
48
  // import the Manager class from lavacord
@@ -59,7 +56,6 @@ const nodes = [
59
56
  // Initilize the Manager with all the data it needs
60
57
  const manager = new Manager(nodes, {
61
58
  user: client.user.id, // Client id
62
- shards: shardCount, // Total number of shards your bot is operating on
63
59
  send: (packet) => {
64
60
  // this needs to send the provided packet to discord using the method from your library. use the @lavacord package for the discord library you use if you don't understand this
65
61
  }
@@ -70,7 +66,7 @@ await manager.connect();
70
66
 
71
67
  // The error event, which you should handle otherwise your application will crash when an error is emitted
72
68
  manager.on("error", (error, node) => {
73
- error // is the error
69
+ error, // is the error
74
70
  node // is the node which the error is from
75
71
  });
76
72
  ```
@@ -78,19 +74,13 @@ manager.on("error", (error, node) => {
78
74
  Resolving tracks using LavaLink REST API
79
75
 
80
76
  ```javascript
81
- const fetch = require("node-fetch");
82
- const { URLSearchParams } = require("url");
77
+ const { Rest } = require("lavacord");
83
78
 
84
79
  async function getSongs(search) {
85
80
  // This gets the best node available, what I mean by that is the idealNodes getter will filter all the connected nodes and then sort them from best to least beast.
86
81
  const node = manager.idealNodes[0];
87
82
 
88
- const params = new URLSearchParams();
89
- params.append("identifier", search);
90
-
91
- return fetch(`http://${node.host}:${node.port}/loadtracks?${params}`, { headers: { Authorization: node.password } })
92
- .then(res => res.json())
93
- .then(data => data.tracks)
83
+ return Rest.load(node, search).then(data => data.tracks)
94
84
  .catch(err => {
95
85
  console.error(err);
96
86
  return null;
@@ -116,7 +106,7 @@ await player.play(track); // Track is a base64 string we get from Lavalink REST
116
106
 
117
107
  player.once("error", error => console.error(error));
118
108
  player.once("end", data => {
119
- if (data.reason === "REPLACED") return; // Ignore REPLACED reason to prevent skip loops
109
+ if (data.type === "TrackEndEvent" && data.reason === "REPLACED") return; // Ignore REPLACED reason to prevent skip loops
120
110
  // Play next song
121
111
  });
122
112
 
@@ -0,0 +1,8 @@
1
+ import { Manager as BaseManager } from "./lib/Manager";
2
+ import type { ManagerOptions, LavalinkNodeOptions } from "./lib/Types";
3
+ import { Client } from "cloudstorm";
4
+ export * from "./index";
5
+ export declare class Manager extends BaseManager {
6
+ readonly client: Client;
7
+ constructor(client: Client, nodes: Array<LavalinkNodeOptions>, options: ManagerOptions);
8
+ }
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.Manager = void 0;
18
+ const Manager_1 = require("./lib/Manager");
19
+ __exportStar(require("./index"), exports);
20
+ class Manager extends Manager_1.Manager {
21
+ client;
22
+ constructor(client, nodes, options) {
23
+ super(nodes, options);
24
+ this.client = client;
25
+ if (!this.send) {
26
+ this.send = packet => {
27
+ if (!this.client.options.totalShards)
28
+ return false;
29
+ // eslint-disable-next-line no-bitwise
30
+ const shardID = Number((BigInt(packet.d.guild_id) >> BigInt(22)) % BigInt(this.client.options.totalShards));
31
+ const s = Object.entries(this.client.shardManager.shards).find(e => String(e[0]) === String(shardID))?.[1];
32
+ if (s) {
33
+ s.connector.betterWs.sendMessage(packet);
34
+ return true;
35
+ }
36
+ else {
37
+ return false;
38
+ }
39
+ };
40
+ }
41
+ client.on("event", packet => {
42
+ if (packet.t === "VOICE_SERVER_UPDATE") {
43
+ this.voiceServerUpdate(packet.d);
44
+ }
45
+ else if (packet.t === "VOICE_STATE_UPDATE") {
46
+ this.voiceStateUpdate(packet.d);
47
+ }
48
+ else if (packet.t === "GUILD_CREATE") {
49
+ for (const state of packet.d.voice_states ?? []) {
50
+ this.voiceStateUpdate({ ...state, guild_id: packet.d.id });
51
+ }
52
+ }
53
+ });
54
+ }
55
+ }
56
+ exports.Manager = Manager;
57
+ //# sourceMappingURL=cloudstorm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cloudstorm.js","sourceRoot":"","sources":["../src/cloudstorm.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,2CAAuD;AAKvD,0CAAwB;AAExB,MAAa,OAAQ,SAAQ,iBAAW;IACD;IAAnC,YAAmC,MAAc,EAAE,KAAiC,EAAE,OAAuB;QACzG,KAAK,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QADS,WAAM,GAAN,MAAM,CAAQ;QAG7C,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE;YACZ,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,EAAE;gBACjB,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,WAAW;oBAAE,OAAO,KAAK,CAAC;gBACnD,sCAAsC;gBACtC,MAAM,OAAO,GAAG,MAAM,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,MAAM,CAAC,EAAE,CAAC,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC;gBAE5G,MAAM,CAAC,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,MAAM,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;gBAE3G,IAAI,CAAC,EAAE;oBACH,CAAC,CAAC,SAAS,CAAC,QAAQ,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;oBACzC,OAAO,IAAI,CAAC;iBACf;qBAAM;oBACH,OAAO,KAAK,CAAC;iBAChB;YACL,CAAC,CAAC;SACL;QAED,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,EAAE;YACxB,IAAI,MAAM,CAAC,CAAC,KAAK,qBAAqB,EAAE;gBACpC,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAsB,CAAC,CAAC;aACzD;iBAAM,IAAI,MAAM,CAAC,CAAC,KAAK,oBAAoB,EAAE;gBAC1C,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAqB,CAAC,CAAC;aACvD;iBAAM,IAAI,MAAM,CAAC,CAAC,KAAK,cAAc,EAAE;gBACpC,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,CAAC,CAAC,YAAY,IAAI,EAAE,EAAE;oBAC7C,IAAI,CAAC,gBAAgB,CAAC,EAAE,GAAG,KAAK,EAAE,QAAQ,EAAG,MAAM,CAAC,CAAgC,CAAC,EAAE,EAAsB,CAAC,CAAC;iBAClH;aACJ;QACL,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AAjCD,0BAiCC"}
@@ -0,0 +1,8 @@
1
+ import { Manager as BaseManager } from "./lib/Manager";
2
+ import type { ManagerOptions, LavalinkNodeOptions } from "./lib/Types";
3
+ import type { ClusterClient, ShardClient } from "detritus-client";
4
+ export * from "./index";
5
+ export declare class Manager extends BaseManager {
6
+ readonly client: ClusterClient | ShardClient;
7
+ constructor(client: ClusterClient | ShardClient, nodes: Array<LavalinkNodeOptions>, options: ManagerOptions);
8
+ }
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.Manager = void 0;
18
+ const Manager_1 = require("./lib/Manager");
19
+ __exportStar(require("./index"), exports);
20
+ class Manager extends Manager_1.Manager {
21
+ client;
22
+ constructor(client, nodes, options) {
23
+ super(nodes, options);
24
+ this.client = client;
25
+ if (!this.send) {
26
+ this.send = packet => {
27
+ const asCluster = this.client;
28
+ const asShard = this.client;
29
+ if (asShard.guilds) {
30
+ asShard.gateway.send(packet.op, packet.d);
31
+ return true;
32
+ }
33
+ else if (asCluster.shards) {
34
+ const shard = asCluster.shards.find(c => c.guilds.has(packet.d.guild_id));
35
+ if (shard) {
36
+ shard.gateway.send(packet.op, packet.d);
37
+ return true;
38
+ }
39
+ else {
40
+ return false;
41
+ }
42
+ }
43
+ };
44
+ }
45
+ client.on("raw", packet => {
46
+ if (packet.t === "VOICE_SERVER_UPDATE")
47
+ this.voiceServerUpdate(packet.d);
48
+ else if (packet.t === "VOICE_STATE_UPDATE")
49
+ this.voiceStateUpdate(packet.d);
50
+ else if (packet.t === "GUILD_CREATE")
51
+ for (const state of packet.d.voice_states ?? [])
52
+ this.voiceStateUpdate({ ...state, guild_id: packet.d.id });
53
+ });
54
+ }
55
+ }
56
+ exports.Manager = Manager;
57
+ //# sourceMappingURL=detritus.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"detritus.js","sourceRoot":"","sources":["../src/detritus.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,2CAAuD;AAKvD,0CAAwB;AAExB,MAAa,OAAQ,SAAQ,iBAAW;IACD;IAAnC,YAAmC,MAAmC,EAAE,KAAiC,EAAE,OAAuB;QAC9H,KAAK,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QADS,WAAM,GAAN,MAAM,CAA6B;QAGlE,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE;YACZ,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,EAAE;gBACjB,MAAM,SAAS,GAAG,IAAI,CAAC,MAAuB,CAAC;gBAC/C,MAAM,OAAO,GAAG,IAAI,CAAC,MAAqB,CAAC;gBAE3C,IAAI,OAAO,CAAC,MAAM,EAAE;oBAChB,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;oBAC1C,OAAO,IAAI,CAAC;iBACf;qBAAM,IAAI,SAAS,CAAC,MAAM,EAAE;oBACzB,MAAM,KAAK,GAAG,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC;oBAC1E,IAAI,KAAK,EAAE;wBACP,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;wBACxC,OAAO,IAAI,CAAC;qBACf;yBAAM;wBACH,OAAO,KAAK,CAAC;qBAChB;iBACJ;YACL,CAAC,CAAC;SACL;QAED,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC,EAAE;YACtB,IAAI,MAAM,CAAC,CAAC,KAAK,qBAAqB;gBAAE,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;iBACpE,IAAI,MAAM,CAAC,CAAC,KAAK,oBAAoB;gBAAE,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;iBACvE,IAAI,MAAM,CAAC,CAAC,KAAK,cAAc;gBAAE,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,CAAC,CAAC,YAAY,IAAI,EAAE;oBAAE,IAAI,CAAC,gBAAgB,CAAC,EAAE,GAAG,KAAK,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QACtJ,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AA9BD,0BA8BC"}
@@ -0,0 +1,8 @@
1
+ import { Manager as BaseManager } from "./lib/Manager";
2
+ import type { ManagerOptions, LavalinkNodeOptions } from "./lib/Types";
3
+ import { Client } from "discord.js";
4
+ export * from "./index";
5
+ export declare class Manager extends BaseManager {
6
+ readonly client: Client;
7
+ constructor(client: Client, nodes: Array<LavalinkNodeOptions>, options?: ManagerOptions);
8
+ }
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.Manager = void 0;
18
+ const Manager_1 = require("./lib/Manager");
19
+ const discord_js_1 = require("discord.js");
20
+ __exportStar(require("./index"), exports);
21
+ class Manager extends Manager_1.Manager {
22
+ client;
23
+ constructor(client, nodes, options) {
24
+ if (!options)
25
+ options = {};
26
+ if (!options.user)
27
+ options.user = client.user?.id;
28
+ super(nodes, options);
29
+ this.client = client;
30
+ if (!this.send) {
31
+ this.send = packet => {
32
+ const guild = this.client.guilds.cache.get(packet.d.guild_id);
33
+ if (guild) {
34
+ guild.shard.send(packet);
35
+ return true;
36
+ }
37
+ else {
38
+ return false;
39
+ }
40
+ };
41
+ }
42
+ client.ws
43
+ .on(discord_js_1.GatewayDispatchEvents.VoiceServerUpdate, this.voiceServerUpdate.bind(this))
44
+ .on(discord_js_1.GatewayDispatchEvents.VoiceStateUpdate, this.voiceStateUpdate.bind(this))
45
+ .on(discord_js_1.GatewayDispatchEvents.GuildCreate, data => {
46
+ for (const state of data.voice_states ?? [])
47
+ this.voiceStateUpdate({ ...state, guild_id: data.id });
48
+ });
49
+ }
50
+ }
51
+ exports.Manager = Manager;
52
+ //# sourceMappingURL=discord.js.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"discord.js.js","sourceRoot":"","sources":["../src/discord.js.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,2CAAuD;AAGvD,2CAA2D;AAE3D,0CAAwB;AAExB,MAAa,OAAQ,SAAQ,iBAAW;IACD;IAAnC,YAAmC,MAAc,EAAE,KAAiC,EAAE,OAAwB;QAC1G,IAAI,CAAC,OAAO;YAAE,OAAO,GAAG,EAAE,CAAC;QAC3B,IAAI,CAAC,OAAO,CAAC,IAAI;YAAE,OAAO,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC;QAClD,KAAK,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QAHS,WAAM,GAAN,MAAM,CAAQ;QAK7C,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE;YACZ,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,EAAE;gBACjB,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;gBAC9D,IAAI,KAAK,EAAE;oBACP,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;oBACzB,OAAO,IAAI,CAAC;iBACf;qBAAM;oBACH,OAAO,KAAK,CAAC;iBAChB;YACL,CAAC,CAAC;SACL;QAED,MAAM,CAAC,EAAE;aACJ,EAAE,CAAC,kCAAqB,CAAC,iBAAiB,EAAE,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;aAC9E,EAAE,CAAC,kCAAqB,CAAC,gBAAgB,EAAE,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;aAC5E,EAAE,CAAC,kCAAqB,CAAC,WAAW,EAAE,IAAI,CAAC,EAAE;YAC1C,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,YAAY,IAAI,EAAE;gBAAE,IAAI,CAAC,gBAAgB,CAAC,EAAE,GAAG,KAAK,EAAE,QAAQ,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC;QACxG,CAAC,CAAC,CAAC;IACX,CAAC;CACJ;AAzBD,0BAyBC"}
package/dist/eris.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ import { Manager as BaseManager } from "./lib/Manager";
2
+ import type { ManagerOptions, LavalinkNodeOptions } from "./lib/Types";
3
+ import type { Client } from "eris";
4
+ export * from "./index";
5
+ export declare class Manager extends BaseManager {
6
+ readonly client: Client;
7
+ constructor(client: Client, nodes: Array<LavalinkNodeOptions>, options?: ManagerOptions);
8
+ }
package/dist/eris.js ADDED
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.Manager = void 0;
18
+ const Manager_1 = require("./lib/Manager");
19
+ __exportStar(require("./index"), exports);
20
+ class Manager extends Manager_1.Manager {
21
+ client;
22
+ constructor(client, nodes, options) {
23
+ if (!options)
24
+ options = {};
25
+ if (!options.user)
26
+ options.user = client.user?.id;
27
+ super(nodes, options);
28
+ this.client = client;
29
+ if (!this.send) {
30
+ this.send = packet => {
31
+ const guild = this.client.guilds.get(packet.d.guild_id);
32
+ if (guild) {
33
+ guild.shard.sendWS(packet.op, packet.d);
34
+ return true;
35
+ }
36
+ else {
37
+ return false;
38
+ }
39
+ };
40
+ }
41
+ client.on("rawWS", (packet) => {
42
+ if (packet.t === "VOICE_SERVER_UPDATE")
43
+ this.voiceServerUpdate(packet.d);
44
+ else if (packet.t === "VOICE_STATE_UPDATE")
45
+ this.voiceStateUpdate(packet.d);
46
+ else if (packet.t === "GUILD_CREATE")
47
+ for (const state of packet.d.voice_states ?? [])
48
+ this.voiceStateUpdate({ ...state, guild_id: packet.d.id });
49
+ });
50
+ }
51
+ }
52
+ exports.Manager = Manager;
53
+ //# sourceMappingURL=eris.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eris.js","sourceRoot":"","sources":["../src/eris.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,2CAAuD;AAKvD,0CAAwB;AAExB,MAAa,OAAQ,SAAQ,iBAAW;IACD;IAAnC,YAAmC,MAAc,EAAE,KAAiC,EAAE,OAAwB;QAC1G,IAAI,CAAC,OAAO;YAAE,OAAO,GAAG,EAAE,CAAC;QAC3B,IAAI,CAAC,OAAO,CAAC,IAAI;YAAE,OAAO,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC;QAClD,KAAK,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QAHS,WAAM,GAAN,MAAM,CAAQ;QAK7C,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE;YACZ,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,EAAE;gBACjB,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;gBACxD,IAAI,KAAK,EAAE;oBACP,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;oBACxC,OAAO,IAAI,CAAC;iBACf;qBAAM;oBACH,OAAO,KAAK,CAAC;iBAChB;YACL,CAAC,CAAC;SACL;QAED,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,MAAqB,EAAE,EAAE;YACzC,IAAI,MAAM,CAAC,CAAC,KAAK,qBAAqB;gBAAE,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;iBACpE,IAAI,MAAM,CAAC,CAAC,KAAK,oBAAoB;gBAAE,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;iBACvE,IAAI,MAAM,CAAC,CAAC,KAAK,cAAc;gBAAE,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,CAAC,CAAC,YAAY,IAAI,EAAE;oBAAE,IAAI,CAAC,gBAAgB,CAAC,EAAE,GAAG,KAAK,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QACtJ,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AAxBD,0BAwBC"}
package/dist/index.d.ts CHANGED
File without changes
package/dist/index.js CHANGED
@@ -1,14 +1,18 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
8
12
  }));
9
13
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
- for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
11
- }
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
12
16
  Object.defineProperty(exports, "__esModule", { value: true });
13
17
  __exportStar(require("./lib/LavalinkNode"), exports);
14
18
  __exportStar(require("./lib/Player"), exports);
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qDAAmC;AACnC,+CAA6B;AAC7B,gDAA8B;AAC9B,6CAA2B;AAC3B,8CAA4B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qDAAmC;AACnC,+CAA6B;AAC7B,gDAA8B;AAC9B,6CAA2B;AAC3B,8CAA4B"}
@@ -1,31 +1,105 @@
1
1
  import WebSocket from "ws";
2
- import { Manager } from "./Manager";
3
- import { LavalinkNodeOptions, LavalinkStats } from "./Types";
2
+ import type { Manager } from "./Manager";
3
+ import type { LavalinkNodeOptions } from "./Types";
4
+ import type { Stats } from "lavalink-types";
5
+ /**
6
+ * The class for handling everything to do with connecting to Lavalink
7
+ */
4
8
  export declare class LavalinkNode {
5
9
  manager: Manager;
10
+ /**
11
+ * The id of the LavalinkNode so Nodes are better organized
12
+ */
6
13
  id: string;
14
+ /**
15
+ * The host of the LavalinkNode, this could be a ip or domain.
16
+ */
7
17
  host: string;
18
+ /**
19
+ * The port of the LavalinkNode
20
+ */
8
21
  port: number | string;
22
+ /**
23
+ * The interval that the node will try to reconnect to lavalink at in milliseconds
24
+ */
9
25
  reconnectInterval: number;
26
+ /**
27
+ * The password of the lavalink node
28
+ */
10
29
  password: string;
30
+ /**
31
+ * The WebSocket instance for this LavalinkNode
32
+ */
11
33
  ws: WebSocket | null;
12
- stats: LavalinkStats;
34
+ /**
35
+ * The statistics of the LavalinkNode
36
+ */
37
+ stats: Stats;
38
+ /**
39
+ * The resume key to send to the LavalinkNode so you can resume properly
40
+ */
13
41
  resumeKey?: string;
42
+ /**
43
+ * The resume timeout
44
+ */
14
45
  resumeTimeout: number;
46
+ /**
47
+ * Extra info attached to your node, not required and is not sent to lavalink, purely for you.
48
+ */
15
49
  state?: any;
50
+ /**
51
+ * The major version of the LavaLink node as indicated by /version
52
+ */
53
+ version?: number;
54
+ /**
55
+ * The session ID sent by LavaLink on connect. Used for some REST routes
56
+ */
57
+ sessionId?: string;
58
+ /**
59
+ * The reconnect timeout
60
+ * @private
61
+ */
16
62
  private _reconnect?;
17
- private _queue;
63
+ /**
64
+ * The base of the connection to lavalink
65
+ * @param manager The manager that created the LavalinkNode
66
+ * @param options The options of the LavalinkNode {@link LavalinkNodeOptions}
67
+ */
18
68
  constructor(manager: Manager, options: LavalinkNodeOptions);
19
- connect(): Promise<WebSocket | boolean>;
20
- send(msg: object): Promise<boolean>;
21
- configureResuming(key: string, timeout?: number): Promise<boolean>;
69
+ /**
70
+ * Connects the node to Lavalink
71
+ */
72
+ connect(): Promise<WebSocket>;
73
+ /**
74
+ * Destroys the connection to the Lavalink Websocket
75
+ */
22
76
  destroy(): boolean;
77
+ /**
78
+ * Whether or not the node is connected
79
+ */
23
80
  get connected(): boolean;
81
+ /**
82
+ * A private function for handling the open event from WebSocket
83
+ */
24
84
  private onOpen;
85
+ /**
86
+ * Private function for handling the message event from WebSocket
87
+ * @param data The data that came from lavalink
88
+ */
25
89
  private onMessage;
90
+ /**
91
+ * Private function for handling the error event from WebSocket
92
+ * @param error WebSocket error
93
+ */
26
94
  private onError;
95
+ /**
96
+ * Private function for handling the close event from WebSocket
97
+ * @param code WebSocket close code
98
+ * @param reason WebSocket close reason
99
+ */
27
100
  private onClose;
101
+ /**
102
+ * Handles reconnecting if something happens and the node discounnects
103
+ */
28
104
  private reconnect;
29
- private _send;
30
- private _queueFlush;
31
105
  }