server ban update, remove reporting
This commit is contained in:
@@ -139,7 +139,7 @@ internal class DiscordBot : IHostedService
|
||||
builder.WithColor(Color.DarkGreen);
|
||||
profile.FlaggedForReport = false;
|
||||
var reportingUser = await dbContext.Auth.SingleAsync(u => u.UserUID == split[2]).ConfigureAwait(false);
|
||||
reportingUser.IsBanned = true;
|
||||
reportingUser.MarkForBan = true;
|
||||
var regReporting = await dbContext.LodeStoneAuth.SingleAsync(u => u.User.UID == reportingUser.UserUID).ConfigureAwait(false);
|
||||
dbContext.BannedRegistrations.Add(new MareSynchronosShared.Models.BannedRegistrations()
|
||||
{
|
||||
@@ -170,7 +170,7 @@ internal class DiscordBot : IHostedService
|
||||
builder.AddField("Resolution", $"User has been banned by <@{userId}>");
|
||||
builder.WithColor(Color.DarkRed);
|
||||
var offendingUser = await dbContext.Auth.SingleAsync(u => u.UserUID == split[1]).ConfigureAwait(false);
|
||||
offendingUser.IsBanned = true;
|
||||
offendingUser.MarkForBan = true;
|
||||
profile.Base64ProfileImage = null;
|
||||
profile.UserDescription = null;
|
||||
profile.ProfileDisabled = true;
|
||||
@@ -210,7 +210,6 @@ internal class DiscordBot : IHostedService
|
||||
await CreateOrUpdateModal(guild).ConfigureAwait(false);
|
||||
_ = UpdateVanityRoles(guild);
|
||||
_ = RemoveUsersNotInVanityRole();
|
||||
_ = ProcessReportsQueue();
|
||||
}
|
||||
|
||||
private async Task UpdateVanityRoles(RestGuild guild)
|
||||
@@ -319,96 +318,6 @@ internal class DiscordBot : IHostedService
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private async Task ProcessReportsQueue()
|
||||
{
|
||||
var guild = (await _discordClient.Rest.GetGuildsAsync()).First();
|
||||
|
||||
_processReportQueueCts?.Cancel();
|
||||
_processReportQueueCts?.Dispose();
|
||||
_processReportQueueCts = new();
|
||||
var token = _processReportQueueCts.Token;
|
||||
while (!token.IsCancellationRequested)
|
||||
{
|
||||
await Task.Delay(TimeSpan.FromSeconds(30)).ConfigureAwait(false);
|
||||
|
||||
if (_discordClient.ConnectionState != ConnectionState.Connected) continue;
|
||||
var reportChannelId = _configurationService.GetValue<ulong?>(nameof(ServicesConfiguration.DiscordChannelForReports));
|
||||
if (reportChannelId == null) continue;
|
||||
|
||||
try
|
||||
{
|
||||
using (var scope = _services.CreateScope())
|
||||
{
|
||||
_logger.LogInformation("Checking for Profile Reports");
|
||||
var dbContext = scope.ServiceProvider.GetRequiredService<MareDbContext>();
|
||||
if (!dbContext.UserProfileReports.Any())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var reports = await dbContext.UserProfileReports.ToListAsync().ConfigureAwait(false);
|
||||
var restChannel = await guild.GetTextChannelAsync(reportChannelId.Value).ConfigureAwait(false);
|
||||
|
||||
foreach (var report in reports)
|
||||
{
|
||||
var reportedUser = await dbContext.Users.SingleAsync(u => u.UID == report.ReportedUserUID).ConfigureAwait(false);
|
||||
var reportedUserLodestone = await dbContext.LodeStoneAuth.SingleOrDefaultAsync(u => u.User.UID == report.ReportedUserUID).ConfigureAwait(false);
|
||||
var reportingUser = await dbContext.Users.SingleAsync(u => u.UID == report.ReportingUserUID).ConfigureAwait(false);
|
||||
var reportingUserLodestone = await dbContext.LodeStoneAuth.SingleOrDefaultAsync(u => u.User.UID == report.ReportingUserUID).ConfigureAwait(false);
|
||||
var reportedUserProfile = await dbContext.UserProfileData.SingleAsync(u => u.UserUID == report.ReportedUserUID).ConfigureAwait(false);
|
||||
EmbedBuilder eb = new();
|
||||
eb.WithTitle("Mare Synchronos Profile Report");
|
||||
|
||||
StringBuilder reportedUserSb = new();
|
||||
StringBuilder reportingUserSb = new();
|
||||
reportedUserSb.Append(reportedUser.UID);
|
||||
reportingUserSb.Append(reportingUser.UID);
|
||||
if (reportedUserLodestone != null)
|
||||
{
|
||||
reportedUserSb.AppendLine($" (<@{reportedUserLodestone.DiscordId}>)");
|
||||
}
|
||||
if (reportingUserLodestone != null)
|
||||
{
|
||||
reportingUserSb.AppendLine($" (<@{reportingUserLodestone.DiscordId}>)");
|
||||
}
|
||||
eb.AddField("Reported User", reportedUserSb.ToString());
|
||||
eb.AddField("Reporting User", reportingUserSb.ToString());
|
||||
eb.AddField("Report Date (UTC)", report.ReportDate);
|
||||
eb.AddField("Report Reason", string.IsNullOrWhiteSpace(report.ReportReason) ? "-" : report.ReportReason);
|
||||
eb.AddField("Reported User Profile Description", string.IsNullOrWhiteSpace(reportedUserProfile.UserDescription) ? "-" : reportedUserProfile.UserDescription);
|
||||
eb.AddField("Reported User Profile Is NSFW", reportedUserProfile.IsNSFW);
|
||||
|
||||
var cb = new ComponentBuilder();
|
||||
cb.WithButton("Dismiss Report", customId: $"mare-report-button-dismiss-{reportedUser.UID}", style: ButtonStyle.Primary);
|
||||
cb.WithButton("Ban profile", customId: $"mare-report-button-banprofile-{reportedUser.UID}", style: ButtonStyle.Secondary);
|
||||
cb.WithButton("Ban user", customId: $"mare-report-button-banuser-{reportedUser.UID}", style: ButtonStyle.Danger);
|
||||
cb.WithButton("Dismiss and Ban Reporting user", customId: $"mare-report-button-banreporting-{reportedUser.UID}-{reportingUser.UID}", style: ButtonStyle.Danger);
|
||||
|
||||
if (!string.IsNullOrEmpty(reportedUserProfile.Base64ProfileImage))
|
||||
{
|
||||
var fileName = reportedUser.UID + "_profile_" + Guid.NewGuid().ToString("N") + ".png";
|
||||
eb.WithImageUrl($"attachment://{fileName}");
|
||||
using MemoryStream ms = new(Convert.FromBase64String(reportedUserProfile.Base64ProfileImage));
|
||||
await restChannel.SendFileAsync(ms, fileName, "User Report", embed: eb.Build(), components: cb.Build(), isSpoiler: true).ConfigureAwait(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
var msg = await restChannel.SendMessageAsync(embed: eb.Build(), components: cb.Build()).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
dbContext.Remove(report);
|
||||
}
|
||||
|
||||
await dbContext.SaveChangesAsync().ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "Failed to process reports");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async Task RemoveUsersNotInVanityRole()
|
||||
{
|
||||
_vanityUpdateCts?.Cancel();
|
||||
|
||||
Reference in New Issue
Block a user