update status via task, update nuget packages
This commit is contained in:
		| @@ -30,8 +30,8 @@ namespace MareSynchronosServer.Discord | ||||
|         private string authToken = string.Empty; | ||||
|         DiscordSocketClient discordClient; | ||||
|         ConcurrentDictionary<ulong, string> DiscordLodestoneMapping = new(); | ||||
|         private Timer _timer; | ||||
|         private CancellationTokenSource verificationTaskCts; | ||||
|         private CancellationTokenSource updateStatusCts; | ||||
|         private readonly string[] LodestoneServers = new[] { "eu", "na", "jp", "fr", "de" }; | ||||
|         private readonly ConcurrentQueue<SocketSlashCommand> verificationQueue = new(); | ||||
|  | ||||
| @@ -374,9 +374,8 @@ namespace MareSynchronosServer.Discord | ||||
|                 discordClient.SlashCommandExecuted += DiscordClient_SlashCommandExecuted; | ||||
|                 discordClient.ModalSubmitted += DiscordClient_ModalSubmitted; | ||||
|  | ||||
|                 _timer = new Timer(UpdateStatus, null, TimeSpan.Zero, TimeSpan.FromSeconds(15)); | ||||
|  | ||||
|                 _ = ProcessQueueWork(); | ||||
|                 _ = UpdateStatusAsync(); | ||||
|             } | ||||
|         } | ||||
|  | ||||
| @@ -404,14 +403,20 @@ namespace MareSynchronosServer.Discord | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         private void UpdateStatus(object state) | ||||
|         private async Task UpdateStatusAsync() | ||||
|         { | ||||
|             using var scope = services.CreateScope(); | ||||
|             using var db = scope.ServiceProvider.GetService<MareDbContext>(); | ||||
|             updateStatusCts = new(); | ||||
|             while (!updateStatusCts.IsCancellationRequested) | ||||
|             { | ||||
|                 using var scope = services.CreateScope(); | ||||
|                 using var db = scope.ServiceProvider.GetService<MareDbContext>(); | ||||
|  | ||||
|             var users = db.Users.Count(c => c.CharacterIdentification != null); | ||||
|                 var users = db.Users.Count(c => c.CharacterIdentification != null); | ||||
|  | ||||
|             discordClient.SetActivityAsync(new Game("Mare for " + users + " Users")); | ||||
|                 await discordClient.SetActivityAsync(new Game("Mare for " + users + " Users")); | ||||
|  | ||||
|                 await Task.Delay(TimeSpan.FromSeconds(15)); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async Task StopAsync(CancellationToken cancellationToken) | ||||
|   | ||||
| @@ -11,18 +11,18 @@ | ||||
|     <PackageReference Include="Bazinga.AspNetCore.Authentication.Basic" Version="2.0.1" /> | ||||
|     <PackageReference Include="Discord.Net" Version="3.7.2" /> | ||||
|     <PackageReference Include="EFCore.NamingConventions" Version="6.0.0" /> | ||||
|     <PackageReference Include="Karambolo.Extensions.Logging.File" Version="3.3.0" /> | ||||
|     <PackageReference Include="Karambolo.Extensions.Logging.File" Version="3.3.1" /> | ||||
|     <PackageReference Include="lz4net" Version="1.0.15.93" /> | ||||
|     <PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="6.0.6" /> | ||||
|     <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="6.0.6" /> | ||||
|     <PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="6.0.6" /> | ||||
|     <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.6"> | ||||
|     <PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="6.0.8" /> | ||||
|     <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="6.0.8" /> | ||||
|     <PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="6.0.8" /> | ||||
|     <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.8"> | ||||
|       <PrivateAssets>all</PrivateAssets> | ||||
|       <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||||
|     </PackageReference> | ||||
|     <PackageReference Include="Microsoft.Extensions.Hosting.Systemd" Version="6.0.0" /> | ||||
|     <PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="6.0.0" /> | ||||
|     <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="6.0.5" /> | ||||
|     <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="6.0.6" /> | ||||
|     <PackageReference Include="prometheus-net" Version="6.0.0" /> | ||||
|     <PackageReference Include="prometheus-net.AspNetCore" Version="6.0.0" /> | ||||
|   </ItemGroup> | ||||
|   | ||||
| @@ -38,8 +38,6 @@ namespace MareSynchronosServer | ||||
|         { | ||||
|             services.AddHttpContextAccessor(); | ||||
|  | ||||
|             services.AddMemoryCache(); | ||||
|  | ||||
|             services.Configure<IpRateLimitOptions>(Configuration.GetSection("IpRateLimiting")); | ||||
|             services.Configure<IpRateLimitPolicies>(Configuration.GetSection("IpRateLimitPolicies")); | ||||
|  | ||||
| @@ -61,7 +59,6 @@ namespace MareSynchronosServer | ||||
|             services.AddHostedService(provider => provider.GetService<SystemInfoService>()); | ||||
|             services.AddHostedService<DiscordBot>(); | ||||
|  | ||||
|             services.AddDatabaseDeveloperPageExceptionFilter(); | ||||
|             services.AddAuthentication(options => | ||||
|                 { | ||||
|                     options.DefaultScheme = SecretKeyAuthenticationHandler.AuthScheme; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Stanley Dimant
					Stanley Dimant