public override async Task <UpdateHandlingResult> HandleCommand(Update update) { var teacher = teachers.GetTeachersNames() .FirstOrDefault(x => x == update.CallbackQuery.Data); if (teacher != null) { teacherSelector.TeacherName = teacher; var teacherSchedule = await scheduleService.CompileScheduleWithSelector(teacherSelector); if (teacherSchedule.ScheduleRoot.Level == ScheduleElemLevel.Week) { await Bot.Client.SendTextMessageAsync( update.CallbackQuery.Message.Chat.Id, teacher); await Bot.Client.AnswerCallbackQueryAsync(update.CallbackQuery.Id, teacher); foreach (var daySchedule in teacherSchedule.ScheduleRoot.Elems.Cast <Day>()) { await SendDay(daySchedule); await Task.Delay(200); } } else if (teacherSchedule.ScheduleRoot.Level == ScheduleElemLevel.Day) { await Bot.Client.SendTextMessageAsync( update.CallbackQuery.Message.Chat.Id, teacher); await Bot.Client.AnswerCallbackQueryAsync(update.CallbackQuery.Id, teacher); await SendDay((Day)teacherSchedule.ScheduleRoot); } else { await Bot.Client.SendTextMessageAsync( update.CallbackQuery.Message.Chat.Id, "Пар нет", replyMarkup : keyboards.GetMainOptionsKeyboard()); } } else { await Bot.Client.SendTextMessageAsync( update.CallbackQuery.Message.Chat.Id, "Нет такого преподавателя.", replyMarkup : keyboards.GetMainOptionsKeyboard()); } return(UpdateHandlingResult.Handled); async Task SendDay(Day day) { var answer = CustomSerializator.ProcessSchedule(day.Elems.OfType <Lesson>(), day.DayOfWeek); await Bot.Client.SendTextMessageAsync( update.CallbackQuery.Message.Chat.Id, answer, ParseMode.Html, replyMarkup : keyboards.GetMainOptionsKeyboard()); } }
public async Task SendNotificationsForIdsAsync(IEnumerable <long> ids, string message) { logger?.LogInformation("Notification about changed sch send:" + message); if (Bot != null) { var list = ids.ToList(); await Task.Run(async() => { foreach (var id in list) { try { await Bot.Client.SendTextMessageAsync(id, $"⚠️ В твоем расписании есть обновления! <b>{message}</b>.", replyMarkup: keyboards.GetMainOptionsKeyboard(), parseMode: ParseMode.Html); await Task.Delay(1000); } catch (Exception e) { logger?.LogWarning(e, "Failed sent to {0}, may be we're blocked?", id); } } }); } else { logger?.LogError("Bot not found"); } }
public override async Task <UpdateHandlingResult> HandleCommand(Update update, DefaultCommandArgs args) { string groupName; try { groupName = args.RawInput.Trim(); } catch (Exception e) { await Bot.Client.SendTextMessageAsync( update.Message.Chat.Id, "Нет такой группы :("); return(UpdateHandlingResult.Handled); } if (Scheduler.GroupsMonitor.TryFindGroupByName(groupName, out IScheduleGroup group) && await Storage.TryAddGroupToChatAsync(group, update.Message.Chat)) { await Bot.Client.SendTextMessageAsync( update.Message.Chat.Id, "Установлено!", replyMarkup : Keyboards.GetMainOptionsKeyboard()); } else { await Bot.Client.SendTextMessageAsync( update.Message.Chat.Id, "Нет такой группы :("); } return(UpdateHandlingResult.Handled); }
public override async Task <UpdateHandlingResult> HandleCommand(Update update, DefaultCommandArgs args) { await Bot.Client.SendTextMessageAsync( update.Message.Chat.Id, "Главное меню", replyMarkup : keyboards.GetMainOptionsKeyboard()); return(UpdateHandlingResult.Handled); }
public override async Task <UpdateHandlingResult> HandleCommand(Update update, DefaultCommandArgs args) { IScheduleGroup userAcademicGroup; IScheduleGroup groupToSet; if (Cache.TryGetValue(update.Id, out ValueTuple <IScheduleGroup, IScheduleGroup> cached)) { userAcademicGroup = cached.Item1 ?? await GetAcademicAsync(update); groupToSet = cached.Item2 ?? GetFirstMatchAllowed(userAcademicGroup, update); Cache.Remove(update.Id); } else { userAcademicGroup = await GetAcademicAsync(update); groupToSet = GetFirstMatchAllowed(userAcademicGroup, update); } if (userAcademicGroup != null && groupToSet != null) { if (await Storage.TryAddGroupToChatAsync(groupToSet, update.Message.Chat)) { await Bot.Client.SendTextMessageAsync( update.Message.Chat.Id, "Установлено!", replyMarkup : Keyboards.GetMainOptionsKeyboard()); } else { await Bot.Client.SendTextMessageAsync( update.Message.Chat.Id, "Не удалось установить группу :("); } } else { logger?.LogError( "Bad situation: allowed group not found but it can handle this command: {0}, {1}", GroupType, JsonConvert.SerializeObject(update)); await Bot.Client.SendTextMessageAsync( update.Message.Chat.Id, "Сначала надо установить группу ☝️. Выбери курс.", replyMarkup : Keyboards.GetCoursesKeyboad()); } return(UpdateHandlingResult.Handled); }
public ReplyKeyboardMarkup GetMainOptionsKeyboard() { return(keyboards.GetMainOptionsKeyboard()); }
public override async Task <UpdateHandlingResult> HandleCommand(Update update, DefaultCommandArgs args) { var diffDaysCount = (DateTime.UtcNow.Date - firstEvenWeekStart).Days; diffDaysCount -= GetCurrentIndexOfDayOfWeekForEuropeanMan(); var weeksSpent = diffDaysCount / 7; bool isEven = weeksSpent % 2 == 0; await Bot.Client.SendTextMessageAsync( update.Message.Chat.Id, isEven?$"Это {weeksSpent + 2}-я неделя - четная." : $"Это {weeksSpent + 2}-я неделя - нечетная.", replyMarkup : keyboards.GetMainOptionsKeyboard()); return(UpdateHandlingResult.Handled); int GetCurrentIndexOfDayOfWeekForEuropeanMan() { var utc = DateTime.UtcNow; if (utc.DayOfWeek == DayOfWeek.Sunday) { return(6); } return((int)(utc.DayOfWeek - 1)); } }