async def start_message(message: types.Message): user = user_db.sql_init_user(message.from_user.id) username = message.from_user.username user_id = message.from_user.id keyboard = types.ReplyKeyboardMarkup(resize_keyboard=True) if user: check_name = user_db.sql_show_users() if check_name[0][1] == 'None': user_db.sql_update_name(username, user_id) if user['admin']: message_text = 'Ты являешься администратором' await message.answer(message_text, reply_markup=keyboard) await main_menu(message) else: message_text = 'Привет, ' + username + '!\n\n' \ + 'Набери " / " для отображения списка доступных команд или выбери из меню ⤵️' await message.answer_sticker( 'CAACAgIAAxkBAAECBF1gS6rbgBgyt_5c6ytFs8rjLhNQ3QACKAMAArVx2gaQekqHXpVKbh4E' ) await message.answer(message_text, reply_markup=keyboard) await main_menu(message) else: message_text = 'Извини, я закрытый бот. Пока работаю для одной компании, но я еще выйду в свет!' \ '\nЕсть вопросы? Обратись к @janki_wtf' await message.answer(message_text, reply_markup=types.ReplyKeyboardRemove())
async def setup_menu(message: types.Message): user = user_db.sql_init_user(message.from_user.id) if user['verif']: keyboard = types.ReplyKeyboardMarkup(resize_keyboard=True) cancel_but = types.KeyboardButton(text='Отмена') keyboard.add('Авто-обновление ➔') keyboard.add(cancel_but) await message.answer('Настройки:', reply_markup=keyboard)
async def add_user(message: types.Message): user = user_db.sql_init_user(message.from_user.id) if user['admin']: keyboard = types.ReplyKeyboardMarkup(resize_keyboard=True) cancel_but = types.KeyboardButton(text='Back') keyboard.add(cancel_but) await SelectMenu.waiting_add_user.set() await message.answer("Enter user's id:", reply_markup=keyboard)
async def admin_menu(message: types.Message): user = user_db.sql_init_user(message.from_user.id) if user['admin']: keyboard = types.ReplyKeyboardMarkup(resize_keyboard=True) cancel_but = types.KeyboardButton(text='Back') keyboard.add(cancel_but) for command in commands_admin: keyboard.add(command) await message.answer('Admin commands:', reply_markup=keyboard)
async def type_delete_menu(message: types.Message): await clean_spam(message, 2) user = user_db.sql_init_user(message.from_user.id) if user['verif']: keyboard = types.ReplyKeyboardMarkup(resize_keyboard=True) cancel_but = types.KeyboardButton(text='Отмена') for butt in type_delete: keyboard.add(butt) keyboard.add(cancel_but) await message.answer('Выбери способ удаления:', reply_markup=keyboard)
async def show_users(message: types.Message): user = user_db.sql_init_user(message.from_user.id) if user['admin']: if url_db.sql_count_keys() != 0: db_users = user_db.sql_show_users() await message.answer('Registered users (%s):' % user_db.sql_count_users()) await message.answer(db_users) else: await message.answer('No registered users')
async def main_menu(message: types.Message): user = user_db.sql_init_user(message.from_user.id) # message_id = message.message_id # await bot.delete_message(message.chat.id, message_id) if user['verif']: keyboard = types.ReplyKeyboardMarkup(resize_keyboard=True) keyboard.add(commands_main[0], commands_main[1]) keyboard.add(commands_main[2], commands_main[3]) if user['admin']: keyboard.add(commands_main[4]) await message.answer('Меню:', reply_markup=keyboard)
async def delete_all_keys(message: types.Message): user = user_db.sql_init_user(message.from_user.id) if user['verif']: keyboard = types.ReplyKeyboardMarkup(resize_keyboard=True) buttons = ['Да', 'Отмена'] if url_db.sql_count_keys() != 0: await SelectMenu.waiting_del_all_links.set() keyboard.add(*buttons) await message.answer('Ты действительно хочешь удалить все дела?', reply_markup=keyboard) else: await message.answer('Нет отслеживаемых дел')
async def delete_key_by_link(message: types.Message): user = user_db.sql_init_user(message.from_user.id) if user['verif']: if url_db.sql_count_keys() != 0: keyboard = types.ReplyKeyboardMarkup(resize_keyboard=True) cancel_but = types.KeyboardButton(text='Отмена') keyboard.add(cancel_but) await message.answer('Введи ссылку на дело:', reply_markup=keyboard) await SelectMenu.waiting_sel_key_link.set() else: await message.answer('Нет отслеживаемых дел')
async def add_key(message: types.Message): await clean_spam(message, 1) user = user_db.sql_init_user(message.from_user.id) if user['verif']: try: keyboard = types.ReplyKeyboardMarkup(resize_keyboard=True) cancel_but = types.KeyboardButton(text='Отмена') keyboard.add(cancel_but) await SelectMenu.waiting_add_key.set() await message.answer('Укажи ссылку на дело:', reply_markup=keyboard) except Exception: await message.answer( 'Произошла внутренняя ошибка. Повтори запрос.\n' 'Если ошибка повторится, обратись к администратору')
async def get_user(message: types.Message, state: FSMContext): user_id = message.text if user_id.lower() == 'back': await admin_menu(message) await state.finish() elif user_id.isdigit(): user = user_db.sql_init_user(user_id) if user is False: user_db.sql_new_user(user_id) await message.reply('User is added') await admin_menu(message) await state.finish() else: await message.reply('Error! User is already added') else: await message.reply('Error! User is not added')
async def delete_key(message: types.Message): user = user_db.sql_init_user(message.from_user.id) if user['verif']: if url_db.sql_count_keys() != 0: keyboard = types.ReplyKeyboardMarkup(resize_keyboard=True) cancel_but = types.KeyboardButton(text='Отмена') for key in url_db.sql_show_party(): row_key = types.KeyboardButton(text=str(key[0])) keyboard.add(row_key) keyboard.add(cancel_but) await message.answer('Отслеживаемые дела (%s)' '\nВыбери, что хочешь удалить:' % url_db.sql_count_keys(), reply_markup=keyboard) await SelectMenu.waiting_sel_link.set() else: await message.answer('Нет отслеживаемых дел')
async def show_party(message: types.Message): await clean_spam(message, 1) user = user_db.sql_init_user(message.from_user.id) if user['verif']: if url_db.sql_count_keys() != 0: keyboard = types.ReplyKeyboardMarkup(resize_keyboard=True) cancel_but = types.KeyboardButton(text='Отмена') for key in url_db.sql_show_party(): row_key = types.KeyboardButton(text=str(key[0])) keyboard.add(row_key) keyboard.add(cancel_but) await message.answer( f'Отслеживаемые дела {url_db.sql_count_keys()}:', reply_markup=keyboard) else: await message.answer('Нет отслеживаемых дел') await SelectMenu.waiting_show_party.set()