Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
supersuklaa committed Apr 11, 2024
2 parents e77e6e2 + 3c667db commit 5e755e5
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/handlers/commands/resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { escapeMarkdown, formatYear } from '../../utils';
import { reactionsKeyboard } from '../events/reaction';
import * as messages from '../../constants/messages';
import type { Context } from '../../types/telegraf';
import logger from '../../logger';

export async function resolveRexpl(ctx: Context) {
const message = ctx.message as Message.TextMessage;
Expand All @@ -26,15 +27,26 @@ export async function resolveRexpl(ctx: Context) {

const key = escapeMarkdown(expl.key);
const year = formatYear(expl.created_at);
const keyboard = await reactionsKeyboard(expl.id);

const chatMember = await ctx.getChatMember(expl.user_id);
const explCreator = chatMember?.user.username;
let reply = `${key}, _${year}_`;

const reply = explCreator
? `${key}, _${explCreator.replace(/_/, '\\_')} ${year}_`
: `${key}, _${year}_`;
// getChatMember throws an error if member not found.
// This happens in private messages with the bot, for example.
try {
const chatMember = await ctx.getChatMember(expl.user_id);
const explCreator = chatMember?.user.username;

const keyboard = await reactionsKeyboard(expl.id);
if (explCreator) {
reply = `${key}, _${explCreator.replace(/_/, '\\_')} ${year}_`;
}
} catch (error) {
const description = _.get(error, ['response', 'description']);

if (description !== 'Bad Request: user not found') {
logger.error(error);
}
}

await ctx.replyWithMarkdown(reply, {
reply_markup: keyboard,
Expand Down

0 comments on commit 5e755e5

Please sign in to comment.