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

improve vscode launching

This commit is contained in:
Fedor Katurov 2023-12-30 12:34:13 +07:00
parent 4bc8b89b78
commit 31af4e11b1
10 changed files with 252 additions and 76 deletions

24
src/config/default.ts Normal file
View file

@ -0,0 +1,24 @@
import { Config } from "./types";
export const defaultConfig: Config = {
http: { port: 80 },
telegram: {
owners: [],
key: "",
webhook: { url: "", enabled: false },
},
postgres: {
uri: "postgres://user:password@db/bot",
},
logger: { level: "info" },
vk: {
endpoint: "/",
groups: [],
},
templates: {
message_new: "templates/message_new.md",
wall_post_new: "templates/post_new.md",
group_join: "templates/group_join.md",
group_leave: "templates/group_leave.md",
},
};

View file

@ -2,20 +2,21 @@ import yaml from "js-yaml";
import fs from "fs";
import path from "path";
import { Config } from "./types";
import { mergeRight } from "ramda";
import { validateConfig } from "./validate";
import { getCmdArg } from "../utils/args";
import { defaultConfig } from "./default";
import { merge } from "lodash";
const configPath = getCmdArg("config");
const defaultConfig = yaml.load<Config>(
fs.readFileSync(path.join(__dirname, "../config.example.yml"), "utf8")
);
const userConfig = yaml.load<Config>(
fs.readFileSync(configPath || path.join(__dirname, "../config.yml"), "utf8")
const data = fs.readFileSync(
configPath || path.join(__dirname, "../config.yml"),
"utf8"
);
const userConfig = yaml.load(data) as Config;
const config =
(userConfig && mergeRight(defaultConfig, userConfig)) || defaultConfig;
(userConfig && merge(defaultConfig, userConfig)) || defaultConfig;
export default function prepareConfig() {
validateConfig(config);

View file

@ -1,6 +1,6 @@
import { createLogger, format, transports } from "winston";
import prepareConfig from "../../config";
import { keys } from "ramda";
import { keys } from "lodash";
const config = prepareConfig();

View file

@ -38,11 +38,14 @@ export class Template<
.use(removeFrontmatter)
.use(parser);
this.file = toVFile.readSync(path.join(__dirname, "../../", filename));
const dir =
process.env.NODE_ENV === "development" ? "../../../" : "../../";
this.file = toVFile.readSync(path.join(__dirname, dir, filename));
const result = processor.processSync(this.file);
this.fields = result.data as F;
} catch (e) {
throw new Error(`Template: ${e.toString()}`);
throw new Error(`Template: ${e?.toString()}`);
}
}

View file

@ -7,17 +7,16 @@ import { ExtraReplyMessage } from "telegraf/typings/telegram-types";
import {
InlineKeyboardButton,
InlineKeyboardMarkup,
Message,
Update,
User,
} from "typegram";
import { keys } from "ramda";
import { keys } from "lodash";
import { extractURLs } from "../../../utils/extract";
import logger from "../../logger";
import Composer from "telegraf";
import CallbackQueryUpdate = Update.CallbackQueryUpdate;
import { Template } from "../../template";
import { getAttachment } from "../../../utils/attachment";
import CallbackQueryUpdate = Update.CallbackQueryUpdate;
type Button = "links" | "likes" | "more";
type UrlPrefix = string;

View file

@ -66,7 +66,7 @@ export class VkService {
await this.db.insertRequest(body);
if (!groupId || !has(groupId, groups) || !has(groupId, this.instances)) {
logger.warn(`vk received unknown call`, { body });
logger.warn(`vk received unknown call`, body);
res.sendStatus(200);
return;
}