private async Task AddModulesAsync() { using var scope = Services.CreateScope(); using var repository = scope.ServiceProvider.GetRequiredService <GlobalConfigRepository>(); var unloadedModules = new List <string>(); var unloadedModulesConfig = await repository.GetItemAsync(GlobalConfigItems.UnloadedModules); if (!string.IsNullOrEmpty(unloadedModulesConfig)) { unloadedModules.AddRange(JsonConvert.DeserializeObject <List <string> >(unloadedModulesConfig)); } var moduleBase = typeof(BotModuleBase); var types = Assembly.GetExecutingAssembly() .GetTypes() .Where(o => !o.IsAbstract && moduleBase.IsAssignableFrom(o) && !unloadedModules.Contains(o.Name)); foreach (var moduleType in types) { await Commands.AddModuleAsync(moduleType, Services); Logger.LogInformation($"Initialized module {moduleType.FullName}"); } }
public async Task ImportCommandsAsync(params Type[] modules) { foreach (var t in modules) { await Commands.AddModuleAsync(t, _host.Services); } }
private async Task RegisterCommandsAsync() { //await Commands.AddModulesAsync(Assembly.GetEntryAssembly(), Services); var moduleTypes = loadedTypes.Where(t => !t.IsAbstract && typeof(CommandModuleBase).IsAssignableFrom(t)); var guildModuleTypes = loadedTypes.Where(t => !t.IsAbstract && typeof(GuildCommandModuleBase).IsAssignableFrom(t)); foreach (var type in moduleTypes.Union(guildModuleTypes)) { await Commands.AddModuleAsync(type, ServiceProvider); } }