add black format
This commit is contained in:
parent
7376de2d13
commit
5bc3eda39b
2
bot.py
2
bot.py
|
@ -38,5 +38,5 @@ async def main():
|
||||||
await bot_session.close()
|
await bot_session.close()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == "__main__":
|
||||||
asyncio.run(main())
|
asyncio.run(main())
|
||||||
|
|
|
@ -5,9 +5,7 @@ from asyncpg.connection import Connection
|
||||||
|
|
||||||
|
|
||||||
async def drop_tables(connection: Connection):
|
async def drop_tables(connection: Connection):
|
||||||
await connection.execute(
|
await connection.execute("DROP TABLE users, tags, categories, projects CASCADE")
|
||||||
"DROP TABLE users, tags, categories, projects CASCADE"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
|
@ -17,5 +15,5 @@ async def main():
|
||||||
await connection.close()
|
await connection.close()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == "__main__":
|
||||||
asyncio.run(main())
|
asyncio.run(main())
|
||||||
|
|
|
@ -52,5 +52,5 @@ async def main():
|
||||||
await connection.close()
|
await connection.close()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == "__main__":
|
||||||
asyncio.run(main())
|
asyncio.run(main())
|
||||||
|
|
|
@ -11,14 +11,12 @@ async def start(message: types.Message, repo: Repos):
|
||||||
await message.answer(
|
await message.answer(
|
||||||
"Добро пожаловать в Бота Теплицы Социальных Технологий "
|
"Добро пожаловать в Бота Теплицы Социальных Технологий "
|
||||||
"для организации антивоенных проектов.",
|
"для организации антивоенных проектов.",
|
||||||
reply_markup=default_kb
|
reply_markup=default_kb,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def request_invite(message: types.Message, repo: Repos):
|
async def request_invite(message: types.Message, repo: Repos):
|
||||||
await repo.get_repo(UserRepo).add(
|
await repo.get_repo(UserRepo).add(message.from_user.id, message.chat.id)
|
||||||
message.from_user.id, message.chat.id
|
|
||||||
)
|
|
||||||
logger.debug(f"Added new user {message.from_user.full_name}")
|
logger.debug(f"Added new user {message.from_user.full_name}")
|
||||||
|
|
||||||
bot_info = await message.bot.get_me()
|
bot_info = await message.bot.get_me()
|
||||||
|
|
|
@ -11,9 +11,7 @@ from states.project import ProjectStates
|
||||||
from services.repositories import Repos, ProjectRepo
|
from services.repositories import Repos, ProjectRepo
|
||||||
|
|
||||||
|
|
||||||
async def create_project(
|
async def create_project(message: types.Message, state: FSMContext):
|
||||||
message: types.Message, state: FSMContext
|
|
||||||
):
|
|
||||||
await state.set_state(ProjectStates.set_fields)
|
await state.set_state(ProjectStates.set_fields)
|
||||||
await message.reply(
|
await message.reply(
|
||||||
"Название проекта: Превращение песиков в котиков\n\n"
|
"Название проекта: Превращение песиков в котиков\n\n"
|
||||||
|
@ -33,14 +31,14 @@ async def create_project(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def get_project_fields(
|
async def get_project_fields(message: types.Message, repo: Repos, state: FSMContext):
|
||||||
message: types.Message, repo: Repos, state: FSMContext
|
|
||||||
):
|
|
||||||
# TODO: для тегов и категорий вытаскивать из таблиц индексы,
|
# TODO: для тегов и категорий вытаскивать из таблиц индексы,
|
||||||
# значением для creator должен быть user_id.
|
# значением для creator должен быть user_id.
|
||||||
field_patterns = {
|
field_patterns = {
|
||||||
"Название проекта": str, "Описание": str, "Кол-во участников": int,
|
"Название проекта": str,
|
||||||
"Статус": BitString
|
"Описание": str,
|
||||||
|
"Кол-во участников": int,
|
||||||
|
"Статус": BitString,
|
||||||
}
|
}
|
||||||
field_values = []
|
field_values = []
|
||||||
|
|
||||||
|
@ -59,6 +57,4 @@ async def get_project_fields(
|
||||||
|
|
||||||
def register_projects_handlers(dp: Dispatcher):
|
def register_projects_handlers(dp: Dispatcher):
|
||||||
dp.register_message_handler(create_project, Text("Создать проект"))
|
dp.register_message_handler(create_project, Text("Создать проект"))
|
||||||
dp.register_message_handler(
|
dp.register_message_handler(get_project_fields, state=ProjectStates.set_fields)
|
||||||
get_project_fields, state=ProjectStates.set_fields
|
|
||||||
)
|
|
||||||
|
|
|
@ -2,8 +2,9 @@ from aiogram.types import ReplyKeyboardMarkup
|
||||||
|
|
||||||
|
|
||||||
default_kb = ReplyKeyboardMarkup(
|
default_kb = ReplyKeyboardMarkup(
|
||||||
resize_keyboard=True, keyboard=[
|
resize_keyboard=True,
|
||||||
|
keyboard=[
|
||||||
["Мои проекты", "Создать проект"],
|
["Мои проекты", "Создать проект"],
|
||||||
["Помощь"],
|
["Помощь"],
|
||||||
]
|
],
|
||||||
)
|
)
|
||||||
|
|
|
@ -8,7 +8,7 @@ class BaseRepo:
|
||||||
self.conn = conn
|
self.conn = conn
|
||||||
|
|
||||||
|
|
||||||
T = TypeVar('T', bound=BaseRepo)
|
T = TypeVar("T", bound=BaseRepo)
|
||||||
|
|
||||||
|
|
||||||
class Repos(BaseRepo):
|
class Repos(BaseRepo):
|
||||||
|
@ -21,7 +21,8 @@ class UserRepo(BaseRepo):
|
||||||
await self.conn.execute(
|
await self.conn.execute(
|
||||||
"INSERT INTO users (user_id, chat_id) "
|
"INSERT INTO users (user_id, chat_id) "
|
||||||
"VALUES ($1, $2) ON CONFLICT (user_id) DO NOTHING",
|
"VALUES ($1, $2) ON CONFLICT (user_id) DO NOTHING",
|
||||||
user_id, chat_id
|
user_id,
|
||||||
|
chat_id,
|
||||||
)
|
)
|
||||||
|
|
||||||
async def get(self, user_id: int):
|
async def get(self, user_id: int):
|
||||||
|
@ -36,11 +37,12 @@ class ProjectRepo(BaseRepo):
|
||||||
"INSERT INTO projects "
|
"INSERT INTO projects "
|
||||||
"(name, description, contributors, status) "
|
"(name, description, contributors, status) "
|
||||||
"VALUES ($1, $2, $3, $4)",
|
"VALUES ($1, $2, $3, $4)",
|
||||||
name, description, *args
|
name,
|
||||||
|
description,
|
||||||
|
*args
|
||||||
)
|
)
|
||||||
|
|
||||||
async def get(self, user_id: int):
|
async def get(self, user_id: int):
|
||||||
return await self.conn.fetchval(
|
return await self.conn.fetchval(
|
||||||
"SELECT name, description FROM projects WHERE creator = $1",
|
"SELECT name, description FROM projects WHERE creator = $1", user_id
|
||||||
user_id
|
|
||||||
)
|
)
|
||||||
|
|
Reference in a new issue