Пример #1
0
        public override Message?Execute(User user, string[] args)
        {
            var keyboard = new ReplyMarkupKeyboard();

            keyboard.AddButton("Приветствую!", "hi", KeyboardColor.Green);
            keyboard.AddPage();
            keyboard.AddButton("Приветствую!", "hi", KeyboardColor.Primary);
            keyboard.AddPage();
            keyboard.AddButton("Приветствую!", "hi", KeyboardColor.Red);

            return(new Message(
                       "Салам, славяне!",
                       new IAttachment[]
            {
                keyboard,
                new PhotoAttachment("https://sun9-3.userapi.com/impg/lCTtJJlI-fPpcAGnXyynuR3JcxQRIIEFz-JNdg/luK9Hvhve2c.jpg?size=743x196&quality=96&sign=c29891f46f0896b082e7026e06821ce4&type=album")
            }));
        }
Пример #2
0
        public override Message?Execute()
        {
            ReplyMarkupKeyboard  markup = null;
            InlineMarkupKeyboard inline = null;

            if (InlineSubcommands != null)
            {
                inline = new InlineMarkupKeyboard();

                foreach (var inlineSubcommand in InlineSubcommands)
                {
                    if (inlineSubcommand is NewLine)
                    {
                        inline.AddLine();
                        continue;
                    }

                    inlineSubcommand.User   = User;
                    inlineSubcommand.Parent = this;
                    inlineSubcommand.Args   = Array.Empty <object>();

                    var isMiddlewaresReturnError = false;

                    foreach (var middleware in inlineSubcommand.Middlewares)
                    {
                        try
                        {
                            if (!middleware(inlineSubcommand))
                            {
                                isMiddlewaresReturnError = true;
                                break;
                            }
                        }
                        catch (JubiException)
                        {
                            isMiddlewaresReturnError = true;
                            break;
                        }
                    }

                    if (isMiddlewaresReturnError)
                    {
                        continue;
                    }

                    inline.AddButton(inlineSubcommand.Alias, () => ExecuteMarkup(inlineSubcommand));
                }
            }

            if (Subcommands != null)
            {
                markup = Parent == null
                    ? new ReplyMarkupKeyboard()
                    : new ReplyMarkupKeyboard(false, () => ExecuteMarkup(Parent));
                markup.MaxInRows = MaxButtonsInRow;

                foreach (var executor in Subcommands)
                {
                    if (executor is NewLine)
                    {
                        markup.AddLine();
                        continue;
                    }

                    executor.User   = User;
                    executor.Parent = this;
                    executor.Args   = Array.Empty <object>();

                    var isMiddlewaresReturnError = false;

                    foreach (var middleware in executor.Middlewares)
                    {
                        try
                        {
                            if (!middleware(executor))
                            {
                                isMiddlewaresReturnError = true;
                                break;
                            }
                        }
                        catch (JubiException)
                        {
                            isMiddlewaresReturnError = true;
                            break;
                        }
                    }

                    if (isMiddlewaresReturnError)
                    {
                        continue;
                    }

                    var isClicked = false;
                    markup.AddButton(executor.Alias, () =>
                    {
                        if (isClicked && IsOnce)
                        {
                            return;
                        }
                        isClicked = true;
                        ExecuteMarkup(executor);
                    });
                }
            }

            return(markup != null && inline != null
                ? new Message(null, markup, inline)
                : (inline != null ? new Message(null, inline) : markup));
        }