コード例 #1
0
ファイル: DaysOfWeekCommand.cs プロジェクト: pacmad/Theatrel
        public override async Task <string> ExecuteAsync(IChatDataInfo chatInfo)
        {
            var stringBuilder = new StringBuilder();

            stringBuilder.AppendLine("В какой день недели Вы хотели бы посетить театр? Вы можете выбрать несколько дней.");
            return(stringBuilder.ToString());
        }
コード例 #2
0
        public override Task <ITgOutboundMessage> AscUserAsync(IChatDataInfo chatInfo, CancellationToken cancellationToken)
        {
            var stringBuilder = new StringBuilder();

            stringBuilder.AppendLine("В какой день недели Вы хотели бы посетить театр? Вы можете выбрать несколько дней.");
            return(Task.FromResult <ITgOutboundMessage>(new TgOutboundMessage(stringBuilder.ToString(), CommandKeyboardMarkup)));
        }
コード例 #3
0
        public override async Task <string> ExecuteAsync(IChatDataInfo chatInfo)
        {
            var stringBuilder = new StringBuilder();

            stringBuilder.AppendLine($"Вас интересует {string.Join(" или ", _types)}?");
            return(stringBuilder.ToString());
        }
コード例 #4
0
        public override string ApplyResult(IChatDataInfo chatInfo, string message)
        {
            Trace.TraceInformation($"reset chat {chatInfo}");
            chatInfo.Clear();

            return(null);
        }
コード例 #5
0
ファイル: StartCommand.cs プロジェクト: pacmad/Theatrel
        public override Task <ITgOutboundMessage> ApplyResultAsync(IChatDataInfo chatInfo, string message, CancellationToken cancellationToken)
        {
            Trace.TraceInformation($"Reset chat {chatInfo.ChatId}");
            chatInfo.Clear();

            return(Task.FromResult <ITgOutboundMessage>(new TgOutboundMessage(null)));
        }
コード例 #6
0
        public override Task <ITgOutboundMessage> ApplyResultAsync(IChatDataInfo chatInfo, string message, CancellationToken cancellationToken)
        {
            var days = ParseMessage(message);

            chatInfo.Days = days;

            var culture = CultureInfo.CreateSpecificCulture(chatInfo.Culture);

            if (days.SequenceEqual(WeekDays))
            {
                return(Task.FromResult <ITgOutboundMessage>(
                           new TgOutboundMessage($"{YouSelected} {WeekDaysNames.First()}. {ReturnMsg}", ReturnCommandMessage)));
            }

            if (days.SequenceEqual(Weekends))
            {
                return(Task.FromResult <ITgOutboundMessage>(
                           new TgOutboundMessage($"{YouSelected} {WeekendsNames.First()}. {ReturnMsg}", ReturnCommandMessage)));
            }

            if (days.SequenceEqual(AllDays))
            {
                return(Task.FromResult <ITgOutboundMessage>(
                           new TgOutboundMessage($"{YouSelected} {AllDaysNames.First()}. {ReturnMsg}", ReturnCommandMessage)));
            }

            return(Task.FromResult <ITgOutboundMessage>(
                       new TgOutboundMessage(
                           $"{YouSelected} {string.Join(" или ", chatInfo.Days.Select(d => culture.DateTimeFormat.GetDayName(d)))}. {ReturnMsg}",
                           ReturnCommandMessage)));
        }
コード例 #7
0
        public override Task <ITgOutboundMessage> AscUserAsync(IChatDataInfo chatInfo, CancellationToken cancellationToken)
        {
            var stringBuilder = new StringBuilder();

            stringBuilder.AppendLine("Какие представления Вас интересуют?");

            return(Task.FromResult <ITgOutboundMessage>(new TgOutboundMessage(stringBuilder.ToString(), CommandKeyboardMarkup)));
        }
コード例 #8
0
        public override async Task <string> ExecuteAsync(IChatDataInfo chatInfo)
        {
            IPerformanceFilter filter = _filterhelper.GetFilter(chatInfo);

            IPerformanceData[] data = await _playBillResolver.RequestProcess(chatInfo.When, new DateTime(), filter);

            return(await PerfomancesMessage(data, filter, chatInfo.When));
        }
