New features
This commit is contained in:
parent
7abdf589aa
commit
63afce795e
3
.gitignore
vendored
3
.gitignore
vendored
@ -13,4 +13,5 @@ __pycache__/
|
||||
!dist.env
|
||||
venv/
|
||||
test.py
|
||||
departed
|
||||
departed
|
||||
.idea
|
14
filters/operator.py
Normal file
14
filters/operator.py
Normal file
@ -0,0 +1,14 @@
|
||||
from aiogram.types import Message
|
||||
from aiogram.dispatcher.filters import BoundFilter
|
||||
|
||||
from utils.database.base import get_operator
|
||||
|
||||
|
||||
class IsOperator(BoundFilter):
|
||||
key = 'is_operator'
|
||||
|
||||
def __init__(self, is_operator):
|
||||
self.is_operator = is_operator
|
||||
|
||||
async def check(self, message: Message):
|
||||
return message.from_user.id in get_operator()
|
1
handlers/callback/operator/__init__.py
Normal file
1
handlers/callback/operator/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
from . import support
|
13
handlers/callback/operator/support.py
Normal file
13
handlers/callback/operator/support.py
Normal file
@ -0,0 +1,13 @@
|
||||
from aiogram import types
|
||||
from aiogram.dispatcher import FSMContext
|
||||
|
||||
from load import dp
|
||||
|
||||
|
||||
@dp.callback_query_handler(lambda x: x.data.split("|")[0] == "support")
|
||||
async def support(callback: types.CallbackQuery, state: FSMContext):
|
||||
user_id = int(callback.data.split("|")[1])
|
||||
support_id = int(callback.data.split("|")[2])
|
||||
await callback.answer()
|
||||
await state.set_state(state="wait_for_support_message")
|
||||
await state.update_data(support_id=support_id, user_id=user_id)
|
1
handlers/operator/__init__.py
Normal file
1
handlers/operator/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
from . import start
|
24
handlers/operator/start.py
Normal file
24
handlers/operator/start.py
Normal file
@ -0,0 +1,24 @@
|
||||
from aiogram import types
|
||||
|
||||
from load import dp, bot, messages
|
||||
from keyboard.default.operator.main_menu import main_menu
|
||||
from keyboard.default.main_menu import back_to_main_menu
|
||||
from utils.database.user import User
|
||||
|
||||
|
||||
@dp.message_handler(lambda x: x.text == messages.operator_panel, is_operator=True)
|
||||
async def cmd_menu(message: types.Message):
|
||||
active = User.get_state(message.from_user.id)
|
||||
await bot.send_message(message.chat.id, "Operator panel", reply_markup=main_menu(active))
|
||||
|
||||
|
||||
@dp.message_handler(lambda x: x.text == messages.leave_work)
|
||||
async def leave_work(message: types.Message):
|
||||
User.set_state(message.from_user.id)
|
||||
await bot.send_message(message.chat.id, "Режим тех. поддержки отключён!", reply_markup=back_to_main_menu)
|
||||
|
||||
|
||||
@dp.message_handler(lambda x: x.text == messages.on_work)
|
||||
async def on_work(message: types.Message):
|
||||
User.set_state(message.from_user.id, True)
|
||||
await bot.send_message(message.chat.id, "Режим тех. поддержки включён!", reply_markup=back_to_main_menu)
|
43
handlers/user/support.py
Normal file
43
handlers/user/support.py
Normal file
@ -0,0 +1,43 @@
|
||||
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"])
|
0
keyboard/default/operator/__init__.py
Normal file
0
keyboard/default/operator/__init__.py
Normal file
12
keyboard/default/operator/main_menu.py
Normal file
12
keyboard/default/operator/main_menu.py
Normal file
@ -0,0 +1,12 @@
|
||||
from aiogram.types.reply_keyboard import ReplyKeyboardMarkup, KeyboardButton
|
||||
|
||||
from load import messages
|
||||
|
||||
|
||||
def main_menu(active: bool = False) -> ReplyKeyboardMarkup:
|
||||
markup = ReplyKeyboardMarkup(resize_keyboard=True)
|
||||
if active:
|
||||
markup.add(KeyboardButton(messages.leave_work))
|
||||
else:
|
||||
markup.add(KeyboardButton(messages.on_work))
|
||||
return markup
|
7
keyboard/inline/operator/support.py
Normal file
7
keyboard/inline/operator/support.py
Normal file
@ -0,0 +1,7 @@
|
||||
from aiogram.types.inline_keyboard import InlineKeyboardMarkup, InlineKeyboardButton
|
||||
|
||||
|
||||
def answer_btn(user_id: int, supp_id: int):
|
||||
markup = InlineKeyboardMarkup()
|
||||
markup.add(InlineKeyboardButton("Ответить", callback_data=f'support|{user_id}|{supp_id}'))
|
||||
return markup
|
6
state/support.py
Normal file
6
state/support.py
Normal file
@ -0,0 +1,6 @@
|
||||
from aiogram.dispatcher.filters.state import StatesGroup, State
|
||||
|
||||
|
||||
class Support(StatesGroup):
|
||||
support_id = State()
|
||||
user_id = State()
|
Loading…
Reference in New Issue
Block a user