Skip to content

Commit aa9411d

Browse files
committed
Fix help menu getting stuck if there are no commands
1 parent e4cc825 commit aa9411d

File tree

1 file changed

+29
-19
lines changed
  • backend/src/plugin/core/command/help

1 file changed

+29
-19
lines changed

backend/src/plugin/core/command/help/list.ts

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -111,40 +111,50 @@ export function renderCommandListPage(context: BaseContext, state: CommandListSt
111111
container.components.push(...entry);
112112
}
113113

114-
if (entries.length === 0) {
114+
if (entries.length === 0)
115115
container.components.push(Text(`**${icons.info} You do not have access to any commands for this plugin!**`));
116-
return { components: [container] };
117-
}
116+
else {
117+
const prevDisabled = sliceStart === 0;
118+
const nextDisabled = sliceEnd >= entries.length;
118119

119-
const prevDisabled = sliceStart === 0;
120-
const nextDisabled = sliceEnd >= entries.length;
120+
container.components.push(Divider());
121121

122-
container.components.push(Divider());
122+
if (!prevDisabled || !nextDisabled) {
123+
container.components.push(ActionRow([
124+
TextButton("←", "prev", { disabled: prevDisabled }),
125+
TextButton("→", "next", { disabled: nextDisabled }),
126+
]));
127+
}
123128

124-
if (!prevDisabled || !nextDisabled) {
125-
container.components.push(ActionRow([
126-
TextButton("←", "prev", { disabled: prevDisabled }),
127-
TextButton("→", "next", { disabled: nextDisabled }),
128-
]));
129+
container.components.push(Text("-# Optional options are surrounded with []."));
129130
}
130131

131-
container.components.push(Text("-# Optional options are surrounded with []."));
132-
133132
return {
134133
components: [container],
135134
async componentHandler(context, customID, values) {
136135
if (context.originalUserID !== context.user.id)
137136
return;
138137

139-
if (customID === "prev")
140-
await context.edit(renderCommandListPage(context, { plugin: state.plugin, entries, page: state.page - 1 }));
141-
else if (customID === "next")
142-
await context.edit(renderCommandListPage(context, { plugin: state.plugin, entries, page: state.page + 1 }));
143-
else if (customID === "plugin") {
138+
if (customID === "prev") {
139+
await context.edit(renderCommandListPage(context, {
140+
plugin: state.plugin,
141+
entries,
142+
page: state.page - 1,
143+
}));
144+
} else if (customID === "next") {
145+
await context.edit(renderCommandListPage(context, {
146+
plugin: state.plugin,
147+
entries,
148+
page: state.page + 1,
149+
}));
150+
} else if (customID === "plugin") {
144151
if (values?.length !== 1)
145152
throw new Error("Selected plugin not present");
146153

147-
await context.edit(renderCommandListPage(context, { plugin: values[0]!, page: 0 }));
154+
await context.edit(renderCommandListPage(context, {
155+
plugin: values[0]!,
156+
page: 0,
157+
}));
148158
}
149159
},
150160
};

0 commit comments

Comments
 (0)