Example #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        public override void Handle(MessageContext context)
        {
            if (string.IsNullOrEmpty(context.User.CurrentCommandClrName))
            {
                return;
            }

            var currentCommandInfo = TelegramBotCommandFactory.GetCommandInfoByClrName(context.User.CurrentCommandClrName);

            if (currentCommandInfo == null)
            {
                return;
            }

            if (currentCommandInfo.NearCommands == null || !currentCommandInfo.NearCommands.Any())
            {
                return;
            }

            var command = currentCommandInfo.NearCommands.FirstOrDefault(f => f.CommandName.IsEqualName(context.Message.Text));

            if (command == null)
            {
                return;
            }

            var handlerCommand = TelegramBotCommandFactory.GetCommandInstance(command);

            ExecuteCommand(context, handlerCommand);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        public override void Handle(MessageContext context)
        {
            if (string.IsNullOrEmpty(context.User.CurrentCommandClrName))
            {
                return;
            }

            var commandInfo = TelegramBotCommandFactory.GetPublicCommandInfo(context.Message.Text, context.UserRole);

            if (commandInfo == null)
            {
                commandInfo = TelegramBotCommandFactory.GetPublicCommandInfo(context.Message.Text);
            }

            if (commandInfo?.CommandName == null)
            {
                return;
            }

            var currentCommandInfo = TelegramBotCommandFactory.GetCommandInfoByClrName(context.User.CurrentCommandClrName);

            if (currentCommandInfo?.CommandName == null)
            {
                return;
            }

            if (!commandInfo.LowCommands.Contains(currentCommandInfo))
            {
                return;
            }

            var handlerCommand = TelegramBotCommandFactory.GetCommandInstance(commandInfo);

            ExecuteCommand(context, handlerCommand);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        public override void Handle(MessageContext context)
        {
            if (string.IsNullOrEmpty(context.User.BackCommandHandlerClrName))
            {
                return;
            }

            var handler = TelegramBotCommandFactory.GetBackCommandHandler(context.User.BackCommandHandlerClrName);

            if (handler?.CommandName == null)
            {
                return;
            }

            if (!handler.CommandName.IsEqualName(context.Message.Text))
            {
                return;
            }

            var handlerCommand = TelegramBotCommandFactory.GetCommandInstance(handler);

            ExecuteCommand(context, handlerCommand);
        }
Example #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        public override void Handle(MessageContext context)
        {
            var commandInfo = TelegramBotCommandFactory.GetPublicCommandInfo(context.Message.Text, context.UserRole);

            if (commandInfo == null)
            {
                commandInfo = TelegramBotCommandFactory.GetPublicCommandInfo(context.Message.Text);
            }

            if (commandInfo == null)
            {
                return;
            }

            if (!commandInfo.IsHighestCommand)
            {
                return;
            }

            var handlerCommand = TelegramBotCommandFactory.GetCommandInstance(commandInfo);

            ExecuteCommand(context, handlerCommand);
        }
Example #5
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        private ITelegramBotCommand GetPriorityCommand(MessageContext context)
        {
            var priorityCommands = context.User.PriorityCommands;
            var commands         = TelegramBotCommandFactory
                                   .GetCommands()
                                   .Where(w => w.CommandType == TelegramBotCommandType.PublicCommand)
                                   .Where(w => priorityCommands.Contains(w.CommandId))
                                   .Where(w => w.CommandRole.IsEqualRole(context.UserRole))
                                   .ToList();

            if (!commands.Any())
            {
                return(null);
            }

            var command = commands.FirstOrDefault(f => f.CommandName.IsEqualName(context.Message.Text));

            if (command == null)
            {
                return(null);
            }

            return(TelegramBotCommandFactory.GetCommandInstance(command));
        }