From 9ff0c929c245ba9c6d6433d419da60de1708476b Mon Sep 17 00:00:00 2001 From: Master Kwoth Date: Thu, 15 Jun 2017 02:34:59 +0200 Subject: [PATCH] fixed .rj --- .../Modules/Searches/Commands/JokeCommands.cs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/NadekoBot/Modules/Searches/Commands/JokeCommands.cs b/src/NadekoBot/Modules/Searches/Commands/JokeCommands.cs index 590e5426..ec653b87 100644 --- a/src/NadekoBot/Modules/Searches/Commands/JokeCommands.cs +++ b/src/NadekoBot/Modules/Searches/Commands/JokeCommands.cs @@ -1,4 +1,5 @@ -using Discord.Commands; +using AngleSharp; +using Discord.Commands; using NadekoBot.Attributes; using NadekoBot.Extensions; using NadekoBot.Services; @@ -37,8 +38,17 @@ namespace NadekoBot.Modules.Searches { using (var http = new HttpClient()) { - var response = await http.GetStringAsync("http://tambal.azurewebsites.net/joke/random").ConfigureAwait(false); - await Context.Channel.SendConfirmAsync(JObject.Parse(response)["joke"].ToString() + " 😆").ConfigureAwait(false); + http.AddFakeHeaders(); + + var config = Configuration.Default.WithDefaultLoader(); + var document = await BrowsingContext.New(config).OpenAsync("http://www.goodbadjokes.com/random"); + + var html = document.QuerySelector(".post > .joke-content"); + + var part1 = html.QuerySelector("dt").TextContent; + var part2 = html.QuerySelector("dd").TextContent; + + await Context.Channel.SendConfirmAsync("", part1 + "\n\n" + part2, footer: document.BaseUri).ConfigureAwait(false); } }