Comparing version 1.1.2 to 1.2.0
@@ -5,3 +5,3 @@ declare module 'shoukaku' { | ||
export const version: string; | ||
export const version: string; | ||
@@ -18,2 +18,5 @@ export class ShoukakuError extends Error { | ||
export class ShoukakuUtil { | ||
public static mergeDefault(def: Object, given: Object); | ||
} | ||
@@ -117,7 +120,2 @@ export interface Track { | ||
export interface ShoukakuBuildOptions { | ||
id: string; | ||
shardCount?: number; | ||
} | ||
class ShoukakuConstants { | ||
@@ -130,3 +128,3 @@ static ShoukakuStatus: ShoukakuStatus; | ||
static ShoukakuNodeOptions: ShoukakuNodeOptions; | ||
static ShoukakuBuildOptions: ShoukakuBuildOptions; | ||
static ShoukakuNodes: Array<ShoukakuNodeOptions>; | ||
} | ||
@@ -307,3 +305,2 @@ | ||
public start(nodes: ShoukakuNodeOptions[], options: ShoukakuBuildOptions): void; | ||
public addNode(nodeOptions: ShoukakuNodeOptions): void; | ||
@@ -316,4 +313,3 @@ public removeNode(name: string, reason?: string): void; | ||
private _reconnect(name: string, code: number, reason: string): void; | ||
private _mergeDefault<T, J>(def: T, given: J): T & J; | ||
} | ||
} |
@@ -0,0 +0,0 @@ module.exports = { |
{ | ||
"name": "shoukaku", | ||
"version": "1.1.2", | ||
"version": "1.2.0", | ||
"description": "A lavalink client for Discord.js v12 only", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -77,3 +77,3 @@ ## Shoukaku | ||
// In this example, I will assign Shoukaku to a carrier variable. Options are the default options if nothing is specified | ||
const Carrier = new Shoukaku(client, { | ||
const Carrier = new Shoukaku(client, MyLavalinkServer, { | ||
moveOnDisconnect: false, | ||
@@ -95,8 +95,2 @@ resumable: false, | ||
client.on('ready', () => { | ||
// Connecting Shoukaku to Lavalink Nodes. | ||
Carrier.start(MyLavalinkServer, { id: client.user.id }); | ||
console.log('Bot Initialized'); | ||
}) | ||
// Now I will show you how to make a simple handler that plays a link on your chnanel. Async Await style | ||
@@ -103,0 +97,0 @@ client.on('message', async (msg) => { |
@@ -116,15 +116,10 @@ /** | ||
/** | ||
* Options that Shoukaku uses when you build the Shoukaku Instance. Init !== Build. | ||
* @typedef {Object} ShoukakuBuildOptions | ||
* @property {string} [id] Your Bot's / Client ID. | ||
* @property {number} [shardCount=1] ShardCount of your Bot, leave this alone if your bot is unsharded. | ||
* @memberof ShoukakuConstants# | ||
*/ | ||
static get ShoukakuBuildOptions() { | ||
return { | ||
id: null, | ||
shardCount: 1 | ||
}; | ||
* An array of ShoukakuNodeOptions | ||
* @typedef {Array<ShoukakuNodeOptions>} ShoukakuNodes | ||
* @memberof ShoukakuConstants# | ||
*/ | ||
static get ShoukakuNodes() { | ||
return [].push(ShoukakuConstants.ShoukakuNodeOptions); | ||
} | ||
} | ||
module.exports = ShoukakuConstants; |
@@ -0,0 +0,0 @@ /** |
@@ -0,0 +0,0 @@ /** |
@@ -0,0 +0,0 @@ const { ShoukakuStatus } = require('../constants/ShoukakuConstants.js'); |
@@ -0,0 +0,0 @@ const EventEmitter = require('events'); |
@@ -0,0 +0,0 @@ const Websocket = require('ws'); |
@@ -0,0 +0,0 @@ const Fetch = require('node-fetch'); |
@@ -0,0 +0,0 @@ const { ShoukakuStatus } = require('../constants/ShoukakuConstants.js'); |
const { RawRouter, ReconnectRouter } = require('./router/ShoukakuRouter.js'); | ||
const util = require('./util/ShoukakuUtil.js'); | ||
const constants = require('./constants/ShoukakuConstants.js'); | ||
@@ -34,5 +35,6 @@ const ShoukakuError = require('./constants/ShoukakuError.js'); | ||
* @param {external:Client} client Your Discord.js client | ||
* @param {ShoukakuConstants#ShoukakuOptions} [options=ShoukakuOptions] Options to initialize Shoukaku with | ||
* @param {ShoukakuConstants#ShoukakuNodes} nodes Lavalink Nodes where Shoukaku will try to connect to. | ||
* @param {ShoukakuConstants#ShoukakuOptions} options Options to initialize Shoukaku with | ||
*/ | ||
constructor(client, options) { | ||
constructor(client, nodes, options) { | ||
super(); | ||
@@ -62,5 +64,16 @@ if (!version.startsWith('12')) | ||
Object.defineProperty(this, 'options', { value: this._mergeDefault(constants.ShoukakuOptions, options) }); | ||
Object.defineProperty(this, 'options', { value: util.mergeDefault(constants.ShoukakuOptions, options) }); | ||
Object.defineProperty(this, 'rawRouter', { value: RawRouter.bind(this) }); | ||
Object.defineProperty(this, 'reconnectRouter', { value: ReconnectRouter.bind(this) }); | ||
this.client.once('ready', () => { | ||
this.id = this.client.user.id; | ||
this.shardCount = this.client.shard ? this.client.shard.count || this.client.shard.shardCount : 1; | ||
for (let node of nodes) { | ||
node = util.mergeDefault(constants.ShoukakuNodeOptions, node); | ||
this.addNode(node); | ||
} | ||
this.client.on('raw', this.rawRouter); | ||
this.client.on('shardReady', this.reconnectRouter); | ||
}); | ||
} | ||
@@ -131,22 +144,2 @@ /** | ||
/** | ||
* The starting point of Shoukaku, must be called in ready event in order for Shoukaku to work. | ||
* @param {ShoukakuConstants#ShoukakuNodeOptions} nodes An array of lavalink nodes for Shoukaku to connect to. | ||
* @param {ShoukakuConstants#ShoukakuBuildOptions} options Options that is need by Shoukaku to build herself. | ||
* @memberof Shoukaku | ||
* @returns {void} | ||
*/ | ||
start(nodes, options) { | ||
if (this.id) | ||
throw new ShoukakuError('You already started Shoukaku, you don\'t need to start her again.'); | ||
options = this._mergeDefault(constants.ShoukakuBuildOptions, options); | ||
this.id = options.id; | ||
if (options.shardCount) this.shardCount = options.shardCount; | ||
for (let node of nodes) { | ||
node = this._mergeDefault(constants.ShoukakuNodeOptions, node); | ||
this.addNode(node); | ||
} | ||
this.client.on('raw', this.rawRouter); | ||
this.client.on('shardReady', this.reconnectRouter); | ||
} | ||
/** | ||
* Function to register a Lavalink Node | ||
@@ -159,3 +152,3 @@ * @param {ShoukakuConstants#ShoukakuNodeOptions} nodeOptions The Node Options to be used to connect to. | ||
if (!this.id) | ||
throw new ShoukakuError('You didn\'t start Shoukaku once. Please call .start() method once before using this.'); | ||
throw new ShoukakuError('Shoukaku is not yet ready to execute this method. Please wait and try again.'); | ||
const node = new ShoukakuSocket(this, nodeOptions); | ||
@@ -180,3 +173,3 @@ node.connect(this.id, this.shardCount, false); | ||
if (!this.id) | ||
throw new ShoukakuError('You didn\'t start Shoukaku once. Please call .start() method once before using this.'); | ||
throw new ShoukakuError('Shoukaku is not yet ready to execute this method. Please wait and try again.'); | ||
const node = this.nodes.get(name); | ||
@@ -216,3 +209,3 @@ if (!node) return; | ||
if (!this.id) | ||
throw new ShoukakuError('You didn\'t start Shoukaku once. Please call .start() method once before using this.'); | ||
throw new ShoukakuError('Shoukaku is not yet ready to execute this method. Please wait and try again.'); | ||
if (!this.nodes.size) | ||
@@ -242,3 +235,3 @@ throw new ShoukakuError('No nodes available. What happened?'); | ||
if (!this.id) | ||
throw new ShoukakuError('You didn\'t start Shoukaku once. Please call .start() method once before using this.'); | ||
throw new ShoukakuError('Shoukaku is not yet ready to execute this method. Please wait and try again.'); | ||
if (!guildID) return null; | ||
@@ -249,20 +242,2 @@ if (!this.nodes.size) return null; | ||
_mergeDefault(def, given) { | ||
if (!given) return def; | ||
const defaultKeys = Object.keys(def); | ||
for (const key of defaultKeys) { | ||
if (def[key] === null) { | ||
if (!given[key]) throw new ShoukakuError(`${key} was not found from the given options.`); | ||
} | ||
if (!given[key]) given[key] = def[key]; | ||
} | ||
for (const key in defaultKeys) { | ||
if (defaultKeys.includes(key)) continue; | ||
delete given[key]; | ||
} | ||
return given; | ||
} | ||
_ready(name, resumed) { | ||
@@ -269,0 +244,0 @@ const node = this.nodes.get(name); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
66432
15
1497
139