From 1e3297ae4d13aee8a0aba33a11f5b79c05a41bce Mon Sep 17 00:00:00 2001 From: Jakub Hampl Date: Fri, 25 Jun 2021 18:29:57 +0200 Subject: [PATCH] Removed the wiki search (#15) --- thorn/Modules/WikiModule.cs | 20 ---------- thorn/Services/ScpService.cs | 77 +----------------------------------- 2 files changed, 1 insertion(+), 96 deletions(-) delete mode 100644 thorn/Modules/WikiModule.cs diff --git a/thorn/Modules/WikiModule.cs b/thorn/Modules/WikiModule.cs deleted file mode 100644 index 443e176..0000000 --- a/thorn/Modules/WikiModule.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System.Threading.Tasks; -using Discord.Commands; -using thorn.Services; - -namespace thorn.Modules -{ - public class WikiModule : ModuleBase - { - private readonly ScpService _scp; - - public WikiModule(ScpService scp) - { - _scp = scp; - } - - [Command("wiki")] - [Alias("w")] - public async Task WikiCommand([Remainder] string query) => await ReplyAsync(embed: await _scp.GetEmbedForArticle(query)); - } -} \ No newline at end of file diff --git a/thorn/Services/ScpService.cs b/thorn/Services/ScpService.cs index 35a6580..feb185e 100644 --- a/thorn/Services/ScpService.cs +++ b/thorn/Services/ScpService.cs @@ -24,8 +24,7 @@ private async Task> GetArticleData(string query) { var request = new GraphQLHttpRequest { - Query = $"{{searchPages(query: \"{query}\") {{url wikidotInfo {{title rating}} " + - $"alternateTitles {{title}} attributions {{user {{name}}}}}}}}", + Query = $"{{searchPages(query: \"{query}\") {{url}}", }; var response = await _graphQlClient.SendQueryAsync(request); @@ -56,79 +55,5 @@ public async Task GetEmbedForReference(List queries) return new EmbedBuilder().WithDescription(description.ToString()).Build(); } - - public async Task GetEmbedForArticle(string query) - { - var articles = await GetArticleData(query); - - if (articles is null) return new EmbedBuilder().WithDescription("Tento článek jsem nenašel :(").Build(); - - var czech = articles.FirstOrDefault(x => Regex.Match(x.Url, @"scp-cs\.wikidot\.com").Success); - var english = articles.FirstOrDefault(x => Regex.Match(x.Url, @"scp-wiki\.wikidot\.com").Success); - - if (czech == null && english == null) return new EmbedBuilder().WithDescription("Tento článek jsem nenašel :(").Build(); - - string title, description; - List fieldBuilders; - EmbedFooterBuilder footerBuilder; - - if (czech != null && english != null) - { - description = $"**Autor: `{english.Attributions.First().User.Name}`**\n" + - $"**Překladatel: `{czech.Attributions.First().User.Name}`**"; - - title = czech.AlternateTitles.FirstOrDefault() == null - ? czech.WikidotInfo.Title - : $"{czech.WikidotInfo.Title} - {czech.AlternateTitles.First().Title}"; - - fieldBuilders = new List - { - new EmbedFieldBuilder().WithName("Překlad").WithValue($"[link]({czech.Url})").WithIsInline(true), - new EmbedFieldBuilder().WithName("Originál").WithValue($"[link]({english.Url})").WithIsInline(true) - }; - - footerBuilder = new EmbedFooterBuilder().WithText($"Hodnocení překladu: {czech.WikidotInfo.Rating}"); - } - else if (czech != null) - { - description = $"**Autor: `{czech.Attributions.First().User.Name}`**"; - - title = czech.AlternateTitles.FirstOrDefault() == null - ? czech.WikidotInfo.Title - : $"{czech.WikidotInfo.Title} - {czech.AlternateTitles.First().Title}"; - - fieldBuilders = new List - { - new EmbedFieldBuilder().WithName("Odkaz").WithValue($"[link]({czech.Url})").WithIsInline(true) - }; - - footerBuilder = new EmbedFooterBuilder().WithText($"Hodnocení: {czech.WikidotInfo.Rating}"); - } - else - { - description = $"**Autor: `{english.Attributions.First().User.Name}`**\n" + - $"Zatím nepřeloženo {_pairs.GetString("SAD_EMOTE")}"; - - title = english.AlternateTitles.FirstOrDefault() == null - ? english.WikidotInfo.Title - : $"{english.WikidotInfo.Title} - {english.AlternateTitles.First().Title}"; - - fieldBuilders = new List - { - new EmbedFieldBuilder().WithName("Odkaz").WithValue($"[link]({english.Url})").WithIsInline(true) - }; - - footerBuilder = new EmbedFooterBuilder().WithText($"Hodnocení: {english.WikidotInfo.Rating}"); - } - - return new EmbedBuilder - { - Title = title, - Description = description, - Color = Color.Blue, - Fields = fieldBuilders, - Footer = footerBuilder - }.Build(); - } } } \ No newline at end of file