Esempio n. 1
0
        public async Task Leave()
        {
            if (!(Context.User is SocketGuildUser guildUser))
            {
                return;
            }

            var userId             = guildUser.Id;
            var guildId            = Context.Guild.Id;
            var verificationResult = await _verificationStorage.GetVerification(guildId, userId);

            if (verificationResult != null)
            {
                var deleteResult = await _verificationStorage.RemoveVerification(guildId, userId);

                if (deleteResult)
                {
                    var role = Context.Guild.GetRole(ulong.Parse(Context.Configuration.RoleId));
                    await guildUser.RemoveRoleAsync(role);

                    await ReplyAsync("Your verified status has been removed.");
                }
                else
                {
                    await ReplyAsync($"Unable to remove your verification.");
                }
            }
            else
            {
                await ReplyAsync("You are not currently verified.");
            }
        }
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 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. 3
0
 private Task RemoveVerificationForUser(ulong guildId, ulong userId)
 {
     return(_verificationStorage.RemoveVerification(guildId, userId));
 }
Esempio n. 4
0
 private Task OnMemberBanned(SocketUser user, SocketGuild guild)
 {
     return(_verificationStorage.RemoveVerification(user.Id, guild.Id));
 }