Last commit was sarcasm. Added local file support. closes #61
This commit is contained in:
parent
a421515906
commit
99d8e09ec9
@ -7,6 +7,13 @@ using Discord.Commands;
|
|||||||
using MusicModule = NadekoBot.Modules.Music;
|
using MusicModule = NadekoBot.Modules.Music;
|
||||||
|
|
||||||
namespace NadekoBot.Classes.Music {
|
namespace NadekoBot.Classes.Music {
|
||||||
|
|
||||||
|
public enum MusicType {
|
||||||
|
Radio,
|
||||||
|
Normal,
|
||||||
|
Local
|
||||||
|
}
|
||||||
|
|
||||||
public class MusicControls {
|
public class MusicControls {
|
||||||
private CommandEventArgs _e;
|
private CommandEventArgs _e;
|
||||||
public bool NextSong { get; set; } = false;
|
public bool NextSong { get; set; } = false;
|
||||||
@ -48,9 +55,11 @@ namespace NadekoBot.Classes.Music {
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal void AddSong(StreamRequest streamRequest) {
|
internal void AddSong(StreamRequest streamRequest) {
|
||||||
|
lock (_voiceLock) {
|
||||||
Stopped = false;
|
Stopped = false;
|
||||||
this.SongQueue.Add(streamRequest);
|
this.SongQueue.Add(streamRequest);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public MusicControls(Channel voiceChannel, CommandEventArgs e, float? vol) : this() {
|
public MusicControls(Channel voiceChannel, CommandEventArgs e, float? vol) : this() {
|
||||||
if (voiceChannel == null)
|
if (voiceChannel == null)
|
||||||
@ -65,9 +74,11 @@ namespace NadekoBot.Classes.Music {
|
|||||||
CurrentSong?.Stop();
|
CurrentSong?.Stop();
|
||||||
CurrentSong = null;
|
CurrentSong = null;
|
||||||
if (SongQueue.Count != 0) {
|
if (SongQueue.Count != 0) {
|
||||||
|
lock (_voiceLock) {
|
||||||
CurrentSong = SongQueue[0];
|
CurrentSong = SongQueue[0];
|
||||||
SongQueue.RemoveAt(0);
|
SongQueue.RemoveAt(0);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
Stop();
|
Stop();
|
||||||
return;
|
return;
|
||||||
@ -92,7 +103,10 @@ namespace NadekoBot.Classes.Music {
|
|||||||
internal void Stop(bool leave = false) {
|
internal void Stop(bool leave = false) {
|
||||||
Stopped = true;
|
Stopped = true;
|
||||||
SongQueue.Clear();
|
SongQueue.Clear();
|
||||||
|
try {
|
||||||
CurrentSong?.Stop();
|
CurrentSong?.Stop();
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
CurrentSong = null;
|
CurrentSong = null;
|
||||||
if (leave) {
|
if (leave) {
|
||||||
VoiceClient?.Disconnect();
|
VoiceClient?.Disconnect();
|
||||||
|
@ -36,11 +36,11 @@ namespace NadekoBot.Classes.Music {
|
|||||||
|
|
||||||
public float Volume => MusicControls?.Volume ?? 1.0f;
|
public float Volume => MusicControls?.Volume ?? 1.0f;
|
||||||
|
|
||||||
public bool RadioLink { get; }
|
public MusicType LinkType { get; }
|
||||||
|
|
||||||
public MusicControls MusicControls;
|
public MusicControls MusicControls;
|
||||||
|
|
||||||
public StreamRequest(CommandEventArgs e, string query, MusicControls mc, bool radio = false) {
|
public StreamRequest(CommandEventArgs e, string query, MusicControls mc, MusicType musicType = MusicType.Normal) {
|
||||||
if (e == null)
|
if (e == null)
|
||||||
throw new ArgumentNullException(nameof(e));
|
throw new ArgumentNullException(nameof(e));
|
||||||
if (query == null)
|
if (query == null)
|
||||||
@ -48,14 +48,19 @@ namespace NadekoBot.Classes.Music {
|
|||||||
this.MusicControls = mc;
|
this.MusicControls = mc;
|
||||||
this.Server = e.Server;
|
this.Server = e.Server;
|
||||||
this.Query = query;
|
this.Query = query;
|
||||||
this.RadioLink = radio;
|
this.LinkType = musicType;
|
||||||
mc.AddSong(this);
|
mc.AddSong(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task Resolve() {
|
public async Task Resolve() {
|
||||||
string uri = null;
|
string uri = null;
|
||||||
try {
|
try {
|
||||||
if (RadioLink) {
|
if (this.LinkType == MusicType.Local) {
|
||||||
|
uri = "\"" + Path.GetFullPath(Query) + "\"";
|
||||||
|
Title = Path.GetFileNameWithoutExtension(Query);
|
||||||
|
Provider = "Local File";
|
||||||
|
}
|
||||||
|
else if (this.LinkType == MusicType.Radio) {
|
||||||
uri = Query;
|
uri = Query;
|
||||||
Title = $"{Query}";
|
Title = $"{Query}";
|
||||||
Provider = "Radio Stream";
|
Provider = "Radio Stream";
|
||||||
@ -259,7 +264,7 @@ namespace NadekoBot.Classes.Music {
|
|||||||
// prebuffering wait stuff start
|
// prebuffering wait stuff start
|
||||||
int bufferAttempts = 0;
|
int bufferAttempts = 0;
|
||||||
int waitPerAttempt = 500;
|
int waitPerAttempt = 500;
|
||||||
int toAttemptTimes = parent.RadioLink ? 4 : 8;
|
int toAttemptTimes = parent.LinkType != MusicType.Normal ? 4 : 8;
|
||||||
while (!prebufferingComplete && bufferAttempts++ < toAttemptTimes) {
|
while (!prebufferingComplete && bufferAttempts++ < toAttemptTimes) {
|
||||||
await Task.Delay(waitPerAttempt);
|
await Task.Delay(waitPerAttempt);
|
||||||
}
|
}
|
||||||
|
@ -203,6 +203,23 @@ namespace NadekoBot.Modules {
|
|||||||
msg?.Edit("🎵 `Playlist queue complete.`");
|
msg?.Edit("🎵 `Playlist queue complete.`");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
cgb.CreateCommand("lopl")
|
||||||
|
.Description("Queues up to 50 songs from a directory.")
|
||||||
|
.Parameter("directory", ParameterType.Unparsed)
|
||||||
|
.Do(async e => {
|
||||||
|
var arg = e.GetArg("directory");
|
||||||
|
if(string.IsNullOrWhiteSpace(e.GetArg("directory")))
|
||||||
|
return;
|
||||||
|
try {
|
||||||
|
var fileEnum = System.IO.Directory.EnumerateFiles(e.GetArg("directory")).Take(50);
|
||||||
|
foreach (var file in fileEnum) {
|
||||||
|
await Task.Run(async() => await QueueSong(e, file, true, MusicType.Local)).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
await e.Channel.SendMessage("🎵 `Directory queue complete.`");
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
});
|
||||||
|
|
||||||
cgb.CreateCommand("radio").Alias("ra")
|
cgb.CreateCommand("radio").Alias("ra")
|
||||||
.Description("Queues a direct radio stream from a link.")
|
.Description("Queues a direct radio stream from a link.")
|
||||||
.Parameter("radio_link", ParameterType.Required)
|
.Parameter("radio_link", ParameterType.Required)
|
||||||
@ -211,7 +228,17 @@ namespace NadekoBot.Modules {
|
|||||||
await e.Channel.SendMessage("💢 You need to be in a voice channel on this server.\n If you are already in a voice channel, try rejoining it.");
|
await e.Channel.SendMessage("💢 You need to be in a voice channel on this server.\n If you are already in a voice channel, try rejoining it.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await QueueSong(e, e.GetArg("radio_link"), radio: true);
|
await QueueSong(e, e.GetArg("radio_link"), musicType: MusicType.Radio);
|
||||||
|
});
|
||||||
|
|
||||||
|
cgb.CreateCommand("lo")
|
||||||
|
.Description("Queues a local file by specifying a full path. BOT OWNER ONLY.")
|
||||||
|
.Parameter("path", ParameterType.Unparsed)
|
||||||
|
.Do(async e => {
|
||||||
|
var arg = e.GetArg("path");
|
||||||
|
if (string.IsNullOrWhiteSpace(arg))
|
||||||
|
return;
|
||||||
|
await QueueSong(e, e.GetArg("path"), musicType: MusicType.Local);
|
||||||
});
|
});
|
||||||
|
|
||||||
cgb.CreateCommand("mv")
|
cgb.CreateCommand("mv")
|
||||||
@ -261,8 +288,9 @@ namespace NadekoBot.Modules {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task QueueSong(CommandEventArgs e, string query, bool silent = false, bool radio = false) {
|
private async Task QueueSong(CommandEventArgs e, string query, bool silent = false, MusicType musicType = MusicType.Normal) {
|
||||||
if (e.User.VoiceChannel?.Server != e.Server) {
|
if (e.User.VoiceChannel?.Server != e.Server) {
|
||||||
|
if(!silent)
|
||||||
await e.Channel.SendMessage("💢 You need to be in a voice channel on this server.\n If you are already in a voice channel, try rejoining.");
|
await e.Channel.SendMessage("💢 You need to be in a voice channel on this server.\n If you are already in a voice channel, try rejoining.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -271,9 +299,8 @@ namespace NadekoBot.Modules {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
query = query.Trim();
|
query = query.Trim();
|
||||||
|
if (musicType != MusicType.Local && IsRadioLink(query)) {
|
||||||
if (IsRadioLink(query)) {
|
musicType = MusicType.Radio;
|
||||||
radio = true;
|
|
||||||
query = await HandleStreamContainers(query) ?? query;
|
query = await HandleStreamContainers(query) ?? query;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -294,7 +321,7 @@ namespace NadekoBot.Modules {
|
|||||||
if (player.SongQueue.Count >= 50) return;
|
if (player.SongQueue.Count >= 50) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var sr = new StreamRequest(e, query, player, radio);
|
var sr = new StreamRequest(e, query, player, musicType);
|
||||||
|
|
||||||
if (sr == null)
|
if (sr == null)
|
||||||
throw new NullReferenceException("StreamRequest is null.");
|
throw new NullReferenceException("StreamRequest is null.");
|
||||||
|
@ -180,7 +180,7 @@ namespace NadekoBot {
|
|||||||
|
|
||||||
if (!repliedRecently) {
|
if (!repliedRecently) {
|
||||||
repliedRecently = true;
|
repliedRecently = true;
|
||||||
await e.Channel.SendMessage("**FULL LIST OF COMMANDS**:\n❤ <https://gist.github.com/Kwoth/1ab3a38424f208802b74> ❤\n\n⚠**COMMANDS DO NOT WORK IN PERSONAL MESSAGES**\n\n\n**Bot Creator's server:** <https://discord.gg/0ehQwTK2RBhxEi0X>");
|
await e.Channel.SendMessage("**FULL LIST OF COMMANDS**:\n❤ <https://gist.github.com/Kwoth/1ab3a38424f208802b74> ❤\n\n⚠**COMMANDS DO NOT WORK IN PERSONAL MESSAGES**\n\n\n**Bot Creator's server:** <https://discord.gg/0ehQwTK2RBjAxzEY>");
|
||||||
Timer t = new Timer();
|
Timer t = new Timer();
|
||||||
t.Interval = 2000;
|
t.Interval = 2000;
|
||||||
t.Start();
|
t.Start();
|
||||||
|
Loading…
Reference in New Issue
Block a user