add descriptions to roles that can set vanity ids
This commit is contained in:
@@ -11,6 +11,7 @@ using MareSynchronosShared.Services;
|
||||
using MareSynchronosShared.Utils;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using StackExchange.Redis;
|
||||
using System.Text;
|
||||
using System.Threading.Channels;
|
||||
@@ -54,6 +55,9 @@ internal class DiscordBot : IHostedService
|
||||
var token = _configurationService.GetValueOrDefault(nameof(ServicesConfiguration.DiscordBotToken), string.Empty);
|
||||
if (!string.IsNullOrEmpty(token))
|
||||
{
|
||||
_logger.LogInformation("Starting DiscordBot");
|
||||
_logger.LogInformation("Using Configuration: " + _configurationService.ToString());
|
||||
|
||||
_interactionModule = new InteractionService(_discordClient);
|
||||
_interactionModule.Log += Log;
|
||||
await _interactionModule.AddModuleAsync(typeof(MareModule), _services).ConfigureAwait(false);
|
||||
@@ -213,18 +217,28 @@ internal class DiscordBot : IHostedService
|
||||
{
|
||||
while (!_updateStatusCts.IsCancellationRequested)
|
||||
{
|
||||
var vanityRoles = _configurationService.GetValueOrDefault(nameof(ServicesConfiguration.VanityRoles), Array.Empty<ulong>());
|
||||
if (vanityRoles.Length != _botServices.VanityRoles.Count)
|
||||
try
|
||||
{
|
||||
_botServices.VanityRoles.Clear();
|
||||
foreach (var role in vanityRoles)
|
||||
_logger.LogInformation("Updating Vanity Roles");
|
||||
Dictionary<ulong, string> vanityRoles = _configurationService.GetValueOrDefault(nameof(ServicesConfiguration.VanityRoles), new Dictionary<ulong, string>());
|
||||
if (vanityRoles.Keys.Count != _botServices.VanityRoles.Count)
|
||||
{
|
||||
var restrole = guild.GetRole(role);
|
||||
if (restrole != null) _botServices.VanityRoles.Add(restrole);
|
||||
}
|
||||
}
|
||||
_botServices.VanityRoles.Clear();
|
||||
foreach (var role in vanityRoles)
|
||||
{
|
||||
_logger.LogInformation("Adding Role: {id} => {desc}", role.Key, role.Value);
|
||||
|
||||
await Task.Delay(TimeSpan.FromSeconds(30), _updateStatusCts.Token).ConfigureAwait(false);
|
||||
var restrole = guild.GetRole(role.Key);
|
||||
if (restrole != null) _botServices.VanityRoles.Add(restrole, role.Value);
|
||||
}
|
||||
}
|
||||
|
||||
await Task.Delay(TimeSpan.FromSeconds(30), _updateStatusCts.Token).ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "Error during UpdateVanityRoles");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -270,7 +284,14 @@ internal class DiscordBot : IHostedService
|
||||
if (prevMessage == null)
|
||||
{
|
||||
var msg = await channel.SendMessageAsync(embed: eb.Build(), components: cb.Build()).ConfigureAwait(false);
|
||||
await msg.PinAsync().ConfigureAwait(false);
|
||||
try
|
||||
{
|
||||
await msg.PinAsync().ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// swallow
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -405,7 +426,7 @@ internal class DiscordBot : IHostedService
|
||||
_logger.LogInformation("Getting application commands from guild {guildName}", guild.Name);
|
||||
var restGuild = await _discordClient.Rest.GetGuildAsync(guild.Id);
|
||||
|
||||
ulong[] allowedRoleIds = _configurationService.GetValueOrDefault(nameof(ServicesConfiguration.VanityRoles), Array.Empty<ulong>());
|
||||
Dictionary<ulong, string> allowedRoleIds = _configurationService.GetValueOrDefault(nameof(ServicesConfiguration.VanityRoles), new Dictionary<ulong, string>());
|
||||
_logger.LogInformation($"Allowed role ids: {string.Join(", ", allowedRoleIds)}");
|
||||
|
||||
if (allowedRoleIds.Any())
|
||||
@@ -423,7 +444,7 @@ internal class DiscordBot : IHostedService
|
||||
var discordUser = await restGuild.GetUserAsync(lodestoneAuth.DiscordId).ConfigureAwait(false);
|
||||
_logger.LogInformation($"Checking User: {lodestoneAuth.DiscordId}, {lodestoneAuth.User.UID} ({lodestoneAuth.User.Alias}), User in Roles: {string.Join(", ", discordUser?.RoleIds ?? new List<ulong>())}");
|
||||
|
||||
if (discordUser == null || !discordUser.RoleIds.Any(u => allowedRoleIds.Contains(u)))
|
||||
if (discordUser == null || !discordUser.RoleIds.Any(u => allowedRoleIds.Keys.Contains(u)))
|
||||
{
|
||||
_logger.LogInformation($"User {lodestoneAuth.User.UID} not in allowed roles, deleting alias");
|
||||
lodestoneAuth.User.Alias = null;
|
||||
@@ -453,7 +474,7 @@ internal class DiscordBot : IHostedService
|
||||
|
||||
_logger.LogInformation($"Checking Group: {group.GID}, owned by {lodestoneUser?.User?.UID ?? string.Empty} ({lodestoneUser?.User?.Alias ?? string.Empty}), User in Roles: {string.Join(", ", discordUser?.RoleIds ?? new List<ulong>())}");
|
||||
|
||||
if (lodestoneUser == null || discordUser == null || !discordUser.RoleIds.Any(u => allowedRoleIds.Contains(u)))
|
||||
if (lodestoneUser == null || discordUser == null || !discordUser.RoleIds.Any(u => allowedRoleIds.Keys.Contains(u)))
|
||||
{
|
||||
_logger.LogInformation($"User {lodestoneUser.User.UID} not in allowed roles, deleting group alias");
|
||||
group.Alias = null;
|
||||
|
||||
@@ -13,7 +13,7 @@ public class DiscordBotServices
|
||||
public ConcurrentDictionary<ulong, DateTime> LastVanityChange = new();
|
||||
public ConcurrentDictionary<string, DateTime> LastVanityGidChange = new();
|
||||
public ConcurrentDictionary<ulong, ulong> ValidInteractions { get; } = new();
|
||||
public List<RestRole> VanityRoles { get; set; } = new();
|
||||
public Dictionary<RestRole, string> VanityRoles { get; set; } = new();
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
private CancellationTokenSource verificationTaskCts;
|
||||
|
||||
|
||||
@@ -17,13 +17,13 @@ public partial class MareWizardModule
|
||||
|
||||
StringBuilder sb = new();
|
||||
var user = await Context.Guild.GetUserAsync(Context.User.Id).ConfigureAwait(false);
|
||||
bool userIsInVanityRole = _botServices.VanityRoles.Exists(u => user.RoleIds.Contains(u.Id)) || !_botServices.VanityRoles.Any();
|
||||
bool userIsInVanityRole = _botServices.VanityRoles.Keys.Any(u => user.RoleIds.Contains(u.Id)) || !_botServices.VanityRoles.Any();
|
||||
if (!userIsInVanityRole)
|
||||
{
|
||||
sb.AppendLine("To be able to set Vanity IDs you must have one of the following roles:");
|
||||
foreach (var role in _botServices.VanityRoles)
|
||||
{
|
||||
sb.Append("- ").AppendLine(role.Mention);
|
||||
sb.Append("- ").Append(role.Key.Mention).Append(" (").Append(role.Value).AppendLine(")");
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
@@ -9,7 +9,7 @@ public class ServicesConfiguration : MareConfigurationBase
|
||||
public ulong? DiscordChannelForReports { get; set; } = null;
|
||||
public ulong? DiscordChannelForCommands { get; set; } = null;
|
||||
public Uri MainServerGrpcAddress { get; set; } = null;
|
||||
public ulong[]? VanityRoles { get; set; } = null;
|
||||
public Dictionary<ulong, string> VanityRoles { get; set; } = new Dictionary<ulong, string>();
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
@@ -22,7 +22,7 @@ public class ServicesConfiguration : MareConfigurationBase
|
||||
sb.AppendLine($"{nameof(DiscordChannelForCommands)} => {DiscordChannelForCommands}");
|
||||
foreach (var role in VanityRoles)
|
||||
{
|
||||
sb.AppendLine($"{nameof(VanityRoles)} => {role}");
|
||||
sb.AppendLine($"{nameof(VanityRoles)} => {role.Key} = {role.Value}");
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user