mirror of
https://github.com/Caraxi/mare.server.git
synced 2025-12-12 16:47:22 +01:00
fix service provider dispoal
This commit is contained in:
parent
76dded0840
commit
a554d751b4
2 changed files with 13 additions and 10 deletions
|
|
@ -11,21 +11,24 @@ namespace MareSynchronosServices.Discord;
|
|||
|
||||
public class DiscordBotServices
|
||||
{
|
||||
public readonly ConcurrentQueue<KeyValuePair<ulong, Action>> verificationQueue = new();
|
||||
public readonly ConcurrentQueue<KeyValuePair<ulong, Action<IServiceProvider>>> verificationQueue = new();
|
||||
public ConcurrentDictionary<ulong, DateTime> LastVanityChange = new();
|
||||
public ConcurrentDictionary<string, DateTime> LastVanityGidChange = new();
|
||||
public ConcurrentDictionary<ulong, string> DiscordLodestoneMapping = new();
|
||||
public ConcurrentDictionary<ulong, string> DiscordRelinkLodestoneMapping = new();
|
||||
public readonly string[] LodestoneServers = new[] { "eu", "na", "jp", "fr", "de" };
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
|
||||
public IConfiguration Configuration { get; init; }
|
||||
public ILogger<DiscordBotServices> Logger { get; init; }
|
||||
public MareMetrics Metrics { get; init; }
|
||||
public Random Random { get; init; }
|
||||
private CancellationTokenSource? verificationTaskCts;
|
||||
|
||||
public DiscordBotServices(IConfiguration configuration, ILogger<DiscordBotServices> logger, MareMetrics metrics)
|
||||
public DiscordBotServices(IConfiguration configuration, IServiceProvider serviceProvider, ILogger<DiscordBotServices> logger, MareMetrics metrics)
|
||||
{
|
||||
Configuration = configuration.GetRequiredSection("MareSynchronos");
|
||||
_serviceProvider = serviceProvider;
|
||||
Logger = logger;
|
||||
Metrics = metrics;
|
||||
Random = new();
|
||||
|
|
@ -50,7 +53,7 @@ public class DiscordBotServices
|
|||
{
|
||||
try
|
||||
{
|
||||
queueitem.Value.Invoke();
|
||||
queueitem.Value.Invoke(_serviceProvider);
|
||||
|
||||
Logger.LogInformation("Sent login information to user");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ public class MareModule : InteractionModuleBase
|
|||
else
|
||||
{
|
||||
await DeferAsync(ephemeral: true).ConfigureAwait(false);
|
||||
_botServices.verificationQueue.Enqueue(new KeyValuePair<ulong, Action>(Context.User.Id, async () => await HandleVerifyAsync((SocketSlashCommand)Context.Interaction)));
|
||||
_botServices.verificationQueue.Enqueue(new KeyValuePair<ulong, Action<IServiceProvider>>(Context.User.Id, async (sp) => await HandleVerifyAsync((SocketSlashCommand)Context.Interaction, sp)));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -120,7 +120,7 @@ public class MareModule : InteractionModuleBase
|
|||
else
|
||||
{
|
||||
await DeferAsync(ephemeral: true).ConfigureAwait(false);
|
||||
_botServices.verificationQueue.Enqueue(new KeyValuePair<ulong, Action>(Context.User.Id, async () => await HandleVerifyRelinkAsync((SocketSlashCommand)Context.Interaction)));
|
||||
_botServices.verificationQueue.Enqueue(new KeyValuePair<ulong, Action<IServiceProvider>>(Context.User.Id, async (sp) => await HandleVerifyRelinkAsync((SocketSlashCommand)Context.Interaction, sp)));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -608,11 +608,11 @@ public class MareModule : InteractionModuleBase
|
|||
}
|
||||
}
|
||||
|
||||
private async Task HandleVerifyRelinkAsync(SocketSlashCommand cmd)
|
||||
private async Task HandleVerifyRelinkAsync(SocketSlashCommand cmd, IServiceProvider serviceProvider)
|
||||
{
|
||||
var embedBuilder = new EmbedBuilder();
|
||||
|
||||
using var scope = _services.CreateScope();
|
||||
using var scope = serviceProvider.CreateScope();
|
||||
var req = new HttpClient();
|
||||
using var db = scope.ServiceProvider.GetService<MareDbContext>();
|
||||
|
||||
|
|
@ -674,7 +674,7 @@ public class MareModule : InteractionModuleBase
|
|||
{
|
||||
embedBuilder.WithTitle("Your auth has expired or something else went wrong");
|
||||
embedBuilder.WithDescription("Start again with **/relink**");
|
||||
_botServices.DiscordLodestoneMapping.TryRemove(cmd.User.Id, out _);
|
||||
_botServices.DiscordRelinkLodestoneMapping.TryRemove(cmd.User.Id, out _);
|
||||
}
|
||||
|
||||
var dataEmbed = embedBuilder.Build();
|
||||
|
|
@ -682,11 +682,11 @@ public class MareModule : InteractionModuleBase
|
|||
await cmd.FollowupAsync(embed: dataEmbed, ephemeral: true).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private async Task HandleVerifyAsync(SocketSlashCommand cmd)
|
||||
private async Task HandleVerifyAsync(SocketSlashCommand cmd, IServiceProvider serviceProvider)
|
||||
{
|
||||
var embedBuilder = new EmbedBuilder();
|
||||
|
||||
using var scope = _services.CreateScope();
|
||||
using var scope = serviceProvider.CreateScope();
|
||||
var req = new HttpClient();
|
||||
using var db = scope.ServiceProvider.GetService<MareDbContext>();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue