From 267d8d29fa7053c17d4e5819477b13db1de32666 Mon Sep 17 00:00:00 2001 From: KChi <59391215+KagChi@users.noreply.github.com> Date: Sat, 12 Mar 2022 15:32:11 +0700 Subject: [PATCH] feat: add utilities --- package.json | 2 +- src/Structures/Kirishima.ts | 12 ------------ src/Structures/KirishimaPlayer.ts | 6 +++--- src/Util.ts | 24 ++++++++++++++++++++++++ src/index.ts | 1 + 5 files changed, 29 insertions(+), 16 deletions(-) create mode 100644 src/Util.ts diff --git a/package.json b/package.json index 1d9fb40..a219fa3 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "main": "dist/index.js", "module": "dist/index.mjs", "description": "Kirishima is extendable, fast, flexible, asynchronous lavalink client", - "version": "0.1.0", + "version": "0.2.0", "license": "GPL-3.0", "repository": { "url": "https://github.com/kirishima-ship/core" diff --git a/src/Structures/Kirishima.ts b/src/Structures/Kirishima.ts index bf48199..5b9f986 100644 --- a/src/Structures/Kirishima.ts +++ b/src/Structures/Kirishima.ts @@ -136,16 +136,4 @@ export class Kirishima extends EventEmitter { private defaultFetchPlayerHandler(guildId: string) { return this.players!.get(guildId); } - - public static createVoiceChannelPayload(options: KirishimaPlayerOptions, leave?: boolean) { - return { - op: GatewayOpcodes.VoiceStateUpdate, - d: { - guild_id: options.guildId, - channel_id: leave ? null : options.voiceId, - self_deaf: (options.selfDeaf ??= false), - self_mute: (options.selfMute ??= false) - } - }; - } } diff --git a/src/Structures/KirishimaPlayer.ts b/src/Structures/KirishimaPlayer.ts index d71e72b..afdc3a0 100644 --- a/src/Structures/KirishimaPlayer.ts +++ b/src/Structures/KirishimaPlayer.ts @@ -1,6 +1,6 @@ import { Kirishima } from './Kirishima'; import type { KirishimaPlayerOptions } from '../typings/index'; -import type { KirishimaNode } from '../index'; +import { createVoiceChannelJoinPayload, KirishimaNode } from '../index'; import { GatewayVoiceServerUpdateDispatch, GatewayVoiceStateUpdateDispatch } from 'discord-api-types/gateway/v9'; import { ChannelMixEqualizer, @@ -25,12 +25,12 @@ export class KirishimaPlayer { public constructor(public options: KirishimaPlayerOptions, public kirishima: Kirishima, public node: KirishimaNode) {} public async connect(): Promise { - await this.kirishima.options.send(this.options.guildId, Kirishima.createVoiceChannelPayload(this.options)); + await this.kirishima.options.send(this.options.guildId, createVoiceChannelJoinPayload(this.options)); return this; } public async disconnect(): Promise { - await this.kirishima.options.send(this.options.guildId, Kirishima.createVoiceChannelPayload(this.options, true)); + await this.kirishima.options.send(this.options.guildId, createVoiceChannelJoinPayload(this.options, true)); return this; } diff --git a/src/Util.ts b/src/Util.ts new file mode 100644 index 0000000..aeeade3 --- /dev/null +++ b/src/Util.ts @@ -0,0 +1,24 @@ +import { GatewayOpcodes } from 'discord-api-types'; +import { KirishimaPartialTrack } from './Structures/Track/KirishimaPartialTrack'; +import { KirishimaTrack } from './Structures/Track/KirishimaTrack'; +import { KirishimaPlayerOptions } from './typings'; + +export function isPartialTrack(track: unknown): track is KirishimaPartialTrack { + return track instanceof KirishimaPartialTrack; +} + +export function isTrack(track: unknown): track is KirishimaTrack { + return track instanceof KirishimaTrack; +} + +export function createVoiceChannelJoinPayload(options: KirishimaPlayerOptions, leave?: boolean) { + return { + op: GatewayOpcodes.VoiceStateUpdate, + d: { + guild_id: options.guildId, + channel_id: leave ? null : options.voiceId, + self_deaf: (options.selfDeaf ??= false), + self_mute: (options.selfMute ??= false) + } + }; +} diff --git a/src/index.ts b/src/index.ts index 8a42d5d..24c3883 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,3 +6,4 @@ export * from './Structures/Track/KirishimaPartialTrack'; export * from './Structures/Track/KirishimaTrack'; export * from './Structures/KirishimaFilter'; export * from './typings/index'; +export * from './Util';