Add add_user method

This commit is contained in:
LoRiot 2022-10-16 16:30:57 +03:00
parent 77b949730e
commit 4730fb646b
2 changed files with 16 additions and 3 deletions

View file

@ -1,12 +1,18 @@
from loguru import logger
from aiogram import types, Dispatcher
from services.repository import Repo
async def create_project(message: types.Message):
async def request_invite(message: types.Message, repo: Repo):
await repo.add_user(message.from_user.id, message.chat.id)
logger.debug(f"Added new user {message.from_user.full_name}")
bot_info = await message.bot.get_me()
await message.reply(
f"Перейдите в лс к боту @{bot_info.username}"
f"Чтобы создать Ваш проект, перейдите в лс к боту @{bot_info.username}"
)
def register_command_handlers(dp: Dispatcher):
dp.register_message_handler(create_project, commands="create_project")
dp.register_message_handler(request_invite, commands="inviteme")

View file

@ -6,3 +6,10 @@ class Repo:
def __init__(self, conn: Connection):
self.conn = conn
async def add_user(self, user_id: int, chat_id: int):
await self.conn.execute(
"INSERT INTO users (user_id, chat_id) "
"VALUES ($1, $2) ON CONFLICT (user_id) DO NOTHING",
user_id, chat_id
)