aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMax Isom <[email protected]>2020-03-15 20:11:45 -0500
committerMax Isom <[email protected]>2020-03-15 20:11:45 -0500
commit18e851821caa13747c8d946abe36d3e2e5d6dcbd (patch)
treedff8b0a1a11e73b6d68cbf79198a5a8330f9e2a0 /src
parent2875c6ceb89ccd22da500f6f3dccbe3c43893d86 (diff)
downloadmuse-18e851821caa13747c8d946abe36d3e2e5d6dcbd.tar.xz
muse-18e851821caa13747c8d946abe36d3e2e5d6dcbd.zip
Don't allow seeking in livestream
Diffstat (limited to 'src')
-rw-r--r--src/commands/fseek.ts17
-rw-r--r--src/commands/play.ts9
-rw-r--r--src/commands/seek.ts17
-rw-r--r--src/services/queue.ts1
4 files changed, 39 insertions, 5 deletions
diff --git a/src/commands/fseek.ts b/src/commands/fseek.ts
index 2fae1e6..e442612 100644
--- a/src/commands/fseek.ts
+++ b/src/commands/fseek.ts
@@ -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');
diff --git a/src/commands/play.ts b/src/commands/play.ts
index 2d91d19..d791be3 100644
--- a/src/commands/play.ts
+++ b/src/commands/play.ts
@@ -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
diff --git a/src/commands/seek.ts b/src/commands/seek.ts
index ac8609c..ec8f0d7 100644
--- a/src/commands/seek.ts
+++ b/src/commands/seek.ts
@@ -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;
diff --git a/src/services/queue.ts b/src/services/queue.ts
index f439a5c..ffc16ae 100644
--- a/src/services/queue.ts
+++ b/src/services/queue.ts
@@ -11,6 +11,7 @@ export interface QueuedSong {
url: string;
length: number;
playlist: QueuedPlaylist | null;
+ isLive: boolean;
}
export default class {