public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) .ConfigureServices((context, services) => { services.AddOptions(); services.AddDbContext <AppDatabase>(options => options.UseSqlServer(context.Configuration.GetConnectionString("Local")).UseLazyLoadingProxies()); var config = context.Configuration; services.Configure <PS3838Settings>(config.GetSection("PS3838")); var tgSettings = new InitSettings(); var tgSettingSection = config.GetSection("Bot"); tgSettingSection.Bind(tgSettings); var psSettings = new PS3838Settings(); var psSettingSection = config.GetSection("PS3838"); psSettingSection.Bind(psSettings); var framework = new TelegramFramework(tgSettings); services.AddSingleton(framework); var ps3838Client = new PS3838Client(psSettings.UserAgent); ps3838Client.Auth(psSettings.Login, psSettings.Password); services.AddSingleton(ps3838Client); services.AddHostedService <NotifierWorker>(); services.AddHostedService <DataWorker>(); });
private bool CanExecute(int fromId, ChatType type) { if (fromId == Framework.Settings.SuperAdminId) { return(true); } if (!Framework.Settings.IsCommandsEnabled) { return(false); } if (TelegramFramework.IsFromPublic(type) && !IsPublic) { return(false); } return(true); }
public async void ConfigureServices(IServiceCollection services) { services.AddControllers().AddNewtonsoftJson(); services.AddDbContext <AppDatabase>(options => options.UseSqlServer(Configuration.GetConnectionString("Local")).UseLazyLoadingProxies()); var settings = new InitSettings(); var settingSection = Configuration.GetSection("Bot"); settingSection.Bind(settings); var framework = new TelegramFramework(settings); services.AddSingleton(framework); services.AddSingleton <ITelegramCommand, SubscribeCommand>(); services.AddSingleton <ITelegramCommand, UnsubscribeCommand>(); }
public NotifierWorker(IServiceProvider serviceProvider, TelegramFramework framework) { Timeout = TimeSpan.FromSeconds(30); _serviceProvider = serviceProvider; _framework = framework; }
public UpdateController(TelegramFramework framework) { _framework = framework; }
public void SetFramework(TelegramFramework framework) { Framework = framework; }