mirror of
https://github.com/flibusta-apps/book_bot.git
synced 2025-12-06 07:25:36 +01:00
Add sentry
This commit is contained in:
@@ -6,6 +6,7 @@
|
|||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "esbuild ./src/main.ts --bundle --platform=node --outfile=./build/main.cjs",
|
"build": "esbuild ./src/main.ts --bundle --platform=node --outfile=./build/main.cjs",
|
||||||
|
"build-minify": "npm run build -- --minify --sourcemap",
|
||||||
"build-watch": "npm run build -- --watch",
|
"build-watch": "npm run build -- --watch",
|
||||||
"run": "node ./build/main.cjs",
|
"run": "node ./build/main.cjs",
|
||||||
"run-watch": "nodemon build/main.cjs"
|
"run-watch": "nodemon build/main.cjs"
|
||||||
@@ -13,6 +14,7 @@
|
|||||||
"author": "",
|
"author": "",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@sentry/node": "^6.16.1",
|
||||||
"docker-ip-get": "^1.1.5",
|
"docker-ip-get": "^1.1.5",
|
||||||
"envalid": "^7.2.2",
|
"envalid": "^7.2.2",
|
||||||
"express": "^4.17.1",
|
"express": "^4.17.1",
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import * as Sentry from '@sentry/node';
|
||||||
|
|
||||||
import { Context, Telegraf, Markup, TelegramError } from 'telegraf';
|
import { Context, Telegraf, Markup, TelegramError } from 'telegraf';
|
||||||
|
|
||||||
import { BotState, Cache } from '@/bots/manager';
|
import { BotState, Cache } from '@/bots/manager';
|
||||||
@@ -18,6 +20,11 @@ import { getPaginatedMessage, registerLanguageSettingsCallback, registerPaginati
|
|||||||
import { getRandomKeyboard, getUpdateLogKeyboard, getUserAllowedLangsKeyboard } from './keyboard';
|
import { getRandomKeyboard, getUpdateLogKeyboard, getUserAllowedLangsKeyboard } from './keyboard';
|
||||||
|
|
||||||
|
|
||||||
|
Sentry.init({
|
||||||
|
dsn: env.SENTRY_DSN,
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
export async function createApprovedBot(token: string, state: BotState): Promise<Telegraf> {
|
export async function createApprovedBot(token: string, state: BotState): Promise<Telegraf> {
|
||||||
const bot = new Telegraf(token, {
|
const bot = new Telegraf(token, {
|
||||||
telegram: {
|
telegram: {
|
||||||
@@ -202,7 +209,7 @@ export async function createApprovedBot(token: string, state: BotState): Promise
|
|||||||
const userSettings = await getUserSettings(ctx.message.from.id);
|
const userSettings = await getUserSettings(ctx.message.from.id);
|
||||||
const allowedLangs = userSettings.allowed_langs.map((lang) => lang.code);
|
const allowedLangs = userSettings.allowed_langs.map((lang) => lang.code);
|
||||||
|
|
||||||
const pMessage = await getPaginatedMessage(CallbackData.AUTHOR_BOOKS_PREFIX, authorId, 1, allowedLangs, BookLibrary.getAuthorBooks, formatBook);
|
const pMessage = await getPaginatedMessage(CallbackData.AUTHOR_BOOKS_PREFIX, parseInt(authorId), 1, allowedLangs, BookLibrary.getAuthorBooks, formatBook);
|
||||||
|
|
||||||
await ctx.reply(pMessage.message, {
|
await ctx.reply(pMessage.message, {
|
||||||
reply_markup: pMessage.keyboard.reply_markup
|
reply_markup: pMessage.keyboard.reply_markup
|
||||||
@@ -219,7 +226,7 @@ export async function createApprovedBot(token: string, state: BotState): Promise
|
|||||||
const userSettings = await getUserSettings(ctx.message.from.id);
|
const userSettings = await getUserSettings(ctx.message.from.id);
|
||||||
const allowedLangs = userSettings.allowed_langs.map((lang) => lang.code);
|
const allowedLangs = userSettings.allowed_langs.map((lang) => lang.code);
|
||||||
|
|
||||||
const pMessage = await getPaginatedMessage(CallbackData.TRANSLATOR_BOOKS_PREFIX, translatorId, 1, allowedLangs, BookLibrary.getTranslatorBooks, formatBook);
|
const pMessage = await getPaginatedMessage(CallbackData.TRANSLATOR_BOOKS_PREFIX, parseInt(translatorId), 1, allowedLangs, BookLibrary.getTranslatorBooks, formatBook);
|
||||||
|
|
||||||
await ctx.reply(pMessage.message, {
|
await ctx.reply(pMessage.message, {
|
||||||
reply_markup: pMessage.keyboard.reply_markup
|
reply_markup: pMessage.keyboard.reply_markup
|
||||||
@@ -236,7 +243,7 @@ export async function createApprovedBot(token: string, state: BotState): Promise
|
|||||||
const userSettings = await getUserSettings(ctx.message.from.id);
|
const userSettings = await getUserSettings(ctx.message.from.id);
|
||||||
const allowedLangs = userSettings.allowed_langs.map((lang) => lang.code);
|
const allowedLangs = userSettings.allowed_langs.map((lang) => lang.code);
|
||||||
|
|
||||||
const pMessage = await getPaginatedMessage(CallbackData.SEQUENCE_BOOKS_PREFIX, sequenceId, 1, allowedLangs, BookLibrary.getSequenceBooks, formatBook);
|
const pMessage = await getPaginatedMessage(CallbackData.SEQUENCE_BOOKS_PREFIX, parseInt(sequenceId), 1, allowedLangs, BookLibrary.getSequenceBooks, formatBook);
|
||||||
|
|
||||||
await ctx.reply(pMessage.message, {
|
await ctx.reply(pMessage.message, {
|
||||||
reply_markup: pMessage.keyboard.reply_markup
|
reply_markup: pMessage.keyboard.reply_markup
|
||||||
@@ -269,7 +276,11 @@ export async function createApprovedBot(token: string, state: BotState): Promise
|
|||||||
reply_to_message_id: ctx.message.message_id,
|
reply_to_message_id: ctx.message.message_id,
|
||||||
reply_markup: keyboard.reply_markup,
|
reply_markup: keyboard.reply_markup,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
bot.catch((err) => {
|
||||||
|
Sentry.captureException(err);
|
||||||
|
});
|
||||||
|
|
||||||
return bot;
|
return bot;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { cleanEnv, str, num } from 'envalid';
|
|||||||
|
|
||||||
|
|
||||||
export default cleanEnv(process.env, {
|
export default cleanEnv(process.env, {
|
||||||
|
SENTRY_DSN: str(),
|
||||||
WEBHOOK_BASE_URL: str(),
|
WEBHOOK_BASE_URL: str(),
|
||||||
WEBHOOK_PORT: num(),
|
WEBHOOK_PORT: num(),
|
||||||
TELEGRAM_BOT_API_ROOT: str({ default: "https://api.telegram.org" }),
|
TELEGRAM_BOT_API_ROOT: str({ default: "https://api.telegram.org" }),
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
import BotsManager from './bots/manager';
|
import BotsManager from './bots/manager';
|
||||||
|
|
||||||
setTimeout(() => BotsManager.start(), 5_000);
|
BotsManager.start();
|
||||||
|
|||||||
Reference in New Issue
Block a user