mirror of
https://github.com/muerwre/vk-tg-bot.git
synced 2025-04-25 15:06:41 +07:00
added calendar service
This commit is contained in:
parent
0b663fb96f
commit
6e34090f8f
31 changed files with 1359 additions and 200 deletions
|
@ -23,4 +23,7 @@ export const defaultConfig: Config = {
|
|||
group_join: "templates/group_join.md",
|
||||
group_leave: "templates/group_leave.md",
|
||||
},
|
||||
calendar: {
|
||||
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
|
||||
},
|
||||
};
|
||||
|
|
|
@ -6,6 +6,10 @@ import { validateConfig } from "./validate";
|
|||
import { getCmdArg } from "../utils/args";
|
||||
import { defaultConfig } from "./default";
|
||||
import { merge } from "lodash";
|
||||
import {
|
||||
CalendarKeyFile,
|
||||
calendarKeyValidator,
|
||||
} from "../service/calendar/config";
|
||||
|
||||
const configPath = getCmdArg("config");
|
||||
const data = fs.readFileSync(
|
||||
|
@ -21,6 +25,18 @@ const config =
|
|||
export default function prepareConfig() {
|
||||
validateConfig(config);
|
||||
|
||||
if (config.calendar?.keyFile) {
|
||||
try {
|
||||
const key = JSON.parse(
|
||||
fs.readFileSync(config.calendar?.keyFile).toString()
|
||||
) as CalendarKeyFile;
|
||||
calendarKeyValidator.validateSync(key);
|
||||
config.calendarKey = key;
|
||||
} catch (error) {
|
||||
console.warn("tried to parse calendar key, got error", error);
|
||||
}
|
||||
}
|
||||
|
||||
config.telegram.templates = {
|
||||
help: config.templates.help,
|
||||
help_admin: config.templates.help_admin,
|
||||
|
|
|
@ -3,6 +3,7 @@ import { VkConfig, VkEvent } from "../service/vk/types";
|
|||
import { HttpConfig } from "../api/http/types";
|
||||
import { LoggerConfig } from "../service/logger/types";
|
||||
import { PostgresConfig } from "../service/db/postgres/types";
|
||||
import { CalendarConfig, CalendarKeyFile } from "src/service/calendar/config";
|
||||
|
||||
export type TemplateConfig = Record<VkEvent, string> &
|
||||
Partial<Record<"help" | "help_admin", string>>;
|
||||
|
@ -14,4 +15,6 @@ export interface Config extends Record<string, any> {
|
|||
logger: LoggerConfig;
|
||||
templates: TemplateConfig;
|
||||
postgres: PostgresConfig;
|
||||
calendar?: Partial<CalendarConfig>;
|
||||
calendarKey?: CalendarKeyFile;
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import { vkConfigSchema } from "../service/vk/validation";
|
|||
import { telegramConfigSchema } from "../service/telegram/validation";
|
||||
import { loggerConfigSchema } from "../service/logger/config";
|
||||
import { dbConfigValidatior } from "../service/db/postgres/validation";
|
||||
import { calendarConfigValidator } from "../service/calendar/config";
|
||||
|
||||
export const templateConfigSchema = object().required().shape({
|
||||
message_new: string().required(),
|
||||
|
@ -29,6 +30,7 @@ const configSchema = object<Config>().required().shape({
|
|||
logger: loggerConfigSchema,
|
||||
templates: templateConfigSchema,
|
||||
postgres: dbConfigValidatior,
|
||||
calendar: calendarConfigValidator.optional(),
|
||||
});
|
||||
|
||||
export const validateConfig = (config: Config) =>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue