mirror of
https://github.com/flibusta-apps/book_bot.git
synced 2025-12-06 07:25:36 +01:00
Add sending annotation images
This commit is contained in:
@@ -17,6 +17,7 @@ import { getCallbackArgs, getPaginatedMessage, getPrefixWithQueryCreator, getSea
|
|||||||
import { getRandomKeyboard, getTextPaginationData, getUpdateLogKeyboard, getUserAllowedLangsKeyboard } from './keyboard';
|
import { getRandomKeyboard, getTextPaginationData, getUpdateLogKeyboard, getUserAllowedLangsKeyboard } from './keyboard';
|
||||||
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';
|
||||||
|
|
||||||
|
|
||||||
Sentry.init({
|
Sentry.init({
|
||||||
@@ -143,6 +144,12 @@ export async function createApprovedBot(token: string, state: BotState): Promise
|
|||||||
|
|
||||||
const data = getTextPaginationData(`${CallbackData.BOOK_ANNOTATION_PREFIX}${bookId}`, annotation.text, 0);
|
const data = getTextPaginationData(`${CallbackData.BOOK_ANNOTATION_PREFIX}${bookId}`, annotation.text, 0);
|
||||||
|
|
||||||
|
if (annotation.file) {
|
||||||
|
const imageData = await downloadImage(annotation.file);
|
||||||
|
|
||||||
|
if (imageData) await ctx.telegram.sendPhoto(ctx.message.chat.id, {source: imageData});
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await ctx.reply(data.current, {
|
await ctx.reply(data.current, {
|
||||||
parse_mode: "HTML",
|
parse_mode: "HTML",
|
||||||
@@ -196,6 +203,12 @@ export async function createApprovedBot(token: string, state: BotState): Promise
|
|||||||
|
|
||||||
const data = getTextPaginationData(`${CallbackData.AUTHOR_ANNOTATION_PREFIX}${authorId}`, annotation.text, 0);
|
const data = getTextPaginationData(`${CallbackData.AUTHOR_ANNOTATION_PREFIX}${authorId}`, annotation.text, 0);
|
||||||
|
|
||||||
|
if (annotation.file) {
|
||||||
|
const imageData = await downloadImage(annotation.file);
|
||||||
|
|
||||||
|
if (imageData) await ctx.telegram.sendPhoto(ctx.message.chat.id, {source: imageData});
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await ctx.reply(data.current, {
|
await ctx.reply(data.current, {
|
||||||
parse_mode: "HTML",
|
parse_mode: "HTML",
|
||||||
|
|||||||
@@ -21,3 +21,14 @@ export async function download(source_id: number, remote_id: number, file_type:
|
|||||||
filename: (response.headers['content-disposition'] || '').split('filename=')[1]
|
filename: (response.headers['content-disposition'] || '').split('filename=')[1]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export async function downloadImage(path: string) {
|
||||||
|
const response = await got(path);
|
||||||
|
|
||||||
|
if (response.statusCode === 200) {
|
||||||
|
return response.rawBody;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user