public async Task PerformAction(Root request)
        {
            var queue = await _queueDatabase.GetQueue(request.channel.id, null);

            if (queue == null)
            {
                var responseNoQueue = new SlackResponseDto
                {
                    Text           = "Queue Does not exist please create one",
                    ResponseType   = BasicResponseTypes.ephemeral,
                    DeleteOriginal = true,
                };

                await _hookService.TriggerWebHook(request.response_url, responseNoQueue);
            }

            //empty queue
            if (queue != null && queue.Queue.Count == 0)
            {
                var responseEmptyQueue = new SlackResponseDto
                {
                    Text           = "No one is in the queue bozo",
                    ResponseType   = BasicResponseTypes.ephemeral,
                    DeleteOriginal = true,
                };

                await _hookService.TriggerWebHook(request.response_url, responseEmptyQueue);
            }

            //Removed from queue
        }
示例#2
0
        public async Task PerformAction(Root request)
        {
            var queue = await _queueDatabase.GetQueue(request.channel.id, null);

            var queueBlock = await _blockCreationService.CurrentQueue(queue);

            SlackResponseDto responseBlocks;

            if (queue.Queue.Any())
            {
                var responseConfirmation = new SlackResponseDto
                {
                    Text           = $"OI MAKE SURE YOU ARE STILL USING THIS @{queue.Queue.Peek()}",
                    ResponseType   = BasicResponseTypes.in_channel,
                    DeleteOriginal = true,
                };

                await _hookService.TriggerWebHook(request.response_url, responseConfirmation);

                responseBlocks = new SlackResponseDto
                {
                    Text           = $"Nudging @{queue.Queue.Peek()}",
                    ResponseType   = BasicResponseTypes.in_channel,
                    Blocks         = queueBlock.Blocks,
                    DeleteOriginal = true,
                };

                await _hookService.TriggerWebHook(request.response_url, responseBlocks);

                var responseNudge = new SlackResponseDto()
                {
                    Text           = $"Nudged the leader",
                    ResponseType   = BasicResponseTypes.ephemeral,
                    DeleteOriginal = true,
                };

                await _hookService.TriggerWebHook(request.response_url, responseNudge);

                return;
            }

            var responseEmpty = new SlackResponseDto
            {
                Text           = "Queue is empty",
                ResponseType   = BasicResponseTypes.ephemeral,
                DeleteOriginal = true,
            };
            await _hookService.TriggerWebHook(request.response_url, responseEmpty);

            responseBlocks = new SlackResponseDto
            {
                ResponseType   = BasicResponseTypes.in_channel,
                Blocks         = queueBlock.Blocks,
                DeleteOriginal = true,
            };

            await _hookService.TriggerWebHook(request.response_url, responseBlocks);
        }
示例#3
0
        public async Task <SlackResponseDto> CreateQueueForChannel(SlashRequest request)
        {
            // check to see if queue already exists
            var currentQueue = await _queueDatabase.GetQueue(request.Channel_Id, request.Enterprise_Id);

            string message;

            //output queue to channel
            QueueBlockDto blocks;

            if (currentQueue == null)
            {
                currentQueue = new QueueDto
                {
                    ChannelId = request.Channel_Id,
                    Name      = request.Text,
                    Queue     = new Queue <string>()
                };

                await _queueDatabase.UpdateQueue(currentQueue);

                message = $"Queue has been added to {request.Channel_Name}";
            }
            else
            {
                blocks = await _blockCreationService.CurrentQueue(currentQueue);

                message = $"Queue Already exists: {currentQueue.Name}";
                return(new SlackResponseDto
                {
                    Text = message,
                    ResponseType = BasicResponseTypes.in_channel,
                    Blocks = blocks.Blocks
                });
            }

            blocks = await _blockCreationService.CurrentQueue(currentQueue);

            var responseNudge = new SlackResponseDto()
            {
                ResponseType   = BasicResponseTypes.ephemeral,
                DeleteOriginal = true,
                Blocks         = blocks.Blocks
            };

            await _hookService.TriggerWebHook(request.Response_Url, responseNudge);

            return(new SlackResponseDto
            {
                Text = "Here's the queue",
                ResponseType = BasicResponseTypes.ephemeral
            });
        }
