예제 #1
0
        public bool Match(AliceRequest request, Matching matching, FillingData fillingData, ConcurrentDictionary <string, SuperHeroDaySession> concurrentDictionary)
        {
            var heroContext = fillingData.FillingHeroContext();

            var prepositional = heroContext.Select(x => x.Prepositional).ToArray();

            var otherCases = heroContext.Select(x => x.OtherCases).ToArray();

            foreach (var i in heroContext)
            {
                if (matching.ContainOneOf(request.Request.Command, i.Prepositional))
                {
                    SuperHeroDaySession tempHero = concurrentDictionary[request.Session.SessionId];
                    tempHero.Hero = i.Id;
                    concurrentDictionary.TryUpdate(request.Session.SessionId, tempHero, concurrentDictionary[request.Session.SessionId]);
                    return(true);
                }
            }
            foreach (var i in heroContext)
            {
                if (matching.ContainOneOf(request.Request.Command, i.OtherCases))
                {
                    SuperHeroDaySession tempHero = concurrentDictionary[request.Session.SessionId];
                    tempHero.Hero = i.Id;
                    concurrentDictionary.TryUpdate(request.Session.SessionId, tempHero, concurrentDictionary[request.Session.SessionId]);
                    return(true);
                }
            }
            SuperHeroDaySession isNullHero = concurrentDictionary[request.Session.SessionId];

            return(isNullHero.Hero != 0);
        }
예제 #2
0
        public bool Match(AliceRequest request, Matching matching, FillingData fillingData, ConcurrentDictionary <string, SuperHeroDaySession> concurrentDictionary)
        {
            var dialogueContext = fillingData.FillingDialogueContext();

            foreach (var i in dialogueContext)
            {
                if (matching.ContainOneOf(request.Request.Command, i.WordsIsContext))
                {
                    SuperHeroDaySession temp = concurrentDictionary[request.Session.SessionId];
                    temp.Context = i.Title;
                    concurrentDictionary.TryUpdate(request.Session.SessionId, temp, concurrentDictionary[request.Session.SessionId]);
                    return(true);
                }
            }
            return(false);
        }
예제 #3
0
        public AliceResponse Proc(AliceRequest request, ConcurrentDictionary <string, SuperHeroDaySession> concurrentDictionary)
        {
            SuperHeroDaySession temp = concurrentDictionary[request.Session.SessionId];

            return(request.Reply("Уточни супергероя"));
        }