コード例 #9
0
ファイル: DaysOfWeekCommand.cs プロジェクト: pacmad/Theatrel
        public override string ApplyResult(IChatDataInfo chatInfo, string message)
        {
            var days = ParseMessage(message);

            chatInfo.Days = days;

            var culture = CultureInfo.CreateSpecificCulture(chatInfo.Culture);

            return($"Вы выбрали {string.Join(" или ", chatInfo.Days.Select(d => culture.DateTimeFormat.GetDayName(d)))}. {ReturnMsg}");
        }
コード例 #10
0
        public override async Task <ITgOutboundMessage> AscUserAsync(IChatDataInfo chatInfo, CancellationToken cancellationToken)
        {
            IPerformanceFilter filter = _filterService.GetFilter(chatInfo);

            IPerformanceData[] data = await _playBillResolver.RequestProcess(filter, cancellationToken);

            return(new TgOutboundMessage(await PerformancesMessage(data, filter, chatInfo.When))
            {
                IsEscaped = true
            });
        }
コード例 #11
0
ファイル: MonthCommand.cs プロジェクト: pacmad/Theatrel
        public override string ApplyResult(IChatDataInfo chatInfo, string message)
        {
            int month = GetMonth(message.Trim().ToLower());

            int year = DateTime.Now.Month > month ? DateTime.Now.Year + 1 : DateTime.Now.Year;

            chatInfo.When = new DateTime(year, month, 1);

            var culture = CultureInfo.CreateSpecificCulture(chatInfo.Culture);

            return($"Вы выбрали {culture.DateTimeFormat.GetMonthName(month)} {year}. {ReturnMsg}");
        }
コード例 #12
0
        public override Task <ITgOutboundMessage> ApplyResultAsync(IChatDataInfo chatInfo, string message, CancellationToken cancellationToken)
        {
            int month = GetMonth(message.Trim().ToLower());

            int year = DateTime.Now.Month > month ? DateTime.Now.Year + 1 : DateTime.Now.Year;

            chatInfo.When = new DateTime(year, month, 1);

            var culture = CultureInfo.CreateSpecificCulture(chatInfo.Culture);

            return(Task.FromResult <ITgOutboundMessage>(new TgOutboundMessage(
                                                            $"Вы выбрали {culture.DateTimeFormat.GetMonthName(month)} {year}. {ReturnMsg}", ReturnKeyboardMarkup)));
        }
コード例 #13
0
ファイル: MonthCommand.cs プロジェクト: pacmad/Theatrel
        public override async Task <string> ExecuteAsync(IChatDataInfo chatInfo)
        {
            switch (chatInfo.DialogState)
            {
            case DialogStateEnum.DialogReturned:
                return(Msg);

            case DialogStateEnum.DialogStarted:
                return($"{GoodDay}{IWillHelpYou}{Msg}");

            default:
                throw new NotImplementedException();
            }
        }
コード例 #14
0
        public override Task <ITgOutboundMessage> AscUserAsync(IChatDataInfo chatInfo, CancellationToken cancellationToken)
        {
            switch (chatInfo.DialogState)
            {
            case DialogStateEnum.DialogReturned:
                return(Task.FromResult <ITgOutboundMessage>(new TgOutboundMessage(Msg, CommandKeyboardMarkup)));

            case DialogStateEnum.DialogStarted:
                return(Task.FromResult <ITgOutboundMessage>(new TgOutboundMessage($"{GoodDay}{IWillHelpYou}{Msg}", CommandKeyboardMarkup)));

            default:
                throw new NotImplementedException();
            }
        }
コード例 #15
0
ファイル: TLBotProcessor.cs プロジェクト: pacmad/Theatrel
        private void OnMessage(object sender, ITLMessage tLMessage)
        {
            Trace.TraceInformation($"{tLMessage.ChatId} {tLMessage.Message}");
            string message = tLMessage.Message;
            long   chatId  = tLMessage.ChatId;

            IChatDataInfo chatInfo = GetChatInfo(chatId);

            chatInfo.LastMessage = DateTime.Now;

            //check if user wants to return at first
            var startCmd = _commands.First();

            if (startCmd.IsMessageClear(message))
            {
                chatInfo.Clear();
            }

            if (message.ToLower().StartsWith("нет"))
            {
                if (chatInfo.ChatStep > 0)
                {
                    --chatInfo.ChatStep;
                }

                chatInfo.DialogState = DialogStateEnum.DialogReturned;

                var prevCommand = _commands.FirstOrDefault(cmd => cmd.Label == chatInfo.ChatStep);
                CommandAskQuestion(prevCommand, chatInfo, null);
                return;
            }

            IDialogCommand command = _commands.FirstOrDefault(cmd => cmd.Label == chatInfo.ChatStep);

            if (!command.IsMessageClear(message))
            {
                SendWrongCommandMessage(chatId, message, chatInfo.ChatStep);
                return;
            }

            string acknowledgement = command.ApplyResult(chatInfo, message);

            ++chatInfo.ChatStep;

            var nextCommand = _commands.FirstOrDefault(cmd => cmd.Label == chatInfo.ChatStep);

            CommandAskQuestion(nextCommand, chatInfo, acknowledgement);
        }
