Improve some command formatting (#504)

* Improve formatting of command help

- Ensure args included in monospace formatting
- Show required args as `<arg>`
- Show optional args as `[arg]`

* Don't print undefined username with Jira `whoami`

* Fix typo in `feed remove` description

* Add changelog

* Relabel changes as a bugfix
This commit is contained in:
Andrew Ferrazzutti 2022-09-30 12:16:44 -04:00 committed by GitHub
parent 0111f4bfa3
commit 24a653f11d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 4 deletions

1
changelog.d/504.bugfix Normal file
View File

@ -0,0 +1 @@
Improve formatting of help commands and Jira's `whoami` command.

View File

@ -49,10 +49,15 @@ export function compileBotCommands(...prototypes: Record<string, BotCommandFunct
const b = Reflect.getMetadata(botCommandSymbol, prototype, propertyKey);
if (b) {
const category = b.category || "default";
const requiredArgs = b.requiredArgs?.join(" ") || "";
const requiredArgs = b.requiredArgs?.map((arg: string) => `<${arg}>`).join(" ") || "";
const optionalArgs = b.optionalArgs?.map((arg: string) => `[${arg}]`).join(" ") || "";
const cmdStr =
` - \`££PREFIX££${b.prefix}` +
(requiredArgs ? ` ${requiredArgs}` : "") +
(optionalArgs ? ` ${optionalArgs}` : "") +
`\` - ${b.help}`;
cmdStrs[category] = cmdStrs[category] || []
cmdStrs[category].push(` - \`££PREFIX££${b.prefix}\` ${requiredArgs} ${optionalArgs} - ${b.help}`);
cmdStrs[category].push(cmdStr);
// We know that these types are safe.
botCommands[b.prefix as string] = {
fn: prototype[propertyKey],

View File

@ -224,7 +224,7 @@ export class SetupConnection extends CommandConnection {
}
}
@botCommand("feed remove", { help: "Unsubscribe from an RSS/Atom.", requiredArgs: ["url"], includeUserId: true, category: "feed"})
@botCommand("feed remove", { help: "Unsubscribe from an RSS/Atom feed.", requiredArgs: ["url"], includeUserId: true, category: "feed"})
public async onFeedRemove(userId: string, url: string) {
await this.checkUserPermissions(userId, "feed", FeedConnection.CanonicalEventType);

View File

@ -59,7 +59,10 @@ export class JiraBotCommands extends AdminRoomCommandHandler {
continue;
}
const user = await clientForResource.getCurrentUser();
response += `\n - ${resource.name} ${user.name} (${user.displayName || ""})`;
response +=
`\n - ${resource.name}` +
(user.name ? ` ${user.name}` : "") +
(user.displayName ? ` (${user.displayName})` : "");
}
await this.sendNotice(response);
}