Пример #1
0
        public async Task <DougResponse> Clean(Command command)
        {
            if (!await _adminValidator.IsUserSlackAdmin(command.UserId))
            {
                return(new DougResponse(DougMessages.NotAnAdmin));
            }

            var slursToRemove = await FilterSlursToRemove(command.ChannelId);

            if (slursToRemove.Count == 0)
            {
                return(new DougResponse(DougMessages.SlursAreClean));
            }

            var slurs      = slursToRemove.Select(slur => _slurRepository.GetSlur(slur)).ToList();
            var attachment = Attachment.DeletedSlursAttachment(slurs);

            await _slack.SendAttachments(new List <Attachment> {
                attachment
            }, command.ChannelId);

            slursToRemove.ForEach(slur => _slurRepository.RemoveSlur(slur));

            _slurRepository.ClearRecentSlurs();

            slurs.ForEach(slur => _userRepository.RemoveCredits(slur.CreatedBy, AddSlurCredit));

            return(NoResponse);
        }