コード例 #16
0
ファイル: TLBotProcessor.cs プロジェクト: pacmad/Theatrel
        private void CommandAskQuestion(IDialogCommand cmd, IChatDataInfo chatInfo, string previousCmdAcknowledgement)
        {
            if (cmd == null)
            {
                return;
            }

            string nextDlgQuestion = cmd.ExecuteAsync(chatInfo).GetAwaiter().GetResult();
            string botResponse     = string.IsNullOrWhiteSpace(previousCmdAcknowledgement)
                ? nextDlgQuestion
                : $"{previousCmdAcknowledgement}{Environment.NewLine}{nextDlgQuestion}";

            Task.Run(() => _botService.SendMessageAsync(chatInfo.ChatId, botResponse));

            if (_commands.FirstOrDefault(cmd => cmd.Label == chatInfo.ChatStep + 1) == null)
            {
                chatInfo.ChatStep = (int)DialogStep.Start;
            }
        }
コード例 #17
0
        public IPerformanceFilter GetFilter(IChatDataInfo dataInfo)
        {
            var filter = new PerformanceFilter();

            if (dataInfo.Days != null && dataInfo.Days.Any())
            {
                var days = dataInfo.Days.Distinct();
                if (days.Count() < 7)
                {
                    filter.DaysOfWeek = days.ToArray();
                }
            }

            if (dataInfo.Types != null && dataInfo.Types.Any())
            {
                filter.PerfomanceTypes = dataInfo.Types;
            }

            return(filter);
        }
コード例 #18
0
ファイル: StartCommand.cs プロジェクト: pacmad/Theatrel
 public override Task <ITgOutboundMessage> AscUserAsync(IChatDataInfo chatInfo, CancellationToken cancellationToken)
 => Task.FromResult <ITgOutboundMessage>(new TgOutboundMessage("Вас приветствует экономный театрал."));
コード例 #19
0
        public override Task <ITgOutboundMessage> ApplyResultAsync(IChatDataInfo chatInfo, string message, CancellationToken cancellationToken)
        {
            chatInfo.Types = ParseMessage(message);

            return(Task.FromResult <ITgOutboundMessage>(new TgOutboundMessage(null)));
        }
コード例 #20
0
 public override async Task <string> ExecuteAsync(IChatDataInfo chatInfo) => "Вас привествует экономный театрал.";
コード例 #21
0
 private IDialogCommand GetPreviousCommand(IChatDataInfo chatInfo)
 {
     return(chatInfo.PreviousStepId == -1
         ? null
         : _commands.FirstOrDefault(cmd => cmd.Label == chatInfo.PreviousStepId));
 }
コード例 #22
0
 public abstract Task <ITgOutboundMessage> ApplyResultAsync(IChatDataInfo chatInfo, string message, CancellationToken cancellationToken);
コード例 #23
0
 public abstract Task <ITgOutboundMessage> AscUserAsync(IChatDataInfo chatInfo, CancellationToken cancellationToken);
コード例 #24
0
 private IDialogCommand GetNextCommand(IChatDataInfo chatInfo)
 => _commands.FirstOrDefault(cmd => cmd.Label == chatInfo.CurrentStepId + 1);
コード例 #25
0
 public override Task <ITgOutboundMessage> ApplyResultAsync(IChatDataInfo chatInfo, string message, CancellationToken cancellationToken)
 => Task.FromResult <ITgOutboundMessage>(new TgOutboundMessage(null));
コード例 #26
0
        public override string ApplyResult(IChatDataInfo chatInfo, string message)
        {
            chatInfo.Types = ParseMessage(message);

            return(null);
        }
コード例 #27
0
 public abstract string ApplyResult(IChatDataInfo chatInfo, string message);
コード例 #28
0
 public abstract Task <string> ExecuteAsync(IChatDataInfo chatInfo);
コード例 #29
0
 public override string ApplyResult(IChatDataInfo chatInfo, string message) => null;