From aff95918e20d3df45b3552650750e616179140f1 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Wed, 20 Jan 2016 18:54:05 +0100 Subject: [PATCH] Music errors. .byemsg added, better descriptions --- NadekoBot/Modules/Administration.cs | 21 +++++++++++++----- NadekoBot/Modules/Music.cs | 33 +++++++++++++++-------------- NadekoBot/Modules/Trello.cs | 2 +- NadekoBot/NadekoBot.csproj | 19 ++++++++--------- NadekoBot/packages.config | 2 ++ 5 files changed, 45 insertions(+), 32 deletions(-) diff --git a/NadekoBot/Modules/Administration.cs b/NadekoBot/Modules/Administration.cs index f552b68e..e9dbb0cf 100644 --- a/NadekoBot/Modules/Administration.cs +++ b/NadekoBot/Modules/Administration.cs @@ -374,6 +374,17 @@ namespace NadekoBot.Modules } }); + cgb.CreateCommand(".greetmsg") + .Description("Sets a new announce message. Type %user% if you want to mention the new member.\n**Usage**: .greetmsg Welcome to the server, %user%.") + .Parameter("msg", ParameterType.Unparsed) + .Do(async e => { + if (e.User.Id != NadekoBot.OwnerID) return; + + if (e.GetArg("msg") == null) return; + announceMsg = e.GetArg("msg"); + await e.Send("New greet message set."); + }); + cgb.CreateCommand(".bye") .Description("Enables or Disables anouncements on the current channel when someone leaves the server.") .Do(async e => { @@ -393,15 +404,15 @@ namespace NadekoBot.Modules } }); - cgb.CreateCommand(".greetmsg") - .Description("Sets a new announce message. Type %user% if you want to mention the new member.\n**Usage**: .greetmsg Welcome to the server, %user%.") - .Parameter("msg",ParameterType.Unparsed) + cgb.CreateCommand(".byemsg") + .Description("Sets a new announce leave message. Type %user% if you want to mention the new member.\n**Usage**: .byemsg %user% has left the server.") + .Parameter("msg", ParameterType.Unparsed) .Do(async e => { if (e.User.Id != NadekoBot.OwnerID) return; if (e.GetArg("msg") == null) return; - announceMsg = e.GetArg("msg"); - await e.Send("New message set."); + announceLeaveMsg = e.GetArg("msg"); + await e.Send("New bye message set."); }); }); diff --git a/NadekoBot/Modules/Music.cs b/NadekoBot/Modules/Music.cs index 8bc9669c..7d38926a 100644 --- a/NadekoBot/Modules/Music.cs +++ b/NadekoBot/Modules/Music.cs @@ -11,7 +11,7 @@ using System.IO; using Discord; using Discord.Audio; using System.Collections.Concurrent; -using VideoLibrary; +using YoutubeExtractor; using System.Threading; using System.Diagnostics; using Discord.Legacy; @@ -90,9 +90,6 @@ namespace NadekoBot.Modules { .Alias("pause") .Description("Pauses the song") .Do(async e => { - /*if (CurrentSong != null) { - CurrentSong. - }*/ await e.Send("Not yet implemented."); }); cgb.CreateCommand("q") @@ -126,7 +123,9 @@ namespace NadekoBot.Modules { } private async Task LoadNextSong() { - if (SongQueue.Count == 0) { + if (SongQueue.Count == 0 || !SongQueue[0].LinkResolved) { + if (CurrentSong != null) + CurrentSong.Cancel(); CurrentSong = null; await Task.Delay(200); return; @@ -141,7 +140,8 @@ namespace NadekoBot.Modules { enum StreamTaskState { Queued, Playing, - Completed + Completed, + NotReady } class StreamRequest { @@ -159,7 +159,7 @@ namespace NadekoBot.Modules { public TimeSpan Length = TimeSpan.FromSeconds(0); public string FileName; - bool linkResolved; + public bool LinkResolved = false; public string StreamUrl; public bool NetworkDone; public long TotalSourceBytes; @@ -191,25 +191,26 @@ namespace NadekoBot.Modules { void ResolveLink() { var query = RequestText; try { - var video = YouTube.Default.GetAllVideos(Searches.FindYoutubeUrlByKeywords(query)) - .Where(v => v.AdaptiveKind == AdaptiveKind.Audio) + var video = DownloadUrlResolver.GetDownloadUrls(Searches.FindYoutubeUrlByKeywords(query)) + .Where(v => v.AdaptiveType == AdaptiveType.Audio) .OrderByDescending(v => v.AudioBitrate).FirstOrDefault(); if (video == null) throw new Exception("Could not load any video elements"); // First one - StreamUrl = video.Uri; + StreamUrl = video.DownloadUrl; Title = video.Title; - var fileName = Title.Replace("\\","_").Replace("/","_"); - Path.GetInvalidPathChars().ForEach(c => { fileName = fileName.Replace(c, '_'); }); - FileName = fileName; + string invalidChars = new string(Path.GetInvalidFileNameChars()) + new string(Path.GetInvalidPathChars()); + foreach (char c in invalidChars) { + FileName = FileName.Replace(c.ToString(), "_"); + } StartBuffering(); - linkResolved = true; - Channel.Send(":musical_note: **Queued** " + video.FullName); + LinkResolved = true; + Channel.Send(":musical_note: **Queued** " + video.Title); } catch (Exception e) { // Send a message to the guy that queued that - Channel.SendMessage(":warning: The url is corrupted somehow..."); + Channel.SendMessage(":warning: Something went wrong..."); Console.WriteLine("Cannot parse youtube url: " + query); Cancel(); } diff --git a/NadekoBot/Modules/Trello.cs b/NadekoBot/Modules/Trello.cs index a922877d..7093a15c 100644 --- a/NadekoBot/Modules/Trello.cs +++ b/NadekoBot/Modules/Trello.cs @@ -72,7 +72,7 @@ namespace NadekoBot.Modules { }); cgb.CreateCommand("bind") - .Description("Bind a trello bot to a certain channel. Bot will operate only in 1 channel at a time") + .Description("Bind a trello bot to a single channel. You will receive notifications from your board when somethign is added or edited.") .Parameter("board_id", Discord.Commands.ParameterType.Required) .Do(async e => { if (e.User.Id != NadekoBot.OwnerID) return; diff --git a/NadekoBot/NadekoBot.csproj b/NadekoBot/NadekoBot.csproj index fe385cef..ec727936 100644 --- a/NadekoBot/NadekoBot.csproj +++ b/NadekoBot/NadekoBot.csproj @@ -12,21 +12,20 @@ v4.5.2 512 true - true + false C:\Users\Master\Desktop\NadekoBot\ true - Web - true + Disk + false Foreground 7 Days false false true - http://www.github.com/Kwoth/NadekoBot/ - true publish.htm - 1 + true + 2 1.0.0.%2a false true @@ -64,10 +63,6 @@ true - - ..\packages\VideoLibrary.1.3.1\lib\portable-net45+win+wpa81+MonoAndroid10+xamarinios10+MonoTouch10\libvideo.dll - True - ..\packages\Manatee.Json.3.2.1\lib\net45\Manatee.Json.dll True @@ -129,6 +124,10 @@ ..\packages\taglib.2.1.0.0\lib\taglib-sharp.dll True + + ..\packages\YoutubeExtractor.0.10.10\lib\net35\YoutubeExtractor.dll + True + diff --git a/NadekoBot/packages.config b/NadekoBot/packages.config index 61a5c710..f3f8c5bd 100644 --- a/NadekoBot/packages.config +++ b/NadekoBot/packages.config @@ -12,4 +12,6 @@ + + \ No newline at end of file