Private
Public Access
forked from FOSS/AutoShop-Djimbo-Simple
Initial local state
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
# - *- coding: utf- 8 - *-
|
||||
from aiogram import Bot
|
||||
from aiogram.types import BotCommand, BotCommandScopeChat, BotCommandScopeDefault
|
||||
|
||||
from tgbot.data.config import get_admins
|
||||
from tgbot.utils.misc.bot_logging import bot_logger
|
||||
|
||||
# Команды для юзеров
|
||||
user_commands = [
|
||||
BotCommand(command='start', description='♻️ Перезапустить бота'),
|
||||
BotCommand(command='support', description='☎️ Поддержка'),
|
||||
BotCommand(command='faq', description='❔ FAQ'),
|
||||
]
|
||||
|
||||
# Команды для админов
|
||||
admin_commands = [
|
||||
BotCommand(command='start', description='♻️ Перезапустить бота'),
|
||||
BotCommand(command='support', description='☎️ Поддержка'),
|
||||
BotCommand(command='faq', description='❔ FAQ'),
|
||||
BotCommand(command='db', description='📦 Получить Базу Данных'),
|
||||
BotCommand(command='log', description='🖨 Получить логи'),
|
||||
]
|
||||
|
||||
|
||||
# Установка команд
|
||||
async def set_commands(bot: Bot):
|
||||
await bot.set_my_commands(user_commands, scope=BotCommandScopeDefault())
|
||||
|
||||
for admin in get_admins():
|
||||
try:
|
||||
await bot.set_my_commands(admin_commands, scope=BotCommandScopeChat(chat_id=admin))
|
||||
except Exception:
|
||||
bot_logger.warning("Не удалось установить команды админу %s", admin, exc_info=True)
|
||||
@@ -0,0 +1,67 @@
|
||||
# - *- coding: utf- 8 - *-
|
||||
from typing import Union
|
||||
|
||||
from aiogram.filters import BaseFilter
|
||||
from aiogram.types import CallbackQuery, Message
|
||||
|
||||
from tgbot.data.config import get_admins
|
||||
from tgbot.database import Settingsx
|
||||
|
||||
|
||||
class IsAdmin(BaseFilter):
|
||||
# Проверка, что пользователь админ
|
||||
async def __call__(self, event: Union[Message, CallbackQuery]) -> bool:
|
||||
user = getattr(event, "from_user", None)
|
||||
|
||||
return bool(user and user.id in get_admins())
|
||||
|
||||
|
||||
class IsPrivate(BaseFilter):
|
||||
# Проверка приватного чата
|
||||
async def __call__(self, event: Union[Message, CallbackQuery]) -> bool:
|
||||
chat = getattr(event, "chat", None)
|
||||
message = getattr(event, "message", None)
|
||||
|
||||
if chat is None and message is not None:
|
||||
chat = message.chat
|
||||
|
||||
if chat is None:
|
||||
return True
|
||||
|
||||
return chat.type == "private"
|
||||
|
||||
|
||||
class IsWork(BaseFilter):
|
||||
# Проверка режима тех. работ
|
||||
async def __call__(self, event: Union[Message, CallbackQuery]) -> bool:
|
||||
user = getattr(event, "from_user", None)
|
||||
settings = await Settingsx().get()
|
||||
|
||||
if settings.status_work == "False" or (user and user.id in get_admins()):
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
|
||||
class IsRefill(BaseFilter):
|
||||
# Проверка доступности пополнений
|
||||
async def __call__(self, event: Union[Message, CallbackQuery]) -> bool:
|
||||
user = getattr(event, "from_user", None)
|
||||
settings = await Settingsx().get()
|
||||
|
||||
if settings.status_refill == "True" or (user and user.id in get_admins()):
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
|
||||
class IsBuy(BaseFilter):
|
||||
# Проверка доступности покупок
|
||||
async def __call__(self, event: Union[Message, CallbackQuery]) -> bool:
|
||||
user = getattr(event, "from_user", None)
|
||||
settings = await Settingsx().get()
|
||||
|
||||
if settings.status_buy == "True" or (user and user.id in get_admins()):
|
||||
return False
|
||||
|
||||
return True
|
||||
@@ -0,0 +1,52 @@
|
||||
# - *- coding: utf- 8 - *-
|
||||
import logging
|
||||
from logging.handlers import RotatingFileHandler
|
||||
from pathlib import Path
|
||||
|
||||
import colorlog
|
||||
|
||||
from tgbot.data.config import PATH_LOGS
|
||||
|
||||
LOG_FILE_MAX_BYTES = 5 * 1024 * 1024
|
||||
LOG_FILE_BACKUP_COUNT = 5
|
||||
|
||||
log_path = Path(PATH_LOGS)
|
||||
log_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
bot_logger = logging.getLogger("tgbot")
|
||||
bot_logger.setLevel(logging.INFO)
|
||||
bot_logger.propagate = False
|
||||
|
||||
if not bot_logger.handlers:
|
||||
file_formatter = logging.Formatter(
|
||||
"%(levelname)s | %(asctime)s | %(name)s | %(filename)s:%(lineno)d | %(message)s",
|
||||
datefmt="%d-%m-%Y %H:%M:%S",
|
||||
)
|
||||
console_formatter = colorlog.ColoredFormatter(
|
||||
"%(log_color)s%(levelname)s%(reset)s | %(blue)s%(asctime)s%(reset)s | "
|
||||
"%(purple)s%(filename)s:%(lineno)d%(reset)s | %(message)s",
|
||||
datefmt="%d-%m-%Y %H:%M:%S",
|
||||
log_colors={
|
||||
"DEBUG": "cyan",
|
||||
"INFO": "green",
|
||||
"WARNING": "yellow",
|
||||
"ERROR": "red",
|
||||
"CRITICAL": "bold_red",
|
||||
},
|
||||
)
|
||||
|
||||
file_handler = RotatingFileHandler(
|
||||
log_path,
|
||||
maxBytes=LOG_FILE_MAX_BYTES,
|
||||
backupCount=LOG_FILE_BACKUP_COUNT,
|
||||
encoding="utf-8",
|
||||
)
|
||||
file_handler.setFormatter(file_formatter)
|
||||
file_handler.setLevel(logging.INFO)
|
||||
|
||||
console_handler = logging.StreamHandler()
|
||||
console_handler.setFormatter(console_formatter)
|
||||
console_handler.setLevel(logging.INFO)
|
||||
|
||||
bot_logger.addHandler(file_handler)
|
||||
bot_logger.addHandler(console_handler)
|
||||
@@ -0,0 +1,7 @@
|
||||
# - *- coding: utf- 8 - *-
|
||||
from aiogram.fsm.context import FSMContext
|
||||
|
||||
from tgbot.services.api_session import AsyncRequestSession
|
||||
|
||||
FSM = FSMContext
|
||||
ARS = AsyncRequestSession
|
||||
Reference in New Issue
Block a user