Esempio n. 1
0
        private async Task CleanupUsers(object state)
        {
            _logger.LogInformation("Begin clean up of users");
            try
            {
                var guilds = await _guildConfig.GetAllConfigurations();

                foreach (var config in guilds)
                {
                    var guildId = ulong.Parse(config.RowKey);
                    if (!config.CleanupEnabled)
                    {
                        _logger.LogInformation($"Skipping cleanup for guild {guildId}");
                        continue;
                    }

                    var guildUsers = await _verificationStorage.GetAllVerificationsInGuild(guildId);

                    foreach (var guildUser in guildUsers)
                    {
                        var exists = await _verificationService.VerifyUser(guildUser, config);

                        if (!exists)
                        {
                            _logger.LogWarning($"{guildUser.Alias} is either no longer with the company, or no longer reports to {config.Organization}, about to remove verification role and storage.");
                            var successful = await RemoveFromRole(guildUser.DiscordId, guildUser.GuildId, ulong.Parse(config.RoleId));

                            if (successful)
                            {
                                _logger.LogInformation($"Removing verification tracking of {guildUser.Alias}");
                                // what-if mode for now
                                var removeVerificationSuccessful = await _verificationStorage.RemoveVerification(guildId, guildUser.DiscordId);

                                if (!removeVerificationSuccessful)
                                {
                                    _logger.LogCritical($"Removing user {guildUser.DiscordId} from the verifications table failed.");
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, $"Error while running the {nameof(CleanupUsers)} background job");
            }
            _logger.LogInformation("Done cleaning up users");
        }
Esempio n. 2
0
        private async Task CleanupUsers(object state)
        {
            _logger.LogInformation("Begin clean up of users");
            try
            {
                var guilds = await _guildConfig.GetAllConfigurations();

                foreach (var config in guilds)
                {
                    var guildUsers = await _verificationStorage.GetAllVerificationsInGuild(ulong.Parse(config.RowKey));

                    //todo: handle if the user is no longer in the guild
                    //todo: remove the role from the user
                    //todo: go through roles and remove users from verifications (with respect to manually added);
                    //todo: go through the list of people in the backend DB and anyone who isn't in the server anymore,
                    //      clear them out of the DB (alt: hook the member left event and remove their verification)

                    foreach (var guildUser in guildUsers)
                    {
                        var exists = await _verificationService.VerifyUser(guildUser, config);

                        if (!exists)
                        {
                            _logger.LogWarning($"{guildUser.Alias} is either no longer with the company, or no longer reports to {config.Organization}, about to remove verification role and storage.");
                            var successful = await RemoveFromRole(guildUser.DiscordId, guildUser.GuildId, ulong.Parse(config.RoleId));

                            if (successful)
                            {
                                _logger.LogInformation($"Removing verification tracking of {guildUser.Alias}");
                                // what-if mode for now
                                //await verificationsTable.ExecuteAsync(TableOperation.Delete(guildUser));
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                // to avoid crashing the whole thing because async void
                _logger.LogError(ex, $"Error while running the {nameof(CleanupUsers)} background job");
            }
            _logger.LogInformation("Done cleaning up users");
        }