public Dispatcher(ITelegramBotData botData, ILogger <Dispatcher <TContext, TController> > logger = null) { _botData = botData; _methods = typeof(TController).GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly).Where(m => !m.IsSpecialName); _noMethodsMethod = _methods.FirstOrDefault(m => m.GetCustomAttribute <NoMethodFilter>() != null); _logger = logger; }
private static void SetControllerData(TController controller, Update update, MessageCommand command, TContext context, TelegramChat chat, ITelegramBotData botData) { controller.Update = update; controller.MessageCommand = command; controller.TelegramContext = context; controller.TelegramChat = chat; controller.BotData = botData; }
public Dispatcher(ITelegramBotData botData, IList <Type> controllers, ILogger <Dispatcher <TContext, TController> >?logger = null) : base(botData, controllers, logger) { Controllers.Add(typeof(TController)); var methodInfos = typeof(TController) .GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly) .Where(m => !m.IsSpecialName); foreach (var methodInfo in methodInfos) { Methods.Add(methodInfo, typeof(TController)); } NoMethodsMethod = Methods.FirstOrDefault(m => m.Key.GetCustomAttribute <NoMethodFilter>() != null); }
/// <inheritdoc /> public override bool IsValid(Update update, TelegramChat?user, MessageCommand command, ITelegramBotData botData) { return(_command.Contains(command?.Command)); }
public override bool IsValid(Update update, TelegramChat?chat, MessageCommand command, ITelegramBotData botData) { return(_type.Any(x => x == update.Type)); }
/// <inheritdoc /> public override bool IsValid(Update update, TelegramChat user, MessageCommand command, ITelegramBotData botData) { return(user != null && _state.Contains(user.State)); }
/// <inheritdoc /> public IDispatcherBuilder SetTelegramBotData(ITelegramBotData botData) { _botData = botData; return(this); }
/// <inheritdoc /> public override bool IsValid(Update update, TelegramChat?user, MessageCommand command, ITelegramBotData botData) { return(update.GetMessage() != null && _type.Contains(update.GetMessage() !.Chat.Type)); }
public override bool IsValid(Update update, TelegramChat?user, MessageCommand command, ITelegramBotData botData) { return(command == null || !command.IsCommand()); }
public override bool IsValid(Update update, TelegramChat?chat, MessageCommand command, ITelegramBotData botData) { return(command?.Parameters.Count == _qnt); }
/// <summary> /// Called when searching for eligible handler method, return true if the method is eligible. /// This method calls the generic IsValid(), override it to implements custom behaviour for methods only. /// </summary> /// <param name="update">Update of the current request</param> /// <param name="chat">Current chat</param> /// <param name="command">MessageCommand generated from current Update</param> /// <param name="botData">Data of the bot in use</param> /// <returns>If true, the method is eligible for the current update. If false, the method is discarded</returns> public virtual bool IsValidMethod(Update update, TelegramChat?chat, MessageCommand command, ITelegramBotData botData) { return(IsValid(update, chat, command, botData)); }
/// <summary> /// Called when searching for eligible handler controller and method, return true if the method is eligible /// </summary> /// <param name="update">Update of the current request</param> /// <param name="chat">Current chat</param> /// <param name="command">MessageCommand generated from current Update</param> /// <param name="botData">Data of the bot in use</param> /// <returns>If true, the mehod is eligible for the currrent update. If false, the method is discarded</returns> public abstract bool IsValid(Update update, TelegramChat?chat, MessageCommand command, ITelegramBotData botData);
/// <inheritdoc /> public override bool IsValid(Update update, TelegramChat user, MessageCommand command, ITelegramBotData botData) { return(_endpoint.Contains(botData?.Endpoint)); }
public override bool IsValid(Update update, TelegramChat?chat, MessageCommand command, ITelegramBotData botData) { if (update.Type != UpdateType.CallbackQuery) { return(false); } var data = InlineDataWrapper.ParseInlineData(update.CallbackQuery !.Data !); return(_commands.Contains(data.Command)); }