Skip to content

Commit

Permalink
fix comments from @Proladge
Browse files Browse the repository at this point in the history
  • Loading branch information
danbilokha committed Apr 19, 2020
1 parent ac59206 commit fd8e048
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 18 deletions.
6 changes: 3 additions & 3 deletions server/src/bots/telegram/botResponse/assistantResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ export const assistantStrategyResponse: CallBackQueryHandlerWithCommandArgument
bot: TelegramBot,
message: TelegramBot.Message,
chatId: number,
parameterAfterCommand?: string
commandParameter?: string
): Promise<TelegramBot.Message> => {
if (!parameterAfterCommand) {
if (!commandParameter) {
return showAssistantFeatures(bot, message, chatId);
}

const answers: Array<Answer> = await fetchAnswer(parameterAfterCommand);
const answers: Array<Answer> = await fetchAnswer(commandParameter);
if (!answers.length) {
return assistantNoAnswerResponse(bot, chatId);
}
Expand Down
6 changes: 3 additions & 3 deletions server/src/bots/telegram/botResponse/countryResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ export const showCountryByNameStrategyResponse: CallBackQueryHandlerWithCommandA
bot: TelegramBot,
message: TelegramBot.Message,
chatId: number,
parameterAfterCommand?: string
commandParameter?: string
): Promise<TelegramBot.Message> => {
if (!parameterAfterCommand) {
if (!commandParameter) {
return bot.sendMessage(chatId, getUserInputWithoutCountryNameMessage());
}

return showCountryResponse(
bot,
message,
chatId,
adaptCountryToSystemRepresentation(parameterAfterCommand)
adaptCountryToSystemRepresentation(commandParameter)
);
};

Expand Down
4 changes: 2 additions & 2 deletions server/src/bots/telegram/botResponse/subscribeResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ export const subscribingStrategyResponse: CallBackQueryHandlerWithCommandArgumen
bot: TelegramBot,
message: TelegramBot.Message,
chatId: number,
parameterAfterCommand?: string
commandParameter?: string
): Promise<TelegramBot.Message> => {
if (!parameterAfterCommand) {
if (!commandParameter) {
return showExistingSubscriptionsResponse(bot, message, chatId);
}

Expand Down
6 changes: 3 additions & 3 deletions server/src/bots/telegram/botResponse/unsubscribeResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ export const unsubscribeStrategyResponse: CallBackQueryHandlerWithCommandArgumen
bot: TelegramBot,
message: TelegramBot.Message,
chatId: number,
parameterAfterCommand?: string
commandParameter?: string
): Promise<TelegramBot.Message> => {
// If it's called from InlineKeyboard, then @param ikCbData will be available
// otherwise @param ikCbData will be null
if (!parameterAfterCommand) {
if (!commandParameter) {
return buildUnsubscribeInlineResponse(bot, message, chatId);
}

const [err, result] = await catchAsyncError<string>(
unsubscribeMeFrom(message.chat, parameterAfterCommand)
unsubscribeMeFrom(message.chat, commandParameter)
);
if (err) {
return bot.sendMessage(chatId, unSubscribeErrorMessage(err.message));
Expand Down
2 changes: 1 addition & 1 deletion server/src/bots/telegram/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export type CallBackQueryHandlerWithCommandArgument<T = TelegramBot.Message> = (
bot: TelegramBot,
message: TelegramBot.Message,
chatId: number,
parameterAfterCommand?: string
commandParameter?: string
) => Promise<T>;

export const TELEGRAM_PREFIX: string = 'telegram';
Expand Down
16 changes: 10 additions & 6 deletions server/src/bots/telegram/services/messageHandlerRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,11 @@ export class MessageHandlerRegistry {
}
}

// This function is wrapper around the original User's query handler
// It adds an additional parameter (if such exist) to original handler,
// which will be an parameter following after command
/**
* This function is wrapper around the original User's query handler
* It adds an additional parameter (if such exist) to original handler,
* which will be an parameter following after command
*/
export const withSingleParameterAfterCommand = (
context: MessageHandlerRegistry,
handlerFn: CallBackQueryHandlerWithCommandArgument
Expand Down Expand Up @@ -186,8 +188,10 @@ export const withSingleParameterAfterCommand = (
};
};

// Check out how it works here
// https://codepen.io/belokha/pen/xxwOdWg?editors=0012
/**
* Check out how it works here
* https://codepen.io/belokha/pen/xxwOdWg?editors=0012
*/
function getParameterAfterCommandFromMessage(
userFullInput: string | undefined
): string | undefined {
Expand All @@ -205,7 +209,7 @@ function getParameterAfterCommandFromMessage(
)})\\s(?<firstargument>.*)`
).exec(makeMagicOverUserFullInput);
if (!execResult) {
logger.log('info', getInfoMessage('Entered unsupported command'));
logger.log('warn', getInfoMessage('Entered unsupported command'));
return undefined;
}

Expand Down

0 comments on commit fd8e048

Please sign in to comment.