* Added WideBot csproj data
* Added TelegratorWideClient * Added WClient extension property for handlers * Code cleanup
This commit is contained in:
@@ -0,0 +1 @@
|
||||
|
||||
@@ -2,9 +2,28 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<RootNamespace>Telegrator</RootNamespace>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<RootNamespace>Telegrator</RootNamespace>
|
||||
<BaseOutputPath>..\..\bin</BaseOutputPath>
|
||||
<DocumentationFile>..\..\docs\$(AssemblyName).xml</DocumentationFile>
|
||||
|
||||
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
|
||||
<GenerateDocumentationFile>True</GenerateDocumentationFile>
|
||||
<EnableNETAnalyzers>True</EnableNETAnalyzers>
|
||||
<EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild>
|
||||
|
||||
<Title>Telegrator.Hosting.WideBot</Title>
|
||||
<Version>1.17.0</Version>
|
||||
<Authors>Rikitav Tim4ik</Authors>
|
||||
<Company>Rikitav Tim4ik</Company>
|
||||
<RepositoryUrl>https://github.com/Rikitav/Telegrator</RepositoryUrl>
|
||||
<PackageTags>telegram;bot;mediator;attributes;aspect;hosting;host;framework;easy;simple;handlers;wtelegrambot;userbot</PackageTags>
|
||||
|
||||
<PackageIcon>telegrator_nuget.png</PackageIcon>
|
||||
<PackageReadmeFile>README.md</PackageReadmeFile>
|
||||
<PackageLicenseFile>LICENSE</PackageLicenseFile>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@@ -15,4 +34,10 @@
|
||||
<ProjectReference Include="..\..\src\Telegrator.Hosting\Telegrator.Hosting.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include=".\README.md" Pack="True" PackagePath="\" />
|
||||
<None Include="..\..\LICENSE" Pack="True" PackagePath="\" />
|
||||
<None Include="..\..\resources\telegrator_nuget.png" Pack="True" PackagePath="\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
// Maybe later...
|
||||
|
||||
/*
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
using System;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
@@ -55,8 +54,8 @@ public class TelegratorWClient : WTelegramBotClient, ITelegratorBot, ICollecting
|
||||
{
|
||||
try
|
||||
{
|
||||
await new HostedWideBotUpdateReceiver(this)
|
||||
.ReceiveAsync(UpdateRouter, cancellationToken)
|
||||
await new HostedWideBotUpdateReceiver(NullLoggerFactory.Instance.CreateLogger<HostedWideBotUpdateReceiver>(), this, UpdateRouter, null)
|
||||
.StartAsync(cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception exception)
|
||||
@@ -72,5 +71,4 @@ public class TelegratorWClient : WTelegramBotClient, ITelegratorBot, ICollecting
|
||||
TelegratorLogging.LogInformation("Telegrator bot stopped (cancelled)");
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
@@ -27,13 +27,26 @@ public static class HandlersExtensions
|
||||
{
|
||||
extension<TUpdate>(AbstractUpdateHandler<TUpdate> handler) where TUpdate : class
|
||||
{
|
||||
public WUpdate WUpdate
|
||||
public WTelegramBotClient WClient
|
||||
{
|
||||
get
|
||||
{
|
||||
object? update = typeof(AbstractUpdateHandler<TUpdate>).GetField("HandlingUpdate")?.GetValue(handler);
|
||||
object? client = handler.GetType().GetField("Client")?.GetValue(handler);
|
||||
if (client is not WTelegramBotClient wideClient)
|
||||
throw new InvalidCastException("Client is not assignable to `WTelegram.Bot.WTelegramBotClient`");
|
||||
|
||||
return wideClient;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public WUpdate WideUpdate
|
||||
{
|
||||
get
|
||||
{
|
||||
object? update = handler.GetType().GetField("HandlingUpdate")?.GetValue(handler);
|
||||
if (update is not WUpdate wUpdate)
|
||||
throw new InvalidCastException();
|
||||
throw new InvalidCastException("Update is not assignable to `WTelegram.Types.Update`");
|
||||
|
||||
return wUpdate;
|
||||
}
|
||||
@@ -41,7 +54,7 @@ public static class HandlersExtensions
|
||||
|
||||
public TLUpdate? TLUpdate
|
||||
{
|
||||
get => handler.WUpdate.TLUpdate;
|
||||
get => handler.WideUpdate.TLUpdate;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,14 +68,8 @@ public static class HandlersExtensions
|
||||
/// <summary>
|
||||
/// Provides extension methods for <see cref="IHostApplicationBuilder"/> to configure Telegrator.
|
||||
/// </summary>
|
||||
public static class ServiceCollectionExtensions
|
||||
public static class WideHostBuilderExtensions
|
||||
{
|
||||
public static IServiceCollection ConfigureWideTelegram(this IServiceCollection services, WTelegramBotClientOptions options)
|
||||
{
|
||||
services.AddSingleton(Options.Create(options));
|
||||
return services;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Replaces TelegramBotHostBuilder. Configures DI, options, and handlers.
|
||||
/// </summary>
|
||||
@@ -133,6 +140,19 @@ public static class ServiceCollectionExtensions
|
||||
services.AddTelegramBotHostDefaults();
|
||||
services.AddMTProtoUpdateReceiver();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Contains extensions for <see cref="IServiceCollection"/>
|
||||
/// Provides method to configure Telegram Bot WebHost
|
||||
/// </summary>
|
||||
public static class WideBotServiceCollectionExtensions
|
||||
{
|
||||
public static IServiceCollection ConfigureWideTelegram(this IServiceCollection services, WTelegramBotClientOptions options)
|
||||
{
|
||||
services.AddSingleton(Options.Create(options));
|
||||
return services;
|
||||
}
|
||||
|
||||
public static IServiceCollection AddMTProtoUpdateReceiver(this IServiceCollection services)
|
||||
{
|
||||
@@ -149,8 +169,12 @@ public static class ServiceCollectionExtensions
|
||||
/// <summary>
|
||||
/// Provides useful methods to adjust Telegram bot Host
|
||||
/// </summary>
|
||||
public static class TelegramBotHostExtensions
|
||||
public static class WideTelegramBotHostExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Replaces the initialization logic from TelegramBotWebHost constructor.
|
||||
/// Initializes the bot and logs handlers on application startup.
|
||||
/// </summary>
|
||||
public static IHost UseWideTelegrator(this IHost botHost)
|
||||
{
|
||||
if (!botHost.Services.TryFindWTelegramBotClient())
|
||||
|
||||
Reference in New Issue
Block a user