mirror of
https://github.com/flibusta-apps/book_bot.git
synced 2025-12-06 07:25:36 +01:00
Fix
This commit is contained in:
8
src/bots/factory/bots/approved/errors_utils.ts
Normal file
8
src/bots/factory/bots/approved/errors_utils.ts
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
import { TelegramError } from 'telegraf';
|
||||||
|
|
||||||
|
|
||||||
|
export function isNotModifiedMessage(e: any): boolean {
|
||||||
|
if (!(e instanceof TelegramError)) return false;
|
||||||
|
|
||||||
|
return e.description === 'Bad Request: message is not modified: specified new message content and reply markup are exactly the same as a current content and reply markup of the message';
|
||||||
|
}
|
||||||
@@ -20,6 +20,7 @@ import { getRandomKeyboard, getTextPaginationData, getUpdateLogKeyboard, getUser
|
|||||||
import { sendFile } from './hooks/downloading';
|
import { sendFile } from './hooks/downloading';
|
||||||
import { setCommands } from './hooks/setCommands';
|
import { setCommands } from './hooks/setCommands';
|
||||||
import { downloadImage } from './services/downloader';
|
import { downloadImage } from './services/downloader';
|
||||||
|
import { isNotModifiedMessage } from './errors_utils';
|
||||||
|
|
||||||
|
|
||||||
Sentry.init({
|
Sentry.init({
|
||||||
@@ -129,9 +130,15 @@ export async function createApprovedBot(token: string, state: BotState): Promise
|
|||||||
`${CallbackData.UPDATE_LOG_PREFIX}${arg}_`, arg, page, allowedLangs, BookLibrary.getBooks, formatBook, header, noItemsMessage,
|
`${CallbackData.UPDATE_LOG_PREFIX}${arg}_`, arg, page, allowedLangs, BookLibrary.getBooks, formatBook, header, noItemsMessage,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
try {
|
||||||
await ctx.editMessageText(pMessage.message, {
|
await ctx.editMessageText(pMessage.message, {
|
||||||
reply_markup: pMessage.keyboard?.reply_markup
|
reply_markup: pMessage.keyboard?.reply_markup
|
||||||
});
|
});
|
||||||
|
} catch (e) {
|
||||||
|
if (!isNotModifiedMessage(e)) {
|
||||||
|
Sentry.captureException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
bot.command(["settings", `settings@${me.username}`], async (ctx: Context) => {
|
bot.command(["settings", `settings@${me.username}`], async (ctx: Context) => {
|
||||||
@@ -149,9 +156,15 @@ export async function createApprovedBot(token: string, state: BotState): Promise
|
|||||||
|
|
||||||
const keyboard = await getUserAllowedLangsKeyboard(ctx.callbackQuery.from.id);
|
const keyboard = await getUserAllowedLangsKeyboard(ctx.callbackQuery.from.id);
|
||||||
|
|
||||||
ctx.editMessageText("Настройки языков:", {
|
try {
|
||||||
|
await ctx.editMessageText("Настройки языков:", {
|
||||||
reply_markup: keyboard.reply_markup,
|
reply_markup: keyboard.reply_markup,
|
||||||
});
|
});
|
||||||
|
} catch (e) {
|
||||||
|
if (!isNotModifiedMessage(e)) {
|
||||||
|
Sentry.captureException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
registerLanguageSettingsCallback(bot, 'on', CallbackData.ENABLE_LANG_PREFIX);
|
registerLanguageSettingsCallback(bot, 'on', CallbackData.ENABLE_LANG_PREFIX);
|
||||||
@@ -212,11 +225,13 @@ export async function createApprovedBot(token: string, state: BotState): Promise
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
if (!isNotModifiedMessage(e)) {
|
||||||
Sentry.captureException(e, {
|
Sentry.captureException(e, {
|
||||||
extra: {
|
extra: {
|
||||||
message: data.current,
|
message: data.current,
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -273,11 +288,13 @@ export async function createApprovedBot(token: string, state: BotState): Promise
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
if (!isNotModifiedMessage(e)) {
|
||||||
Sentry.captureException(e, {
|
Sentry.captureException(e, {
|
||||||
extra: {
|
extra: {
|
||||||
message: data.current,
|
message: data.current,
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,22 @@
|
|||||||
import { Context, Markup, Telegraf } from 'telegraf';
|
import { Context, Markup, Telegraf } from 'telegraf';
|
||||||
import { InlineKeyboardMarkup } from 'typegram';
|
import { InlineKeyboardMarkup } from 'typegram';
|
||||||
import { URLSearchParams } from 'url';
|
import { URLSearchParams } from 'url';
|
||||||
|
import * as Sentry from '@sentry/node';
|
||||||
|
|
||||||
|
import env from '@/config';
|
||||||
|
|
||||||
|
|
||||||
|
import { isNotModifiedMessage } from './errors_utils';
|
||||||
import { getPaginationKeyboard, getUserAllowedLangsKeyboard } from './keyboard';
|
import { getPaginationKeyboard, getUserAllowedLangsKeyboard } from './keyboard';
|
||||||
import * as BookLibrary from "./services/book_library";
|
import * as BookLibrary from "./services/book_library";
|
||||||
import { createOrUpdateUserSettings, getUserSettings } from './services/user_settings';
|
import { createOrUpdateUserSettings, getUserSettings } from './services/user_settings';
|
||||||
|
|
||||||
|
|
||||||
|
Sentry.init({
|
||||||
|
dsn: env.SENTRY_DSN,
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
interface PreparedMessage {
|
interface PreparedMessage {
|
||||||
message: string;
|
message: string;
|
||||||
keyboard?: Markup.Markup<InlineKeyboardMarkup>;
|
keyboard?: Markup.Markup<InlineKeyboardMarkup>;
|
||||||
@@ -79,8 +89,10 @@ export function registerPaginationCommand<T, Q extends string | number>(
|
|||||||
await ctx.editMessageText(pMessage.message, {
|
await ctx.editMessageText(pMessage.message, {
|
||||||
reply_markup: pMessage.keyboard?.reply_markup
|
reply_markup: pMessage.keyboard?.reply_markup
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (e) {
|
||||||
console.log(err);
|
if (!isNotModifiedMessage(e)) {
|
||||||
|
Sentry.captureException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user