コード例 #1
0
#pragma warning disable 1998
        private async Task AddNewInvitationsToPlan(PizzaPlan pizzaPlan)
#pragma warning restore 1998
        {
            var totalInvited = pizzaPlan.Accepted.Count + pizzaPlan.Invited.Count;

            if (totalInvited < _config.InvitesPerEvent)
            {
                var ignoreUsers = pizzaPlan.Rejected.ToList();
                ignoreUsers.AddRange(pizzaPlan.Accepted);
                var newInvites = await FindPeopleToInvite(_config.PizzaRoom.Room, _config.InvitesPerEvent - totalInvited, ignoreUsers);

                if (!newInvites.Any())
                {
                    _logger.Information("Found no more eligible users to invite to event '{EventId}'.", pizzaPlan.Id);
                }
                else
                {
                    _logger.Debug("Adding {InvitedCount} more guests to event '{PizzaPlanId}'", newInvites.Count, pizzaPlan.Id);
                }

                var inviteList = newInvites.Select(i => new Invitation()
                {
                    EventId   = pizzaPlan.Id,
                    UserId    = i.UserId,
                    UserName  = i.UserName,
                    EventTime = pizzaPlan.TimeOfEvent,
                    Room      = pizzaPlan.Channel,
                    City      = pizzaPlan.City
                }).ToList();

                _pizzaInviter.Invite(inviteList);
                pizzaPlan.Invited.AddRange(newInvites);
                _storage.SaveArray(ACTIVEEVENTSFILE, _activePlans.ToArray());
            }
        }
コード例 #2
0
        private async Task ScheduleNewEvent(DateTime mondayInWeekToScheduleEvent)
        {
            _logger.Debug("Creating new event...");

            var eventId     = WordGenerator.GetRandomWordString(3);
            var timeOfEvent = GetTimeOfNextEvent(mondayInWeekToScheduleEvent);
            var toInvite    = await FindPeopleToInvite(_config.PizzaRoom.Room, _config.InvitesPerEvent, new List <Person>());

            var newPlan = new PizzaPlan()
            {
                Id          = eventId,
                TimeOfEvent = timeOfEvent,
                Invited     = toInvite.ToList(),
                Channel     = _config.PizzaRoom.Room,
                City        = _config.PizzaRoom.City
            };
            var inviteList = toInvite.Select(i => new Invitation()
            {
                EventId   = eventId,
                UserId    = i.UserId,
                UserName  = i.UserName,
                EventTime = timeOfEvent,
                Room      = newPlan.Channel,
                City      = newPlan.City
            }).ToList();

            _pizzaInviter.Invite(inviteList);

            _activityLog.Log($"Created a new Pizza Plan '{newPlan.Id}' for {inviteList.Count} participants.");
            _activePlans.Add(newPlan);
            _storage.SaveArray(ACTIVEEVENTSFILE, _activePlans.ToArray());
        }
コード例 #3
0
#pragma warning disable 1998
        public async Task AddPlanToFinished(PizzaPlan plan)
#pragma warning restore 1998
        {
            var oldPlans = _storage.ReadArray <PizzaPlan>(OLDEVENTSFILE).ToList();

            if (oldPlans.FirstOrDefault(p => p.Id == plan.Id) != null)
            {
                throw new InvalidOperationException($"Trying to add a finished pizza plan to old plans, but that pizza plan Id already exists {plan.Id}");
            }
            oldPlans.Add(plan);
            _storage.SaveArray(OLDEVENTSFILE, oldPlans.ToArray());;
        }
コード例 #4
0
        public async Task SetUp()
        {
            _harness = TestHarness.CreateHarness();
            _harness.Start();

            _harness.Tick();
            _plan   = _harness.ActivePizzaPlans.Single();
            _userId = _plan.Invited.First().UserId;
            await _harness.Inviter.HandleMessage(
                new NewMessage()
            {
                user = _plan.Invited.First().UserId, text = "yes"
            });
        }
コード例 #5
0
        private async Task CancelPizzaPlan(PizzaPlan pizzaPlan)
        {
            var messages = pizzaPlan.CreateNewEventIsCancelledMessage();

            foreach (var message in messages)
            {
                await _core.SendMessage(message);
            }
            _activePlans.Remove(pizzaPlan);
            _storage.SaveArray(ACTIVEEVENTSFILE, _activePlans.ToArray());
            pizzaPlan.Cancelled = _funcNow();
            await AddPlanToFinished(pizzaPlan);

            _activityLog.Log($"Cancelling '{pizzaPlan.Id}' because only {pizzaPlan.Accepted.Count} had accepted");
        }
