Beispiel #1
0
        public override async Task <UpdateHandlingResult> HandleCommand(Update update, DefaultCommandArgs args)
        {
            var userAcademicGroup =
                (await storage.GetGroupsForChatAsync(update.Message.Chat)).FirstOrDefault(g =>
                                                                                          g.GType == ScheduleGroupType.Academic);

            if (userAcademicGroup != null)
            {
                var engGroups = scheduler.GroupsMonitor.GetAllowedGroups(ScheduleGroupType.Eng, userAcademicGroup)?.ToList() ?? new List <IScheduleGroup>();
                if (engGroups.Any())
                {
                    await Bot.Client.SendTextMessageAsync(
                        update.Message.Chat.Id,
                        "Выбери свою группу по английскому.",
                        replyMarkup : keyboards.GetKeyboardForCollection(engGroups,
                                                                         g => g.Name));
                }
                else
                {
                    await Bot.Client.SendTextMessageAsync(
                        update.Message.Chat.Id,
                        "У тебя не нашлось групп по английскому, прости.",
                        replyMarkup : keyboards.GetSettingsKeyboard());
                }
            }
            else
            {
                await Bot.Client.SendTextMessageAsync(
                    update.Message.Chat.Id,
                    "Сначала надо установить группу ☝️. Выбери курс.", replyMarkup : keyboards.GetCoursesKeyboad());
            }


            return(UpdateHandlingResult.Handled);
        }
        public override async Task <UpdateHandlingResult> HandleCommand(Update update, DefaultCommandArgs args)
        {
            var userGroups = await Storage.GetGroupsForChatAsync(update.Message.Chat);

            if (userGroups != null)
            {
                var weekSchedule = await Scheduler.GetScheduleForAsync(userGroups, ScheduleRequiredFor.Week);

                foreach (var daySchedule in weekSchedule.ScheduleRoot.Elems.Cast <Day>())
                {
                    var answer =
                        CustomSerializator.ProcessSchedule(daySchedule.Elems.Cast <Lesson>(), daySchedule.DayOfWeek);
                    await Bot.Client.SendTextMessageAsync(
                        update.Message.Chat.Id,
                        answer, ParseMode.Html);

                    Thread.Sleep(200);
                }
            }
            else
            {
                await Bot.Client.SendTextMessageAsync(
                    update.Message.Chat.Id,
                    "А группа?");
            }

            return(UpdateHandlingResult.Handled);
        }
        protected async Task <UpdateHandlingResult> HandleCommandForPeriod(Update update, DefaultCommandArgs args,
                                                                           ScheduleRequiredFor period)
        {
            if (DateTime.Today.DayOfWeek == DayOfWeek.Sunday && period == ScheduleRequiredFor.Today ||
                DateTime.Today.DayOfWeek == DayOfWeek.Saturday && period == ScheduleRequiredFor.Tomorrow)
            {
                await Bot.Client.SendTextMessageAsync(update.Message.Chat.Id, "Выходной день 😃");

                return(UpdateHandlingResult.Handled);
            }

            var userGroups = await Storage.GetGroupsForChatAsync(update.Message.Chat);

            if (userGroups != null)
            {
                var schedule = await Scheduler.GetScheduleForAsync(userGroups, period);

                if (schedule.ScheduleRoot.Level == ScheduleElemLevel.Undefined)
                {
                    await Bot.Client.SendTextMessageAsync(update.Message.Chat.Id, "Пар нет 😃");

                    return(UpdateHandlingResult.Handled);
                }

                var answer =
                    CustomSerializator.ProcessSchedule(schedule.ScheduleRoot.Elems.Cast <Lesson>(),
                                                       ((Day)schedule.ScheduleRoot).DayOfWeek);

                await Bot.Client.SendTextMessageAsync(
                    update.Message.Chat.Id,
                    answer, ParseMode.Html);
            }
            else
            {
                await Bot.Client.SendTextMessageAsync(
                    update.Message.Chat.Id,
                    "А группа?");
            }


            return(UpdateHandlingResult.Handled);
        }
Beispiel #4
0
        public override async Task <UpdateHandlingResult> HandleCommand(Update update, DefaultCommandArgs args)
        {
            var userAcademicGroup =
                (await Storage.GetGroupsForChatAsync(update.Message.Chat)).FirstOrDefault(g =>
                                                                                          g.GType == ScheduleGroupType.Academic);

            if (userAcademicGroup != null)
            {
                var allowedGroups =
                    Scheduler.GroupsMonitor.GetAllowedGroups(GroupType, userAcademicGroup)?.ToList() ??
                    new List <IScheduleGroup>();
                if (allowedGroups.Any())
                {
                    await Bot.Client.SendTextMessageAsync(
                        update.Message.Chat.Id,
                        ResponseText,
                        replyMarkup : Keyboards.GetKeyboardForCollection(allowedGroups,
                                                                         g => g.Name));
                }
                else
                {
                    await Bot.Client.SendTextMessageAsync(
                        update.Message.Chat.Id,
                        NotFoundResponseText,
                        replyMarkup : Keyboards.GetSettingsKeyboard());
                }
            }
            else
            {
                await Bot.Client.SendTextMessageAsync(
                    update.Message.Chat.Id,
                    "Сначала надо установить группу ☝️. Выбери курс.", replyMarkup : Keyboards.GetCoursesKeyboad());
            }


            return(UpdateHandlingResult.Handled);
        }
Beispiel #5
0
 protected async Task <IScheduleGroup> GetAcademicAsync(Update update)
 {
     return((await Storage.GetGroupsForChatAsync(update.Message.Chat)).FirstOrDefault(g =>
                                                                                      g.GType == ScheduleGroupType.Academic));
 }