mirror of
https://github.com/BluemediaGER/muse.git
synced 2024-11-23 01:05:30 +01:00
Don't allow seeking in livestream
This commit is contained in:
parent
2875c6ceb8
commit
18e851821c
|
@ -2,6 +2,7 @@ import {Message, TextChannel} from 'discord.js';
|
|||
import {TYPES} from '../types';
|
||||
import {inject, injectable} from 'inversify';
|
||||
import PlayerManager from '../managers/player';
|
||||
import QueueManager from '../managers/queue';
|
||||
import LoadingMessage from '../utils/loading-message';
|
||||
import Command from '.';
|
||||
|
||||
|
@ -10,12 +11,26 @@ export default class implements Command {
|
|||
public name = 'fseek';
|
||||
public description = 'forward seek position in currently playing song';
|
||||
private readonly playerManager: PlayerManager;
|
||||
private readonly queueManager: QueueManager;
|
||||
|
||||
constructor(@inject(TYPES.Managers.Player) playerManager: PlayerManager) {
|
||||
constructor(@inject(TYPES.Managers.Player) playerManager: PlayerManager, @inject(TYPES.Managers.Queue) queueManager: QueueManager) {
|
||||
this.playerManager = playerManager;
|
||||
this.queueManager = queueManager;
|
||||
}
|
||||
|
||||
public async execute(msg: Message, args: string []): Promise<void> {
|
||||
const queue = this.queueManager.get(msg.guild!.id);
|
||||
|
||||
if (queue.get().length === 0) {
|
||||
await msg.channel.send('nothing is playing');
|
||||
return;
|
||||
}
|
||||
|
||||
if (queue.get()[0].isLive) {
|
||||
await msg.channel.send('can\'t seek in a livestream');
|
||||
return;
|
||||
}
|
||||
|
||||
const seekTime = parseInt(args[0], 10);
|
||||
|
||||
const loading = new LoadingMessage(msg.channel as TextChannel, 'hold on a sec');
|
||||
|
|
|
@ -72,7 +72,8 @@ export default class implements Command {
|
|||
artist: videoDetails.snippet.channelTitle,
|
||||
length: toSeconds(parse(videoDetails.contentDetails.duration)),
|
||||
url: videoDetails.id,
|
||||
playlist: null
|
||||
playlist: null,
|
||||
isLive: videoDetails.snippet.liveBroadcastContent === 'live'
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -106,7 +107,8 @@ export default class implements Command {
|
|||
artist: video.snippet.channelTitle,
|
||||
length,
|
||||
url: video.contentDetails.videoId,
|
||||
playlist: queuedPlaylist
|
||||
playlist: queuedPlaylist,
|
||||
isLive: false
|
||||
});
|
||||
});
|
||||
} else {
|
||||
|
@ -190,7 +192,8 @@ export default class implements Command {
|
|||
artist: track.artists[0].name,
|
||||
length: track.duration_ms / 1000,
|
||||
url: video.link,
|
||||
playlist
|
||||
playlist,
|
||||
isLive: video.live
|
||||
};
|
||||
} catch (_) {
|
||||
// TODO: handle error
|
||||
|
|
|
@ -2,6 +2,7 @@ import {Message, TextChannel} from 'discord.js';
|
|||
import {TYPES} from '../types';
|
||||
import {inject, injectable} from 'inversify';
|
||||
import PlayerManager from '../managers/player';
|
||||
import QueueManager from '../managers/queue';
|
||||
import LoadingMessage from '../utils/loading-message';
|
||||
import Command from '.';
|
||||
|
||||
|
@ -10,12 +11,26 @@ export default class implements Command {
|
|||
public name = 'seek';
|
||||
public description = 'seeks position in currently playing song';
|
||||
private readonly playerManager: PlayerManager;
|
||||
private readonly queueManager: QueueManager;
|
||||
|
||||
constructor(@inject(TYPES.Managers.Player) playerManager: PlayerManager) {
|
||||
constructor(@inject(TYPES.Managers.Player) playerManager: PlayerManager, @inject(TYPES.Managers.Queue) queueManager: QueueManager) {
|
||||
this.playerManager = playerManager;
|
||||
this.queueManager = queueManager;
|
||||
}
|
||||
|
||||
public async execute(msg: Message, args: string []): Promise<void> {
|
||||
const queue = this.queueManager.get(msg.guild!.id);
|
||||
|
||||
if (queue.get().length === 0) {
|
||||
await msg.channel.send('nothing is playing');
|
||||
return;
|
||||
}
|
||||
|
||||
if (queue.get()[0].isLive) {
|
||||
await msg.channel.send('can\'t seek in a livestream');
|
||||
return;
|
||||
}
|
||||
|
||||
const time = args[0];
|
||||
|
||||
let seekTime = 0;
|
||||
|
|
|
@ -11,6 +11,7 @@ export interface QueuedSong {
|
|||
url: string;
|
||||
length: number;
|
||||
playlist: QueuedPlaylist | null;
|
||||
isLive: boolean;
|
||||
}
|
||||
|
||||
export default class {
|
||||
|
|
Loading…
Reference in a new issue