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

added templaters

This commit is contained in:
Fedor Katurov 2021-04-28 15:51:59 +07:00
parent 1754092f7c
commit d5228ef146
13 changed files with 406 additions and 17 deletions

View file

@ -7,13 +7,19 @@ import { NextFunction } from "connect";
import { VkEventHandler } from "./handlers/VkEventHandler";
import { vkEventToHandler } from "./handlers";
import { TelegramService } from "../telegram";
import { Template } from "../template";
import { TemplateConfig } from "../../config/types";
export class VkService {
public endpoint: string = "/";
private readonly instances: Record<string, GroupInstance>;
private readonly groups: Record<number, ConfigGroup>;
constructor(private config: VkConfig, private telegram: TelegramService) {
constructor(
private config: VkConfig,
private telegram: TelegramService,
private templates: TemplateConfig
) {
if (!config.groups.length) {
throw new Error("No vk groups to handle. Specify them in config");
}
@ -101,11 +107,15 @@ export class VkService {
return flatten(
group.channels.map((chan) =>
chan.events.reduce((acc, event) => {
const handler = new (vkEventToHandler as any)[event](
const template = new Template(this.templates[event]);
const handler = new vkEventToHandler[event](
event,
group,
instance,
this,
this.telegram
this.telegram,
template
);
return { ...acc, [event]: handler };
}, {} as Record<VkEvent, VkEventHandler>[])