-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Will Nelson
committed
Jul 7, 2019
1 parent
7768d5b
commit 9791861
Showing
2 changed files
with
35 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |