-
Notifications
You must be signed in to change notification settings - Fork 64
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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} { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
@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? |
No description provided.