All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.mikuac.shiro.common.utils.Keyboard Maven / Gradle / Ivy

package com.mikuac.shiro.common.utils;

import com.alibaba.fastjson2.annotation.JSONField;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

import java.util.ArrayList;
import java.util.List;

/**
 * 自定义按钮内容,一般可以发送5行按钮,每一行一般5个按钮。
 */
@Getter
@Setter
@SuppressWarnings("unused")
public class Keyboard {

    public static final int STYLE_GREY = 0;
    public static final int STYLE_BLUE = 1;
    public static final int ACTION_TYPE_JUMP = 0;
    public static final int ACTION_TYPE_CALLBACK = 1;
    public static final int ACTION_TYPE_CMD = 2;
    public static final int PERMISSION_TYPE_USER = 0;
    public static final int PERMISSION_TYPE_MANAGER = 1;
    public static final int PERMISSION_TYPE_ALL = 2;
    public static final int PERMISSION_TYPE_ROLE = 3;
    public static final int ANCHOR_NONE = 0;
    public static final int ANCHOR_SELECT = 1;
    private String type = "keyboard";

    private Data data = new Data();

    public static Keyboard builder() {
        return new Keyboard();
    }

    public static ButtonBuilder callButtonBuilder() {
        return new ButtonBuilder().actionType(ACTION_TYPE_CALLBACK);
    }

    public static ButtonBuilder textButtonBuilder() {
        return new ButtonBuilder().actionType(ACTION_TYPE_CMD);
    }

    public static ButtonBuilder urlButtonBuilder() {
        return new ButtonBuilder().actionType(ACTION_TYPE_JUMP);
    }

    public Keyboard build() {
        return this;
    }

    /**
     * 添加按钮
     *
     * @param button {@code Keyboard.TextButtonBuilder().build()}
     * @return {@link Keyboard}
     */
    public Keyboard addButton(Button button) {
        List rows = getData().getContent().getRows();
        if (rows.isEmpty()) {
            addRow();
        }
        rows.get(rows.size() - 1).addButton(button);
        return this;
    }

    @SuppressWarnings("UnusedReturnValue")
    public Keyboard addRow() {
        List rows = getData().getContent().getRows();
        if (!rows.isEmpty() && rows.get(rows.size() - 1).getButtons().isEmpty()) {
            return this;
        }
        rows.add(new Row());
        return this;
    }

    @Getter
    @Setter
    public static class Data {
        private Content content = new Content();
    }

    @Getter
    @Setter
    public static class Content {
        private List rows = new ArrayList<>();
    }

    @Getter
    @Setter
    public static class Row {
        private List




© 2015 - 2025 Weber Informatics LLC | Privacy Policy