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

improve messageHandlerRegistry.ts #85

Merged

Conversation

danbilokha
Copy link
Owner

No description provided.

@danbilokha danbilokha mentioned this pull request Apr 18, 2020
Copy link
Collaborator

@Proladge Proladge left a comment

Choose a reason for hiding this comment

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

Looks good!

bot: TelegramBot,
message: TelegramBot.Message,
chatId: number,
parameterAfterCommand?: string
Copy link
Collaborator

Choose a reason for hiding this comment

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

CommandParameter, I'd rename

Copy link
Owner Author

Choose a reason for hiding this comment

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

done

isMessageIsCommand(message.text, UserRegExps.Unsubscribe) ||
isMatchingDashboardItem(message.text, UserMessages.Unsubscribe)
) {
if (!parameterAfterCommand) {
return buildUnsubscribeInlineResponse(bot, message, chatId);
}

const [err, result] = await catchAsyncError<string>(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks like it just made us remove tons of manupulations with parameters

Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

@@ -134,7 +128,10 @@ export class MessageHandlerRegistry {
}
}

export const withCommandArgument = (
// This function is wrapper around the original User's query handler
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd add comments the way they could be read as docs
https://www.valentinog.com/blog/jsdoc/

But that's absolutely optional

Copy link
Owner Author

Choose a reason for hiding this comment

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

we have TS, I do not think we'd ever use jsdoc, what do you think?

Copy link
Owner Author

Choose a reason for hiding this comment

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

but done ;) who knows

if (!execResult) {
throw new Error('Please input any command from available');
logger.log('info', getInfoMessage('Entered unsupported command'));
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd change severity level here to be warning.
BUT
and it also seems like in current approach this error will be generated each time we call command wich has single handler serving ofr both cases /command and /command [parameter]

I'm still thinking of what is the best way to solve here 🤔

Copy link
Owner Author

Choose a reason for hiding this comment

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

@Proladge you're almost right. and it also seems like in current approach this error will be generated each time we call command wich has single handler serving ofr both cases /command and /command will appear at 220 line in this file.

Copy link
Owner Author

Choose a reason for hiding this comment

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

replaced info with warn

}

/* tslint:disable:no-string-literal */
if (execResult.groups['command'] && !execResult.groups['firstargument']) {
throw new Error(`please provide argument for \\${execResult.groups['command']}`);
logger.log('info', getInfoMessage(`No parameter for ${execResult.groups['command']}`));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same as above.

Probably we shouldn't even log it.
Since it's absolutely normal situatuin.

BUT who knews.

isMessageIsCommand(message.text, UserRegExps.Subscribe) ||
isMatchingDashboardItem(message.text, UserMessages.SubscriptionManager)
) {
if (!parameterAfterCommand) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

much better now

@danbilokha 🙇
massive thank you, for improving our code base!!!

@danbilokha danbilokha linked an issue Apr 19, 2020 that may be closed by this pull request
@danbilokha danbilokha merged commit 64b41a4 into feature/dbilokha/cleanup Apr 19, 2020
@danbilokha danbilokha deleted the feature/dbiloka/improve-message-registry branch April 19, 2020 15:01
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.

Make command not case sensitive as well
2 participants