|
|
@ -26,9 +26,11 @@ init_bd_cmd = '''CREATE TABLE IF NOT EXISTS projects( |
|
|
|
# --------------------------------------------------------- |
|
|
|
# --------------------------------------------------------- |
|
|
|
# Сообщения |
|
|
|
# Сообщения |
|
|
|
|
|
|
|
|
|
|
|
select_project_message = ''' |
|
|
|
base_project_message = ''' |
|
|
|
<b>🛒 Проекты</b> |
|
|
|
<b>🛒 Проекты</b> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
''' |
|
|
|
|
|
|
|
select_project_message = ''' |
|
|
|
Пожалуйста, выберите проект: |
|
|
|
Пожалуйста, выберите проект: |
|
|
|
''' |
|
|
|
''' |
|
|
|
|
|
|
|
|
|
|
@ -43,6 +45,9 @@ project_open_message = ''' |
|
|
|
''' |
|
|
|
''' |
|
|
|
|
|
|
|
|
|
|
|
projects_button_name = "📰 Проекты" |
|
|
|
projects_button_name = "📰 Проекты" |
|
|
|
|
|
|
|
add_project_button_name = "📰 Добавить проект" |
|
|
|
|
|
|
|
del_project_button_name = "📰 Удалить проект" |
|
|
|
|
|
|
|
edit_project_button_name = "📰 Редактировать проект" |
|
|
|
|
|
|
|
|
|
|
|
# Префиксы |
|
|
|
# Префиксы |
|
|
|
select_project_callback_prefix = 'project:' |
|
|
|
select_project_callback_prefix = 'project:' |
|
|
@ -50,36 +55,47 @@ select_project_callback_prefix = 'project:' |
|
|
|
# --------------------------------------------------------- |
|
|
|
# --------------------------------------------------------- |
|
|
|
# Работа с кнопками |
|
|
|
# Работа с кнопками |
|
|
|
|
|
|
|
|
|
|
|
def GetStartKeyboardButtons(a_UserAccess): |
|
|
|
def GetEditProjectKeyboardButtons(a_UserAccess, a_ParentID): |
|
|
|
|
|
|
|
proj_buttons = [add_project_button_name, del_project_button_name, edit_project_button_name] |
|
|
|
mods = [start] |
|
|
|
mods = [start] |
|
|
|
return keyboard.MakeKeyboardForMods(mods, a_UserAccess) |
|
|
|
return keyboard.MakeKeyboard(keyboard.GetButtons(mods, a_UserAccess) + proj_buttons) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def GetProjectsListKeyboardButtons(a_UserAccess, a_ParentID): |
|
|
|
|
|
|
|
projects = GetProjectList(a_ParentID) |
|
|
|
|
|
|
|
projects_button_list = [] |
|
|
|
|
|
|
|
for t in projects: |
|
|
|
|
|
|
|
projects_button_list += [keyboard.Button(str(t[1]), t[4])] |
|
|
|
|
|
|
|
return keyboard.MakeInlineKeyboard(projects_button_list, select_project_callback_prefix) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def GetUserAccess(a_UserID): |
|
|
|
|
|
|
|
return None |
|
|
|
|
|
|
|
|
|
|
|
# --------------------------------------------------------- |
|
|
|
# --------------------------------------------------------- |
|
|
|
# Обработка сообщений |
|
|
|
# Обработка сообщений |
|
|
|
|
|
|
|
|
|
|
|
# Отображение всех проектов без родителя |
|
|
|
# Отображение всех проектов без родителя |
|
|
|
async def ProjectsOpen(a_Message): |
|
|
|
async def ProjectsOpen(a_Message, **kwargs): |
|
|
|
projects = GetProjectList(0) |
|
|
|
print('test', kwargs) |
|
|
|
projects_button_list = [] |
|
|
|
user_access = GetUserAccess(a_Message.from_user.id) |
|
|
|
for t in projects: |
|
|
|
await bot.send_message(a_Message.from_user.id, base_project_message, reply_markup = GetEditProjectKeyboardButtons(user_access, 0)) |
|
|
|
b = keyboard.Button(str(t[1]), t[4]) |
|
|
|
await bot.send_message(a_Message.from_user.id, select_project_message, reply_markup = GetProjectsListKeyboardButtons(user_access, 0)) |
|
|
|
await bot.send_message(a_Message.from_user.id, select_project_message, reply_markup=keyboard.MakeInlineKeyboard(projects_button_list, select_project_callback_prefix)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def ShowProject(a_CallbackQuery : types.CallbackQuery): |
|
|
|
async def ShowProject(a_CallbackQuery : types.CallbackQuery): |
|
|
|
project_id = str(a_CallbackQuery.data).replace(select_project_callback_prefix, '') |
|
|
|
project_id = str(a_CallbackQuery.data).replace(select_project_callback_prefix, '') |
|
|
|
|
|
|
|
user_access = GetUserAccess(a_CallbackQuery.from_user.id) |
|
|
|
project = GetProject(project_id) |
|
|
|
project = GetProject(project_id) |
|
|
|
if len(project) != 1: |
|
|
|
if len(project) != 1: |
|
|
|
log.Error(f'Проект не найден {project_id}') |
|
|
|
log.Error(f'Проект не найден {project_id}') |
|
|
|
msg = Ошибка.replace('@project_id', project_id) |
|
|
|
msg = Ошибка.replace('@project_id', project_id) |
|
|
|
await bot.send_message(a_CallbackQuery.from_user.id, msg, reply_markup=keyboard.MakeKeyboardForMods([start])) |
|
|
|
await bot.send_message(a_CallbackQuery.from_user.id, msg, reply_markup = GetEditProjectKeyboardButtons(user_access, project_id)) |
|
|
|
return |
|
|
|
return |
|
|
|
|
|
|
|
|
|
|
|
p = project[0] |
|
|
|
p = project[0] |
|
|
|
msg = project_open_message.replace('@proj_name', p[1]).replace('@proj_desk', p[2]) |
|
|
|
msg = project_open_message.replace('@proj_name', p[1]).replace('@proj_desk', p[2]) |
|
|
|
await bot.send_photo(a_CallbackQuery.from_user.id, p[0], msg, reply_markup=keyboard.MakeKeyboardForMods([start])) |
|
|
|
await bot.send_photo(a_CallbackQuery.from_user.id, p[0], msg, reply_markup = GetEditProjectKeyboardButtons(user_access, project_id)) |
|
|
|
|
|
|
|
|
|
|
|
# --------------------------------------------------------- |
|
|
|
# --------------------------------------------------------- |
|
|
|
# Работа с базой данных пользователей |
|
|
|
# Работа с базой данных проектов |
|
|
|
|
|
|
|
|
|
|
|
def GetProjectList(a_ParentID): |
|
|
|
def GetProjectList(a_ParentID): |
|
|
|
db = sqlite3.connect(bot_bd.GetBDFileName()) |
|
|
|
db = sqlite3.connect(bot_bd.GetBDFileName()) |
|
|
@ -92,7 +108,7 @@ def GetProjectList(a_ParentID): |
|
|
|
def GetProject(a_ProjectID): |
|
|
|
def GetProject(a_ProjectID): |
|
|
|
db = sqlite3.connect(bot_bd.GetBDFileName()) |
|
|
|
db = sqlite3.connect(bot_bd.GetBDFileName()) |
|
|
|
cursor = db.cursor() |
|
|
|
cursor = db.cursor() |
|
|
|
project = cursor.execute('SELECT * FROM categories WHERE catID = ?', ([catID])).fetchall() |
|
|
|
project = cursor.execute('SELECT * FROM projects WHERE projectID = ?', ([a_ProjectID])).fetchall() |
|
|
|
cursor.close() |
|
|
|
cursor.close() |
|
|
|
db.close() |
|
|
|
db.close() |
|
|
|
return project |
|
|
|
return project |
|
|
@ -112,3 +128,10 @@ def GetButtonNames(a_UserAccess): |
|
|
|
def RegisterHandlers(dp : Dispatcher): |
|
|
|
def RegisterHandlers(dp : Dispatcher): |
|
|
|
dp.register_message_handler(ProjectsOpen, text = projects_button_name) |
|
|
|
dp.register_message_handler(ProjectsOpen, text = projects_button_name) |
|
|
|
dp.register_callback_query_handler(ShowProject, lambda x: x.data.startswith(select_project_callback_prefix)) |
|
|
|
dp.register_callback_query_handler(ShowProject, lambda x: x.data.startswith(select_project_callback_prefix)) |
|
|
|
|
|
|
|
''' |
|
|
|
|
|
|
|
dp.register_message_handler(ProjectCreate, text = add_project_button_name) |
|
|
|
|
|
|
|
dp.register_message_handler(ProjectDelete, text = del_project_button_name) |
|
|
|
|
|
|
|
dp.register_callback_query_handler(catDelete, lambda x: x.data.startswith('delcat ')) |
|
|
|
|
|
|
|
dp.register_message_handler(ProjectPhotoLoad, content_types = ['photo'], state = FSMCreateCategory.catPhoto) |
|
|
|
|
|
|
|
dp.register_message_handler(ProjectNameLoad, state = FSMCreateCategory.catName) |
|
|
|
|
|
|
|
dp.register_message_handler(ProjectDescLoad, state = FSMCreateCategory.catDesc)''' |
|
|
|