Started fix on imdb, fixed message repeater
This commit is contained in:
parent
435c06f27b
commit
6c734afa69
@ -46,12 +46,15 @@ namespace NadekoBot.Modules.Administration
|
|||||||
{
|
{
|
||||||
source = new CancellationTokenSource();
|
source = new CancellationTokenSource();
|
||||||
token = source.Token;
|
token = source.Token;
|
||||||
|
IUserMessage oldMsg = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
while (!token.IsCancellationRequested)
|
while (!token.IsCancellationRequested)
|
||||||
{
|
{
|
||||||
await Task.Delay(Repeater.Interval, token).ConfigureAwait(false);
|
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) { }
|
catch (OperationCanceledException) { }
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using NadekoBot.Modules.Searches.Models;
|
using NadekoBot.Extensions;
|
||||||
|
using NadekoBot.Modules.Searches.Models;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@ -71,7 +72,7 @@ namespace NadekoBot.Modules.Searches.IMDB
|
|||||||
mov.Status = true;
|
mov.Status = true;
|
||||||
mov.Title = Match(@"<title>(IMDb \- )*(.*?) \(.*?</title>", html, 2);
|
mov.Title = Match(@"<title>(IMDb \- )*(.*?) \(.*?</title>", html, 2);
|
||||||
mov.OriginalTitle = Match(@"title-extra"">(.*?)<", html);
|
mov.OriginalTitle = Match(@"title-extra"">(.*?)<", html);
|
||||||
mov.Year = Match(@"<title>.*?\(.*?(\d{4}).*?).*?</title>", Match(@"(<title>.*?</title>)", html));
|
mov.Year = Match(@"<title>.*?\(.*?(\d{4}).*?\).*?</title>", Match(@"(<title>.*?</title>)", html));
|
||||||
mov.Rating = Match(@"<b>(\d.\d)/10</b>", html);
|
mov.Rating = Match(@"<b>(\d.\d)/10</b>", html);
|
||||||
mov.Genres = MatchAll(@"<a.*?>(.*?)</a>", Match(@"Genre.?:(.*?)(</div>|See more)", html)).Cast<string>().ToList();
|
mov.Genres = MatchAll(@"<a.*?>(.*?)</a>", Match(@"Genre.?:(.*?)(</div>|See more)", html)).Cast<string>().ToList();
|
||||||
mov.Plot = Match(@"Plot:</h5>.*?<div class=""info-content"">(.*?)(<a|</div)", html);
|
mov.Plot = Match(@"Plot:</h5>.*?<div class=""info-content"">(.*?)(<a|</div)", html);
|
||||||
@ -146,7 +147,7 @@ namespace NadekoBot.Modules.Searches.IMDB
|
|||||||
//Match single instance
|
//Match single instance
|
||||||
private static string Match(string regex, string html, int i = 1)
|
private static string Match(string regex, string html, int i = 1)
|
||||||
{
|
{
|
||||||
return new Regex(regex, RegexOptions.Multiline).Match(html).Groups[i].Value.Trim();
|
return new Regex(regex, RegexOptions.Multiline | RegexOptions.IgnoreCase).Match(html).Groups[i].ToString().Trim();
|
||||||
}
|
}
|
||||||
//Match all instances and return as List<string>
|
//Match all instances and return as List<string>
|
||||||
private static List<string> MatchAll(string regex, string html, int i = 1)
|
private static List<string> MatchAll(string regex, string html, int i = 1)
|
||||||
@ -162,12 +163,12 @@ namespace NadekoBot.Modules.Searches.IMDB
|
|||||||
return Regex.Replace(inputString, @"<.*?>", string.Empty);
|
return Regex.Replace(inputString, @"<.*?>", string.Empty);
|
||||||
}
|
}
|
||||||
//Get URL Data
|
//Get URL Data
|
||||||
private static Task<string> GetUrlDataAsync(string url)
|
private static async Task<string> GetUrlDataAsync(string url)
|
||||||
{
|
{
|
||||||
using (var http = new HttpClient())
|
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");
|
http.AddFakeHeaders();
|
||||||
return http.GetStringAsync(url);
|
return await http.GetStringAsync(url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -81,9 +81,10 @@ $@"🌍 **Weather for** 【{obj["target"]}】
|
|||||||
if (movie.Status) result = movie.ToString();
|
if (movie.Status) result = movie.ToString();
|
||||||
else result = "Failed to find that movie.";
|
else result = "Failed to find that movie.";
|
||||||
}
|
}
|
||||||
catch
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
await channel.SendMessageAsync("Failed to find that movie.").ConfigureAwait(false);
|
await channel.SendMessageAsync("Failed to find that movie.").ConfigureAwait(false);
|
||||||
|
_log.Warn(ex);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user