Don't allow seeking in livestream

This commit is contained in:
Max Isom 2020-03-15 20:11:45 -05:00
parent 2875c6ceb8
commit 18e851821c
4 changed files with 39 additions and 5 deletions

View file

@ -2,6 +2,7 @@ import {Message, TextChannel} from 'discord.js';
import {TYPES} from '../types'; import {TYPES} from '../types';
import {inject, injectable} from 'inversify'; import {inject, injectable} from 'inversify';
import PlayerManager from '../managers/player'; import PlayerManager from '../managers/player';
import QueueManager from '../managers/queue';
import LoadingMessage from '../utils/loading-message'; import LoadingMessage from '../utils/loading-message';
import Command from '.'; import Command from '.';
@ -10,12 +11,26 @@ export default class implements Command {
public name = 'fseek'; public name = 'fseek';
public description = 'forward seek position in currently playing song'; public description = 'forward seek position in currently playing song';
private readonly playerManager: PlayerManager; 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.playerManager = playerManager;
this.queueManager = queueManager;
} }
public async execute(msg: Message, args: string []): Promise<void> { 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 seekTime = parseInt(args[0], 10);
const loading = new LoadingMessage(msg.channel as TextChannel, 'hold on a sec'); const loading = new LoadingMessage(msg.channel as TextChannel, 'hold on a sec');

View file

@ -72,7 +72,8 @@ export default class implements Command {
artist: videoDetails.snippet.channelTitle, artist: videoDetails.snippet.channelTitle,
length: toSeconds(parse(videoDetails.contentDetails.duration)), length: toSeconds(parse(videoDetails.contentDetails.duration)),
url: videoDetails.id, 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, artist: video.snippet.channelTitle,
length, length,
url: video.contentDetails.videoId, url: video.contentDetails.videoId,
playlist: queuedPlaylist playlist: queuedPlaylist,
isLive: false
}); });
}); });
} else { } else {
@ -190,7 +192,8 @@ export default class implements Command {
artist: track.artists[0].name, artist: track.artists[0].name,
length: track.duration_ms / 1000, length: track.duration_ms / 1000,
url: video.link, url: video.link,
playlist playlist,
isLive: video.live
}; };
} catch (_) { } catch (_) {
// TODO: handle error // TODO: handle error

View file

@ -2,6 +2,7 @@ import {Message, TextChannel} from 'discord.js';
import {TYPES} from '../types'; import {TYPES} from '../types';
import {inject, injectable} from 'inversify'; import {inject, injectable} from 'inversify';
import PlayerManager from '../managers/player'; import PlayerManager from '../managers/player';
import QueueManager from '../managers/queue';
import LoadingMessage from '../utils/loading-message'; import LoadingMessage from '../utils/loading-message';
import Command from '.'; import Command from '.';
@ -10,12 +11,26 @@ export default class implements Command {
public name = 'seek'; public name = 'seek';
public description = 'seeks position in currently playing song'; public description = 'seeks position in currently playing song';
private readonly playerManager: PlayerManager; 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.playerManager = playerManager;
this.queueManager = queueManager;
} }
public async execute(msg: Message, args: string []): Promise<void> { 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]; const time = args[0];
let seekTime = 0; let seekTime = 0;

View file

@ -11,6 +11,7 @@ export interface QueuedSong {
url: string; url: string;
length: number; length: number;
playlist: QueuedPlaylist | null; playlist: QueuedPlaylist | null;
isLive: boolean;
} }
export default class { export default class {