コード例 #1
0
        private static async void BotOnCallbackQueryReceived(object sender, CallbackQueryEventArgs callbackQueryEventArgs)
        {
            var callbackQuery = callbackQueryEventArgs.CallbackQuery;

            await Bot.AnswerCallbackQueryAsync(
                callbackQuery.Id,
                $"Selected {callbackQuery.Data}");

            string      username = callbackQuery.From.Username;
            UserSession session;

            if (_userSessions.TryGetValue(username, out session))
            {
                switch (session.Step)
                {
                case Step.ChooseGenre:
                    session.FilterValue = getGenreId(callbackQuery.Data).ToString();
                    displayFilteredMovies(session);
                    break;

                case Step.ChooseFilter:
                    session.Filter = callbackQuery.Data;
                    if (session.Filter == "Genres")
                    {
                        getGenresAsync(session);
                        session.Step = Step.ChooseGenre;
                    }
                    else
                    {
                        session.Step = Step.InputFilterValue;
                    }
                    break;

                case Step.SelectMovie:
                    session.SelectedMovie = callbackQuery.Data;
                    session.Step          = Step.ChooseMovieAction;
                    getMovieActionChoiceAsync(session);
                    break;

                case Step.ChooseMovieAction:
                    switch (callbackQuery.Data)
                    {
                    case "Add to WatchList":
                        _movieController.AddToWatch(username, session.SelectedMovie);
                        break;

                    case "Comment":
                        session.Step = Step.CommentMovie;
                        break;

                    case "Rate":
                        session.Step = Step.RateMovie;
                        break;

                    case "See comments":
                        DisplayComments(_movieController.GetCommentsByMovie(session.SelectedMovie), session, "Comments");
                        session.Step = Step.Default;
                        break;

                    case "See average rate":
                        double        average = _movieController.GetAverageRateByMovie(session.SelectedMovie);
                        List <string> dis     = new List <string>();
                        dis.Add(average.ToString());
                        DisplayComments(dis, session, "Average rate");
                        session.Step = Step.Default;
                        break;
                    }
                    break;

                case Step.ChooseFriend:
                    session.SelectedFriend = callbackQuery.Data;
                    session.Step           = Step.ChooseFriendAction;
                    GetFriendActionChoiceAsync(session);
                    break;

                case Step.ChooseFriendAction:
                    switch (callbackQuery.Data)
                    {
                    case "See watchlist":
                        _movieController.GetFriendTowatchList(session.SelectedFriend);
                        break;
                    }
                    break;
                }
            }
            await Bot.SendTextMessageAsync(
                callbackQuery.Message.Chat.Id,
                $"{callbackQuery.Data}");
        }