From 1872544b5aea07d3ef49cad08983a78921f286f3 Mon Sep 17 00:00:00 2001 From: Redume Date: Fri, 6 Dec 2024 18:40:17 +0300 Subject: [PATCH] feat: setup channel for forward message --- commands/set_channel.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 commands/set_channel.py diff --git a/commands/set_channel.py b/commands/set_channel.py new file mode 100644 index 0000000..cd95492 --- /dev/null +++ b/commands/set_channel.py @@ -0,0 +1,24 @@ +from aiogram import Router +from aiogram.filters import Command +from aiogram.types import Message + +from database.database import pg_con + +router = Router() + +@router.message(Command('set_channel')) +async def set_channel(message: Message): + print(message) + args = message.text.split() + + if len(args) < 2: + return message.reply('Отсутствует ID канала (формат BOT API)') + + conn = await pg_con() + + data = await conn.fetchrow('SELECT channel_id FROM chat WHERE chat_id = $1', message.chat.id) + + if data[0] == args[1]: + return message.reply('Такой ID канала уже установлен') + + await conn.execute('UPDATE chat SET channel_id = $1 WHERE chat_id = $2 ', args[1], message.chat.id) \ No newline at end of file