Example #1
0
        public async Task ApproveAll()
        {
            var invokingUser = DiscordUserDataHandler.GetGuildUserById(Context.User.Id, Context.Guild.Id);

            if (invokingUser == null || invokingUser.PermissionLevel != DiscordGuildUser.PermissionLevels.Approve)
            {
                await _replyservice.ReplyEmbedAsync(context : Context,
                                                    message : "You do not have permissions to invoke this command.");

                return;
            }

            var query = VerificationFormDataHandler.GetPendingVerificationFormsByGuild(Context.Guild.Id);

            if (query.Count() < 1)
            {
                await _replyservice.ReplyEmbedAsync(context : Context,
                                                    message : $"No pending verifications");

                return;
            }

            var roleQuery = DiscordRoleDataHandler.GetGuildRoles(Context.Guild.Id);

            var toBeAddedQuery   = roleQuery.Where(x => x.Action == DiscordRole.ActionType.Add);
            var toBeRemovedQuery = roleQuery.Where(x => x.Action == DiscordRole.ActionType.Remove);

            List <IRole> toBeAdded   = new List <IRole>();
            List <IRole> toBeRemoved = new List <IRole>();

            foreach (var role in toBeAddedQuery)
            {
                var socketRole = Context.Guild.GetRole(role.RoleId);

                toBeAdded.Add(socketRole);
            }

            foreach (var role in toBeRemovedQuery)
            {
                var socketRole = Context.Guild.GetRole(role.RoleId);

                toBeRemoved.Add(socketRole);
            }

            foreach (var form in query)
            {
                var user = Context.Guild.GetUser(form.Verified);

                await user.AddRolesAsync(toBeAdded);

                await user.RemoveRolesAsync(toBeRemoved);

                form.Approver   = Context.User.Id;
                form.IsApproved = true;
                await VerificationFormDataHandler.AddFullVerificationForm(form);
            }

            Log.Information(
                "Bulk approval ({FormCount} forms) by {UserID} in guild {GuildID}",
                query.Count(), Context.User.Id, Context.Guild.Id
                );

            await _replyservice.ReplyEmbedAsync(context : Context,
                                                message : $"The pending forms ({ query.Count() }) have been bulk approved by { Context.User.Username }");
        }
Example #2
0
        public async Task Verify(IGuildUser user)
        {
            var invokingUser = DiscordUserDataHandler.GetGuildUserById(Context.User.Id, Context.Guild.Id);

            if (invokingUser == null)
            {
                await _replyservice.ReplyEmbedAsync(context : Context,
                                                    message : "You do not have permissions to invoke this command.");

                return;
            }

            var form = new VerificationForm
            {
                GuildId   = Context.Guild.Id,
                Verified  = user.Id,
                Verifier  = Context.User.Id,
                IssuedUtc = DateTime.UtcNow
            };

            if (invokingUser.PermissionLevel == DiscordGuildUser.PermissionLevels.Approve)
            {
                form.Approver   = Context.User.Id;
                form.IsApproved = true;

                var query = DiscordRoleDataHandler.GetGuildRoles(Context.Guild.Id);

                var toBeAddedQuery   = query.Where(x => x.Action == DiscordRole.ActionType.Add);
                var toBeRemovedQuery = query.Where(x => x.Action == DiscordRole.ActionType.Remove);

                List <IRole> toBeAdded   = new List <IRole>();
                List <IRole> toBeRemoved = new List <IRole>();

                foreach (var role in toBeAddedQuery)
                {
                    var socketRole = Context.Guild.GetRole(role.RoleId);

                    toBeAdded.Add(socketRole);
                }

                foreach (var role in toBeRemovedQuery)
                {
                    var socketRole = Context.Guild.GetRole(role.RoleId);

                    toBeRemoved.Add(socketRole);
                }

                await user.AddRolesAsync(toBeAdded);

                await user.RemoveRolesAsync(toBeRemoved);

                await VerificationFormDataHandler.AddFullVerificationForm(form);

                var message = $"User {user.Username} has been verified ";
                if (form.Verifier != Context.User.Id)
                {
                    message += $"by { Context.Guild.GetUser(form.Verifier).Username } ";
                }
                message += "and approved.";

                Log.Information(
                    "User {UserID} verified and approved by {InvokingUserID} in guild {GuildID}",
                    user.Id, Context.User.Id, Context.Guild.Id
                    );

                await _replyservice.ReplyEmbedAsync(context : Context,
                                                    message : message);
            }
            else
            {
                try
                {
                    await VerificationFormDataHandler.AddPendingVerificationForm(form);

                    Log.Information(
                        "Verification form for user {UserID} submitted by {InvokingUserID} in guild {GuildID}",
                        user.Id, Context.User.Id, Context.Guild.Id
                        );

                    await _replyservice.ReplyEmbedAsync(context : Context,
                                                        message : $"Verification form for user {user.Username} has been submitted by {Context.User.Username}.");
                }
                catch (VerificationFormExistsException)
                {
                    await _replyservice.ReplyEmbedAsync(context : Context,
                                                        message : $"User {user.Username} already has a pending verification form");
                }
            }
        }