From 9791861c3f1b5343339022ab14bcc3d3140e19bb Mon Sep 17 00:00:00 2001 From: Will Nelson Date: Sun, 7 Jul 2019 09:40:56 -0700 Subject: [PATCH] move node out of index --- src/Node.ts | 32 ++++++++++++++++++++++++++++++++ src/index.ts | 35 +++-------------------------------- 2 files changed, 35 insertions(+), 32 deletions(-) create mode 100644 src/Node.ts diff --git a/src/Node.ts b/src/Node.ts new file mode 100644 index 0000000..a23e21d --- /dev/null +++ b/src/Node.ts @@ -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); + }); + } + } +} diff --git a/src/index.ts b/src/index.ts index 5dff0fd..092041d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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;