Skip to content

Commit

Permalink
Merge pull request #59 from RainyXeon/dev
Browse files Browse the repository at this point in the history
doc: correcting some missinfomation
  • Loading branch information
RainyXeon authored May 25, 2024
2 parents fb8a936 + 3a5b63d commit 5f11a97
Show file tree
Hide file tree
Showing 24 changed files with 128 additions and 39 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rainlink",
"version": "1.0.4",
"version": "1.0.5",
"description": "Another lavalink wrapper but focus on stability and rich features",
"repository": {
"type": "git",
Expand Down
4 changes: 4 additions & 0 deletions src/Drivers/AbstractDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import { RainlinkWebsocket } from '../Utilities/RainlinkWebsocket';
import { RainlinkPlayer } from '../Player/RainlinkPlayer';
import { Rainlink } from '../Rainlink';

/**
* The abstract class for developing driver
* to use another audio sending server.
*/
export abstract class AbstractDriver {
/** The id for the driver*/
abstract id: string;
Expand Down
3 changes: 3 additions & 0 deletions src/Interface/Manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import { RainlinkFilter } from '../Player/RainlinkFilter';
*/
export type Constructor<T> = new (...args: any[]) => T;

/**
* The structures options interface for custom class/structures
*/
export interface Structures {
/**
* A custom structure that extends the RainlinkRest class
Expand Down
4 changes: 4 additions & 0 deletions src/Interface/Node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export interface LavalinkNodeStatsResponse {
uptime: number;
}

/** The audio sending node infomation interface */
export type NodeInfo = {
version: NodeInfoVersion;
buildTime: number;
Expand All @@ -56,6 +57,7 @@ export type NodeInfo = {
plugins: NodeInfoPlugin[];
};

/** The audio sending node version infomation interface */
export type NodeInfoVersion = {
semver: string;
major: number;
Expand All @@ -65,12 +67,14 @@ export type NodeInfoVersion = {
build?: string;
};

/** The audio sending node git infomation interface */
export type NodeInfoGit = {
branch: string;
commit: string;
commitTime: number;
};

/** The audio sending node plugin infomation interface */
export type NodeInfoPlugin = {
name: string;
version: string;
Expand Down
6 changes: 6 additions & 0 deletions src/Interface/Player.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/**
* The voice channel options interface for creating player
*/
export interface VoiceChannelOptions {
guildId: string;
shardId: number;
Expand All @@ -9,6 +12,9 @@ export interface VoiceChannelOptions {
mute?: boolean;
}

/**
* The filter options interface for using with updatePlyer()
*/
export interface FilterOptions {
volume?: number;
equalizer?: Band[];
Expand Down
22 changes: 22 additions & 0 deletions src/Library/AbstractLibrary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import { RainlinkNodeOptions } from '../Interface/Manager';
import { Rainlink } from '../Rainlink';
export const AllowedPackets = ['VOICE_STATE_UPDATE', 'VOICE_SERVER_UPDATE'];

/**
* The abstract class for developing library
*/
export abstract class AbstractLibrary {
protected readonly client: any;
protected manager: Rainlink | null;
Expand All @@ -23,17 +26,36 @@ export abstract class AbstractLibrary {
for (const node of nodes) this.manager?.nodes.add(node);
}

/** @ignore */
public set(manager: Rainlink): AbstractLibrary {
this.manager = manager;
return this;
}

/**
* A getter where the lib stores the client user (the one logged in as a bot) id
* @returns string
*/
abstract getId(): string;

/**
* For dealing ws with lavalink server
* @returns number
*/
abstract getShardCount(): number;

/**
* Where your library send packets to Discord Gateway
* @param shardId The current shard Id
* @param payload The payload data to request with discord gateway
* @param important If this payload important or not
*/
abstract sendPacket(shardId: number, payload: any, important: boolean): void;

/**
* Listen attaches the event listener to the library you are using
* @param nodes All current nodes in the array
*/
abstract listen(nodes: RainlinkNodeOptions[]): void;

protected raw(packet: any): void {
Expand Down
4 changes: 0 additions & 4 deletions src/Library/DiscordJS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,18 @@ import { AbstractLibrary } from './AbstractLibrary';
import { RainlinkNodeOptions } from '../Interface/Manager';

export class DiscordJS extends AbstractLibrary {
// sendPacket is where your library send packets to Discord Gateway
public sendPacket(shardId: number, payload: any, important: boolean): void {
return this.client.ws.shards.get(shardId)?.send(payload, important);
}

// getId is a getter where the lib stores the client user (the one logged in as a bot) id
public getId(): string {
return this.client.user.id;
}

// getShardCount is for dealing ws with lavalink server
public getShardCount(): number {
return this.client.shard && this.client.shard.count ? this.client.shard.count : 1;
}

// Listen attaches the event listener to the library you are using
public listen(nodes: RainlinkNodeOptions[]): void {
this.client.once('ready', () => this.ready(nodes));
this.client.on('raw', (packet: any) => this.raw(packet));
Expand Down
6 changes: 0 additions & 6 deletions src/Library/ErisJS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,20 @@ import { AbstractLibrary } from './AbstractLibrary';
import { RainlinkNodeOptions } from '../Interface/Manager';

export class ErisJS extends AbstractLibrary {
// sendPacket is where your library send packets to Discord Gateway
public sendPacket(shardId: number, payload: any, important: boolean): void {
return this.client.shards.get(shardId)?.sendWS(payload.op, payload.d, important);
}

// getId is a getter where the lib stores the client user (the one logged in as a bot) id
public getId(): string {
return this.client.user.id;
}

// getShardCount is for dealing ws with lavalink server
public getShardCount(): number {
return this.client.shards && this.client.shards.size ? this.client.shards.size : 1;
}

// Listen attaches the event listener to the library you are using
public listen(nodes: RainlinkNodeOptions[]): void {
// Only attach to ready event once, refer to your library for its ready event
this.client.once('ready', () => this.ready(nodes));
// Attach to the raw websocket event, this event must be 1:1 on spec with dapi (most libs implement this)
this.client.on('rawWS', (packet: any) => this.raw(packet));
}
}
6 changes: 0 additions & 6 deletions src/Library/OceanicJS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,20 @@ import { AbstractLibrary } from './AbstractLibrary';
import { RainlinkNodeOptions } from '../Interface/Manager';

export class OceanicJS extends AbstractLibrary {
// sendPacket is where your library send packets to Discord Gateway
public sendPacket(shardId: number, payload: any, important: boolean): void {
return this.client.shards.get(shardId)?.send(payload.op, payload.d, important);
}

// getId is a getter where the lib stores the client user (the one logged in as a bot) id
public getId(): string {
return this.client.user.id;
}

// getShardCount is for dealing ws with lavalink server
public getShardCount(): number {
return this.client.shards && this.client.shards.size ? this.client.shards.size : 1;
}

// Listen attaches the event listener to the library you are using
public listen(nodes: RainlinkNodeOptions[]): void {
// Only attach to ready event once, refer to your library for its ready event
this.client.once('ready', () => this.ready(nodes));
// Attach to the raw websocket event, this event must be 1:1 on spec with dapi (most libs implement this)
this.client.on('packet', (packet: any) => this.raw(packet));
}
}
6 changes: 0 additions & 6 deletions src/Library/Seyfert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,22 @@ import { AbstractLibrary } from './AbstractLibrary';
import { RainlinkNodeOptions } from '../Interface/Manager';

export class Seyfert extends AbstractLibrary {
// sendPacket is where your library send packets to Discord Gateway
public sendPacket(shardId: number, payload: any): void {
return this.client.gateway.send(shardId, payload);
}
// getId is a getter where the lib stores the client user (the one logged in as a bot) id
public getId(): string {
return this.client.botId;
}

// getShardCount is for dealing ws with lavalink server
public getShardCount(): number {
return this.client.gateway.totalShards;
}

// Listen attaches the event listener to the library you are using
public listen(nodes: RainlinkNodeOptions[]): void {
this.client.events.values.RAW = {
data: { name: 'raw' },
run: (packet: any) => {
// Only attach to ready event once, refer to your library for its ready event
if (packet.t === 'READY') return this.ready(nodes);
// Attach to the raw websocket event, this event must be 1:1 on spec with dapi (most libs implement this)
return this.raw(packet);
},
};
Expand Down
1 change: 1 addition & 0 deletions src/Manager/RainlinkNodeManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { RainlinkNode } from '../Node/RainlinkNode';
import { Rainlink } from '../Rainlink';
import { RainlinkDatabase } from '../Utilities/RainlinkDatabase';

/** The node manager class for managing all audio sending server/node */
export class RainlinkNodeManager extends RainlinkDatabase<RainlinkNode> {
/** The rainlink manager */
public manager: Rainlink;
Expand Down
1 change: 1 addition & 0 deletions src/Manager/RainlinkPlayerManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { RainlinkPlayer } from '../Player/RainlinkPlayer';
import { Rainlink } from '../Rainlink';
import { RainlinkDatabase } from '../Utilities/RainlinkDatabase';

/** The node manager class for managing all active players */
export class RainlinkPlayerManager extends RainlinkDatabase<RainlinkPlayer> {
/** The rainlink manager */
public manager: Rainlink;
Expand Down
1 change: 1 addition & 0 deletions src/Node/RainlinkNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { AbstractDriver } from '../Drivers/AbstractDriver';
import { Lavalink4 } from '../Drivers/Lavalink4';
import { RainlinkWebsocket } from '../Utilities/RainlinkWebsocket';

/** The node manager class for managing current audio sending server/node */
export class RainlinkNode {
/** The rainlink manager */
public manager: Rainlink;
Expand Down
4 changes: 4 additions & 0 deletions src/Node/RainlinkRest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ import {
} from '../Interface/Rest';
import { NodeInfo } from '../Interface/Node';

/**
* The rest class for get and calling
* from audio sending node/server REST API
*/
export class RainlinkRest {
/** The rainlink manager */
public manager: Rainlink;
Expand Down
14 changes: 14 additions & 0 deletions src/Player/RainlinkFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,15 @@ import {
} from '../Interface/Player';
import { RainlinkPlayer } from './RainlinkPlayer';

/**
* This class is for set, clear and managing filter
*/
export class RainlinkFilter {
/**
* Current filter config
*/
public currentFilter: FilterOptions | null = null;

constructor(protected player: RainlinkPlayer) {}

/**
Expand All @@ -43,6 +51,8 @@ export class RainlinkFilter {
},
});

this.currentFilter = filterData;

this.debug(
filter !== 'clear'
? `${filter} filter has been successfully set.`
Expand All @@ -66,6 +76,8 @@ export class RainlinkFilter {
},
});

this.currentFilter = null;

this.debug('All filters have been successfully reset to their default positions.');

return this.player;
Expand Down Expand Up @@ -166,6 +178,8 @@ export class RainlinkFilter {
},
});

this.currentFilter = filter;

this.debug('Custom filter has been successfully set. Data: ' + util.inspect(filter));

return this.player;
Expand Down
3 changes: 3 additions & 0 deletions src/Player/RainlinkPlayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import { EventEmitter } from 'node:events';
import { RainlinkDatabase } from '../Utilities/RainlinkDatabase.js';
import { RainlinkFilter } from './RainlinkFilter.js';

/**
* A class for managing player action.
*/
export class RainlinkPlayer extends EventEmitter {
/**
* Main manager class
Expand Down
3 changes: 3 additions & 0 deletions src/Player/RainlinkQueue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { Rainlink } from '../Rainlink';
import { RainlinkPlayer } from './RainlinkPlayer';
import { RainlinkTrack } from './RainlinkTrack';

/**
* A class for managing track queue
*/
export class RainlinkQueue extends Array<RainlinkTrack> {
/** Rainlink manager */
manager: Rainlink;
Expand Down
3 changes: 3 additions & 0 deletions src/Player/RainlinkTrack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import { RawTrack } from '../Interface/Rest';
import { ResolveOptions } from '../Interface/Track';
import { RainlinkPlayer } from './RainlinkPlayer';

/**
* A class for managing track info
*/
export class RainlinkTrack {
/** Encoded string from lavalink */
encoded: string;
Expand Down
1 change: 1 addition & 0 deletions src/Rainlink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ export declare interface Rainlink {
// ------------------------- OFF EVENT ------------------------- //
}

/** The heart of Rainlink. Manage all package action */
export class Rainlink extends EventEmitter {
/**
* Discord library connector
Expand Down
Loading

0 comments on commit 5f11a97

Please sign in to comment.