Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BotCommands: Don't use user input as JavaScript object keys #603

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

jaller94
Copy link
Contributor

@jaller94 jaller94 commented Jan 2, 2023

No description provided.

@jaller94 jaller94 requested a review from a team as a code owner January 2, 2023 16:03
Copy link
Contributor

@Half-Shot Half-Shot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems fine, but I hope we have adequate tests for BotCommands

@@ -38,42 +38,44 @@ export interface BotCommandOptions {
type BotCommandResult = {status?: boolean, reaction?: string}|undefined;
type BotCommandFunction = (...args: string[]) => Promise<BotCommandResult>;

export type BotCommands = {[prefix: string]: {fn: BotCommandFunction} & BotCommandOptions};
export type BotCommands = Map<string, {fn: BotCommandFunction} & BotCommandOptions>;
export type HelpFunction = (cmdPrefix?: string, categories?: string[], includeTitles?: boolean) => MatrixMessageContent

export function compileBotCommands(...prototypes: Record<string, BotCommandFunction>[]): {helpMessage: HelpFunction, botCommands: BotCommands} {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do wonder if we should add a test case for BotCommands to just ensure nothing breaks?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried... but this relies on Reflect and decorators (not enabled for the tests director yet), multiple levels of inheritance and using prototypes as JavaScript objects.
All three on their own make code super hard to write unit tests for.

@Half-Shot
Copy link
Contributor

@jaller94 In the interests of time, I'll settle for just having you eyeball this and test that nothing is broken on a test instance?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants