From cf2e3c99ded0f48bd565858aedc7f10a0d932a61 Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Sun, 18 Apr 2021 20:10:34 +0300 Subject: Add db connection --- src/middleware.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/middleware.ts') diff --git a/src/middleware.ts b/src/middleware.ts index e2814e0..9aa0775 100644 --- a/src/middleware.ts +++ b/src/middleware.ts @@ -1,10 +1,13 @@ import { Context } from "telegraf"; -import config from "./config"; +import { getPermittedUsers } from "./db"; const auth = async (ctx: Context, next: () => Promise): Promise => { const userId = ctx.message?.from.id; - if (!userId || !config.tgUserIds.includes(userId)) { + const tgUsers = await getPermittedUsers(); + const tgUserIds = tgUsers.map(u => u.id); + + if (!userId || !tgUserIds.includes(userId)) { ctx.reply("Käyttäjälläsi ei ole oikeuksia startata HommaBottia."); } else { await next(); -- cgit v1.3