* Renamed "LeveledDebug" to "Alligator", cuz its funny name

* Changed debug writing to trace writing inside "Alligator"
* Added "HostedTelegramBotInfo" representing hosted version of ITelegramBotInfo. Provides access to services and configuration
* Filters now can acces services and configuration using new "HostedTelegramBotInfo" through context.BotInfo property
This commit is contained in:
2025-08-01 13:50:21 +04:00
parent 16e599bed8
commit 49310439e0
10 changed files with 84 additions and 45 deletions
@@ -0,0 +1,17 @@
using Microsoft.Extensions.Configuration;
using Telegram.Bot;
using Telegram.Bot.Types;
using Telegrator.Configuration;
namespace Telegrator.Hosting
{
public class HostedTelegramBotInfo(ITelegramBotClient client, IServiceProvider services, IConfigurationManager configuration) : ITelegramBotInfo
{
/// <inheritdoc/>
public User User { get; } = client.GetMe().Result;
public IServiceProvider Services { get; } = services;
public IConfigurationManager Configuration { get; } = configuration;
}
}
+9
View File
@@ -3,6 +3,7 @@ using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System.Text;
using Telegram.Bot.Types.Enums;
using Telegrator.Configuration;
using Telegrator.Hosting.Components;
using Telegrator.Hosting.Providers;
using Telegrator.MadiatorCore;
@@ -39,12 +40,20 @@ namespace Telegrator.Hosting
/// <param name="handlers"></param>
internal TelegramBotHost(HostApplicationBuilder hostApplicationBuilder, HostHandlersCollection handlers)
{
// Registering this host in services for easy access
RegisterHostServices(hostApplicationBuilder, handlers);
// Building proxy hoster
_innerHost = hostApplicationBuilder.Build();
// Initializing bot info, as it requires to make a request via tg bot
Services.GetRequiredService<ITelegramBotInfo>();
// Reruesting services for this host
_updateRouter = Services.GetRequiredService<IUpdateRouter>();
_logger = Services.GetRequiredService<ILogger<TelegramBotHost>>();
// Logging registering handlers in DEBUG purposes
LogHandlers(handlers);
}
+3 -2
View File
@@ -47,8 +47,9 @@ namespace Telegrator.Hosting
services.AddSingleton<IAwaitingProvider, HostAwaitingProvider>();
services.AddSingleton<IHandlersProvider, HostHandlersProvider>();
services.AddSingleton<IUpdateRouter, HostUpdateRouter>();
services.AddSingleton<ITelegramBotInfo, TelegramBotInfo>(services => new TelegramBotInfo(services.GetRequiredService<ITelegramBotClient>().GetMe().Result));
//services.AddSingleton<ITelegramBotInfo, TelegramBotInfo>(services => new TelegramBotInfo(services.GetRequiredService<ITelegramBotClient>().GetMe().Result));
services.AddSingleton<ITelegramBotInfo, HostedTelegramBotInfo>();
return services;
}