Skip to content

Commit

Permalink
feat: add utilities
Browse files Browse the repository at this point in the history
  • Loading branch information
KagChi committed Mar 12, 2022
1 parent 320ebc4 commit 267d8d2
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 0 additions & 12 deletions src/Structures/Kirishima.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
};
}
}
6 changes: 3 additions & 3 deletions src/Structures/KirishimaPlayer.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -25,12 +25,12 @@ export class KirishimaPlayer {
public constructor(public options: KirishimaPlayerOptions, public kirishima: Kirishima, public node: KirishimaNode) {}

public async connect(): Promise<KirishimaPlayer> {
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<KirishimaPlayer> {
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;
}

Expand Down
24 changes: 24 additions & 0 deletions src/Util.ts
Original file line number Diff line number Diff line change
@@ -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)
}
};
}
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

0 comments on commit 267d8d2

Please sign in to comment.