コード例 #6
0
        private async Task LockParticipants(PizzaPlan pizzaPlan)
        {
            pizzaPlan.ParticipantsLocked = true;

            var stringList = pizzaPlan.Accepted.GetStringListOfPeople();

            _activityLog.Log($"Locking pizza plan '{pizzaPlan.Id}' with  participants ({pizzaPlan.Accepted.Count}) {stringList}");

            var messages = pizzaPlan.CreateParticipantsLockedResponseMessage();

            foreach (var m in messages)
            {
                await _core.SendMessage(m);
            }
            _storage.SaveArray(ACTIVEEVENTSFILE, _activePlans.ToArray());
        }
コード例 #7
0
        public static IEnumerable <MessageToSend> CreateNewEventIsCancelledMessage(this PizzaPlan pizzaPlan)
        {
            var day  = pizzaPlan.TimeOfEvent.LocalDateTime.ToString("dddd, MMMM dd");
            var time = pizzaPlan.TimeOfEvent.LocalDateTime.ToString("HH:mm");

            foreach (var person in pizzaPlan.Accepted)
            {
                var text = $"Hello again @{person.UserName}. \n" +
                           $"Unfortunately due to lack of interest the *pizza dinner on {day} at {time} will have to be cancelled.* \n " +
                           $"I'll make sure to invite you to another dinner at another time.";
                yield return(new MessageToSend()
                {
                    UserId = person.UserId,
                    Text = text
                });
            }
        }
コード例 #8
0
        public static IEnumerable <MessageToSend> CreateRemindParticipantsOfEvent(this PizzaPlan pizzaPlan)
        {
            var day             = pizzaPlan.TimeOfEvent.LocalDateTime.ToString("dddd, MMMM dd");
            var time            = pizzaPlan.TimeOfEvent.LocalDateTime.ToString("HH:mm");
            var participantlist = pizzaPlan.Accepted.GetListOfFormattedUserId();

            foreach (var person in pizzaPlan.Accepted)
            {
                var text = $"Hello again @{person.UserName}. \n" +
                           $"I'm sending you this message to remind you that you have an upcoming *pizza dinner on {day} at {time}* together with {participantlist} \n ";

                yield return(new MessageToSend()
                {
                    UserId = person.UserId,
                    Text = text
                });
            }
        }
コード例 #9
0
        public async Task SetUp()
        {
            _harness = TestHarness.CreateHarness();
            _harness.Start();

            _harness.Tick();
            _plan = _harness.ActivePizzaPlans.Single();
            _userIdOfGustRejecting = _plan.Invited.First().UserId;
            _firstInvitedUsers     = _plan.Invited.Select(u => u.UserId).ToList();
            await _harness.Inviter.HandleMessage(
                new NewMessage()
            {
                user = _userIdOfGustRejecting, text = "no"
            });

            _harness.Core.Invocations.Clear();
            _harness.Tick();
        }
コード例 #10
0
        public static MessageToSend CreateNewDesignateToHandleExpensesMessage(this PizzaPlan pizzaPlan, string botRoom)
        {
            var day             = pizzaPlan.TimeOfEvent.LocalDateTime.ToString("dddd, MMMM dd");
            var time            = pizzaPlan.TimeOfEvent.LocalDateTime.ToString("HH:mm");
            var participantlist = pizzaPlan.Accepted.GetListOfFormattedUserId();

            var text = $"Hello again, @{pizzaPlan.PersonDesignatedToHandleExpenses.UserName} \n" +
                       $"I need someone to help me handle the expenses for the upcoming pizza dinner planned on *{day} at {time}*.\n" +
                       $"I have chosen you for this honor. What you have to do is pay the bill for the dinner and file for the expenses. Someone else will chose a venue and make a reservation, all you have to do is show up and be ready to pay. \n" +
                       $"If you have any questions please ask someone else in your group or head over to #{botRoom} .\n" +
                       $"The participants are {participantlist} \n" +
                       $"Thank you!";

            return(new MessageToSend()
            {
                UserId = pizzaPlan.PersonDesignatedToHandleExpenses.UserId,
                Text = text
            });
        }
