ref: replace "ctx.from.language_code" with a function to get the language code and fix ts implementation for "reply_to_message_id" (#51)

Co-authored-by: Lucas Gabriel <lucmsilva651@gmail.com>
This commit is contained in:
Giovani Finazzi 2025-05-02 21:08:13 -03:00 committed by GitHub
parent 6dce40d333
commit 87c987c16d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 193 additions and 160 deletions

View file

@ -4,13 +4,16 @@ import { isOnSpamWatch } from '../spamwatch/spamwatch';
import spamwatchMiddlewareModule from '../spamwatch/Middleware';
import axios from 'axios';
import { Telegraf, Context } from 'telegraf';
import { languageCode } from '../utils/language-code';
import { replyToMessageId } from '../utils/reply-to-message-id';
const spamwatchMiddleware = spamwatchMiddlewareModule(isOnSpamWatch);
export default (bot: Telegraf<Context>) => {
// TODO: this would greatly benefit from a loading message
bot.command(["rpony", "randompony", "mlpart"], spamwatchMiddleware, async (ctx: Context & { message: { text: string } }) => {
const Strings = getStrings(ctx.from?.language_code || 'en');
const Strings = getStrings(languageCode(ctx));
const reply_to_message_id = replyToMessageId(ctx);
try {
const response = await axios(Resources.randomPonyApi);
let tags: string[] = [];
@ -26,15 +29,13 @@ export default (bot: Telegraf<Context>) => {
ctx.replyWithPhoto(response.data.pony.representations.full, {
caption: `${response.data.pony.sourceURL}\n\n${tags.length > 0 ? tags.join(', ') : ''}`,
parse_mode: 'Markdown',
// @ts-ignore
reply_to_message_id: ctx.message.message_id
...({ reply_to_message_id })
});
} catch (error) {
const message = Strings.ponyApi.apiErr.replace('{error}', error.message);
ctx.reply(message, {
parse_mode: 'Markdown',
// @ts-ignore
reply_to_message_id: ctx.message.message_id
...({ reply_to_message_id })
});
return;
}