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;
|
||||
|
||||
namespace NadekoBot.Classes.Music {
|
||||
|
||||
public enum MusicType {
|
||||
Radio,
|
||||
Normal,
|
||||
Local
|
||||
}
|
||||
|
||||
public class MusicControls {
|
||||
private CommandEventArgs _e;
|
||||
public bool NextSong { get; set; } = false;
|
||||
@ -48,9 +55,11 @@ namespace NadekoBot.Classes.Music {
|
||||
}
|
||||
|
||||
internal void AddSong(StreamRequest streamRequest) {
|
||||
lock (_voiceLock) {
|
||||
Stopped = false;
|
||||
this.SongQueue.Add(streamRequest);
|
||||
}
|
||||
}
|
||||
|
||||
public MusicControls(Channel voiceChannel, CommandEventArgs e, float? vol) : this() {
|
||||
if (voiceChannel == null)
|
||||
@ -65,9 +74,11 @@ namespace NadekoBot.Classes.Music {
|
||||
CurrentSong?.Stop();
|
||||
CurrentSong = null;
|
||||
if (SongQueue.Count != 0) {
|
||||
lock (_voiceLock) {
|
||||
CurrentSong = SongQueue[0];
|
||||
SongQueue.RemoveAt(0);
|
||||
}
|
||||
}
|
||||
else {
|
||||
Stop();
|
||||
return;
|
||||
@ -92,7 +103,10 @@ namespace NadekoBot.Classes.Music {
|
||||
internal void Stop(bool leave = false) {
|
||||
Stopped = true;
|
||||
SongQueue.Clear();
|
||||
try {
|
||||
CurrentSong?.Stop();
|
||||
}
|
||||
catch { }
|
||||
CurrentSong = null;
|
||||
if (leave) {
|
||||
VoiceClient?.Disconnect();
|
||||
|
@ -36,11 +36,11 @@ namespace NadekoBot.Classes.Music {
|
||||
|
||||
public float Volume => MusicControls?.Volume ?? 1.0f;
|
||||
|
||||
public bool RadioLink { get; }
|
||||
public MusicType LinkType { get; }
|
||||
|
||||
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)
|
||||
throw new ArgumentNullException(nameof(e));
|
||||
if (query == null)
|
||||
@ -48,14 +48,19 @@ namespace NadekoBot.Classes.Music {
|
||||
this.MusicControls = mc;
|
||||
this.Server = e.Server;
|
||||
this.Query = query;
|
||||
this.RadioLink = radio;
|
||||
this.LinkType = musicType;
|
||||
mc.AddSong(this);
|
||||
}
|
||||
|
||||
public async Task Resolve() {
|
||||
string uri = null;
|
||||
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;
|
||||
Title = $"{Query}";
|
||||
Provider = "Radio Stream";
|
||||
@ -259,7 +264,7 @@ namespace NadekoBot.Classes.Music {
|
||||
// prebuffering wait stuff start
|
||||
int bufferAttempts = 0;
|
||||
int waitPerAttempt = 500;
|
||||
int toAttemptTimes = parent.RadioLink ? 4 : 8;
|
||||
int toAttemptTimes = parent.LinkType != MusicType.Normal ? 4 : 8;
|
||||
while (!prebufferingComplete && bufferAttempts++ < toAttemptTimes) {
|
||||
await Task.Delay(waitPerAttempt);
|
||||
}
|
||||
|
@ -203,6 +203,23 @@ namespace NadekoBot.Modules {
|
||||
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")
|
||||
.Description("Queues a direct radio stream from a link.")
|
||||
.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.");
|
||||
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")
|
||||
@ -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(!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.");
|
||||
return;
|
||||
}
|
||||
@ -271,9 +299,8 @@ namespace NadekoBot.Modules {
|
||||
return;
|
||||
|
||||
query = query.Trim();
|
||||
|
||||
if (IsRadioLink(query)) {
|
||||
radio = true;
|
||||
if (musicType != MusicType.Local && IsRadioLink(query)) {
|
||||
musicType = MusicType.Radio;
|
||||
query = await HandleStreamContainers(query) ?? query;
|
||||
}
|
||||
|
||||
@ -294,7 +321,7 @@ namespace NadekoBot.Modules {
|
||||
if (player.SongQueue.Count >= 50) return;
|
||||
|
||||
try {
|
||||
var sr = new StreamRequest(e, query, player, radio);
|
||||
var sr = new StreamRequest(e, query, player, musicType);
|
||||
|
||||
if (sr == null)
|
||||
throw new NullReferenceException("StreamRequest is null.");
|
||||
|
@ -180,7 +180,7 @@ namespace NadekoBot {
|
||||
|
||||
if (!repliedRecently) {
|
||||
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();
|
||||
t.Interval = 2000;
|
||||
t.Start();
|
||||
|
Loading…
Reference in New Issue
Block a user