예제 #4
0
        public AliceResponse Proc(AliceRequest request, ConcurrentDictionary <string, SuperHeroDaySession> concurrentDictionary, FillingData fillingData, Random random)
        {
            SuperHeroDaySession heroAndDialog = concurrentDictionary[request.Session.SessionId];

            switch (heroAndDialog.Context)
            {
            case EnumDialogueContext.History:
                var history = fillingData.FillingHero().Where(x => x.Id == heroAndDialog.Hero).Select(x => x.History).FirstOrDefault();
                return(request.Reply($"{history}"));

            case EnumDialogueContext.Facts:
                Facts facts = fillingData.FillingHero().Where(x => x.Id == heroAndDialog.Hero).Select(y => y.Facts[random.Next(1, y.Facts.Count)]).FirstOrDefault();
                if (request.HasScreen())
                {
                    return(request.Reply($"{facts.Fact}"));
                    // todo: add buttom "ещё"
                }
                else
                {
                    return(request.Reply($"{facts.Fact}"));
                }

            case EnumDialogueContext.DebutComicBook:
                if (request.HasScreen())
                {
                    var          superHero    = fillingData.FillingHero().Where(x => x.Id == heroAndDialog.Hero).Select(x => x).FirstOrDefault();
                    ResponseCard responseCard = new ResponseCardItemsList()
                    {
                        Header = new ResponseItemsListHeader {
                            Text = superHero.HeroicName
                        },
                        Items = new ResponseItemsListImage[] { new ResponseItemsListImage {
                                                                   Title = $"Дебютировал {superHero.DebutDate.ToLongDateString()}", Descriptin = superHero.DebutComicBook + superHero.DebutComicBookNumber
                                                               } },
                        // todo: format date
                        Footer = new ResponseCardFooter {
                            Text = "Оценить навык", Button = new ResponseCardButton {
                                Text = "Оценить навык"
                            }
                        }
                    };
                    return(request.Reply(responseCard));
                }
                else
                {
                    var comicBook = fillingData.FillingHero().Where(x => x.Id == heroAndDialog.Hero).Select(y => new { y.DebutComicBook, y.DebutComicBookNumber, y.DebutDate }).FirstOrDefault();
                    return(request.Reply($"{comicBook.DebutComicBook}{comicBook.DebutComicBookNumber} {comicBook.DebutDate.Month} {comicBook.DebutDate.Year}"));
                }

            case EnumDialogueContext.Universe:
                if (request.HasScreen())
                {
                    var          superHero    = fillingData.FillingHero().Where(x => x.Id == heroAndDialog.Hero).Select(x => x).FirstOrDefault();
                    ResponseCard responseCard = new ResponseCardItemsList()
                    {
                        Header = new ResponseItemsListHeader {
                            Text = superHero.HeroicName
                        },
                        Items = new ResponseItemsListImage[] { new ResponseItemsListImage {
                                                                   Title = superHero.Universe, Descriptin = "Вселенная"
                                                               } },
                        Footer = new ResponseCardFooter {
                            Text = "Оценить навык", Button = new ResponseCardButton {
                                Text = "Оценить навык"
                            }
                        }
                    };
                    return(request.Reply(responseCard));
                }
                else
                {
                    var universe = fillingData.FillingHero().Where(x => x.Id == heroAndDialog.Hero).Select(x => x.Universe).FirstOrDefault();
                    return(request.Reply($"{universe}"));
                }

            case EnumDialogueContext.Nickname:
                if (request.HasScreen())
                {
                    var          superHero    = fillingData.FillingHero().Where(x => x.Id == heroAndDialog.Hero).Select(x => x).FirstOrDefault();
                    ResponseCard responseCard = new ResponseCardItemsList()
                    {
                        Header = new ResponseItemsListHeader {
                            Text = superHero.RealName
                        },
                        Items = new ResponseItemsListImage[] { new ResponseItemsListImage {
                                                                   Title = superHero.HeroicName, Descriptin = "Супергеройское имя"
                                                               } },
                        Footer = new ResponseCardFooter {
                            Text = "Оценить навык", Button = new ResponseCardButton {
                                Text = "Оценить навык"
                            }
                        }
                    };
                    return(request.Reply(responseCard));
                }
                else
                {
                    var nickname = fillingData.FillingHero().Where(x => x.Id == heroAndDialog.Hero).Select(x => x.HeroicName).FirstOrDefault();
                    return(request.Reply($"{nickname}"));
                }

            case EnumDialogueContext.RealName:
                if (request.HasScreen())
                {
                    var          superHero    = fillingData.FillingHero().Where(x => x.Id == heroAndDialog.Hero).Select(x => x).FirstOrDefault();
                    ResponseCard responseCard = new ResponseCardItemsList()
                    {
                        Header = new ResponseItemsListHeader {
                            Text = superHero.HeroicName
                        },
                        Items = new ResponseItemsListImage[] { new ResponseItemsListImage {
                                                                   Title = superHero.RealName, Descriptin = "Настоящее имя"
                                                               } },
                        Footer = new ResponseCardFooter {
                            Text = "Оценить навык", Button = new ResponseCardButton {
                                Text = "Оценить навык"
                            }
                        }
                    };
                    return(request.Reply(responseCard));
                }
                else
                {
                    var realName = fillingData.FillingHero().Where(x => x.Id == heroAndDialog.Hero).Select(x => x.RealName).FirstOrDefault();
                    return(request.Reply($"{realName}"));
                }

            case EnumDialogueContext.Horoscop:
                //if (request.HasScreen()) {
                //    Facts horoscop = fillingData.FillingHero().Where(x => x.Id == heroAndDialog.Hero).Select(y => y.Facts.Where(z => z.IsHoroscope == true).ElementAt(random.Next(0, y.Facts.Count()))).FirstOrDefault();
                //    ResponseCard responseCard = new ResponseCardItemsList()
                //    {
                //        Header = new ResponseItemsListHeader { Text = "Гороскоп" },
                //        Items = new ResponseItemsListImage[] { new ResponseItemsListImage { Title = DateTime.Now.ToLongDateString(), Descriptin = horoscop.Fact } },
                //        Footer = new ResponseCardFooter { Text = "Оценить навык", Button = new ResponseCardButton { Text = "Оценить навык" } }
                //    };
                //    return request.Reply(responseCard);
                //} else {
                Facts horoscop = fillingData.FillingHero().Where(x => x.Id == heroAndDialog.Hero).Select(y => y.Facts.Where(z => z.IsHoroscope == true).ElementAt(random.Next(0, y.Facts.Count()))).FirstOrDefault();
                return(request.Reply($"{horoscop.Fact}"));

            //}
            case EnumDialogueContext.All:
                if (request.HasScreen())
                {
                    var          defaultSuperHero = fillingData.FillingHero().Where(x => x.Id == heroAndDialog.Hero).Select(x => x).FirstOrDefault();
                    ResponseCard responseCard     = new ResponseCardItemsList()
                    {
                        Header = new ResponseItemsListHeader {
                            Text = defaultSuperHero.HeroicName
                        },
                        Items = new ResponseItemsListImage[] { new ResponseItemsListImage {
                                                                   ImageId = defaultSuperHero.ImageSuperHero, Title = defaultSuperHero.Universe, Descriptin = defaultSuperHero.RealName
                                                               },
                                                               new ResponseItemsListImage {
                                                                   Title = defaultSuperHero.DebutDate.ToLongDateString(), Descriptin = defaultSuperHero.DebutComicBook + defaultSuperHero.DebutComicBookNumber
                                                               } },
                        Footer = new ResponseCardFooter {
                            Text = "Оценить навык", Button = new ResponseCardButton {
                                Text = "Оценить навык"
                            }
                        }
                    };
                    return(request.Reply(responseCard));
                    // todo: format date && add buttons
                }
                else
                {
                    var defaultSuperHero = fillingData.FillingHero().Where(x => x.Id == heroAndDialog.Hero).Select(x => x).FirstOrDefault();
                    return(request.Reply($"{defaultSuperHero.HeroicName} из вселенной {defaultSuperHero.Universe} дебютировал {defaultSuperHero.DebutDate.ToLongDateString()} в {defaultSuperHero.DebutComicBook}{defaultSuperHero.DebutComicBookNumber}"));
                }

            default:
                if (request.HasScreen())
                {
                    var          defaultSuperHero = fillingData.FillingHero().Where(x => x.Id == heroAndDialog.Hero).Select(x => x).FirstOrDefault();
                    ResponseCard responseCard     = new ResponseCardItemsList()
                    {
                        Header = new ResponseItemsListHeader {
                            Text = defaultSuperHero.HeroicName
                        },
                        Items = new ResponseItemsListImage[] { new ResponseItemsListImage {
                                                                   ImageId = defaultSuperHero.ImageSuperHero, Title = defaultSuperHero.Universe, Descriptin = defaultSuperHero.RealName
                                                               },
                                                               new ResponseItemsListImage {
                                                                   Title = defaultSuperHero.DebutDate.ToLongDateString(), Descriptin = defaultSuperHero.DebutComicBook + defaultSuperHero.DebutComicBookNumber
                                                               } },
                        Footer = new ResponseCardFooter {
                            Text = "Оценить навык", Button = new ResponseCardButton {
                                Text = "Оценить навык"
                            }
                        }
                    };
                    return(request.Reply(responseCard));
                    // todo: format date && add buttons
                }
                else
                {
                    var defaultHistory = fillingData.FillingHero().Where(x => x.Id == heroAndDialog.Hero).Select(x => x.History).FirstOrDefault();
                    return(request.Reply(defaultHistory));
                }
            }
        }