fix commands not being added properly to discord, remove cached auth on regeneration

This commit is contained in:
Stanley Dimant
2022-08-30 17:12:02 +02:00
parent 900e71c8fc
commit 1fce2ac8d6

View File

@@ -10,6 +10,7 @@ using System.Threading;
using System.Threading.Tasks;
using Discord;
using Discord.WebSocket;
using MareSynchronosServices.Authentication;
using MareSynchronosShared.Data;
using MareSynchronosShared.Metrics;
using MareSynchronosShared.Models;
@@ -211,7 +212,8 @@ public class DiscordBot : IHostedService
private async Task DiscordClient_ModalSubmitted(SocketModal arg)
{
switch (arg.Data.CustomId) {
switch (arg.Data.CustomId)
{
case "register_modal":
{
var embed = await HandleRegisterModalAsync(arg).ConfigureAwait(false);
@@ -375,6 +377,9 @@ public class DiscordBot : IHostedService
await db.Auth.AddAsync(auth).ConfigureAwait(false);
await db.SaveChangesAsync().ConfigureAwait(false);
var authHandler = scope.ServiceProvider.GetService<SecretKeyAuthenticationHandler>();
authHandler.RemoveAuthentication(existingLodestoneAuth.User.UID);
}
}
@@ -510,10 +515,16 @@ public class DiscordBot : IHostedService
var guild = (await discordClient.Rest.GetGuildsAsync()).First();
var commands = await guild.GetApplicationCommandsAsync();
if (!commands.Any(c => c.Name.Contains("setvanityuid")))
if (!commands.Any(c => c.Name.Contains("register")))
{
await guild.CreateApplicationCommandAsync(register.Build()).ConfigureAwait(false);
}
if (!commands.Any(c => c.Name.Contains("verify")))
{
await guild.CreateApplicationCommandAsync(verify.Build()).ConfigureAwait(false);
}
if (!commands.Any(c => c.Name.Contains("setvanityuid")))
{
await guild.CreateApplicationCommandAsync(recover.Build()).ConfigureAwait(false);
var vanityCommand = await guild.CreateApplicationCommandAsync(vanityuid.Build()).ConfigureAwait(false);
vanityCommandId = vanityCommand.Id;
@@ -522,6 +533,10 @@ public class DiscordBot : IHostedService
{
vanityCommandId = commands.First(c => c.Name.Contains("setvanityuid")).Id;
}
if (!commands.Any(c => c.Name.Contains("recover")))
{
await guild.CreateApplicationCommandAsync(recover.Build()).ConfigureAwait(false);
}
}
catch (Exception ex)
{