Beispiel #1
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);
        }
        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());
        }
Beispiel #4
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));
            }
        }
Beispiel #5
0
 protected abstract Task<ISlackActionResponse> Respond(SlackActionPayload payload, MemeMessage message);
 protected abstract Task <ISlackDialogResponse> Respond(SlackDialogPayload payload, MemeMessage message, Response response);
Beispiel #7
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));
        }
Beispiel #8
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());
        }