Skip to content

Commit

Permalink
Removed the wiki search (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
chamik committed Jun 25, 2021
1 parent 9b9e33e commit 1e3297a
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 96 deletions.
20 changes: 0 additions & 20 deletions thorn/Modules/WikiModule.cs

This file was deleted.

77 changes: 1 addition & 76 deletions thorn/Services/ScpService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ private async Task<List<ArticleData>> 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<ResponseType>(request);
Expand Down Expand Up @@ -56,79 +55,5 @@ public async Task<Embed> GetEmbedForReference(List<string> queries)

return new EmbedBuilder().WithDescription(description.ToString()).Build();
}

public async Task<Embed> 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<EmbedFieldBuilder> 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<EmbedFieldBuilder>
{
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<EmbedFieldBuilder>
{
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<EmbedFieldBuilder>
{
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();
}
}
}

0 comments on commit 1e3297a

Please sign in to comment.