Exemplo n.º 1
0
        protected override async Task <ISlackActionResponse> Respond(SlackActionPayload payload, MemeMessage message)
        {
            if (payload == null)
            {
                throw new ArgumentNullException(nameof(payload));
            }
            if (message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }

            var template = await _configService.GetTemplate(payload.ActionValue, message.UserId);

            var imageUrl = await _imageUtility.GetImageUrl(message.Message, template);

            var updatedMessage = await DatabaseRepo.UpdatePreview(
                id : message.Id,
                templateId : template.Id,
                message : message.Message,
                imageUrl : imageUrl);

            if (updatedMessage == null || updatedMessage.PublishDate.HasValue || updatedMessage.DeleteDate.HasValue)
            {
                return(await _langResponse.RenderDelete());
            }

            return(await _langResponse.RenderPreview(updatedMessage));
        }
 public LangCommandResponder(LangResponse langResponse, DatabaseRepo databaseRepo, ConfigService configService, ImageUtility imageUtility, Serializer serializer)
 {
     _langResponse  = langResponse;
     _databaseRepo  = databaseRepo;
     _configService = configService;
     _imageUtility  = imageUtility;
     _serializer    = serializer;
 }
        protected override async Task <ISlackActionResponse> Respond(SlackActionPayload payload, MemeMessage message)
        {
            if (payload == null)
            {
                throw new ArgumentNullException(nameof(payload));
            }
            if (message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }

            await DatabaseRepo.DeletePreview(message.Id);

            return(await _langResponse.RenderDelete());
        }
Exemplo n.º 4
0
        private async Task <SlackMessage> AddVote(SlackActionPayload payload, MemeMessage message)
        {
            if (payload == null)
            {
                throw new ArgumentNullException(nameof(payload));
            }
            if (message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }

            var updatedMessage = await DatabaseRepo.AddReaction(message.Id, Constants.Reactions.UpVote, payload.User.Id, payload.User.Name, null);

            return(await _langResponse.RenderPublished(updatedMessage));
        }
        protected async override Task <ISlackActionResponse> Respond(SlackActionPayload payload, MemeMessage message)
        {
            if (payload == null)
            {
                throw new ArgumentNullException(nameof(payload));
            }
            if (message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }

            var updatedMessage = await DatabaseRepo.PublishMessage(message.Id);

            if (updatedMessage == null || updatedMessage.DeleteDate.HasValue)
            {
                return(await _langResponse.RenderDelete());
            }
            var result = await _langResponse.RenderPublished(message);

            result.DeleteOriginal = true;
            return(result);
        }
Exemplo n.º 6
0
        protected async override Task <ISlackActionResponse> Respond(SlackActionPayload payload, MemeMessage message)
        {
            if (payload == null)
            {
                throw new ArgumentNullException(nameof(payload));
            }
            if (message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }

            var alreadyUpvoted = await DatabaseRepo.HasReacted(message.Id, Constants.Reactions.UpVote, payload.User.Id);

            if (alreadyUpvoted)
            {
                return(await RemoveVote(payload, message));
            }
            else
            {
                return(await AddVote(payload, message));
            }
        }
 public SubmitActionResponder(DatabaseRepo databaseRepo, LangResponse langResponse) : base(databaseRepo)
 {
     _langResponse = langResponse;
 }
 public CancelActionResponder(DatabaseRepo databaseRepo, LangResponse langResponse) : base(databaseRepo)
 {
     _langResponse = langResponse;
 }
Exemplo n.º 9
0
 public UpVoteActionResponder(DatabaseRepo databaseRepo, LangResponse langResponse) : base(databaseRepo)
 {
     _langResponse = langResponse;
 }
Exemplo n.º 10
0
 public BaseActionResponder(DatabaseRepo databaseRepo)
 {
     DatabaseRepo = databaseRepo;
 }
Exemplo n.º 11
0
 public BaseDialogResponder(DatabaseRepo databaseRepo)
 {
     DatabaseRepo = databaseRepo;
 }
Exemplo n.º 12
0
 public SwitchActionResponder(DatabaseRepo databaseRepo, LangResponse langResponse, ConfigService configService, ImageUtility imageUtility) : base(databaseRepo)
 {
     _langResponse  = langResponse;
     _configService = configService;
     _imageUtility  = imageUtility;
 }
Exemplo n.º 13
0
        protected override async Task <ISlackActionResponse> Respond(SlackActionPayload payload, MemeMessage message)
        {
            if (payload == null)
            {
                throw new ArgumentNullException(nameof(payload));
            }
            if (message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }

            var response = await DatabaseRepo.InsertResponse(
                messageId : message.Id,
                responseUrl : payload.ResponseUrl,
                teamId : payload.Team.Id,
                teamDomain : payload.Team.Domain,
                channelId : payload.Channel.Id,
                channelName : payload.Channel.Name,
                userId : payload.User.Id,
                userName : payload.User.Name);

            var config = await _configService.GetConfig();

            var template = await _configService.GetTemplate(message.TemplateId, message.UserId);

            var boxes = template.Boxes ?? config.TemplateDefaults.Boxes;
            var lines = _textSplitter.SplitText(message.Message, boxes.Count);

            var elements = lines.SelectWithIndex((line, i) => new SlackDialogText
            {
                Label    = String.IsNullOrEmpty(boxes[i].Label) ? $"Line {i + 1}" : boxes[i].Label,
                Name     = $"line{i}",
                Optional = true,
                Value    = line,
            }).ToList <ISlackDialogElement>();

            elements.Add(new SlackDialogSelect
            {
                Label    = "Post anonymously",
                Name     = "isAnonymous",
                Optional = false,
                Value    = message.IsAnonymous.ToString(),
                Options  = new[]
                {
                    new SlackDialogOption
                    {
                        Label = "Yes",
                        Value = Boolean.TrueString,
                    },
                    new SlackDialogOption
                    {
                        Label = "No",
                        Value = Boolean.FalseString,
                    },
                }
            });

            await _slackClient.DialogOpen(new SlackApiDialogOpenRequest
            {
                TriggerId = payload.TriggerId,
                Dialog    = new SlackDialog
                {
                    CallbackId  = $"{Constants.CallbackIds.Edit}:{response.Guid}",
                    Title       = "Edit",
                    SubmitLabel = "Preview",
                    Elements    = elements,
                }
            });

            return(new SlackEmptyResponse());
        }
Exemplo n.º 14
0
 public EditActionResponder(DatabaseRepo databaseRepo, SlackClient slackClient, ConfigService configService, TextSplitter textSplitter) : base(databaseRepo)
 {
     _slackClient   = slackClient;
     _configService = configService;
     _textSplitter  = textSplitter;
 }