Beispiel #1
0
        static ProfileBotCommand ParseAdminCommand(string normalizedMessage)
        {
            switch (normalizedMessage)
            {
            case "validate all users":
                return(ValidateAllProfilesCommand.Create());

            case "notify all users":
                return(NotifyAllProfilesCommand.Create());
            }

            var commandParts = normalizedMessage.Split(' ');

            if (commandParts.Length == 2 && commandParts[1].StartsWith("<@"))
            {
                var verb    = commandParts[0];
                var subject = new SlackStringUser(commandParts[1].ToUpper());
                switch (verb)
                {
                case "validate":
                    return(new ValidateSingleProfileCommand(subject));

                case "notify":
                    return(new NotifySingleProfileCommand(subject));
                }
            }

            return(UnknownCommand.Create());
        }
        async Task ValidateSingleProfile(string sender, SlackStringUser user, bool notify = false)
        {
            var verb = notify ? "Notifying" : "Validating";
            await slackIntegration.SendDirectMessage(sender, $"{verb} {user.SlackUserIdAsString}");

            var userToCheck = await slackIntegration.GetUser(user.UserId);

            var verificationResult = slackProfileValidator.ValidateProfile(userToCheck);

            if (verificationResult.IsValid)
            {
                await slackIntegration.SendDirectMessage(sender,
                                                         $"{user.SlackUserIdAsString} has a complete profile");

                return;
            }

            await slackIntegration.SendDirectMessage(sender, verificationResult.Errors);

            if (notify)
            {
                await slackIntegration.SendDirectMessage(verificationResult.UserId, verificationResult.Errors);
            }
        }