Skip to content

Commit

Permalink
move node out of index
Browse files Browse the repository at this point in the history
  • Loading branch information
Will Nelson committed Jul 7, 2019
1 parent 7768d5b commit 9791861
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 32 deletions.
32 changes: 32 additions & 0 deletions src/Node.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import Node, { ConnectionOptions, NodeOptions } from 'lavalink';
import Redis = require('ioredis');
import Queue from './Queue';
import QueueStore from './QueueStore';

export interface Options extends NodeOptions {
hosts?: {
ws?: string | { url: string, options: ConnectionOptions };
rest?: string;
redis?: Redis.Redis | Redis.RedisOptions;
},
advanceBy?: (queue: Queue, info: { previous: string, remaining: number }) => number;
}

export default class LavaqueueNode extends Node {
public readonly queues: QueueStore;
public advanceBy: (queue: Queue, info: { previous: string, remaining: number }) => number;

constructor(opts: Options) {
if (!opts.hosts || !opts.hosts.redis) throw new Error('cannot make a queue without a Redis connection');

super(opts);
this.queues = new QueueStore(this, opts.hosts.redis instanceof Redis ? opts.hosts.redis : new Redis(opts.hosts.redis));
this.advanceBy = opts.advanceBy || (() => 1);

for (const name of ['event', 'playerUpdate']) {
this.on(name, (d) => {
this.queues.get(d.guildId).emit(name, d);
});
}
}
}
35 changes: 3 additions & 32 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,11 @@
import BaseClient from 'lavalink';
import Redis = require('ioredis');
import Node from './Node';
import QueueStore from './QueueStore';
import Queue from './Queue';
import { NodeOptions } from 'lavalink';

export interface Options extends NodeOptions {
hosts?: {
ws?: string;
rest?: string;
redis?: Redis.Redis | Redis.RedisOptions;
},
advanceBy?: (queue: Queue, info: { previous: string, remaining: number }) => number;
}

export class Client extends BaseClient {
public readonly queues: QueueStore;
public advanceBy: (queue: Queue, info: { previous: string, remaining: number }) => number;

constructor(opts: Options) {
if (!opts.hosts || !opts.hosts.redis) throw new Error('cannot make a queue without a Redis connection');

super(opts);
this.queues = new QueueStore(this, opts.hosts.redis instanceof Redis ? opts.hosts.redis : new Redis(opts.hosts.redis));
this.advanceBy = opts.advanceBy || (() => 1);

for (const name of ['event', 'playerUpdate']) {
this.on(name, (d) => {
this.queues.get(d.guildId).emit(name, d);
});
}
}
}

export const Client = Node;
export {
QueueStore,
Queue,
}

export default Client;
export default Node;

0 comments on commit 9791861

Please sign in to comment.