Ejemplo n.º 1
0
        public override async Task Handle(ChatContext context, string message, Providers.Telegram telegram)
        {
            string group = context.Group;

            if (group == null)
            {
                await telegram.SendTextMessageAsync(context.GetChat(), "Сначала нужно настроить ваши данные. Используйте /setup.");

                context.CurrentState = new CommandState();
                return;
            }

            var keyboard = new InlineKeyboardMarkup(new InlineKeyboardButton[][]
            {
                new[]
                {
                    InlineKeyboardButton.WithCallbackData("Сегодня", "Today"),
                    InlineKeyboardButton.WithCallbackData("Завтра", "Tomorrow")
                },
                new[]
                {
                    InlineKeyboardButton.WithCallbackData(DateTime.Now.AddDays(2).ToString("dd.MM"), "Date " + DateTime.Now.AddDays(2).ToString("dd.MM")),
                    InlineKeyboardButton.WithCallbackData(DateTime.Now.AddDays(3).ToString("dd.MM"), "Date " + DateTime.Now.AddDays(3).ToString("dd.MM")),
                    InlineKeyboardButton.WithCallbackData(DateTime.Now.AddDays(4).ToString("dd.MM"), "Date " + DateTime.Now.AddDays(4).ToString("dd.MM"))
                }
            });

            await telegram.SendTextMessageAsync(context.GetChat(), "Выберите день:", keyboard);

            context.CurrentState = new CommandState();
        }
Ejemplo n.º 2
0
        public override async Task Handle(ChatContext context, string message, Providers.Telegram telegram)
        {
            if (message.Contains("/subscribe"))
            {
                await telegram.SendTextMessageAsync(context.GetChat(), "Введите время получения ежедневных уведомлений. \n Рекомендуемый формат времени 'hh:mm'");
            }
            else if (message.Contains("/quit"))
            {
                context.CurrentState = new CommandState();
            }
            else if (TimeSpan.TryParse(message, out TimeSpan time))
            {
                var interval         = TimeSpan.FromDays(1);
                var lastNotification = time >= DateTime.Now.TimeOfDay ?  DateTime.Today + time - interval : DateTime.Today + time;

                var subscription = new Subscription()
                {
                    ChatContext          = context,
                    NotificationTime     = time,
                    LastNotificationTime = lastNotification,
                    NotificationInterval = interval
                };
                context.Subscriptions.Add(subscription);

                await telegram.SendTextMessageAsync(context.GetChat(),
                                                    $"Отлично. Теперь вы будете получать расписание в {time}.");

                context.CurrentState = new CommandState();
            }
            else
            {
                await telegram.SendTextMessageAsync(context.GetChat(), "Введите время для уведомлений или /quit для выхода из режима настройки.");
            }
        }
Ejemplo n.º 3
0
        public override async Task Handle(ChatContext context, string message, Providers.Telegram telegram)
        {
            if (message.Contains("/schedule"))
            {
                context.CurrentState = new ScheduleState();

                await context.CurrentState.Handle(context, message, telegram);
            }
            else if (message.Contains("/subscribe"))
            {
                context.CurrentState = new SubscribeState();

                await context.CurrentState.Handle(context, message, telegram);
            }
            else if (message.Contains("/setup"))
            {
                context.CurrentState = new SetupState();

                await context.CurrentState.Handle(context, message, telegram);
            }
        }
Ejemplo n.º 4
0
        public override async Task Handle(ChatContext context, string message, Providers.Telegram telegram)
        {
            var groupRegex = new Regex("[0-9]{4}");
            var match      = groupRegex.Match(message);

            if (match.Success)
            {
                string group = match.Value;
                context.Group = group;

                await telegram.SendTextMessageAsync(context.GetChat(), "Хорошо. Теперь можно смотреть расписание.");

                context.CurrentState = new CommandState();
            }
            else if (message.Contains("/quit"))
            {
                context.CurrentState = new CommandState();
            }
            else
            {
                await telegram.SendTextMessageAsync(context.GetChat(), "Введите номер группы или /quit для выхода из режима настройки.");
            }
        }
Ejemplo n.º 5
0
 public abstract Task Handle(ChatContext context, string message, Providers.Telegram telegram);