mirror of
https://github.com/BluemediaDev/muse.git
synced 2025-05-10 12:11:35 +02:00
Use manager instances for guild services
This commit is contained in:
parent
0cebca7917
commit
3408c7a0c2
13 changed files with 178 additions and 162 deletions
|
@ -1,21 +1,21 @@
|
|||
import {Message} from 'discord.js';
|
||||
import {TYPES} from '../types';
|
||||
import {inject, injectable} from 'inversify';
|
||||
import Queue from '../services/queue';
|
||||
import QueueManager from '../managers/queue';
|
||||
import Command from '.';
|
||||
|
||||
@injectable()
|
||||
export default class implements Command {
|
||||
public name = 'clear';
|
||||
public description = 'clears all songs in queue (except currently playing)';
|
||||
private readonly queue: Queue;
|
||||
private readonly queueManager: QueueManager;
|
||||
|
||||
constructor(@inject(TYPES.Services.Queue) queue: Queue) {
|
||||
this.queue = queue;
|
||||
constructor(@inject(TYPES.Managers.Queue) queueManager: QueueManager) {
|
||||
this.queueManager = queueManager;
|
||||
}
|
||||
|
||||
public async execute(msg: Message, _: string []): Promise<void> {
|
||||
this.queue.clear(msg.guild!.id);
|
||||
this.queueManager.get(msg.guild!.id).clear();
|
||||
|
||||
await msg.channel.send('cleared');
|
||||
}
|
||||
|
|
|
@ -9,8 +9,9 @@ import got from 'got';
|
|||
import {parse, toSeconds} from 'iso8601-duration';
|
||||
import {TYPES} from '../types';
|
||||
import {inject, injectable} from 'inversify';
|
||||
import Queue, {QueuedSong, QueuedPlaylist} from '../services/queue';
|
||||
import Player from '../services/player';
|
||||
import {QueuedSong, QueuedPlaylist} from '../services/queue';
|
||||
import QueueManager from '../managers/queue';
|
||||
import PlayerManager from '../managers/player';
|
||||
import {getMostPopularVoiceChannel} from '../utils/channels';
|
||||
import LoadingMessage from '../utils/loading-message';
|
||||
import Command from '.';
|
||||
|
@ -19,15 +20,15 @@ import Command from '.';
|
|||
export default class implements Command {
|
||||
public name = 'play';
|
||||
public description = 'plays a song';
|
||||
private readonly queue: Queue;
|
||||
private readonly player: Player;
|
||||
private readonly queueManager: QueueManager;
|
||||
private readonly playerManager: PlayerManager;
|
||||
private readonly youtube: YouTube;
|
||||
private readonly youtubeKey: string;
|
||||
private readonly spotify: Spotify;
|
||||
|
||||
constructor(@inject(TYPES.Services.Queue) queue: Queue, @inject(TYPES.Services.Player) player: Player, @inject(TYPES.Lib.YouTube) youtube: YouTube, @inject(TYPES.Config.YOUTUBE_API_KEY) youtubeKey: string, @inject(TYPES.Lib.Spotify) spotify: Spotify) {
|
||||
this.queue = queue;
|
||||
this.player = player;
|
||||
constructor(@inject(TYPES.Managers.Queue) queueManager: QueueManager, @inject(TYPES.Managers.Player) playerManager: PlayerManager, @inject(TYPES.Lib.YouTube) youtube: YouTube, @inject(TYPES.Config.YOUTUBE_API_KEY) youtubeKey: string, @inject(TYPES.Lib.Spotify) spotify: Spotify) {
|
||||
this.queueManager = queueManager;
|
||||
this.playerManager = playerManager;
|
||||
this.youtube = youtube;
|
||||
this.youtubeKey = youtubeKey;
|
||||
this.spotify = spotify;
|
||||
|
@ -208,7 +209,7 @@ export default class implements Command {
|
|||
return;
|
||||
}
|
||||
|
||||
newSongs.forEach(song => this.queue.add(msg.guild!.id, song));
|
||||
newSongs.forEach(song => this.queueManager.get(msg.guild!.id).add(song));
|
||||
|
||||
// TODO: better response
|
||||
await res.stop('song(s) queued');
|
||||
|
@ -216,8 +217,8 @@ export default class implements Command {
|
|||
const channel = getMostPopularVoiceChannel(msg.guild!);
|
||||
|
||||
// TODO: don't connect if already connected.
|
||||
await this.player.connect(msg.guild!.id, channel);
|
||||
await this.playerManager.get(msg.guild!.id).connect(channel);
|
||||
|
||||
await this.player.play(msg.guild!.id);
|
||||
await this.playerManager.get(msg.guild!.id).play();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,21 +1,21 @@
|
|||
import {Message} from 'discord.js';
|
||||
import {TYPES} from '../types';
|
||||
import {inject, injectable} from 'inversify';
|
||||
import Queue from '../services/queue';
|
||||
import QueueManager from '../managers/queue';
|
||||
import Command from '.';
|
||||
|
||||
@injectable()
|
||||
export default class implements Command {
|
||||
public name = 'queue';
|
||||
public description = 'shows current queue';
|
||||
private readonly queue: Queue;
|
||||
private readonly queueManager: QueueManager;
|
||||
|
||||
constructor(@inject(TYPES.Services.Queue) queue: Queue) {
|
||||
this.queue = queue;
|
||||
constructor(@inject(TYPES.Managers.Queue) queueManager: QueueManager) {
|
||||
this.queueManager = queueManager;
|
||||
}
|
||||
|
||||
public async execute(msg: Message, _: string []): Promise<void> {
|
||||
const queue = this.queue.get(msg.guild!.id);
|
||||
const queue = this.queueManager.get(msg.guild!.id).get();
|
||||
|
||||
await msg.channel.send('`' + JSON.stringify(queue.slice(0, 10)) + '`');
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import {Message, TextChannel} from 'discord.js';
|
||||
import {TYPES} from '../types';
|
||||
import {inject, injectable} from 'inversify';
|
||||
import Player from '../services/player';
|
||||
import PlayerManager from '../managers/player';
|
||||
import LoadingMessage from '../utils/loading-message';
|
||||
import Command from '.';
|
||||
|
||||
|
@ -9,10 +9,10 @@ import Command from '.';
|
|||
export default class implements Command {
|
||||
public name = 'seek';
|
||||
public description = 'seeks position in currently playing song';
|
||||
private readonly player: Player;
|
||||
private readonly playerManager: PlayerManager;
|
||||
|
||||
constructor(@inject(TYPES.Services.Player) player: Player) {
|
||||
this.player = player;
|
||||
constructor(@inject(TYPES.Managers.Player) playerManager: PlayerManager) {
|
||||
this.playerManager = playerManager;
|
||||
}
|
||||
|
||||
public async execute(msg: Message, args: string []): Promise<void> {
|
||||
|
@ -31,7 +31,7 @@ export default class implements Command {
|
|||
await loading.start();
|
||||
|
||||
try {
|
||||
await this.player.seek(msg.guild!.id, seekTime);
|
||||
await this.playerManager.get(msg.guild!.id).seek(seekTime);
|
||||
|
||||
await loading.stop('seeked');
|
||||
} catch (_) {
|
||||
|
|
|
@ -1,29 +1,29 @@
|
|||
import {Message} from 'discord.js';
|
||||
import {TYPES} from '../types';
|
||||
import {inject, injectable} from 'inversify';
|
||||
import Queue from '../services/queue';
|
||||
import QueueManager from '../managers/queue';
|
||||
import Command from '.';
|
||||
|
||||
@injectable()
|
||||
export default class implements Command {
|
||||
public name = 'shuffle';
|
||||
public description = 'shuffle current queue';
|
||||
private readonly queue: Queue;
|
||||
private readonly queueManager: QueueManager;
|
||||
|
||||
constructor(@inject(TYPES.Services.Queue) queue: Queue) {
|
||||
this.queue = queue;
|
||||
constructor(@inject(TYPES.Managers.Queue) queueManager: QueueManager) {
|
||||
this.queueManager = queueManager;
|
||||
}
|
||||
|
||||
public async execute(msg: Message, _: string []): Promise<void> {
|
||||
const queue = this.queue.get(msg.guild!.id);
|
||||
const queue = this.queueManager.get(msg.guild!.id).get();
|
||||
|
||||
if (queue.length <= 2) {
|
||||
await msg.channel.send('error: not enough songs to shuffle');
|
||||
return;
|
||||
}
|
||||
|
||||
this.queue.shuffle(msg.guild!.id);
|
||||
this.queueManager.get(msg.guild!.id).shuffle();
|
||||
|
||||
await msg.channel.send('`' + JSON.stringify(this.queue.get(msg.guild!.id).slice(0, 10)) + '`');
|
||||
await msg.channel.send('`' + JSON.stringify(this.queueManager.get(msg.guild!.id).get().slice(0, 10)) + '`');
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue