From 1e87e4cf7f9e7be3d932084cc7a53f55dbac84c2 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Sat, 15 Oct 2016 08:25:52 +0200 Subject: [PATCH] Fixed crash, fixed imdb --- .../Modules/Administration/Administration.cs | 15 +++++++++++++++ .../Commands/AutoAssignRoleCommands.cs | 1 - .../Searches/Commands/IMDB/ImdbScraper.cs | 17 +++++------------ .../Searches/Commands/Models/ImdbMovie.cs | 2 +- src/NadekoBot/Modules/Searches/Searches.cs | 4 ++++ src/NadekoBot/Services/Impl/GoogleApiService.cs | 17 ++++++++++++++--- 6 files changed, 39 insertions(+), 17 deletions(-) diff --git a/src/NadekoBot/Modules/Administration/Administration.cs b/src/NadekoBot/Modules/Administration/Administration.cs index eaeb163a..b3a7cd36 100644 --- a/src/NadekoBot/Modules/Administration/Administration.cs +++ b/src/NadekoBot/Modules/Administration/Administration.cs @@ -35,6 +35,7 @@ namespace NadekoBot.Modules.Administration if (channel == null) return; + //todo cache this bool shouldDelete; using (var uow = DbHandler.UnitOfWork()) { @@ -695,12 +696,14 @@ namespace NadekoBot.Modules.Administration await channel.SendMessageAsync(send).ConfigureAwait(false); } + IGuild nadekoSupportServer; [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] public async Task Donators(IUserMessage umsg) { var channel = (ITextChannel)umsg.Channel; IEnumerable donatorsOrdered; + using (var uow = DbHandler.UnitOfWork()) { donatorsOrdered = uow.Donators.GetDonatorsOrdered(); @@ -708,6 +711,18 @@ namespace NadekoBot.Modules.Administration string str = $"**Thanks to the people listed below for making this project happen!**\n"; await channel.SendMessageAsync(str + string.Join("⭐", donatorsOrdered.Select(d => d.Name))).ConfigureAwait(false); + + nadekoSupportServer = nadekoSupportServer ?? NadekoBot.Client.GetGuild(117523346618318850); + + if (nadekoSupportServer == null) + return; + + var patreonRole = nadekoSupportServer.GetRole(236667642088259585); + if (patreonRole == null) + return; + + var usrs = nadekoSupportServer.GetUsers().Where(u => u.Roles.Contains(patreonRole)); + await channel.SendMessageAsync("\n`Patreon supporters:`\n" + string.Join("⭐", usrs.Select(d => d.Username))).ConfigureAwait(false); } diff --git a/src/NadekoBot/Modules/Administration/Commands/AutoAssignRoleCommands.cs b/src/NadekoBot/Modules/Administration/Commands/AutoAssignRoleCommands.cs index 968f9dd9..dd35927c 100644 --- a/src/NadekoBot/Modules/Administration/Commands/AutoAssignRoleCommands.cs +++ b/src/NadekoBot/Modules/Administration/Commands/AutoAssignRoleCommands.cs @@ -28,7 +28,6 @@ namespace NadekoBot.Modules.Administration { conf = uow.GuildConfigs.For(user.Guild.Id); } - var aarType = conf.AutoAssignRoleId.GetType(); if (conf.AutoAssignRoleId == 0) return; diff --git a/src/NadekoBot/Modules/Searches/Commands/IMDB/ImdbScraper.cs b/src/NadekoBot/Modules/Searches/Commands/IMDB/ImdbScraper.cs index ce8f8a37..3f635099 100644 --- a/src/NadekoBot/Modules/Searches/Commands/IMDB/ImdbScraper.cs +++ b/src/NadekoBot/Modules/Searches/Commands/IMDB/ImdbScraper.cs @@ -74,17 +74,9 @@ namespace NadekoBot.Modules.Searches.IMDB mov.OriginalTitle = Match(@"title-extra"">(.*?)<", html); mov.Year = Match(@".*?\(.*?(\d{4}).*?\).*?", Match(@"(.*?)", html)); mov.Rating = Match(@"(\d.\d)/10", html); - mov.Genres = MatchAll(@"(.*?)", Match(@"Genre.?:(.*?)(|See more)", html)).Cast().ToList(); - mov.Plot = Match(@"Plot:.*?
(.*?)(.*?", html); - if (!string.IsNullOrEmpty(mov.Poster) && mov.Poster.IndexOf("media-imdb.com") > 0) - { - mov.Poster = Regex.Replace(mov.Poster, @"_V1.*?.jpg", "_V1._SY200.jpg"); - } - else - { - mov.Poster = string.Empty; - } + mov.Genres = MatchAll(@"(.*?)", Match(@"Genre.?:((.|\n)*?)(<\/div>|See more)", html)).Cast().ToList(); + mov.Plot = Match(@"Plot:\n
\n((.|\n)*?)( private static List MatchAll(string regex, string html, int i = 1) diff --git a/src/NadekoBot/Modules/Searches/Commands/Models/ImdbMovie.cs b/src/NadekoBot/Modules/Searches/Commands/Models/ImdbMovie.cs index f4fa1770..318eb6dc 100644 --- a/src/NadekoBot/Modules/Searches/Commands/Models/ImdbMovie.cs +++ b/src/NadekoBot/Modules/Searches/Commands/Models/ImdbMovie.cs @@ -26,7 +26,7 @@ $@"`Title:` {WebUtility.HtmlDecode(Title)} {(string.IsNullOrEmpty(OriginalTitle) `Genre:` {GenresAsString} `Link:` <{ImdbURL}> `Plot:` {System.Net.WebUtility.HtmlDecode(Plot.TrimTo(500))} -`img:` " + Poster; +`Poster:` " + NadekoBot.Google.ShortenUrl(Poster).GetAwaiter().GetResult(); public string GenresAsString => string.Join(", ", Genres); } diff --git a/src/NadekoBot/Modules/Searches/Searches.cs b/src/NadekoBot/Modules/Searches/Searches.cs index 5f676709..d18d94a9 100644 --- a/src/NadekoBot/Modules/Searches/Searches.cs +++ b/src/NadekoBot/Modules/Searches/Searches.cs @@ -66,6 +66,10 @@ $@"🌍 **Weather for** 【{obj["target"]}】 await channel.SendMessageAsync(result).ConfigureAwait(false); } + //todo move to omdb + // | + // v + //{"Title":"Shutter Island","Year":"2010","Rated":"R","Released":"19 Feb 2010","Runtime":"138 min","Genre":"Mystery, Thriller","Director":"Martin Scorsese","Writer":"Laeta Kalogridis (screenplay), Dennis Lehane (novel)","Actors":"Leonardo DiCaprio, Mark Ruffalo, Ben Kingsley, Max von Sydow","Plot":"In 1954, a U.S. marshal investigates the disappearance of a murderess who escaped from a hospital for the criminally insane.","Language":"English, German","Country":"USA","Awards":"8 wins & 59 nominations.","Poster":"https://images-na.ssl-images-amazon.com/images/M/MV5BMTMxMTIyNzMxMV5BMl5BanBnXkFtZTcwOTc4OTI3Mg@@._V1_SX300.jpg","Metascore":"63","imdbRating":"8.1","imdbVotes":"798,447","imdbID":"tt1130884","Type":"movie","Response":"True"} [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] public async Task Imdb(IUserMessage umsg, [Remainder] string query = null) diff --git a/src/NadekoBot/Services/Impl/GoogleApiService.cs b/src/NadekoBot/Services/Impl/GoogleApiService.cs index 4d74e290..c1df1513 100644 --- a/src/NadekoBot/Services/Impl/GoogleApiService.cs +++ b/src/NadekoBot/Services/Impl/GoogleApiService.cs @@ -7,6 +7,7 @@ using Google.Apis.Services; using System.Text.RegularExpressions; using Google.Apis.Urlshortener.v1; using Google.Apis.Urlshortener.v1.Data; +using NLog; namespace NadekoBot.Services.Impl { @@ -14,6 +15,7 @@ namespace NadekoBot.Services.Impl { private YouTubeService yt; private UrlshortenerService sh; + private Logger _log { get; } public GoogleApiService() { @@ -23,6 +25,8 @@ namespace NadekoBot.Services.Impl ApiKey = NadekoBot.Credentials.GoogleApiKey }; + _log = LogManager.GetCurrentClassLogger(); + yt = new YouTubeService(bcs); sh = new UrlshortenerService(bcs); } @@ -85,9 +89,16 @@ namespace NadekoBot.Services.Impl { if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - - var response = await sh.Url.Insert(new Url { LongUrl = url }).ExecuteAsync(); - return response.Id; + try + { + var response = await sh.Url.Insert(new Url { LongUrl = url }).ExecuteAsync(); + return response.Id; + } + catch (Exception ex) + { + _log.Warn(ex); + return url; + } } public async Task> GetPlaylistTracksAsync(string playlistId, int count = 50)