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