From 8917a8ba5fcb9da0dc4647643ba2df2a20250fad Mon Sep 17 00:00:00 2001 From: Andriy <30056636+West14@users.noreply.github.com> Date: Sun, 9 Feb 2025 15:47:52 +0200 Subject: [PATCH] chore: drop unused modules These two are making lots of problems during update process: the `ChatQuotes` one was never operational and the `Destiny2.WhereIsXur` became obsolete, since Xur was granted his permanent place on the Tower --- Dockerfile | 2 - Kruzya.TelegramBot.sln | 14 ----- modules/ChatQuotes/ChatQuotes.cs | 31 ---------- modules/ChatQuotes/ChatQuotes.csproj | 22 -------- modules/ChatQuotes/Handler/Quote.cs | 38 ------------- .../Json/NullToEmptyObjectResolver.cs | 17 ------ .../Json/NullToEmptyObjectValueProvider.cs | 26 --------- modules/ChatQuotes/Model/Quote/MediaType.cs | 6 -- modules/ChatQuotes/Model/Quote/Message.cs | 56 ------------------- modules/ChatQuotes/Model/Quote/Request.cs | 35 ------------ modules/ChatQuotes/Model/Quote/Response.cs | 16 ------ modules/ChatQuotes/Model/Quote/Result.cs | 13 ----- modules/ChatQuotes/Model/Quote/Type.cs | 8 --- modules/ChatQuotes/Model/User.cs | 22 -------- modules/ChatQuotes/QuoteGeneratorService.cs | 41 -------------- .../Destiny2.WhereIsXur.csproj | 18 ------ .../Provider/IXurPlaceProvider.cs | 9 --- .../Destiny2.WhereIsXur/Provider/XurWiki.cs | 27 --------- modules/Destiny2.WhereIsXur/RequestHandler.cs | 36 ------------ modules/Destiny2.WhereIsXur/WhereIsXur.cs | 17 ------ 20 files changed, 454 deletions(-) delete mode 100644 modules/ChatQuotes/ChatQuotes.cs delete mode 100644 modules/ChatQuotes/ChatQuotes.csproj delete mode 100644 modules/ChatQuotes/Handler/Quote.cs delete mode 100644 modules/ChatQuotes/Json/NullToEmptyObjectResolver.cs delete mode 100644 modules/ChatQuotes/Json/NullToEmptyObjectValueProvider.cs delete mode 100644 modules/ChatQuotes/Model/Quote/MediaType.cs delete mode 100644 modules/ChatQuotes/Model/Quote/Message.cs delete mode 100644 modules/ChatQuotes/Model/Quote/Request.cs delete mode 100644 modules/ChatQuotes/Model/Quote/Response.cs delete mode 100644 modules/ChatQuotes/Model/Quote/Result.cs delete mode 100644 modules/ChatQuotes/Model/Quote/Type.cs delete mode 100644 modules/ChatQuotes/Model/User.cs delete mode 100644 modules/ChatQuotes/QuoteGeneratorService.cs delete mode 100644 modules/Destiny2.WhereIsXur/Destiny2.WhereIsXur.csproj delete mode 100644 modules/Destiny2.WhereIsXur/Provider/IXurPlaceProvider.cs delete mode 100644 modules/Destiny2.WhereIsXur/Provider/XurWiki.cs delete mode 100644 modules/Destiny2.WhereIsXur/RequestHandler.cs delete mode 100644 modules/Destiny2.WhereIsXur/WhereIsXur.cs diff --git a/Dockerfile b/Dockerfile index 5f16d55..83ea206 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,13 +7,11 @@ COPY Kruzya.TelegramBot.sln ./ COPY ./Core/*.csproj ./Core/ COPY ./tests/*.csproj ./tests/ COPY ./modules/CombotAntiSpam/*.csproj ./modules/CombotAntiSpam/ -COPY ./modules/Destiny2.WhereIsXur/*.csproj ./modules/Destiny2.WhereIsXur/ COPY ./modules/RichSiteSummary/*.csproj ./modules/RichSiteSummary/ COPY ./modules/UrlLimitations/*.csproj ./modules/UrlLimitations/ COPY ./modules/ChatManagement/*.csproj ./modules/ChatManagement/ COPY ./modules/Entertainment/*.csproj ./modules/Entertainment/ COPY ./modules/UserGroupTag/*.csproj ./modules/UserGroupTag/ -COPY ./modules/ChatQuotes/*.csproj ./modules/ChatQuotes/ COPY ./modules/Reputation/*.csproj ./modules/Reputation/ COPY ./modules/ContentStore/*.csproj ./modules/ContentStore/ COPY ./modules/DebugTools/*.csproj ./modules/DebugTools/ diff --git a/Kruzya.TelegramBot.sln b/Kruzya.TelegramBot.sln index 3dc09f6..7a6e911 100644 --- a/Kruzya.TelegramBot.sln +++ b/Kruzya.TelegramBot.sln @@ -15,16 +15,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tests", "tests\Tests.csproj EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UrlLimitations", "modules\UrlLimitations\UrlLimitations.csproj", "{B82E3339-3B34-4600-8C59-C5A3640B1982}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Destiny2.WhereIsXur", "modules\Destiny2.WhereIsXur\Destiny2.WhereIsXur.csproj", "{AE782132-BED8-4D1E-98FA-CB768171D332}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ChatManagement", "modules\ChatManagement\ChatManagement.csproj", "{55ACF7F7-409A-45EE-A41D-D8417DE7EAA7}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UserGroupTag", "modules\UserGroupTag\UserGroupTag.csproj", "{5B89E22A-78CF-4037-BE0D-5F88EF47022B}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Entertainment", "modules\Entertainment\Entertainment.csproj", "{1D62101B-C2B1-4E79-8F7A-690E44E3EE81}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ChatQuotes", "modules\ChatQuotes\ChatQuotes.csproj", "{04F16325-8F44-4250-9B2E-0F77E8F65CBF}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Reputation", "modules\Reputation\Reputation.csproj", "{03F3C7D5-6FEF-4A83-9191-501091BFC1AC}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ContentStore", "modules\ContentStore\ContentStore.csproj", "{4F1E8FE8-640F-4671-87FC-0FFCCB6EDF5E}" @@ -61,10 +57,6 @@ Global {B82E3339-3B34-4600-8C59-C5A3640B1982}.Debug|Any CPU.Build.0 = Debug|Any CPU {B82E3339-3B34-4600-8C59-C5A3640B1982}.Release|Any CPU.ActiveCfg = Release|Any CPU {B82E3339-3B34-4600-8C59-C5A3640B1982}.Release|Any CPU.Build.0 = Release|Any CPU - {AE782132-BED8-4D1E-98FA-CB768171D332}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {AE782132-BED8-4D1E-98FA-CB768171D332}.Debug|Any CPU.Build.0 = Debug|Any CPU - {AE782132-BED8-4D1E-98FA-CB768171D332}.Release|Any CPU.ActiveCfg = Release|Any CPU - {AE782132-BED8-4D1E-98FA-CB768171D332}.Release|Any CPU.Build.0 = Release|Any CPU {55ACF7F7-409A-45EE-A41D-D8417DE7EAA7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {55ACF7F7-409A-45EE-A41D-D8417DE7EAA7}.Debug|Any CPU.Build.0 = Debug|Any CPU {55ACF7F7-409A-45EE-A41D-D8417DE7EAA7}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -77,10 +69,6 @@ Global {1D62101B-C2B1-4E79-8F7A-690E44E3EE81}.Debug|Any CPU.Build.0 = Debug|Any CPU {1D62101B-C2B1-4E79-8F7A-690E44E3EE81}.Release|Any CPU.ActiveCfg = Release|Any CPU {1D62101B-C2B1-4E79-8F7A-690E44E3EE81}.Release|Any CPU.Build.0 = Release|Any CPU - {04F16325-8F44-4250-9B2E-0F77E8F65CBF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {04F16325-8F44-4250-9B2E-0F77E8F65CBF}.Debug|Any CPU.Build.0 = Debug|Any CPU - {04F16325-8F44-4250-9B2E-0F77E8F65CBF}.Release|Any CPU.ActiveCfg = Release|Any CPU - {04F16325-8F44-4250-9B2E-0F77E8F65CBF}.Release|Any CPU.Build.0 = Release|Any CPU {03F3C7D5-6FEF-4A83-9191-501091BFC1AC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {03F3C7D5-6FEF-4A83-9191-501091BFC1AC}.Debug|Any CPU.Build.0 = Debug|Any CPU {03F3C7D5-6FEF-4A83-9191-501091BFC1AC}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -109,11 +97,9 @@ Global {F1E1FBB7-ABA4-4304-9A42-D4975822B002} = {C7821F15-DEDD-474F-A575-A296D4B58F10} {C50D64C3-204B-4B58-927B-C8D759787252} = {C7821F15-DEDD-474F-A575-A296D4B58F10} {B82E3339-3B34-4600-8C59-C5A3640B1982} = {C7821F15-DEDD-474F-A575-A296D4B58F10} - {AE782132-BED8-4D1E-98FA-CB768171D332} = {C7821F15-DEDD-474F-A575-A296D4B58F10} {55ACF7F7-409A-45EE-A41D-D8417DE7EAA7} = {C7821F15-DEDD-474F-A575-A296D4B58F10} {5B89E22A-78CF-4037-BE0D-5F88EF47022B} = {C7821F15-DEDD-474F-A575-A296D4B58F10} {1D62101B-C2B1-4E79-8F7A-690E44E3EE81} = {C7821F15-DEDD-474F-A575-A296D4B58F10} - {04F16325-8F44-4250-9B2E-0F77E8F65CBF} = {C7821F15-DEDD-474F-A575-A296D4B58F10} {03F3C7D5-6FEF-4A83-9191-501091BFC1AC} = {C7821F15-DEDD-474F-A575-A296D4B58F10} {4F1E8FE8-640F-4671-87FC-0FFCCB6EDF5E} = {C7821F15-DEDD-474F-A575-A296D4B58F10} {B95C9180-4893-4A33-BF43-AB2EE998650C} = {C7821F15-DEDD-474F-A575-A296D4B58F10} diff --git a/modules/ChatQuotes/ChatQuotes.cs b/modules/ChatQuotes/ChatQuotes.cs deleted file mode 100644 index 95addda..0000000 --- a/modules/ChatQuotes/ChatQuotes.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System.Globalization; -using Kruzya.TelegramBot.Core; -using Microsoft.Extensions.DependencyInjection; -using Newtonsoft.Json; -using Newtonsoft.Json.Converters; -using Newtonsoft.Json.Serialization; -using West.TelegramBot.ChatQuotes.Json; - -namespace West.TelegramBot.ChatQuotes; - -public class ChatQuotes : Module -{ - public static readonly JsonSerializerSettings SerializerSettings = new() - { - MetadataPropertyHandling = MetadataPropertyHandling.Ignore, - DateParseHandling = DateParseHandling.None, - Converters = - { - new IsoDateTimeConverter { DateTimeStyles = DateTimeStyles.AssumeUniversal }, - new StringEnumConverter(new CamelCaseNamingStrategy()) - }, - ContractResolver = new NullToEmptyObjectResolver() - }; - - public ChatQuotes(Core core) : base(core) { } - - public override void ConfigureServices(IServiceCollection services) - { - services.AddSingleton(); - } -} \ No newline at end of file diff --git a/modules/ChatQuotes/ChatQuotes.csproj b/modules/ChatQuotes/ChatQuotes.csproj deleted file mode 100644 index 7dbc820..0000000 --- a/modules/ChatQuotes/ChatQuotes.csproj +++ /dev/null @@ -1,22 +0,0 @@ - - - - net8.0 - enable - enable - West.TelegramBot.ChatQuotes - TelegramBot.ChatQuotes - - - - - - - - - - - - - - diff --git a/modules/ChatQuotes/Handler/Quote.cs b/modules/ChatQuotes/Handler/Quote.cs deleted file mode 100644 index eadc57c..0000000 --- a/modules/ChatQuotes/Handler/Quote.cs +++ /dev/null @@ -1,38 +0,0 @@ -using BotFramework; -using BotFramework.Attributes; -using BotFramework.Enums; -using Telegram.Bot; -using Telegram.Bot.Types; - -namespace West.TelegramBot.ChatQuotes.Handler; - -public class Quote : BotEventHandler -{ - private readonly QuoteGeneratorService _quoteGenerator; - - public Quote(QuoteGeneratorService quoteGenerator) - { - _quoteGenerator = quoteGenerator; - } - - [InChat(InChat.Public)] - [Command("q", CommandParseMode.Both)] - public async Task HandleQuote() - { - var msg = RawUpdate.Message; - var replyToMessage = msg?.ReplyToMessage; - if (msg == null || replyToMessage == null) - { - return; - } - - var quoteImage = await _quoteGenerator.GenerateQuoteImage(replyToMessage); - if (quoteImage == null) - { - return; - } - - await Bot.SendStickerAsync(Chat.Id, new InputFile(quoteImage), - replyToMessageId: msg.MessageId); - } -} \ No newline at end of file diff --git a/modules/ChatQuotes/Json/NullToEmptyObjectResolver.cs b/modules/ChatQuotes/Json/NullToEmptyObjectResolver.cs deleted file mode 100644 index 4a06d91..0000000 --- a/modules/ChatQuotes/Json/NullToEmptyObjectResolver.cs +++ /dev/null @@ -1,17 +0,0 @@ -using Newtonsoft.Json; -using Newtonsoft.Json.Serialization; - -namespace West.TelegramBot.ChatQuotes.Json; - -class NullToEmptyObjectResolver : DefaultContractResolver -{ - protected override IList CreateProperties(Type type, MemberSerialization memberSerialization) - { - return type.GetProperties() - .Select(p => { - var jp = base.CreateProperty(p, memberSerialization); - jp.ValueProvider = new NullToEmptyObjectValueProvider(p); - return jp; - }).ToList(); - } -} \ No newline at end of file diff --git a/modules/ChatQuotes/Json/NullToEmptyObjectValueProvider.cs b/modules/ChatQuotes/Json/NullToEmptyObjectValueProvider.cs deleted file mode 100644 index cb6d497..0000000 --- a/modules/ChatQuotes/Json/NullToEmptyObjectValueProvider.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System.Reflection; -using Newtonsoft.Json.Serialization; -using Telegram.Bot.Types; - -namespace West.TelegramBot.ChatQuotes.Json; - -public class NullToEmptyObjectValueProvider : IValueProvider -{ - private readonly PropertyInfo _memberInfo; - public NullToEmptyObjectValueProvider(PropertyInfo memberInfo) - { - _memberInfo = memberInfo; - } - - public object? GetValue(object target) - { - var result = _memberInfo.GetValue(target); - if (_memberInfo.PropertyType == typeof(Message) && result == null) result = new object(); - return result; - } - - public void SetValue(object target, object? value) - { - _memberInfo.SetValue(target, value); - } -} \ No newline at end of file diff --git a/modules/ChatQuotes/Model/Quote/MediaType.cs b/modules/ChatQuotes/Model/Quote/MediaType.cs deleted file mode 100644 index 10b63a9..0000000 --- a/modules/ChatQuotes/Model/Quote/MediaType.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace West.TelegramBot.ChatQuotes.Model.Quote; - -public enum MediaType -{ - Sticker = 0 -} \ No newline at end of file diff --git a/modules/ChatQuotes/Model/Quote/Message.cs b/modules/ChatQuotes/Model/Quote/Message.cs deleted file mode 100644 index b3bf0b7..0000000 --- a/modules/ChatQuotes/Model/Quote/Message.cs +++ /dev/null @@ -1,56 +0,0 @@ -using Newtonsoft.Json; -using Newtonsoft.Json.Serialization; -using File = Telegram.Bot.Types.File; -using TgUser = Telegram.Bot.Types.User; - -namespace West.TelegramBot.ChatQuotes.Model.Quote; - -[JsonObject(NamingStrategyType = typeof(CamelCaseNamingStrategy))] -public class Message -{ - public List? Media { get; set; } - public MediaType? MediaType { get; set; } - public long ChatId { get; set; } - public bool Avatar { get; set; } = true; - public User? From { get; set; } - public string? Text { get; set; } - public Telegram.Bot.Types.Message? ReplyMessage { get; set; } - - public static Message FromMessage(Telegram.Bot.Types.Message msg) - { - var quoteMessage = new Message(); - - if (msg.Text != null) - { - quoteMessage.Text = msg.Text; - } - - var sticker = msg.Sticker; - if (sticker != null) - { - var file = new File - { - FileId = sticker.FileId, - FileSize = sticker.FileSize, - FileUniqueId = sticker.FileUniqueId - }; - quoteMessage.Media = new List { file }; - quoteMessage.MediaType = Quote.MediaType.Sticker; - } - - TgUser? user = null; - if (msg.ForwardSenderName != null && msg.ForwardFrom == null) - { - user = new TgUser - { - FirstName = msg.ForwardSenderName - }; - } - - quoteMessage.ChatId = msg.From?.Id ?? msg.Chat.Id; - quoteMessage.ReplyMessage = msg.ReplyToMessage; - quoteMessage.From = User.FromTgUser(user ?? msg.ForwardFrom ?? msg.From!); - - return quoteMessage; - } -} \ No newline at end of file diff --git a/modules/ChatQuotes/Model/Quote/Request.cs b/modules/ChatQuotes/Model/Quote/Request.cs deleted file mode 100644 index 2a68390..0000000 --- a/modules/ChatQuotes/Model/Quote/Request.cs +++ /dev/null @@ -1,35 +0,0 @@ -#nullable enable - -using Newtonsoft.Json; -using Newtonsoft.Json.Serialization; - -namespace West.TelegramBot.ChatQuotes.Model.Quote; - -[JsonObject(NamingStrategyType = typeof(CamelCaseNamingStrategy))] -public class Request -{ - public Request(Telegram.Bot.Types.Message msg) - { - // TODO: move default values to config - Format = "webp"; - BackgroundColor = "#1b1429"; - Width = 512; - Height = 768; - Scale = 2; - - Messages = new List {Message.FromMessage(msg)}; - } - - public Type Type { get; set; } - public string Format { get; set; } - public string BackgroundColor { get; set; } - public int Width { get; set; } - public int Height { get; set; } - public int Scale { get; set; } - public List? Messages { get; set; } - - public string ToJson() - { - return JsonConvert.SerializeObject(this, ChatQuotes.SerializerSettings); - } -} \ No newline at end of file diff --git a/modules/ChatQuotes/Model/Quote/Response.cs b/modules/ChatQuotes/Model/Quote/Response.cs deleted file mode 100644 index 23ca597..0000000 --- a/modules/ChatQuotes/Model/Quote/Response.cs +++ /dev/null @@ -1,16 +0,0 @@ -#nullable disable - -using Newtonsoft.Json; -using Newtonsoft.Json.Serialization; - -namespace West.TelegramBot.ChatQuotes.Model.Quote; - -[JsonObject(NamingStrategyType = typeof(CamelCaseNamingStrategy))] -public class Response -{ - public bool Ok { get; set; } - - public Result Result { get; set; } - public static Response FromJson(string json) - => JsonConvert.DeserializeObject(json, ChatQuotes.SerializerSettings); -} \ No newline at end of file diff --git a/modules/ChatQuotes/Model/Quote/Result.cs b/modules/ChatQuotes/Model/Quote/Result.cs deleted file mode 100644 index 56f87e8..0000000 --- a/modules/ChatQuotes/Model/Quote/Result.cs +++ /dev/null @@ -1,13 +0,0 @@ -using Newtonsoft.Json; -using Newtonsoft.Json.Serialization; - -namespace West.TelegramBot.ChatQuotes.Model.Quote; - -[JsonObject(NamingStrategyType = typeof(CamelCaseNamingStrategy))] -public class Result -{ - public string Image { get; set; } = ""; - public Type Type { get; set; } - public long Width { get; set; } - public long Height { get; set; } -} \ No newline at end of file diff --git a/modules/ChatQuotes/Model/Quote/Type.cs b/modules/ChatQuotes/Model/Quote/Type.cs deleted file mode 100644 index b30a38c..0000000 --- a/modules/ChatQuotes/Model/Quote/Type.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace West.TelegramBot.ChatQuotes.Model.Quote; - -public enum Type -{ - Quote = 0, - Image, - Null -} \ No newline at end of file diff --git a/modules/ChatQuotes/Model/User.cs b/modules/ChatQuotes/Model/User.cs deleted file mode 100644 index 455d297..0000000 --- a/modules/ChatQuotes/Model/User.cs +++ /dev/null @@ -1,22 +0,0 @@ -using Newtonsoft.Json; - -namespace West.TelegramBot.ChatQuotes.Model; - -public class User : Telegram.Bot.Types.User -{ - [JsonProperty] - public string Name => LastName != null ? $"{FirstName} {LastName}" : FirstName; - - public static User FromTgUser(Telegram.Bot.Types.User user) - { - return new User - { - Id = user.Id, - FirstName = user.FirstName, - LastName = user.LastName, - Username = user.Username, - LanguageCode = user.LanguageCode, - IsBot = user.IsBot - }; - } -} \ No newline at end of file diff --git a/modules/ChatQuotes/QuoteGeneratorService.cs b/modules/ChatQuotes/QuoteGeneratorService.cs deleted file mode 100644 index 8c7263c..0000000 --- a/modules/ChatQuotes/QuoteGeneratorService.cs +++ /dev/null @@ -1,41 +0,0 @@ -using System.Net.Http.Headers; -using System.Text; -using Microsoft.Extensions.Configuration; -using Newtonsoft.Json; -using West.TelegramBot.ChatQuotes.Model.Quote; -using Message = Telegram.Bot.Types.Message; - -namespace West.TelegramBot.ChatQuotes; - -public class QuoteGeneratorService -{ - private readonly HttpClient _httpClient; - private readonly MediaTypeHeaderValue _mediaType; - - public QuoteGeneratorService(IConfiguration configuration) - { - _httpClient = new HttpClient - { - BaseAddress = new Uri(configuration.GetValue("QuoteApiUrl")) - }; - - _mediaType = MediaTypeHeaderValue.Parse("application/json"); - } - - public async Task GenerateQuoteImage(Message msg) - { - var request = new Request(msg); - var content = new ByteArrayContent(Encoding.UTF8.GetBytes(request.ToJson().ToCharArray())) - { - Headers = - { - ContentType = _mediaType - } - }; - - var resp = await _httpClient.PostAsync("/generate", content); - var quoteResponse = JsonConvert.DeserializeObject(await resp.Content.ReadAsStringAsync()); - - return quoteResponse.Ok ? new MemoryStream(Convert.FromBase64String(quoteResponse.Result.Image)) : null; - } -} \ No newline at end of file diff --git a/modules/Destiny2.WhereIsXur/Destiny2.WhereIsXur.csproj b/modules/Destiny2.WhereIsXur/Destiny2.WhereIsXur.csproj deleted file mode 100644 index dcb29ac..0000000 --- a/modules/Destiny2.WhereIsXur/Destiny2.WhereIsXur.csproj +++ /dev/null @@ -1,18 +0,0 @@ - - - - net8.0 - TelegramBot.D2_WhereIsXur - Kruzya.TelegramBot.Destiny2.WhereIsXur - - - - - - - - - - - - diff --git a/modules/Destiny2.WhereIsXur/Provider/IXurPlaceProvider.cs b/modules/Destiny2.WhereIsXur/Provider/IXurPlaceProvider.cs deleted file mode 100644 index b9a101d..0000000 --- a/modules/Destiny2.WhereIsXur/Provider/IXurPlaceProvider.cs +++ /dev/null @@ -1,9 +0,0 @@ -using System.Threading.Tasks; - -namespace Kruzya.TelegramBot.Destiny2.WhereIsXur.Provider; - -public interface IXurPlaceProvider -{ - public Task GetPlaceAsync(); - public string GetPlace(); -} \ No newline at end of file diff --git a/modules/Destiny2.WhereIsXur/Provider/XurWiki.cs b/modules/Destiny2.WhereIsXur/Provider/XurWiki.cs deleted file mode 100644 index 6f32b08..0000000 --- a/modules/Destiny2.WhereIsXur/Provider/XurWiki.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System.Threading.Tasks; -using Fizzler.Systems.HtmlAgilityPack; -using HtmlAgilityPack; - -namespace Kruzya.TelegramBot.Destiny2.WhereIsXur.Provider; - -public class XurWiki : IXurPlaceProvider -{ - public async Task GetPlaceAsync() - { - var web = new HtmlWeb(); - var document = await web.LoadFromWebAsync("https://xur.wiki"); - - var place = document.DocumentNode.QuerySelector(".location_name"); - if (place != null) - { - return place.InnerText.Trim(); - } - - return ""; - } - - public string GetPlace() - { - return GetPlaceAsync().GetAwaiter().GetResult(); - } -} \ No newline at end of file diff --git a/modules/Destiny2.WhereIsXur/RequestHandler.cs b/modules/Destiny2.WhereIsXur/RequestHandler.cs deleted file mode 100644 index acce169..0000000 --- a/modules/Destiny2.WhereIsXur/RequestHandler.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Threading.Tasks; -using BotFramework; -using BotFramework.Attributes; -using Kruzya.TelegramBot.Destiny2.WhereIsXur.Provider; -using Telegram.Bot; -using Telegram.Bot.Types.Enums; - -namespace Kruzya.TelegramBot.Destiny2.WhereIsXur; - -public class RequestHandler : BotEventHandler -{ - protected readonly IXurPlaceProvider _placeProvider; - - public RequestHandler(IXurPlaceProvider xurPlaceProvider) - { - _placeProvider = xurPlaceProvider; - } - - [Command("d2_xur")] - public async Task WhereIsXur() - { - var place = await _placeProvider.GetPlaceAsync(); - if (string.IsNullOrWhiteSpace(place)) - { - await Response("unknown"); - return; - } - - await Response(place); - } - - protected async Task Response(string place) - { - await Bot.SendTextMessageAsync(Chat, $"Xûr place is {place}", parseMode: ParseMode.Html); - } -} \ No newline at end of file diff --git a/modules/Destiny2.WhereIsXur/WhereIsXur.cs b/modules/Destiny2.WhereIsXur/WhereIsXur.cs deleted file mode 100644 index bd4fcf4..0000000 --- a/modules/Destiny2.WhereIsXur/WhereIsXur.cs +++ /dev/null @@ -1,17 +0,0 @@ -using Kruzya.TelegramBot.Core; -using Kruzya.TelegramBot.Destiny2.WhereIsXur.Provider; -using Microsoft.Extensions.DependencyInjection; - -namespace Kruzya.TelegramBot.Destiny2.WhereIsXur; - -public class WhereIsXur : Module -{ - public WhereIsXur(Core.Core core) : base(core) - { - } - - public override void ConfigureServices(IServiceCollection services) - { - services.AddSingleton(); - } -} \ No newline at end of file