2022-05-10 19:11:01 +03:00
|
|
|
using Kruzya.TelegramBot.Core;
|
2023-07-21 17:14:11 +03:00
|
|
|
using Kruzya.TelegramBot.Core.Options;
|
2022-02-16 17:07:30 +02:00
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2023-07-21 17:14:11 +03:00
|
|
|
using West.TelegramBot.ContentStore.Option;
|
2022-02-16 17:07:30 +02:00
|
|
|
using West.TelegramBot.ContentStore.Service;
|
|
|
|
|
|
|
|
|
|
namespace West.TelegramBot.ContentStore;
|
|
|
|
|
|
|
|
|
|
public class ContentStore : Module
|
|
|
|
|
{
|
2022-02-16 18:08:02 +02:00
|
|
|
public readonly List<Type> MediaServiceTypes = new();
|
2022-02-16 17:43:57 +02:00
|
|
|
|
2022-02-16 17:07:30 +02:00
|
|
|
public ContentStore(Core core) : base(core)
|
|
|
|
|
{
|
2022-02-16 17:43:57 +02:00
|
|
|
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
|
|
|
|
|
{
|
|
|
|
|
foreach (var exportedType in assembly.GetExportedTypes()
|
2022-02-16 18:08:02 +02:00
|
|
|
.Where(t => !t.IsAbstract && t.GetInterface(nameof(IRandomMediaService)) != null))
|
2022-02-16 17:43:57 +02:00
|
|
|
{
|
2022-02-16 18:08:02 +02:00
|
|
|
MediaServiceTypes.Add(exportedType);
|
2022-02-16 17:43:57 +02:00
|
|
|
}
|
|
|
|
|
}
|
2022-02-16 17:07:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void ConfigureServices(IServiceCollection services)
|
|
|
|
|
{
|
2023-07-21 17:14:11 +03:00
|
|
|
services.AddScoped<IOption, AllowNsfw>();
|
|
|
|
|
|
2022-02-16 18:08:02 +02:00
|
|
|
foreach (var serviceType in MediaServiceTypes)
|
2022-02-16 17:43:57 +02:00
|
|
|
{
|
2022-11-14 00:23:36 +02:00
|
|
|
services.AddScoped(typeof(IRandomMediaService), serviceType);
|
2022-02-16 17:43:57 +02:00
|
|
|
}
|
2022-02-16 17:07:30 +02:00
|
|
|
}
|
|
|
|
|
}
|