/// <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="command"></param> /// <param name="servicesProvider"></param> public TelegramBotCommandService(ITelegramBotCommand command, ITelegramBotServicesProvider servicesProvider) { Command = command; TelegramBotServicesProvider = servicesProvider; TelegramBotCommandFactory = servicesProvider.GetService <ITelegramBotCommandFactory>(); Info = TelegramBotCommandFactory.GetCommandInfo(command.GetType()); MessageService = TelegramBotServicesProvider.GetService <ITelegramBotMessageService>(); }
/// <summary> /// /// </summary> /// <param name="context"></param> public override void Handle(MessageContext context) { if (string.IsNullOrEmpty(context.User.CurrentCommandClrName)) { return; } var currentCommand = TelegramBotCommandFactory.GetPublicOrInternalCommandByClrName(context.User.CurrentCommandClrName); ExecuteCommand(context, currentCommand); }
/// <summary> /// /// </summary> /// <typeparam name="T"></typeparam> /// <param name="chatId"></param> /// <returns></returns> public virtual T GetBackCommand <T>(long chatId) where T : class, ITelegramBotCommand { var user = TelegramBotDb.Users.FindOne(f => f.ChatId == chatId); if (user == null) { return(default(T)); } return(TelegramBotCommandFactory.GetCommandByClrName(user.BackCommand) as T); }
/// <summary> /// /// </summary> /// <typeparam name="T"></typeparam> /// <returns></returns> public virtual T GetBackCommandHandler <T>() where T : class, ITelegramBotCommand { var user = TelegramBotDb.Users.FindOne(f => f.ChatId == MessageService.Message.Chat.Id); if (user == null) { return(default(T)); } return(TelegramBotCommandFactory.GetCommandByClrName(user.BackCommandHandler) as T); }
/// <summary> /// /// </summary> /// <param name="context"></param> public override void Handle(MessageContext context) { var command = TelegramBotCommandFactory.GetPublicCommand(context.Message.Text, context.UserRole); if (command == null) { command = TelegramBotCommandFactory.GetPublicCommand(context.Message.Text); } if (command == null) { return; } ExecuteCommand(context, command); }
/// <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); }
/// <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); }
/// <summary> /// /// </summary> public virtual void RemovePriorityCommand <TCommand>(long chatId) where TCommand : ITelegramBotCommand { var user = TelegramBotDb.Users.FindOne(f => f.ChatId == chatId); if (user == null) { return; } var command = TelegramBotCommandFactory.GetCommandInfo(typeof(TCommand)); if (command == null) { return; } if (user.PriorityCommands == null) { return; } user.PriorityCommands.RemoveAll(r => r == command.CommandId); TelegramBotDb.Users.Update(user); }
/// <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)); }