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
This commit is contained in:
Andriy
2025-02-09 15:47:52 +02:00
parent a0203f2bf6
commit 8917a8ba5f
20 changed files with 0 additions and 454 deletions
-31
View File
@@ -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<QuoteGeneratorService>();
}
}
-22
View File
@@ -1,22 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>West.TelegramBot.ChatQuotes</RootNamespace>
<AssemblyName>TelegramBot.ChatQuotes</AssemblyName>
</PropertyGroup>
<ItemGroup>
<Folder Include="Handler\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Core\Core.csproj" />
</ItemGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Delete Files="$(OutDir)\TelegramBot.dll" />
</Target>
</Project>
-38
View File
@@ -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);
}
}
@@ -1,17 +0,0 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
namespace West.TelegramBot.ChatQuotes.Json;
class NullToEmptyObjectResolver : DefaultContractResolver
{
protected override IList<JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization)
{
return type.GetProperties()
.Select(p => {
var jp = base.CreateProperty(p, memberSerialization);
jp.ValueProvider = new NullToEmptyObjectValueProvider(p);
return jp;
}).ToList();
}
}
@@ -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);
}
}
@@ -1,6 +0,0 @@
namespace West.TelegramBot.ChatQuotes.Model.Quote;
public enum MediaType
{
Sticker = 0
}
-56
View File
@@ -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<File>? 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> { 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;
}
}
-35
View File
@@ -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> {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<Message>? Messages { get; set; }
public string ToJson()
{
return JsonConvert.SerializeObject(this, ChatQuotes.SerializerSettings);
}
}
@@ -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<Response>(json, ChatQuotes.SerializerSettings);
}
-13
View File
@@ -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; }
}
-8
View File
@@ -1,8 +0,0 @@
namespace West.TelegramBot.ChatQuotes.Model.Quote;
public enum Type
{
Quote = 0,
Image,
Null
}
-22
View File
@@ -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
};
}
}
@@ -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<string>("QuoteApiUrl"))
};
_mediaType = MediaTypeHeaderValue.Parse("application/json");
}
public async Task<Stream?> 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<Response>(await resp.Content.ReadAsStringAsync());
return quoteResponse.Ok ? new MemoryStream(Convert.FromBase64String(quoteResponse.Result.Image)) : null;
}
}
@@ -1,18 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<AssemblyName>TelegramBot.D2_WhereIsXur</AssemblyName>
<RootNamespace>Kruzya.TelegramBot.Destiny2.WhereIsXur</RootNamespace>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\Core\Core.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Fizzler.Systems.HtmlAgilityPack" Version="1.2.1" />
<PackageReference Include="HtmlAgilityPack" Version="1.11.39" />
</ItemGroup>
</Project>
@@ -1,9 +0,0 @@
using System.Threading.Tasks;
namespace Kruzya.TelegramBot.Destiny2.WhereIsXur.Provider;
public interface IXurPlaceProvider
{
public Task<string> GetPlaceAsync();
public string GetPlace();
}
@@ -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<string> 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();
}
}
@@ -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, $"<b>Xûr</b> place is <code>{place}</code>", parseMode: ParseMode.Html);
}
}
-17
View File
@@ -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<IXurPlaceProvider, XurWiki>();
}
}