attempt to switch ident service to redis
This commit is contained in:
@@ -6,7 +6,7 @@ using MareSynchronosShared.Data;
|
||||
using MareSynchronosShared.Services;
|
||||
using MareSynchronosShared.Utils;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using static MareSynchronosShared.Protos.IdentificationService;
|
||||
using StackExchange.Redis;
|
||||
|
||||
namespace MareSynchronosServices.Discord;
|
||||
|
||||
@@ -16,19 +16,19 @@ internal class DiscordBot : IHostedService
|
||||
private readonly IServiceProvider _services;
|
||||
private readonly IConfigurationService<ServicesConfiguration> _configurationService;
|
||||
private readonly ILogger<DiscordBot> _logger;
|
||||
private readonly IdentificationServiceClient _identificationServiceClient;
|
||||
private readonly IConnectionMultiplexer _connectionMultiplexer;
|
||||
private readonly DiscordSocketClient _discordClient;
|
||||
private CancellationTokenSource? _updateStatusCts;
|
||||
private CancellationTokenSource? _vanityUpdateCts;
|
||||
|
||||
public DiscordBot(DiscordBotServices botServices, IServiceProvider services, IConfigurationService<ServicesConfiguration> configuration,
|
||||
ILogger<DiscordBot> logger, IdentificationServiceClient identificationServiceClient)
|
||||
ILogger<DiscordBot> logger, IConnectionMultiplexer connectionMultiplexer)
|
||||
{
|
||||
_botServices = botServices;
|
||||
_services = services;
|
||||
_configurationService = configuration;
|
||||
_logger = logger;
|
||||
this._identificationServiceClient = identificationServiceClient;
|
||||
_connectionMultiplexer = connectionMultiplexer;
|
||||
_discordClient = new(new DiscordSocketConfig()
|
||||
{
|
||||
DefaultRetryMode = RetryMode.AlwaysRetry
|
||||
@@ -170,9 +170,11 @@ internal class DiscordBot : IHostedService
|
||||
_updateStatusCts = new();
|
||||
while (!_updateStatusCts.IsCancellationRequested)
|
||||
{
|
||||
var onlineUsers = await _identificationServiceClient.GetOnlineUserCountAsync(new MareSynchronosShared.Protos.ServerMessage());
|
||||
_logger.LogInformation("Users online: " + onlineUsers.Count);
|
||||
await _discordClient.SetActivityAsync(new Game("Mare for " + onlineUsers.Count + " Users")).ConfigureAwait(false);
|
||||
var endPoint = _connectionMultiplexer.GetEndPoints().First();
|
||||
var onlineUsers = await _connectionMultiplexer.GetServer(endPoint).KeysAsync(pattern: "UID:*").CountAsync();
|
||||
|
||||
_logger.LogInformation("Users online: " + onlineUsers);
|
||||
await _discordClient.SetActivityAsync(new Game("Mare for " + onlineUsers + " Users")).ConfigureAwait(false);
|
||||
await Task.Delay(TimeSpan.FromSeconds(15)).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,9 +8,9 @@ using Prometheus;
|
||||
using MareSynchronosShared.Models;
|
||||
using MareSynchronosShared.Utils;
|
||||
using MareSynchronosShared.Services;
|
||||
using static MareSynchronosShared.Protos.IdentificationService;
|
||||
using Grpc.Net.ClientFactory;
|
||||
using MareSynchronosShared.Protos;
|
||||
using StackExchange.Redis;
|
||||
|
||||
namespace MareSynchronosServices.Discord;
|
||||
|
||||
@@ -28,21 +28,21 @@ public class MareModule : InteractionModuleBase
|
||||
private readonly ILogger<MareModule> _logger;
|
||||
private readonly IServiceProvider _services;
|
||||
private readonly DiscordBotServices _botServices;
|
||||
private readonly IdentificationServiceClient _identificationServiceClient;
|
||||
private readonly IConfigurationService<ServerConfiguration> _mareClientConfigurationService;
|
||||
private readonly GrpcClientFactory _grpcClientFactory;
|
||||
private readonly IConnectionMultiplexer _connectionMultiplexer;
|
||||
private Random random = new();
|
||||
|
||||
public MareModule(ILogger<MareModule> logger, IServiceProvider services, DiscordBotServices botServices,
|
||||
IdentificationServiceClient identificationServiceClient, IConfigurationService<ServerConfiguration> mareClientConfigurationService,
|
||||
GrpcClientFactory grpcClientFactory)
|
||||
IConfigurationService<ServerConfiguration> mareClientConfigurationService,
|
||||
GrpcClientFactory grpcClientFactory, IConnectionMultiplexer connectionMultiplexer)
|
||||
{
|
||||
_logger = logger;
|
||||
_services = services;
|
||||
_botServices = botServices;
|
||||
_identificationServiceClient = identificationServiceClient;
|
||||
_mareClientConfigurationService = mareClientConfigurationService;
|
||||
_grpcClientFactory = grpcClientFactory;
|
||||
_connectionMultiplexer = connectionMultiplexer;
|
||||
}
|
||||
|
||||
[SlashCommand("register", "Starts the registration process for the Mare Synchronos server of this Discord")]
|
||||
@@ -392,7 +392,7 @@ public class MareModule : InteractionModuleBase
|
||||
var lodestoneUser = await db.LodeStoneAuth.Include(u => u.User).SingleOrDefaultAsync(u => u.DiscordId == userToCheckForDiscordId).ConfigureAwait(false);
|
||||
var dbUser = lodestoneUser.User;
|
||||
var auth = await db.Auth.SingleOrDefaultAsync(u => u.UserUID == dbUser.UID).ConfigureAwait(false);
|
||||
var identity = await _identificationServiceClient.GetIdentForUidAsync(new MareSynchronosShared.Protos.UidMessage { Uid = dbUser.UID });
|
||||
var identity = await _connectionMultiplexer.GetDatabase().StringGetAsync("UID:" + dbUser.UID).ConfigureAwait(false);
|
||||
var groups = await db.Groups.Where(g => g.OwnerUID == dbUser.UID).ToListAsync().ConfigureAwait(false);
|
||||
var groupsJoined = await db.GroupPairs.Where(g => g.GroupUserUID == dbUser.UID).ToListAsync().ConfigureAwait(false);
|
||||
|
||||
@@ -405,7 +405,7 @@ public class MareModule : InteractionModuleBase
|
||||
eb.AddField("Vanity UID", dbUser.Alias);
|
||||
}
|
||||
eb.AddField("Last Online (UTC)", dbUser.LastLoggedIn.ToString("U"));
|
||||
eb.AddField("Currently online: ", !string.IsNullOrEmpty(identity.Ident));
|
||||
eb.AddField("Currently online: ", !string.IsNullOrEmpty(identity));
|
||||
eb.AddField("Hashed Secret Key", auth.HashedKey);
|
||||
eb.AddField("Joined Syncshells", groupsJoined.Count);
|
||||
eb.AddField("Owned Syncshells", groups.Count);
|
||||
@@ -419,9 +419,9 @@ public class MareModule : InteractionModuleBase
|
||||
eb.AddField("Owned Syncshell " + group.GID + " User Count", syncShellUserCount);
|
||||
}
|
||||
|
||||
if (isAdminCall && !string.IsNullOrEmpty(identity.Ident))
|
||||
if (isAdminCall && !string.IsNullOrEmpty(identity))
|
||||
{
|
||||
eb.AddField("Character Ident", identity.Ident);
|
||||
eb.AddField("Character Ident", identity);
|
||||
}
|
||||
|
||||
return eb;
|
||||
|
||||
Reference in New Issue
Block a user