예제 #1
0
 public Task <ISchedule> GetScheduleForAsync(IScheduleGroup @group, ScheduleRequiredFor period)
 {
     if (period != ScheduleRequiredFor.Week)
     {
         return(GetScheduleForAsync(new[] { group }, DayOfWeekFromPeriod(period)));
     }
     else
     {
         return(GetWeekScheduleForAsync(new[] { group }));
     }
 }
예제 #2
0
        private DayOfWeek DayOfWeekFromPeriod(ScheduleRequiredFor period)
        {
            switch (period)
            {
            case ScheduleRequiredFor.Today:
                return(DateTime.Now.DayOfWeek);

            case ScheduleRequiredFor.Tomorrow:
                return(DateTime.UtcNow.AddDays(1).ToLocalTime().DayOfWeek);
            }

            throw new ArgumentOutOfRangeException();
        }
예제 #3
0
        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);
        }
예제 #4
0
 public Task <ISchedule> GetScheduleForAsync(IEnumerable <IScheduleGroup> groups, ScheduleRequiredFor period)
 {
     if (period != ScheduleRequiredFor.Week)
     {
         return(GetScheduleForAsync(groups, DayOfWeekFromPeriod(period)));
     }
     else
     {
         return(GetWeekScheduleForAsync(groups));
     }
 }