Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }