1
0
Fork 0
mirror of https://github.com/muerwre/vk-tg-bot.git synced 2025-04-25 06:56:40 +07:00

#4 added duplicate check for wall_post_new

This commit is contained in:
Fedor Katurov 2021-05-04 14:58:39 +07:00
parent e73ab3cb4f
commit f75e3068a0
8 changed files with 75 additions and 16 deletions

View file

@ -41,14 +41,26 @@ export class PostNewHandler extends VkEventHandler<Fields, Values> {
private likes: string[] = ["👎", "👍"];
public execute = async (context: WallPostContext, next: NextMiddleware) => {
const id = context?.wall?.id;
if (
context.isRepost ||
!PostNewHandler.isValidPostType(context?.wall?.postType)
!PostNewHandler.isValidPostType(context?.wall?.postType) ||
!id
) {
await next();
return;
}
const exist = await this.getEventFromDB(id);
if (exist) {
logger.warn(
`received duplicate entry for ${this.group.name}, ${this.type}, ${id}`
);
await next();
return;
}
const user = context.wall.signerId
? await this.getUserByID(String(context.wall.signerId))
: undefined;
@ -67,7 +79,13 @@ export class PostNewHandler extends VkEventHandler<Fields, Values> {
this.appendExtras(extras, text);
await this.telegram.sendMessageToChan(this.channel, parsed, extras);
const msg = await this.telegram.sendMessageToChan(
this.channel,
parsed,
extras
);
await this.storeInDB(id, msg.message_id);
await next();
};