add more info

This commit is contained in:
Stanley Dimant
2025-01-03 11:41:40 +01:00
parent 698890f991
commit ef93a5f55a
2 changed files with 18 additions and 6 deletions

View File

@@ -262,31 +262,42 @@ internal class DiscordBot : IHostedService
var executionStartTime = DateTimeOffset.UtcNow;
int processedUsers = 0;
int addedRoles = 0;
int kickedUsers = 0;
await _botServices.LogToChannel($"Starting to process registered users: Adding Role {registrationRole.Name}. Kick Stale Unregistered: {kickUnregistered}.").ConfigureAwait(false);
await foreach (var userList in guild.GetUsersAsync(new RequestOptions { CancelToken = token }).ConfigureAwait(false))
{
_logger.LogInformation("Processing chunk of {count} users", userList.Count);
_logger.LogInformation("Processing chunk of {count} users, total processed: {proc}, roles added: {added}, users kicked: {kicked}",
userList.Count, processedUsers, addedRoles, kickedUsers);
foreach (var user in userList)
{
if (registeredUsers.Contains(user.Id))
{
await _botServices.AddRegisteredRoleAsync(user, registrationRole).ConfigureAwait(false);
bool roleAdded = await _botServices.AddRegisteredRoleAsync(user, registrationRole).ConfigureAwait(false);
if (roleAdded) addedRoles++;
}
else
{
if (kickUnregistered)
{
if ((executionStartTime - user.JoinedAt.Value).TotalDays > 7)
{
await _botServices.KickUserAsync(user).ConfigureAwait(false);
kickedUsers++;
}
}
}
token.ThrowIfCancellationRequested();
}
processedUsers++;
}
await _botServices.LogToChannel("Processing registered users finished").ConfigureAwait(false);
await _botServices.LogToChannel($"Processing registered users finished. Processed {processedUsers} users, added {addedRoles} roles and kicked {kickedUsers}").ConfigureAwait(false);
}
}
private async Task RemoveUsersNotInVanityRole(CancellationToken token)

View File

@@ -130,10 +130,11 @@ public class DiscordBotServices
await RetryAsync(restUser.AddRoleAsync(registeredRole.Value), user, $"Add Registered Role").ConfigureAwait(false);
}
public async Task AddRegisteredRoleAsync(RestGuildUser user, RestRole role)
public async Task<bool> AddRegisteredRoleAsync(RestGuildUser user, RestRole role)
{
if (user.RoleIds.Contains(role.Id)) return;
if (user.RoleIds.Contains(role.Id)) return false;
await RetryAsync(user.AddRoleAsync(role), user, $"Add Registered Role", false).ConfigureAwait(false);
return true;
}
public async Task KickUserAsync(RestGuildUser user)