Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

All notable changes to this project are documented here.

## [1.1.3] - 2026-09-29

### Fixed

- `/ask` and `/docs search` failed with "didn't respond in time" whenever a docs site's home page was among the results: its empty slug made an empty menu option, and Discord rejects the whole reply for that. The home page is now left out of the results menu.

### Changed

- `/docs page` with text that isn't a page slug, such as `tiktok`, now searches for that text instead of replying "Page not found".

## [1.1.2] - 2026-09-29

### Fixed
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ctrlaltbot",
"version": "1.1.2",
"version": "1.1.3",
"description": "Discord bot for ctrl alt doc documentation sites, running as a Cloudflare Worker.",
"repository": {
"type": "git",
Expand Down
3 changes: 2 additions & 1 deletion src/discord/responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ function searchResultSelect(results: SearchResult[], selectedValue: string): Sel

for (const result of results) {
const value = resultValue(result.slug, result.heading?.id);
if (value.length > MAX_CHOICE_LENGTH || seen.has(value)) continue;
// The home page has an empty slug, and Discord rejects the whole reply if any option value is empty.
if (!result.slug || value.length > MAX_CHOICE_LENGTH || seen.has(value)) continue;
seen.add(value);

const option: SelectOption = { label: truncate(resultTitle(result), MAX_CHOICE_LENGTH), value, default: value === selectedValue };
Expand Down
7 changes: 6 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,14 @@ async function pageMessage(slug: string, header: string | undefined, env: Env, b

return formatPageResult(page, env.CAD_BASE_URL, brand, header);
} catch (error) {
// Text typed instead of a suggestion, such as "tiktok", is more useful as a search than as an error.
if (error instanceof Error && error.message === 'CAD_NOT_FOUND') {
return searchMessage(slug, env, brand);
}

console.error('CAD page failed:', describeCadError(error));

return cadErrorMessage(error, brand, `There’s no page at \`${slug}\`. Pick one of the suggestions while typing, or try \`/ask\`.`);
return cadErrorMessage(error, brand);
}
}

Expand Down
8 changes: 8 additions & 0 deletions test/responses.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ test('omits the menu for a single result and skips values Discord would reject',
assert.equal(select(formatSearchResults([results[1]!, longSlug], baseUrl, 'pasta', brand) as Message), undefined);
});

test('leaves the home page out of the menu, since Discord rejects empty option values', () => {
const home = { title: 'Home', description: 'Welcome.', slug: '', excerpt: '' };
const options = select(formatSearchResults([...results, home], baseUrl, 'cooking', brand) as Message)?.options ?? [];

assert.deepEqual(options.map((option) => option.value), ['cooking/eggs#boiling-an-egg', 'cooking/pasta']);
assert.ok(options.every((option) => option.value.length > 0 && option.value.length <= 100));
});

test('moves the selection when another result is chosen', () => {
const original = formatSearchResults(results, baseUrl, 'cooking', brand) as Message;
const updated = formatSelectedResult(eggsPage, baseUrl, brand, 'cooking/eggs#frying', original.components) as Message;
Expand Down
Loading