Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Update to DJS v13 #70

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,20 @@
"devDependencies": {
"@types/node": "^14.0.14",
"@types/ws": "^7.2.6",
"@typescript-eslint/eslint-plugin": "^2.33.0",
"@typescript-eslint/parser": "^2.33.0",
"discord.js": "^12.2.0",
"@typescript-eslint/eslint-plugin": "^4.28.2",
"@typescript-eslint/parser": "^4.28.2",
"discord.js": "discordjs/discord.js",
"eslint": "^7.3.1",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^4.2.1",
"typescript": "^3.9.5"
},
"peerDependencies": {
"discord.js": "^12.2.0"
"discord.js": "discordjs/discord.js"
},
"files": [
"dist",
"LICENCE"
"LICENSE"
],
"engines": {
"node": ">=10",
Expand Down
48 changes: 32 additions & 16 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,54 @@
/* eslint-disable @typescript-eslint/ban-ts-ignore */
import { Manager as LavacordManager, LavalinkNodeOptions, DiscordPacket, ManagerOptions } from "lavacord";
import { Client as DiscordClient } from "discord.js";
import {
Manager as LavacordManager,
LavalinkNodeOptions,
DiscordPacket,
ManagerOptions
} from "lavacord";
import {
Client as DiscordClient,
Collection,
Guild,
Snowflake
} from "discord.js";

export * from "lavacord";

export class Manager extends LavacordManager {
public constructor(readonly client: DiscordClient, nodes: LavalinkNodeOptions[], options?: ManagerOptions) {
public constructor(
readonly client: DiscordClient,
nodes: LavalinkNodeOptions[],
options?: ManagerOptions
) {
super(nodes, options || {});

this.send = packet => {
if (this.client.guilds.cache) {
const guild = this.client.guilds.cache.get(packet.d.guild_id);
if (guild) return guild.shard.send(packet);
} else {
// @ts-ignore
const guild = this.client.guilds.get(packet.d.guild_id);
// @ts-ignore
if (guild) return typeof this.client.ws.send === "function" ? this.client.ws.send(packet) : guild.shard.send(packet);
const guild = (
this.client.guilds.cache as Collection<Snowflake, Guild>
).get(packet.d.guild_id);

if (guild) return guild.shard.send(packet);
}
};

client.once("ready", () => {
this.user = client.user!.id;
if (!options) {
this.user = client.user?.id as Snowflake;
this.shards = client.options.shardCount || 1;
});
}

if (client.guilds.cache && typeof (this.client.ws as any).send === "undefined") {
if (client.guilds.cache) {
client.ws
.on("VOICE_SERVER_UPDATE", this.voiceServerUpdate.bind(this))
.on("VOICE_STATE_UPDATE", this.voiceStateUpdate.bind(this))
.on("GUILD_CREATE", async data => {
for (const state of data.voice_states) await this.voiceStateUpdate({ ...state, guild_id: data.id });
for (const state of data.voice_states) {
await this.voiceStateUpdate({ ...state, guild_id: data.id });
}
});
} else {
// @ts-ignore
client.on("raw", async (packet: DiscordPacket) => {
switch (packet.t) {
case "VOICE_SERVER_UPDATE":
Expand All @@ -43,11 +58,12 @@ export class Manager extends LavacordManager {
await this.voiceStateUpdate(packet.d);
break;
case "GUILD_CREATE":
for (const state of packet.d.voice_states) await this.voiceStateUpdate({ ...state, guild_id: packet.d.id });
for (const state of packet.d.voice_states) {
await this.voiceStateUpdate({ ...state, guild_id: packet.d.id });
}
break;
}
});
}
}

}
Loading