Ejemplo n.º 1
0
        public void SetCallback(CallbackQueryEventArgs callbackQueryEventArgs, int access)
        {
            if (callbackQueryEventArgs.CallbackQuery.Message.Type != MessageType.Text)
            {
                return;
            }
            var methods = GetMethod <CallbackAttribute>();

            foreach (var method in methods) // iterate through all found methods
            {
                var attributes = method.GetCustomAttributes(false);

                var attributesAll = attributes.Select(CheckTypeCallback).ToList();
                attributesAll.RemoveAll(x => x == null);

                var attribute = attributesAll.FirstOrDefault();
                if (attribute == null)
                {
                    return;
                }

                var botCallback = new BotCallback();
                botCallback.Parse(callbackQueryEventArgs.CallbackQuery.Data);

                if (attribute.Access > access)
                {
                    continue;
                }

                if (!attribute.Commands.All(x => String.Equals(x, botCallback.AllText, StringComparison.CurrentCultureIgnoreCase) ||
                                            String.Equals(x, botCallback.Command, StringComparison.CurrentCultureIgnoreCase) ||
                                            String.Equals(x, botCallback.NoCommand, StringComparison.CurrentCultureIgnoreCase)))
                {
                    continue;
                }

                Log.Information(string.Join("", new List <string>()
                {
                    $"Message Id: {callbackQueryEventArgs.CallbackQuery.Message.MessageId}, ",
                    $"Callback: {callbackQueryEventArgs.CallbackQuery.Data}, ",
                    $"Chat: {callbackQueryEventArgs.CallbackQuery.Message.Chat.Id}, ",
                    $"From: {callbackQueryEventArgs.CallbackQuery.From}, ",
                    $"Type: {callbackQueryEventArgs.CallbackQuery.Message.Type}, ",
                    $"Date: {callbackQueryEventArgs.CallbackQuery.Message.Type}, ",
                }));

                var obj = Activator.CreateInstance(method.DeclaringType); // Instantiate the class
                method.Invoke(obj, parameters: new object[]
                {
                    new TextParams(callback: botCallback, callbackQuery: callbackQueryEventArgs.CallbackQuery),
                }
                              ); // invoke the method

                break;
            }
        }
Ejemplo n.º 2
0
 public TextParams(BotCallback callback, CallbackQuery callbackQuery)
 {
     this.Callback      = callback;
     this.CallbackQuery = callbackQuery;
 }