Add author annotations

This commit is contained in:
2022-01-03 13:01:36 +03:00
parent 14f8c406d5
commit fc1caf0d18
2 changed files with 25 additions and 0 deletions

View File

@@ -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;

View File

@@ -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<BookAnnotation>
}
export async function getAuthorAnnotation(authorId: number): Promise<AuthorAnnnotation> {
return _makeRequest<AuthorAnnnotation>(`/api/v1/authors/${authorId}/annotation`);
}
export async function getAuthorBooks(authorId: number, page: number, allowedLangs: string[]): Promise<Page<AuthorBook>> {
const searchParams = getAllowedLangsSearchParams(allowedLangs);
searchParams.append('page', page.toString());