コード例 #11
0
        public static MessageToSend CreateNewDesignateToMakeReservationMessage(this PizzaPlan pizzaPlan, string botRoom)
        {
            var day             = pizzaPlan.TimeOfEvent.LocalDateTime.ToString("dddd, MMMM dd");
            var time            = pizzaPlan.TimeOfEvent.LocalDateTime.ToString("HH:mm");
            var participantlist = pizzaPlan.Accepted.GetListOfFormattedUserId();

            var text = $"Hello again, @{pizzaPlan.PersonDesignatedToMakeReservation.UserName} \n" +
                       $"I need someone to help me make a reservation at a suitable location for the upcoming pizza dinner planned on *{day} at {time}*.\n" +
                       $"I have chosen you for this honor and wish you the best of luck to find a suitable location and make the necessary arrangements. If you need help finding a venue or have any questions please head over to #{botRoom}. \n" +
                       $"Someone else has been chosen to pay for the event and expense it, all you have to do is to make a reservation. \n" +
                       $"Also remember to inform or invite the other participants once you have made the reservation. The other participants are {participantlist} \n" +
                       $"Thank you!";

            return(new MessageToSend()
            {
                UserId = pizzaPlan.PersonDesignatedToMakeReservation.UserId,
                Text = text
            });
        }
        public async Task SetUp()
        {
            _harness = TestHarness.CreateHarness();
            _harness.Start();

            _harness.Tick();
            _plan = _harness.ActivePizzaPlans.Single();
            foreach (var person in _plan.Invited.ToList())
            {
                await _harness.Inviter.HandleMessage(new SlackAPI.WebSocketMessages.NewMessage()
                {
                    user = person.UserId, text = "yes"
                });
            }
            _harness.Core.Invocations.Clear();

            _harness.Tick();

            _harness.Logger.Verify(l => l.Fatal(It.IsAny <Exception>(), It.IsAny <string>()), Times.Never);
        }
コード例 #13
0
        public static MessageToSend CreatePizzaRoomAnnouncementMessage(this PizzaPlan pizzaPlan, string botRoom)
        {
            var day             = pizzaPlan.TimeOfEvent.LocalDateTime.ToString("dddd, MMMM dd");
            var time            = pizzaPlan.TimeOfEvent.LocalDateTime.ToString("HH:mm");
            var participantlist = pizzaPlan.Accepted.GetListOfFormattedUserId();

            var text = $"On *{day} at {time}*, {participantlist} will get together and eat some tasty pizza.\n" +
                       $"{pizzaPlan.PersonDesignatedToMakeReservation.GetFormattedUserId()} will make a reservation for the group.\n" +
                       $"{pizzaPlan.PersonDesignatedToHandleExpenses.GetFormattedUserId()} will expense the meal afterwards.\n" +
                       $"All the rest of you have to do is show up and have a great time and get to know each other better.\n" +
                       $"Maybe once you are done you can upload an image of you all enjoying yourselves?" +
                       $"" +
                       $"I want to remind you all to be mindful of local recommendations during these times and please stay at home if you are showing any symptoms.";

            var message = new MessageToSend()
            {
                ChannelName = botRoom,
                Text        = text
            };


            return(message);
        }
コード例 #14
0
        public async Task SetUp()
        {
            _harness = TestHarness.CreateHarness();
            _harness.Start();

            _harness.Tick();
            _plan = _harness.ActivePizzaPlans.Single();
            foreach (var person in _plan.Invited.Take(4).ToList())
            {
                await _harness.Inviter.HandleMessage(new NewMessage()
                {
                    user = person.UserId, text = "yes"
                });
            }
            _harness.Tick();
            Assert.IsNull(_plan.Cancelled);
            _harness.Core.Invocations.Clear();

            _harness.Now = _harness.Now.AddDays(8);
            _harness.Tick();

            _harness.Logger.Verify(l => l.Fatal(It.IsAny <Exception>(), It.IsAny <string>()), Times.Never);
        }
コード例 #15
0
        public static IEnumerable <MessageToSend> CreateParticipantsLockedResponseMessage(this PizzaPlan pizzaPlan)
        {
            foreach (var person in pizzaPlan.Accepted)
            {
                var day             = pizzaPlan.TimeOfEvent.LocalDateTime.ToString("dddd, MMMM dd");
                var time            = pizzaPlan.TimeOfEvent.LocalDateTime.ToString("HH:mm");
                var participantlist = pizzaPlan.Accepted.GetListOfFormattedUserId();

                var text = $"*Great news!* \n" +
                           $"This amazing group of people has accepted the invitation for pizza on *{day} at {time}* \n" +
                           $"{participantlist} \n" +
                           $"If you don't know them all yet, now is an excellent opportunity. Please be mindful of local recommendations, stay safe and have a fantastic time!";

                var message = new MessageToSend()
                {
                    UserId = person.UserId,
                    Text   = text,
                };
                yield return(message);
            }
        }