44 lines
1.7 KiB
Python
44 lines
1.7 KiB
Python
|
import random
|
||
|
|
||
|
from aiogram import types
|
||
|
from aiogram.dispatcher import FSMContext
|
||
|
|
||
|
from load import dp, bot, messages
|
||
|
from keyboard.default.admin.main_menu import base_menu
|
||
|
from keyboard.inline.operator.support import answer_btn
|
||
|
from state.support import Support
|
||
|
from utils.database.base import get_active_operator
|
||
|
|
||
|
|
||
|
@dp.message_handler(commands='sos')
|
||
|
async def support(message: types.Message):
|
||
|
await bot.send_message(message.chat.id, 'Напишите сообщение', reply_markup=base_menu())
|
||
|
await Support.support_id.set()
|
||
|
|
||
|
|
||
|
@dp.message_handler(state=Support.support_id, content_types=types.ContentTypes.ANY)
|
||
|
async def send_msg(message: types.Message, state: FSMContext):
|
||
|
operators = get_active_operator()
|
||
|
if not operators:
|
||
|
await bot.send_message(message.chat.id, "Нет свободных операторов:(\nПовторите попытку позже!")
|
||
|
support_id = random.choice(operators)
|
||
|
await state.update_data(user_id=message.from_user.id, support_id=support_id)
|
||
|
await bot.send_message(
|
||
|
support_id,
|
||
|
messages.admin_user.format(
|
||
|
user_id=message.from_user.id,
|
||
|
first_name=message.from_user.first_name,
|
||
|
last_name=message.from_user.last_name,
|
||
|
username=message.from_user.username
|
||
|
),
|
||
|
parse_mode="Markdown"
|
||
|
)
|
||
|
await message.send_copy(support_id, reply_markup=answer_btn(message.from_user.id, support_id))
|
||
|
|
||
|
|
||
|
@dp.message_handler(state="wait_for_support_message", content_types=types.ContentTypes.ANY)
|
||
|
async def support_answer(message: types.Message, state: FSMContext):
|
||
|
data = await state.get_data()
|
||
|
await bot.send_message(data['user_id'], "Вам пришёл ответ от оператора!")
|
||
|
await message.copy_to(data["user_id"])
|