mirror of
https://github.com/muerwre/vk-tg-bot.git
synced 2025-04-24 14:36:41 +07:00
fix link handler and too much buttons
Some checks failed
Build & Publish / Build & Publish (push) Failing after 44s
Some checks failed
Build & Publish / Build & Publish (push) Failing after 44s
This commit is contained in:
parent
ba3d274cab
commit
933fa40805
3 changed files with 16 additions and 5 deletions
|
@ -47,6 +47,7 @@ type LikeCtx = Composer.Context<CallbackQueryUpdate> & { match: string[] };
|
|||
|
||||
const PHOTO_CAPTION_LIMIT = 1000;
|
||||
const POST_TEXT_LIMIT = 4096;
|
||||
const URL_BUTTON_LIMIT = 4;
|
||||
|
||||
export class PostNewHandler extends VkEventHandler<Fields, Values> {
|
||||
constructor(...props: ConstructorParameters<typeof VkEventHandler<Fields, Values>>) {
|
||||
|
@ -152,10 +153,8 @@ export class PostNewHandler extends VkEventHandler<Fields, Values> {
|
|||
return;
|
||||
}
|
||||
|
||||
const rows = await Promise.all(
|
||||
buttons.map((button) =>
|
||||
this.extrasGenerators[button](text, eventId, postId)
|
||||
)
|
||||
const rows = buttons.map((button) =>
|
||||
this.extrasGenerators[button](text, eventId, postId)
|
||||
);
|
||||
|
||||
const inline_keyboard = rows.filter(
|
||||
|
@ -193,6 +192,7 @@ export class PostNewHandler extends VkEventHandler<Fields, Values> {
|
|||
|
||||
return label ? { text: links[label], url: url.toString() } : undefined;
|
||||
})
|
||||
.slice(0, URL_BUTTON_LIMIT)
|
||||
.filter((el) => el) as InlineKeyboardButton[];
|
||||
};
|
||||
|
||||
|
|
|
@ -52,4 +52,15 @@ describe("extractURLs", () => {
|
|||
"https://map.vault48.org/test5",
|
||||
]);
|
||||
});
|
||||
|
||||
it("skipps link description", () => {
|
||||
const result = extractURLs(
|
||||
`Trying out links: [#alias|map.vault48.org/test3|https://map.vault48.org/test] https://map.vault48.org/test2`
|
||||
).map((it) => it.href);
|
||||
|
||||
expect(result).toEqual([
|
||||
"https://map.vault48.org/test",
|
||||
"https://map.vault48.org/test2",
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -15,7 +15,7 @@ export const extractURLs = (text: string): URL[] => {
|
|||
text
|
||||
.match(weirdLongUrlRegex)
|
||||
?.forEach((match) =>
|
||||
urls.add(fixUrl(match.replace(weirdLongUrlRegex, "$2")))
|
||||
urls.add(fixUrl(match.replace(weirdLongUrlRegex, "$3")))
|
||||
);
|
||||
|
||||
text.match(simpleUrlRegex)?.forEach((match) => urls.add(match));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue