Template
mirror of
https://github.com/djimboy/djimbo_template_aio3.git
synced 2026-08-25 06:27:43 +00:00
Update
This commit is contained in:
@@ -0,0 +1 @@
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
# - *- coding: utf- 8 - *-
|
||||
from aiogram import Bot
|
||||
from aiogram.types import BotCommand, BotCommandScopeChat, BotCommandScopeDefault
|
||||
|
||||
from tgbot.config import get_admins
|
||||
|
||||
# Команды для юзеров
|
||||
user_commands = [
|
||||
BotCommand(command="start", description="♻ Перезапустить бота"),
|
||||
BotCommand(command="inline", description="🌀 Получить Inline клавиатуру"),
|
||||
]
|
||||
|
||||
# Команды для админов
|
||||
admin_commands = [
|
||||
BotCommand(command="start", description="♻ Перезапустить бота"),
|
||||
BotCommand(command="inline", description="🌀 Получить Inline клавиатуру"),
|
||||
BotCommand(command="log", description="🖨 Получить Логи"),
|
||||
BotCommand(command="db", 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:
|
||||
pass
|
||||
@@ -0,0 +1,14 @@
|
||||
# - *- coding: utf- 8 - *-
|
||||
from aiogram.dispatcher.filters import BaseFilter
|
||||
from aiogram.types import Message
|
||||
|
||||
from tgbot.config import get_admins
|
||||
|
||||
|
||||
# Проверка на админа
|
||||
class IsAdmin(BaseFilter):
|
||||
async def __call__(self, message: Message):
|
||||
if message.from_user.id in get_admins():
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
@@ -0,0 +1,32 @@
|
||||
# - *- coding: utf- 8 - *-
|
||||
import logging as bot_logger
|
||||
|
||||
import colorlog
|
||||
|
||||
from tgbot.config import PATH_LOGS
|
||||
|
||||
# Формат логгирования
|
||||
log_formatter_file = bot_logger.Formatter("%(levelname)s | %(asctime)s | %(filename)s:%(lineno)d | %(message)s")
|
||||
log_formatter_console = colorlog.ColoredFormatter(
|
||||
"%(purple)s%(levelname)s %(blue)s|%(purple)s %(asctime)s %(blue)s|%(purple)s %(filename)s:%(lineno)d %(blue)s|%(purple)s %(message)s%(red)s",
|
||||
datefmt="%d-%m-%Y %H:%M:%S",
|
||||
)
|
||||
|
||||
# Логгирование в файл logs.log
|
||||
file_handler = bot_logger.FileHandler(PATH_LOGS, "w", "utf-8")
|
||||
file_handler.setFormatter(log_formatter_file)
|
||||
file_handler.setLevel(bot_logger.INFO)
|
||||
|
||||
# Логгирование в консоль
|
||||
console_handler = bot_logger.StreamHandler()
|
||||
console_handler.setFormatter(log_formatter_console)
|
||||
console_handler.setLevel(bot_logger.CRITICAL)
|
||||
|
||||
# Подключение настроек логгирования
|
||||
bot_logger.basicConfig(
|
||||
format="%(levelname)s | %(asctime)s | %(filename)s:%(lineno)d | %(message)s",
|
||||
handlers=[
|
||||
file_handler,
|
||||
console_handler
|
||||
]
|
||||
)
|
||||
@@ -0,0 +1,10 @@
|
||||
# - *- coding: utf- 8 - *-
|
||||
from textwrap import dedent
|
||||
|
||||
from aiogram.dispatcher.fsm.context import FSMContext
|
||||
|
||||
from tgbot.services.api_session import RequestsSession
|
||||
|
||||
ded = dedent
|
||||
FSM = FSMContext
|
||||
RS = RequestsSession
|
||||
Reference in New Issue
Block a user