diff --git a/src/NadekoBot/DataStructures/PoopyRingBuffer.cs b/src/NadekoBot/DataStructures/PoopyRingBuffer.cs index acb7db8e..296a5c47 100644 --- a/src/NadekoBot/DataStructures/PoopyRingBuffer.cs +++ b/src/NadekoBot/DataStructures/PoopyRingBuffer.cs @@ -9,7 +9,7 @@ namespace NadekoBot.DataStructures // readpos == writepos means empty // writepos == readpos - 1 means full - private readonly byte[] buffer; + private byte[] buffer; public int Capacity { get; } private int _readPos = 0; @@ -110,7 +110,7 @@ namespace NadekoBot.DataStructures public void Dispose() { - + buffer = null; } } } diff --git a/src/NadekoBot/NadekoBot.csproj b/src/NadekoBot/NadekoBot.csproj index d5d72b38..84884614 100644 --- a/src/NadekoBot/NadekoBot.csproj +++ b/src/NadekoBot/NadekoBot.csproj @@ -74,6 +74,7 @@ + diff --git a/src/NadekoBot/Services/Impl/GoogleApiService.cs b/src/NadekoBot/Services/Impl/GoogleApiService.cs index d7d93f4c..ec09f169 100644 --- a/src/NadekoBot/Services/Impl/GoogleApiService.cs +++ b/src/NadekoBot/Services/Impl/GoogleApiService.cs @@ -42,16 +42,17 @@ namespace NadekoBot.Services.Impl sh = new UrlshortenerService(bcs); cs = new CustomsearchService(bcs); } - + private static readonly Regex plRegex = new Regex("(?:youtu\\.be\\/|list=)(?[\\da-zA-Z\\-_]*)", RegexOptions.Compiled); public async Task> GetPlaylistIdsByKeywordsAsync(string keywords, int count = 1) { + await Task.Yield(); if (string.IsNullOrWhiteSpace(keywords)) throw new ArgumentNullException(nameof(keywords)); if (count <= 0) throw new ArgumentOutOfRangeException(nameof(count)); - var match = new Regex("(?:youtu\\.be\\/|list=)(?[\\da-zA-Z\\-_]*)").Match(keywords); + var match = plRegex.Match(keywords); if (match.Length > 1) { return new[] { match.Groups["id"].Value.ToString() }; @@ -64,22 +65,17 @@ namespace NadekoBot.Services.Impl return (await query.ExecuteAsync()).Items.Select(i => i.Id.PlaylistId); } - private readonly Regex YtVideoIdRegex = new Regex(@"(?:youtube\.com\/\S*(?:(?:\/e(?:mbed))?\/|watch\?(?:\S*?&?v\=))|youtu\.be\/)(?[a-zA-Z0-9_-]{6,11})", RegexOptions.Compiled); + //private readonly Regex YtVideoIdRegex = new Regex(@"(?:youtube\.com\/\S*(?:(?:\/e(?:mbed))?\/|watch\?(?:\S*?&?v\=))|youtu\.be\/)(?[a-zA-Z0-9_-]{6,11})", RegexOptions.Compiled); private readonly IBotCredentials _creds; public async Task> GetRelatedVideosAsync(string id, int count = 1) { + await Task.Yield(); if (string.IsNullOrWhiteSpace(id)) throw new ArgumentNullException(nameof(id)); if (count <= 0) throw new ArgumentOutOfRangeException(nameof(count)); - - var match = YtVideoIdRegex.Match(id); - if (match.Length > 1) - { - id = match.Groups["id"].Value; - } var query = yt.Search.List("snippet"); query.MaxResults = count; query.RelatedToVideoId = id; @@ -89,22 +85,13 @@ namespace NadekoBot.Services.Impl public async Task> GetVideoLinksByKeywordAsync(string keywords, int count = 1) { + await Task.Yield(); if (string.IsNullOrWhiteSpace(keywords)) throw new ArgumentNullException(nameof(keywords)); if (count <= 0) throw new ArgumentOutOfRangeException(nameof(count)); - - string id = ""; - var match = YtVideoIdRegex.Match(keywords); - if (match.Length > 1) - { - id = match.Groups["id"].Value; - } - if (!string.IsNullOrWhiteSpace(id)) - { - return new[] { "http://www.youtube.com/watch?v=" + id }; - } + var query = yt.Search.List("snippet"); query.MaxResults = count; query.Q = keywords; @@ -114,6 +101,7 @@ namespace NadekoBot.Services.Impl public async Task> GetVideoInfosByKeywordAsync(string keywords, int count = 1) { + await Task.Yield(); if (string.IsNullOrWhiteSpace(keywords)) throw new ArgumentNullException(nameof(keywords)); @@ -129,6 +117,7 @@ namespace NadekoBot.Services.Impl public async Task ShortenUrl(string url) { + await Task.Yield(); if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); @@ -149,6 +138,7 @@ namespace NadekoBot.Services.Impl public async Task> GetPlaylistTracksAsync(string playlistId, int count = 50) { + await Task.Yield(); if (string.IsNullOrWhiteSpace(playlistId)) throw new ArgumentNullException(nameof(playlistId)); @@ -181,6 +171,7 @@ namespace NadekoBot.Services.Impl public async Task> GetVideoDurationsAsync(IEnumerable videoIds) { + await Task.Yield(); var videoIdsList = videoIds as List ?? videoIds.ToList(); Dictionary toReturn = new Dictionary(); @@ -211,6 +202,7 @@ namespace NadekoBot.Services.Impl public async Task GetImageAsync(string query, int start = 1) { + await Task.Yield(); if (string.IsNullOrWhiteSpace(query)) throw new ArgumentNullException(nameof(query)); @@ -362,6 +354,7 @@ namespace NadekoBot.Services.Impl public async Task Translate(string sourceText, string sourceLanguage, string targetLanguage) { + await Task.Yield(); string text; if (!_languageDictionary.ContainsKey(sourceLanguage) || diff --git a/src/NadekoBot/Services/Music/MusicPlayer.cs b/src/NadekoBot/Services/Music/MusicPlayer.cs index 688bf1c8..156e0801 100644 --- a/src/NadekoBot/Services/Music/MusicPlayer.cs +++ b/src/NadekoBot/Services/Music/MusicPlayer.cs @@ -161,7 +161,7 @@ namespace NadekoBot.Services.Music continue; _log.Info("Starting"); - using (var b = new SongBuffer(await data.Song.Uri(), "")) + using (var b = new SongBuffer(await data.Song.Uri(), "", data.Song.ProviderType == Database.Models.MusicType.Local)) { _log.Info("Created buffer, buffering..."); AudioOutStream pcm = null; diff --git a/src/NadekoBot/ShardsCoordinator.cs b/src/NadekoBot/ShardsCoordinator.cs index ad112cbf..6846e4d2 100644 --- a/src/NadekoBot/ShardsCoordinator.cs +++ b/src/NadekoBot/ShardsCoordinator.cs @@ -73,36 +73,38 @@ namespace NadekoBot { _log.Error(ex); } - await Task.Run(() => - { - string input; - while ((input = Console.ReadLine()?.ToLowerInvariant()) != "quit") - { - try - { - switch (input) - { - case "ls": - var groupStr = string.Join(",", Statuses - .ToArray() - .Where(x => x != null) - .GroupBy(x => x.ConnectionState) - .Select(x => x.Count() + " " + x.Key)); - _log.Info(string.Join("\n", Statuses - .ToArray() - .Where(x => x != null) - .Select(x => $"Shard {x.ShardId} is in {x.ConnectionState.ToString()} state with {x.Guilds} servers. {(DateTime.UtcNow - x.Time).ToString(@"hh\:mm\:ss")} ago")) + "\n" + groupStr); - break; - default: - break; - } - } - catch (Exception ex) - { - _log.Warn(ex); - } - } - }); + //await Task.Run(() => + //{ + // string input; + // while ((input = Console.ReadLine()?.ToLowerInvariant()) != "quit") + // { + // try + // { + // switch (input) + // { + // case "ls": + // var groupStr = string.Join(",", Statuses + // .ToArray() + // .Where(x => x != null) + // .GroupBy(x => x.ConnectionState) + // .Select(x => x.Count() + " " + x.Key)); + // _log.Info(string.Join("\n", Statuses + // .ToArray() + // .Where(x => x != null) + // .Select(x => $"Shard {x.ShardId} is in {x.ConnectionState.ToString()} state with {x.Guilds} servers. {(DateTime.UtcNow - x.Time).ToString(@"hh\:mm\:ss")} ago")) + "\n" + groupStr); + // break; + // default: + // break; + // } + // } + // catch (Exception ex) + // { + // _log.Warn(ex); + // } + // } + //}); + + await Task.Delay(-1); foreach (var p in ShardProcesses) { try { p.Kill(); } catch { }