From fc1caf0d18a8c0ad4b630462d6338a745f3fcf9e Mon Sep 17 00:00:00 2001 From: Kurbanov Bulat Date: Mon, 3 Jan 2022 13:01:36 +0300 Subject: [PATCH] Add author annotations --- src/bots/factory/bots/approved/index.ts | 12 ++++++++++++ .../factory/bots/approved/services/book_library.ts | 13 +++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/bots/factory/bots/approved/index.ts b/src/bots/factory/bots/approved/index.ts index 89947ff..76abd4b 100644 --- a/src/bots/factory/bots/approved/index.ts +++ b/src/bots/factory/bots/approved/index.ts @@ -150,6 +150,18 @@ export async function createApprovedBot(token: string, state: BotState): Promise ctx.reply(annotation.text); }); + bot.hears(/^\/a_info_[\d]+$/gm, async (ctx: Context) => { + if (!ctx.message || !('text' in ctx.message)) { + return; + } + + const authorId = ctx.message.text.split('_')[2]; + + const annotation = await BookLibrary.getAuthorAnnotation(parseInt(authorId)); + + ctx.reply(annotation.text); + }); + bot.hears(/^\/a_[\d]+$/gm, async (ctx: Context) => { if (!ctx.message || !('text' in ctx.message)) { return; diff --git a/src/bots/factory/bots/approved/services/book_library.ts b/src/bots/factory/bots/approved/services/book_library.ts index e5bb53a..760a846 100644 --- a/src/bots/factory/bots/approved/services/book_library.ts +++ b/src/bots/factory/bots/approved/services/book_library.ts @@ -69,6 +69,14 @@ export interface Sequence { } +export interface AuthorAnnnotation { + id: number; + title: string; + text: string; + file: string | null; +} + + export interface BookAnnotation { id: number; title: string; @@ -127,6 +135,11 @@ export async function getBookAnnotation(bookId: number): Promise } +export async function getAuthorAnnotation(authorId: number): Promise { + return _makeRequest(`/api/v1/authors/${authorId}/annotation`); +} + + export async function getAuthorBooks(authorId: number, page: number, allowedLangs: string[]): Promise> { const searchParams = getAllowedLangsSearchParams(allowedLangs); searchParams.append('page', page.toString());