public Task Execute()
        {
            var currentUser   = _currentTelegramUserProvider.GetCurrentTelegramRozkladUser();
            var facultyGroups = currentUser.FacultyGroups;
            var inlineMenu    = _timetableFacultyGroupsRemoveMenu.CreateInlineMenu(facultyGroups);
            var messageText   = _currentUserLocalizationService["select-group-to-remove"];

            return(_telegramBotService.SendOrEditMessageAsync(
                       messageText,
                       replyMarkup: inlineMenu));
        }
        public async Task Execute(ResetCurrentUserOptions options = null)
        {
            var          replyKeyboard = _mainMenuCreator.CreateMenu();
            const string messageText   = "Reset";

            var currentUser = _currentTelegramUserProvider.GetCurrentTelegramRozkladUser();
            await _telegramRozkladUserDao.Delete(currentUser);

            await _telegramBotService.SendOrEditMessageAsync(
                messageText,
                replyMarkup : replyKeyboard,
                forceNewMessage : true);
        }
        public async Task <bool> Handle(Message message)
        {
            var currentUser = _currentTelegramUserProvider.GetCurrentTelegramRozkladUser();

            LongLastingUserActionArguments userLongLastingActionArguments = null;
            ILongLastingUserActionHandler  handler = null;

            try
            {
                bool isHandled = false;

                userLongLastingActionArguments = await _longLastingUserActionManager.GetUserLongLastingAction(currentUser);

                if (userLongLastingActionArguments == null)
                {
                    return(isHandled);
                }

                userLongLastingActionArguments.Parameters[typeof(Message)] = message;
                handler   = _longLastingUserActionHandlerFactory.GetHandler(userLongLastingActionArguments);
                isHandled = await handler.Handle(userLongLastingActionArguments);

                return(isHandled);
            }
            catch (Exception e)
            {
                await _longLastingUserActionManager.ClearUserAction(currentUser);

                var currentUserTelegramId = currentUser.TelegramId;
                var outException          = new LongLastingUserActionHandlerException(currentUserTelegramId, e);

                var messageId       = message.MessageId;
                var messageFromUser = message.From;
                var messageText     = message.Text;

                _logger.LogError(TelegramLogEvents.LongLastingUserActionError, outException,
                                 "Current user telegram id: {currentUserTelegramId}. " +
                                 "userLongLastingActionArguments: {userLongLastingActionArguments}. " +
                                 "handler: {handler}. " +
                                 "Telegram message id : {messageId}. " +
                                 "Message from user: {messageFromUser}. " +
                                 "Message text: {messageText}",
                                 currentUserTelegramId, userLongLastingActionArguments, handler, messageId, messageFromUser,
                                 messageText);

                return(false);
            }
        }
        protected override async Task HandleImplementation(CallbackQueryData callbackQueryData)
        {
            _callbackQueryData = callbackQueryData;
            ProcessCallbackQueryData();

            var currentUser          = _currentTelegramUserProvider.GetCurrentTelegramRozkladUser();
            var facultyGroupToRemove =
                currentUser.FacultyGroups
                .FirstOrDefault(g =>
                                g.TypeId == _facultyGroupTypeId &&
                                g.Faculty.TypeId == _facultyTypeId);

            if (facultyGroupToRemove != null)
            {
                currentUser.FacultyGroups.Remove(facultyGroupToRemove);
                await _telegramRozkladUserDao.Update(currentUser);
            }

            await _botActions.ShowTimetableFacultyGroupsRemoveMenu();
        }
        public async Task Execute(ShowTimetableSelectingFacultyMenuOptions menuOptions)
        {
            var faculties = await _facultiesProvider.GetFaculties().ConfigureAwait(false);

            var currentUser = _currentTelegramUserProvider.GetCurrentTelegramRozkladUser();

            await _longLastingUserActionManager.UpsertUserAction(
                new LongLastingUserActionArguments
            {
                TelegramRozkladUser = currentUser,
                UserActionType      = LongLastingUserActionType.TimetableSelectingFaculty
            })
            .ConfigureAwait(false);

            var replyKeyboard =
                _keyboardCreator.CreateMarkup(new TimetableFacultyListKeyboardOptions {
                Faculties = faculties
            });

            await _telegramBotService.SendOrEditMessageAsync(
                _currentUserLocalizationService["choose-faculty-message"],
                replyMarkup : replyKeyboard);
        }
Пример #6
0
        private ICollection <Group> GetFacultyGroups(ShowTimetableFacultyGroupsMenuOptions options)
        {
            var facultyGroups = options?.FacultyGroups;

            return(facultyGroups ?? _currentTelegramUserProvider.GetCurrentTelegramRozkladUser().FacultyGroups);
        }