mirror of
https://github.com/muerwre/vk-tg-bot.git
synced 2025-04-26 07:26:41 +07:00
#4 added simple DB layer
This commit is contained in:
parent
f3a746efe8
commit
c0588acd26
15 changed files with 476 additions and 11 deletions
|
@ -3,6 +3,7 @@ import { ConfigGroup, GroupInstance, VkEvent } from "../types";
|
|||
import { VkService } from "../index";
|
||||
import { TelegramService } from "../../telegram";
|
||||
import { Template } from "../../template";
|
||||
import { Storage } from "../../db";
|
||||
|
||||
export class VkEventHandler<
|
||||
F extends Record<string, any> = any,
|
||||
|
@ -15,7 +16,8 @@ export class VkEventHandler<
|
|||
protected instance: GroupInstance,
|
||||
protected vk: VkService,
|
||||
protected telegram: TelegramService,
|
||||
protected template: Template<F, V>
|
||||
protected template: Template<F, V>,
|
||||
protected db: Storage
|
||||
) {}
|
||||
|
||||
public execute: (
|
||||
|
|
|
@ -6,6 +6,7 @@ import { VkService } from "../index";
|
|||
import { TelegramService } from "../../telegram";
|
||||
import { Template } from "../../template";
|
||||
import { PostNewHandler } from "./PostNewHandler";
|
||||
import { Storage } from "../../db";
|
||||
|
||||
interface Handler {
|
||||
new (
|
||||
|
@ -15,7 +16,8 @@ interface Handler {
|
|||
instance: GroupInstance,
|
||||
vk: VkService,
|
||||
telegram: TelegramService,
|
||||
template: Template<any, any>
|
||||
template: Template<any, any>,
|
||||
db: Storage
|
||||
): VkEventHandler;
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ import { vkEventToHandler } from "./handlers";
|
|||
import { TelegramService } from "../telegram";
|
||||
import { Template } from "../template";
|
||||
import { TemplateConfig } from "../../config/types";
|
||||
import { Storage } from "../db";
|
||||
|
||||
/**
|
||||
* Service to handle VK to Telegram interactions
|
||||
|
@ -21,7 +22,8 @@ export class VkService {
|
|||
constructor(
|
||||
private config: VkConfig,
|
||||
private telegram: TelegramService,
|
||||
private templates: TemplateConfig
|
||||
private templates: TemplateConfig,
|
||||
private db: Storage
|
||||
) {
|
||||
if (!config.groups.length) {
|
||||
throw new Error("No vk groups to handle. Specify them in config");
|
||||
|
@ -122,7 +124,8 @@ export class VkService {
|
|||
instance,
|
||||
this,
|
||||
this.telegram,
|
||||
template
|
||||
template,
|
||||
this.db
|
||||
);
|
||||
return { ...acc, [event]: handler };
|
||||
}, {} as Record<VkEvent, VkEventHandler>[])
|
||||
|
|
|
@ -14,7 +14,7 @@ export interface ConfigGroup {
|
|||
channels: GroupChannel[];
|
||||
}
|
||||
|
||||
interface GroupChannel {
|
||||
export interface GroupChannel {
|
||||
id: string;
|
||||
events: VkEvent[];
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue