From 6c734afa69e69a6973f1d9623f96bc4fe9f73d1d Mon Sep 17 00:00:00 2001 From: Kwoth Date: Thu, 13 Oct 2016 02:31:10 +0200 Subject: [PATCH] Started fix on imdb, fixed message repeater --- .../Administration/Commands/MessageRepeater.cs | 5 ++++- .../Modules/Searches/Commands/IMDB/ImdbScraper.cs | 13 +++++++------ src/NadekoBot/Modules/Searches/Searches.cs | 3 ++- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/NadekoBot/Modules/Administration/Commands/MessageRepeater.cs b/src/NadekoBot/Modules/Administration/Commands/MessageRepeater.cs index 501de4f2..0a5d7a20 100644 --- a/src/NadekoBot/Modules/Administration/Commands/MessageRepeater.cs +++ b/src/NadekoBot/Modules/Administration/Commands/MessageRepeater.cs @@ -46,12 +46,15 @@ namespace NadekoBot.Modules.Administration { source = new CancellationTokenSource(); token = source.Token; + IUserMessage oldMsg = null; try { while (!token.IsCancellationRequested) { await Task.Delay(Repeater.Interval, token).ConfigureAwait(false); - try { await Channel.SendMessageAsync("🔄 " + Repeater.Message).ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); try { source.Cancel(); } catch { } } + if (oldMsg != null) + try { await oldMsg.DeleteAsync(); } catch { } + try { oldMsg = await Channel.SendMessageAsync("🔄 " + Repeater.Message).ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); try { source.Cancel(); } catch { } } } } catch (OperationCanceledException) { } diff --git a/src/NadekoBot/Modules/Searches/Commands/IMDB/ImdbScraper.cs b/src/NadekoBot/Modules/Searches/Commands/IMDB/ImdbScraper.cs index 32f2c34f..ce8f8a37 100644 --- a/src/NadekoBot/Modules/Searches/Commands/IMDB/ImdbScraper.cs +++ b/src/NadekoBot/Modules/Searches/Commands/IMDB/ImdbScraper.cs @@ -1,4 +1,5 @@ -using NadekoBot.Modules.Searches.Models; +using NadekoBot.Extensions; +using NadekoBot.Modules.Searches.Models; using System; using System.Collections.Generic; using System.Linq; @@ -71,7 +72,7 @@ namespace NadekoBot.Modules.Searches.IMDB mov.Status = true; mov.Title = Match(@"(IMDb \- )*(.*?) \(.*?", html, 2); mov.OriginalTitle = Match(@"title-extra"">(.*?)<", html); - mov.Year = Match(@".*?\(.*?(\d{4}).*?).*?", Match(@"(.*?)", 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:.*?
(.*?)( private static List MatchAll(string regex, string html, int i = 1) @@ -162,12 +163,12 @@ namespace NadekoBot.Modules.Searches.IMDB return Regex.Replace(inputString, @"<.*?>", string.Empty); } //Get URL Data - private static Task GetUrlDataAsync(string url) + private static async Task GetUrlDataAsync(string url) { using (var http = new HttpClient()) { - http.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.202 Safari/535.1"); - return http.GetStringAsync(url); + http.AddFakeHeaders(); + return await http.GetStringAsync(url); } } } diff --git a/src/NadekoBot/Modules/Searches/Searches.cs b/src/NadekoBot/Modules/Searches/Searches.cs index e88656d3..5f676709 100644 --- a/src/NadekoBot/Modules/Searches/Searches.cs +++ b/src/NadekoBot/Modules/Searches/Searches.cs @@ -81,9 +81,10 @@ $@"🌍 **Weather for** 【{obj["target"]}】 if (movie.Status) result = movie.ToString(); else result = "Failed to find that movie."; } - catch + catch (Exception ex) { await channel.SendMessageAsync("Failed to find that movie.").ConfigureAwait(false); + _log.Warn(ex); return; }