Fixed crash, fixed imdb

This commit is contained in:
Kwoth 2016-10-15 08:25:52 +02:00
parent a7ac590e9d
commit 1e87e4cf7f
6 changed files with 39 additions and 17 deletions

View File

@ -35,6 +35,7 @@ namespace NadekoBot.Modules.Administration
if (channel == null) if (channel == null)
return; return;
//todo cache this
bool shouldDelete; bool shouldDelete;
using (var uow = DbHandler.UnitOfWork()) using (var uow = DbHandler.UnitOfWork())
{ {
@ -695,12 +696,14 @@ namespace NadekoBot.Modules.Administration
await channel.SendMessageAsync(send).ConfigureAwait(false); await channel.SendMessageAsync(send).ConfigureAwait(false);
} }
IGuild nadekoSupportServer;
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
public async Task Donators(IUserMessage umsg) public async Task Donators(IUserMessage umsg)
{ {
var channel = (ITextChannel)umsg.Channel; var channel = (ITextChannel)umsg.Channel;
IEnumerable<Donator> donatorsOrdered; IEnumerable<Donator> donatorsOrdered;
using (var uow = DbHandler.UnitOfWork()) using (var uow = DbHandler.UnitOfWork())
{ {
donatorsOrdered = uow.Donators.GetDonatorsOrdered(); 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"; 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); 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);
} }

View File

@ -28,7 +28,6 @@ namespace NadekoBot.Modules.Administration
{ {
conf = uow.GuildConfigs.For(user.Guild.Id); conf = uow.GuildConfigs.For(user.Guild.Id);
} }
var aarType = conf.AutoAssignRoleId.GetType();
if (conf.AutoAssignRoleId == 0) if (conf.AutoAssignRoleId == 0)
return; return;

View File

@ -74,17 +74,9 @@ namespace NadekoBot.Modules.Searches.IMDB
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.?:((.|\n)*?)(<\/div>|See more)", html)).Cast<string>().ToList();
mov.Plot = Match(@"Plot:</h5>.*?<div class=""info-content"">(.*?)(<a|</div)", html); mov.Plot = Match(@"Plot:</h5>\n<div class=""info-content"">\n((.|\n)*?)(<a|</div)", html);
mov.Poster = Match(@"<div class=""photo"">.*?<a name=""poster"".*?><img.*?src=""(.*?)"".*?</div>", html); mov.Poster = Match(@"<a name=""poster"".*src=""(.*)""", 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.ImdbURL = "http://www.imdb.com/title/" + mov.Id + "/"; mov.ImdbURL = "http://www.imdb.com/title/" + mov.Id + "/";
if (GetExtraInfo) if (GetExtraInfo)
{ {
@ -147,7 +139,8 @@ 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 | RegexOptions.IgnoreCase).Match(html).Groups[i].ToString().Trim(); var m = new Regex(regex, RegexOptions.Multiline).Match(html);
return m.Groups[i].Value.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)

View File

@ -26,7 +26,7 @@ $@"`Title:` {WebUtility.HtmlDecode(Title)} {(string.IsNullOrEmpty(OriginalTitle)
`Genre:` {GenresAsString} `Genre:` {GenresAsString}
`Link:` <{ImdbURL}> `Link:` <{ImdbURL}>
`Plot:` {System.Net.WebUtility.HtmlDecode(Plot.TrimTo(500))} `Plot:` {System.Net.WebUtility.HtmlDecode(Plot.TrimTo(500))}
`img:` " + Poster; `Poster:` " + NadekoBot.Google.ShortenUrl(Poster).GetAwaiter().GetResult();
public string GenresAsString => public string GenresAsString =>
string.Join(", ", Genres); string.Join(", ", Genres);
} }

View File

@ -66,6 +66,10 @@ $@"🌍 **Weather for** 【{obj["target"]}】
await channel.SendMessageAsync(result).ConfigureAwait(false); 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] [NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
public async Task Imdb(IUserMessage umsg, [Remainder] string query = null) public async Task Imdb(IUserMessage umsg, [Remainder] string query = null)

View File

@ -7,6 +7,7 @@ using Google.Apis.Services;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using Google.Apis.Urlshortener.v1; using Google.Apis.Urlshortener.v1;
using Google.Apis.Urlshortener.v1.Data; using Google.Apis.Urlshortener.v1.Data;
using NLog;
namespace NadekoBot.Services.Impl namespace NadekoBot.Services.Impl
{ {
@ -14,6 +15,7 @@ namespace NadekoBot.Services.Impl
{ {
private YouTubeService yt; private YouTubeService yt;
private UrlshortenerService sh; private UrlshortenerService sh;
private Logger _log { get; }
public GoogleApiService() public GoogleApiService()
{ {
@ -23,6 +25,8 @@ namespace NadekoBot.Services.Impl
ApiKey = NadekoBot.Credentials.GoogleApiKey ApiKey = NadekoBot.Credentials.GoogleApiKey
}; };
_log = LogManager.GetCurrentClassLogger();
yt = new YouTubeService(bcs); yt = new YouTubeService(bcs);
sh = new UrlshortenerService(bcs); sh = new UrlshortenerService(bcs);
} }
@ -85,9 +89,16 @@ namespace NadekoBot.Services.Impl
{ {
if (string.IsNullOrWhiteSpace(url)) if (string.IsNullOrWhiteSpace(url))
throw new ArgumentNullException(nameof(url)); throw new ArgumentNullException(nameof(url));
try
var response = await sh.Url.Insert(new Url { LongUrl = url }).ExecuteAsync(); {
return response.Id; 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<IEnumerable<string>> GetPlaylistTracksAsync(string playlistId, int count = 50) public async Task<IEnumerable<string>> GetPlaylistTracksAsync(string playlistId, int count = 50)