feat: add multiple row support for link buttons

This commit is contained in:
hirzidevs
2024-09-13 09:40:44 +07:00
parent 4ca8bf97e0
commit 3cc57bb9a1
2 changed files with 22 additions and 14 deletions

View File

@@ -52,10 +52,15 @@ embed:
button:
enable: true # Enable or disable buttons in messages.
row1:
- label: "Panel"
- label: "Panel" # Label for the first button.
url: "https://panel.example.com" # URL for the first button.
# - label: "Dashboard" # Uncomment to add a second button.
# url: "https://dash.example.com" # URL for the second button.
# - label: "Dashboard" # Remove "#" at the start of the line to use this button
# url: "https://dash.example.com" # Remove "#" at the start of the line to use this button
# row2: # Remove "#" at the start of the line to use this row
# - label: "Backup Panel"
# url: "https://panel2.example.com"
# - label: "Backup Dashboard"
# url: "https://dash2.example.com"
# Status Message Configuration
# For details on using custom emojis, visit: https://github.com/HirziDevs/PteroStats#using-custom-emoji

View File

@@ -191,17 +191,20 @@ async function createMessage({ cache, panel, nodes, servers, users }) {
const components = []
if (config.button.enable && config.button.row1?.length > 0) {
components.push(
new ActionRowBuilder().addComponents(
config.button.row1.map(button =>
new ButtonBuilder()
.setLabel(button.label)
.setURL(button.url)
.setStyle(ButtonStyle.Link)
)
)
)
if (config.button.enable) {
for (const row of ["row1", "row2", "row3", "row4", "row5"]) {
if (config.button[row] && config.button[row].length > 0 && config.button[row].label && config.button[row].url)
components.push(
new ActionRowBuilder().addComponents(
config.button[row].slice(0, 5).map(button =>
new ButtonBuilder()
.setLabel(button.label)
.setURL(button.url)
.setStyle(ButtonStyle.Link)
)
)
);
}
}
try {