generated from kirishima-ship/template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
50 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { GatewayVoiceServerUpdateDispatch, GatewayVoiceStateUpdateDispatch } from 'discord-api-types/gateway/v9'; | ||
import { WebsocketOpEnum } from 'lavalink-api-types'; | ||
import { KirishimaPlayerOptions, Kirishima, KirishimaNode, createVoiceChannelJoinPayload } from '..'; | ||
|
||
export class BasePlayer { | ||
public voiceServer: GatewayVoiceServerUpdateDispatch['d'] | undefined; | ||
public voiceState: GatewayVoiceStateUpdateDispatch['d'] | undefined; | ||
|
||
public constructor(public options: KirishimaPlayerOptions, public kirishima: Kirishima, public node: KirishimaNode) {} | ||
|
||
public async connect(): Promise<BasePlayer> { | ||
await this.kirishima.options.send(this.options.guildId, createVoiceChannelJoinPayload(this.options)); | ||
return this; | ||
} | ||
|
||
public async disconnect(): Promise<BasePlayer> { | ||
await this.kirishima.options.send(this.options.guildId, createVoiceChannelJoinPayload(this.options, true)); | ||
return this; | ||
} | ||
|
||
public async setServerUpdate(packet: GatewayVoiceServerUpdateDispatch) { | ||
this.voiceServer = packet.d; | ||
if (!this.voiceState?.session_id) return; | ||
|
||
await this.node.ws.send({ | ||
op: WebsocketOpEnum.VOICE_UPDATE, | ||
guildId: this.voiceServer.guild_id, | ||
sessionId: this.voiceState.session_id, | ||
event: this.voiceServer | ||
}); | ||
} | ||
|
||
public setStateUpdate(packet: GatewayVoiceStateUpdateDispatch) { | ||
this.voiceState = packet.d; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters