-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dev
- Loading branch information
Showing
73 changed files
with
949 additions
and
532 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,21 @@ | ||
from app.bot.callback_data.cancel_callback_factory import CancelCallbackFactory | ||
from app.bot.callback_data.main_menu_callback_factory import MainMenuCallbackFactory | ||
from app.bot.callback_data.result_callback_factory import ResultCallbackFactory | ||
from app.bot.callback_data.select_image_callback_factory import SelectImageCallbackFactory | ||
from app.bot.callback_data.subscription_buy_callback_factory import SubscriptionBuyCallbackFactory | ||
from app.bot.callback_data.sudscription_callback_factory import SubscriptionCallbackFactory | ||
from app.bot.callback_data.result_callback_factory import ResultFeedbackCallbackFactory | ||
from app.bot.callback_data.select_image_callback_factory import ( | ||
SelectImageCallbackFactory, | ||
) | ||
from app.bot.callback_data.subscription_buy_callback_factory import ( | ||
SubscriptionBuyCallbackFactory, | ||
) | ||
from app.bot.callback_data.sudscription_callback_factory import ( | ||
SubscriptionCallbackFactory, | ||
) | ||
|
||
__all__ = [ | ||
"MainMenuCallbackFactory", | ||
"SubscriptionBuyCallbackFactory", | ||
"SubscriptionCallbackFactory", | ||
"CancelCallbackFactory", | ||
"SelectImageCallbackFactory", | ||
"ResultCallbackFactory", | ||
"ResultFeedbackCallbackFactory", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
from aiogram.filters.callback_data import CallbackData | ||
|
||
|
||
class ResultCallbackFactory(CallbackData, prefix="result"): | ||
class ResultFeedbackCallbackFactory(CallbackData, prefix="result"): | ||
action: str | ||
message_id: int |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
|
||
class SelectImageCallbackFactory(CallbackData, prefix="select_image"): | ||
index: int | ||
message_id: int |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,85 +1,89 @@ | ||
import logging | ||
|
||
from aiogram import Router, F | ||
from aiogram.fsm.context import FSMContext | ||
from aiogram.types import Message, CallbackQuery | ||
from i18next import trans | ||
from i18next import trans as t | ||
|
||
from app.bot.callback_data import MainMenuCallbackFactory | ||
from app.bot.keyboards import create_cancel_menu | ||
from app.bot.states import AdminStates | ||
from app.bot.utils.callback_utils import get_username_from_callback | ||
from app.bot.utils.message_utils import get_username_from_message | ||
from app.service import user_service, UserAlreadyBannedException, UserNotBannedException | ||
|
||
router = Router(name="admin") | ||
logger = logging.getLogger("admin_callbacks") | ||
|
||
|
||
@router.callback_query(MainMenuCallbackFactory.filter(F.action == "ban_user")) | ||
async def ban_user(callback: CallbackQuery, state: FSMContext): | ||
logger.info(f"{get_username_from_callback(callback)}: Start ban user") | ||
await callback.message.answer(trans("message.enter_username"), reply_markup=create_cancel_menu()) | ||
await callback.message.answer( | ||
t("message.enter_username"), reply_markup=create_cancel_menu() | ||
) | ||
await state.set_state(AdminStates.awaiting_banned_username) | ||
logger.info(f"{get_username_from_callback(callback)}: Awaiting username of banned user") | ||
|
||
|
||
@router.message(AdminStates.awaiting_banned_username) | ||
async def process_ban(message: Message, state: FSMContext): | ||
logger.info( | ||
f"{get_username_from_message(message)}: Enter username of banned user {message.text}") | ||
username = message.text | ||
if username.startswith('@'): | ||
try: | ||
user_service.ban_user(username[1:]) | ||
await message.answer(trans("message.user_is_banned", params={"username": username})) | ||
logger.info(f"{get_username_from_message(message)}: User {username} is banned") | ||
except UserAlreadyBannedException as e: | ||
logger.warning(e) | ||
await message.answer(trans("error.user_already_banned", params={"username": username})) | ||
else: | ||
await message.answer(trans("error.incorrect_username")) | ||
logger.warning( | ||
f"{get_username_from_message(message)}: Incorrect username of banned user {username}") | ||
banned_username = message.text | ||
|
||
if not banned_username.startswith("@"): | ||
await message.answer(t("error.incorrect_username")) | ||
await state.clear() | ||
return | ||
|
||
try: | ||
user_service.ban_user(banned_username[1:]) | ||
await message.answer( | ||
t("message.user_is_banned", params={"username": banned_username}) | ||
) | ||
except UserAlreadyBannedException as e: | ||
await message.answer( | ||
t("error.user_already_banned", params={"username": banned_username}) | ||
) | ||
await state.clear() | ||
|
||
|
||
@router.callback_query(MainMenuCallbackFactory.filter(F.action == "unban_user")) | ||
async def unban_user(callback: CallbackQuery, state: FSMContext): | ||
logger.info(f"{get_username_from_callback(callback)}: Start unban user") | ||
await callback.message.answer(trans("message.enter_username"), reply_markup=create_cancel_menu()) | ||
await callback.message.answer( | ||
t("message.enter_username"), reply_markup=create_cancel_menu() | ||
) | ||
await state.set_state(AdminStates.awaiting_unbanned_username) | ||
logger.info(f"{get_username_from_callback(callback)}: Awaiting username of unbanned user") | ||
|
||
|
||
@router.message(AdminStates.awaiting_unbanned_username) | ||
async def process_ban(message: Message, state: FSMContext): | ||
username = message.text | ||
logger.info(f"{get_username_from_message(message)}: Enter username of unbanned user {username}") | ||
if username.startswith('@'): | ||
try: | ||
user_service.unban_user(username[1:]) | ||
await message.answer(trans("message.user_is_unbanned", params={"username": username})) | ||
logger.info(f"{get_username_from_message(message)}: User {username} is unbanned") | ||
except UserNotBannedException as e: | ||
logger.warning(e) | ||
await message.answer(trans("error.user_not_banned", params={"username": username})) | ||
else: | ||
await message.answer(trans("error.incorrect_username")) | ||
logger.warning( | ||
f"{get_username_from_message(message)}: Incorrect username of unbanned user {username}") | ||
if not username.startswith("@"): | ||
await message.answer(t("error.incorrect_username")) | ||
await state.clear() | ||
return | ||
|
||
try: | ||
user_service.unban_user(username[1:]) | ||
await message.answer( | ||
t("message.user_is_unbanned", params={"username": username}) | ||
) | ||
except UserNotBannedException as e: | ||
await message.answer(t("error.user_not_banned", params={"username": username})) | ||
await state.clear() | ||
|
||
|
||
@router.callback_query(MainMenuCallbackFactory.filter(F.action == "list_banned_users")) | ||
async def list_banned_users(callback: CallbackQuery): | ||
banned_users = user_service.get_banned_users() | ||
if len(banned_users) > 0: | ||
content = trans("message.list_banned_users") + "\n" | ||
content = t("message.list_banned_users") + "\n" | ||
for banned_user in banned_users: | ||
content += "\n@" + banned_user.username | ||
else: | ||
content = trans("message.no_banned_users") | ||
content = t("message.no_banned_users") | ||
await callback.message.answer(content) | ||
|
||
|
||
@router.callback_query(MainMenuCallbackFactory.filter(F.action == "list_admins")) | ||
async def list_admins(callback: CallbackQuery): | ||
admins = user_service.get_admins() | ||
if len(admins) > 0: | ||
content = t("message.list_admins") + "\n" | ||
for admin in admins: | ||
content += "\n@" + admin.username | ||
else: | ||
content = t("message.no_admins") | ||
await callback.message.answer(content) | ||
logger.info(f"{get_username_from_callback(callback)}: List banned users") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,13 @@ | ||
import logging | ||
|
||
from aiogram import Router | ||
from aiogram.fsm.context import FSMContext | ||
from aiogram.types import CallbackQuery | ||
from i18next import trans | ||
|
||
from app.bot.callback_data import CancelCallbackFactory | ||
from app.bot.utils.callback_utils import get_username_from_callback | ||
|
||
router = Router(name="cancel") | ||
logger = logging.getLogger("cancel") | ||
|
||
|
||
@router.callback_query(CancelCallbackFactory.filter()) | ||
async def cancel(callback: CallbackQuery, state: FSMContext): | ||
await callback.message.answer(trans("message.canceled")) | ||
await state.clear() | ||
logger.info(f"{get_username_from_callback(callback)}: Cancel the operation") | ||
await callback.message.delete() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,17 @@ | ||
import logging | ||
|
||
from aiogram import Router | ||
from aiogram.filters import Command | ||
from aiogram.types import Message | ||
from i18next import trans | ||
from i18next import trans as t | ||
|
||
from app.bot.keyboards import create_main_menu | ||
from app.bot.utils.message_utils import get_username_from_message | ||
|
||
router = Router(name="menu") | ||
logger = logging.getLogger("menu") | ||
|
||
|
||
@router.message(Command(commands=["menu"])) | ||
async def menu(message: Message): | ||
username = get_username_from_message(message) | ||
await message.answer(trans("message.available_commands"), | ||
reply_markup=create_main_menu(username)) | ||
logger.info(f"{get_username_from_message(message)}: Show main menu") | ||
await message.answer( | ||
t("message.available_commands"), reply_markup=create_main_menu(username) | ||
) |
Oops, something went wrong.