Bug fixes in !wiki and errorHandler

This commit is contained in:
runebaas 2018-04-28 02:46:30 +02:00
parent 4548c6083a
commit f5fd9ba017
No known key found for this signature in database
GPG key ID: 2677AF508D0300D6
4 changed files with 9 additions and 5 deletions

View file

@ -29,7 +29,7 @@ namespace Geekbot.net.Commands
sb.AppendLine("https://geekbot.pizzaandcoffee.rocks/commands"); sb.AppendLine("https://geekbot.pizzaandcoffee.rocks/commands");
var dm = await Context.User.GetOrCreateDMChannelAsync(); var dm = await Context.User.GetOrCreateDMChannelAsync();
await dm.SendMessageAsync(sb.ToString()); await dm.SendMessageAsync(sb.ToString());
Context.Message.AddReactionAsync(new Emoji("✅")); await Context.Message.AddReactionAsync(new Emoji("✅"));
} }
catch (Exception e) catch (Exception e)
{ {

View file

@ -59,12 +59,12 @@ namespace Geekbot.net.Commands
{ {
Title = article.Title, Title = article.Title,
Description = article.Extract, Description = article.Extract,
ImageUrl = article.Thumbnail.Source.ToString(), ImageUrl = article.Thumbnail?.Source.ToString(),
Url = article.ContentUrls.Desktop.Page.ToString() Url = article.ContentUrls.Desktop.Page.ToString()
}; };
await ReplyAsync("", false, eb.Build()); await ReplyAsync("", false, eb.Build());
} }
catch (HttpRequestException e) catch (HttpRequestException)
{ {
await ReplyAsync("I couldn't find that article"); await ReplyAsync("I couldn't find that article");
} }
@ -79,6 +79,7 @@ namespace Geekbot.net.Commands
var doc = new HtmlDocument(); var doc = new HtmlDocument();
doc.LoadHtml(extractHtml); doc.LoadHtml(extractHtml);
var nodes = doc.DocumentNode.SelectNodes("//li"); var nodes = doc.DocumentNode.SelectNodes("//li");
if (nodes == null) return "(List is to long to show)";
var sb = new StringBuilder(); var sb = new StringBuilder();
foreach (var node in nodes) foreach (var node in nodes)
{ {

View file

@ -47,7 +47,9 @@ namespace Geekbot.net.Lib
{ {
if (_errorsInChat) if (_errorsInChat)
{ {
Context.Channel.SendMessageAsync($"{e.Message}\r\n```\r\n{e.InnerException}\r\n```"); var resStackTrace = string.IsNullOrEmpty(e.InnerException?.ToString()) ? e.StackTrace : e.InnerException.ToString();
var maxLen = Math.Min(resStackTrace.Length, 1850);
Context.Channel.SendMessageAsync($"{e.Message}\r\n```\r\n{resStackTrace?.Substring(0, maxLen)}\r\n```");
} }
else else
{ {
@ -72,6 +74,7 @@ namespace Geekbot.net.Lib
} }
catch (Exception ex) catch (Exception ex)
{ {
Context.Channel.SendMessageAsync("Something went really really wrong here");
_logger.Error("Geekbot", "Errorception", ex); _logger.Error("Geekbot", "Errorception", ex);
} }
} }

View file

@ -9,7 +9,7 @@ namespace WikipediaApi.Page
{ {
[JsonProperty("type")] [JsonProperty("type")]
[JsonConverter(typeof(StringEnumConverter))] [JsonConverter(typeof(StringEnumConverter))]
public PageTypes Type { get; set; } = PageTypes.NoExtract; public PageTypes Type { get; set; }
[JsonProperty("title")] [JsonProperty("title")]
public string Title { get; set; } public string Title { get; set; }