public static void AddTelegramBot(this IServiceCollection services, ITelegramBotOptions options) { services.AddSingleton(serviceProvider => { var instance = new TelegramBotWrapper(options); return(instance); }); }
/// <summary> /// Constructor. You may inject IServiceProvider to freely use you registered services in your modules /// </summary> /// <param name="key"></param> /// <param name="adminId"></param> /// <param name="serviceProvider"></param> /// <param name="alias"></param> public TelegramBotWrapperWithDb(ITelegramBotOptions options, IDbContextFactory <TDbContext> contextFactory) { DbContextFactory = contextFactory; Options = options; if (Options.InMemoryDb) { using (var db = DbContextFactory.CreateDbContext()) { db.Database.EnsureCreated(); db.Database.Migrate(); } } if (!String.IsNullOrEmpty(options.Directory)) { RootDirectory = options.Directory; } if (!Directory.Exists(Path.Combine(RootDirectory))) { Directory.CreateDirectory(Path.Combine(RootDirectory)); } Log = new TelegramBotLogger(Path.Combine(RootDirectory, "Logs-" + Options.Alias)); var setting = new TelegramBotSetting() { Alias = options.Alias, TelegramDefaultAdminUserId = Options.AdminId, TelegramBotAPIKey = Options.Key }; LoadedSetting = setting; try { using (Db) { Db.Database.EnsureCreated(); Db.SaveChanges(); } } catch (Exception ex) { Log.WriteLine($"Db creating data error: {ex.ToString()}", LogLevel.Error, null, "error.log"); } Console.OutputEncoding = Encoding.UTF8; Messenger.MessageSent += MessengerOnMessageSent; AppDomain.CurrentDomain.UnhandledException += CurrentDomainOnUnhandledException; //var telegramBotModuleDir = Path.Combine(RootDirectory, "AddonModules-" + alias); //WatchForNewModules(telegramBotModuleDir); }
public TelegramBotService(ITelegramBotOptions telegramBotOptions, ILogger <TelegramBotService> loggers) { this.bot = new TelegramBotClient(telegramBotOptions.Token); this.telegramBotOptions = telegramBotOptions; this.logger = loggers; }
public TelegramBotWrapperWithUserDb(ITelegramBotOptions options, IDbContextFactory <TDbContext> factory) : base(options, factory) { }
public TelegramBotWrapper(ITelegramBotOptions options) : base(options, new DefaultDbContextFactory(options.Alias, options.InMemoryDb)) { }
public SimpleTelegramBot(ITelegramBotOptions opts) : base(opts) { }
public static void AddTelegramBotWithDbContext <TDbContext>(this IServiceCollection services, ITelegramBotOptions options, IDbContextFactory <TDbContext> contextFactory) where TDbContext : DbContext, ITelegramBotDbContext { services.AddSingleton(serviceProvider => { var instance = new TelegramBotWrapperWithUserDb <TDbContext>(options, contextFactory); return(instance); }); }