mirror of
https://github.com/Caraxi/mare.server.git
synced 2025-12-13 16:24:14 +01:00
set user role on join
This commit is contained in:
parent
86ae9d40e0
commit
98ed5cb472
1 changed files with 19 additions and 0 deletions
|
|
@ -7,6 +7,7 @@ using MareSynchronosShared.Models;
|
||||||
using MareSynchronosShared.Services;
|
using MareSynchronosShared.Services;
|
||||||
using MareSynchronosShared.Utils.Configuration;
|
using MareSynchronosShared.Utils.Configuration;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
using StackExchange.Redis;
|
using StackExchange.Redis;
|
||||||
|
|
||||||
namespace MareSynchronosServices.Discord;
|
namespace MareSynchronosServices.Discord;
|
||||||
|
|
@ -66,11 +67,29 @@ internal class DiscordBot : IHostedService
|
||||||
var ctx = new SocketInteractionContext(_discordClient, x);
|
var ctx = new SocketInteractionContext(_discordClient, x);
|
||||||
await _interactionModule.ExecuteCommandAsync(ctx, _services).ConfigureAwait(false);
|
await _interactionModule.ExecuteCommandAsync(ctx, _services).ConfigureAwait(false);
|
||||||
};
|
};
|
||||||
|
_discordClient.UserJoined += OnUserJoined;
|
||||||
|
|
||||||
await _botServices.Start().ConfigureAwait(false);
|
await _botServices.Start().ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task OnUserJoined(SocketGuildUser arg)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using MareDbContext dbContext = await _dbContextFactory.CreateDbContextAsync().ConfigureAwait(false);
|
||||||
|
var alreadyRegistered = await dbContext.LodeStoneAuth.AnyAsync(u => u.DiscordId == arg.Id).ConfigureAwait(false);
|
||||||
|
if (alreadyRegistered)
|
||||||
|
{
|
||||||
|
await _botServices.AddRegisteredRoleAsync(arg).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogWarning(ex, "Failed to set user role on join");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public async Task StopAsync(CancellationToken cancellationToken)
|
public async Task StopAsync(CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
if (!string.IsNullOrEmpty(_configurationService.GetValueOrDefault(nameof(ServicesConfiguration.DiscordBotToken), string.Empty)))
|
if (!string.IsNullOrEmpty(_configurationService.GetValueOrDefault(nameof(ServicesConfiguration.DiscordBotToken), string.Empty)))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue