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

@ -4,6 +4,7 @@ import { VkService } from "../index";
import { TelegramService } from "../../telegram";
import { Template } from "../../template";
import { Storage } from "../../db";
import { Event } from "../../db/postgres/entities/Event";
export class VkEventHandler<
F extends Record<string, any> = any,
@ -46,4 +47,28 @@ export class VkEventHandler<
*/
protected makeDialogUrl = (groupId: number, userId: number): string =>
`https://vk.com/gim${groupId}?sel=${userId}`;
/**
* Checks for duplicates
*/
getEventFromDB = async (id?: number): Promise<Event | undefined> => {
if (!id) {
return undefined;
}
return await this.db.getEvent(this.type, id, this.group.id, this.channel);
};
/**
* Creates event record in DB
*/
storeInDB = async (id: number, tgMessageId: number) => {
return await this.db.createEvent(
this.type,
id,
this.group.id,
this.channel,
tgMessageId
);
};
}