示例#4
0
        public async Task PerformAction(Root request)
        {
            var queue = await _queueDatabase.GetQueue(request.channel.id, null);

            if (queue == null)
            {
                var responseNoQueue = new SlackResponseDto
                {
                    Text           = "Queue Does not exist please create one",
                    ResponseType   = BasicResponseTypes.ephemeral,
                    DeleteOriginal = true,
                };

                await _hookService.TriggerWebHook(request.response_url, responseNoQueue);

                return;
            }
        }
示例#5
0
        public async Task PerformAction(Root request)
        {
            var queue = await _queueDatabase.GetQueue(request.channel.id, null);

            if (queue == null)
            {
                var responseNoQueue = new SlackResponseDto()
                {
                    Text           = "Queue Does not exist please create one",
                    ResponseType   = BasicResponseTypes.in_channel,
                    DeleteOriginal = true,
                };

                await _hookService.TriggerWebHook(request.response_url, responseNoQueue);

                return;
            }

            if (queue.Queue.Contains(request.user.username))
            {
                var queueBlock = await _blockCreationService.CurrentQueue(queue);

                var responseAlreadyInQueueBlock = new SlackResponseDto()
                {
                    Text            = "test",
                    ResponseType    = BasicResponseTypes.in_channel,
                    Blocks          = queueBlock.Blocks,
                    DeleteOriginal  = true,
                    ReplaceOriginal = false
                };

                await _hookService.TriggerWebHook(request.response_url, responseAlreadyInQueueBlock);

                var responseAlreadyInQueue = new SlackResponseDto
                {
                    Text         = "Already in the queue",
                    ResponseType = BasicResponseTypes.ephemeral
                };

                await _hookService.TriggerWebHook(request.response_url, responseAlreadyInQueue);
            }
            else
            {
                queue.Queue.Enqueue(request.user.username);
                await _queueDatabase.UpdateQueue(queue);

                var queueBlock = await _blockCreationService.CurrentQueue(queue);

                var responseJoinBlock = new SlackResponseDto
                {
                    Text            = "Queue",
                    ResponseType    = BasicResponseTypes.in_channel,
                    Blocks          = queueBlock.Blocks,
                    DeleteOriginal  = true,
                    ReplaceOriginal = false
                };
                await _hookService.TriggerWebHook(request.response_url, responseJoinBlock);

                var responseJoinMessage = new SlackResponseDto
                {
                    Text         = $"@{request.user.username} Has joined the queue",
                    ResponseType = BasicResponseTypes.in_channel,
                };
                await _hookService.TriggerWebHook(request.response_url, responseJoinMessage);
            }
        }
        public async Task PerformAction(Root request)
        {
            var queue = await _queueDatabase.GetQueue(request.channel.id, null);

            if (queue == null)
            {
                var responseNoQueue = new SlackResponseDto()
                {
                    Text           = "Queue Does not exist please create one",
                    ResponseType   = BasicResponseTypes.in_channel,
                    DeleteOriginal = true,
                };

                await _hookService.TriggerWebHook(request.response_url, responseNoQueue);

                return;
            }

            if (!queue.Queue.Contains(request.user.username))
            {
                var responseNotInQueue = new SlackResponseDto()
                {
                    Text           = "you're not in the queue numpty",
                    ResponseType   = BasicResponseTypes.ephemeral,
                    DeleteOriginal = false,
                };

                await _hookService.TriggerWebHook(request.response_url, responseNotInQueue);

                return;
            }

            var leaver   = request.user.username;
            var wasFirst = queue.Queue.Peek().Equals(leaver);

            queue.Queue = new Queue <string>(queue.Queue.Where(x => x != leaver));
            await _queueDatabase.UpdateQueue(queue);

            var responseWebHook = new SlackResponseDto()
            {
                ResponseType   = BasicResponseTypes.in_channel,
                DeleteOriginal = true,
                Blocks         = _blockCreationService.CurrentQueue(queue).Result.Blocks
            };

            await _hookService.TriggerWebHook(request.response_url, responseWebHook);

            var text = $"@{request.user.name} has left the queue" + "\n";

            if (wasFirst)
            {
                text += queue.Queue.Any() ? $"@{queue.Queue.Peek()} ITS GO TIME" : "Queue is empty";
            }

            var slackMessage = new SlackResponseDto
            {
                Text         = text,
                ResponseType = BasicResponseTypes.in_channel,
            };
            await _hookService.TriggerWebHook(request.response_url, slackMessage);
        }