mirror of
https://gitflic.ru/project/maks1ms/ocab.git
synced 2024-12-24 00:33:05 +03:00
Админ модуль: удаление сообщений
Модуль фильтров Добавлены роутеры
This commit is contained in:
parent
d71fef0fed
commit
88f40c7f82
@ -1 +1 @@
|
|||||||
import service
|
import src.service
|
@ -1,18 +1,19 @@
|
|||||||
from src.modules.standard.config.config import get_config
|
from src.core.routers import include_routers
|
||||||
from src.modules.standard.database.models.base import database
|
from src.modules.standard.config.config import get_telegram_token
|
||||||
from src.modules.standard.database.api import connect_database
|
from src.modules.standard.database.api import connect_database, create_tables
|
||||||
|
|
||||||
from asyncio import run
|
from asyncio import run
|
||||||
from aiogram import Bot, Dispatcher
|
from aiogram import Bot, Dispatcher
|
||||||
|
|
||||||
|
|
||||||
async def main():
|
async def main(bot: Bot):
|
||||||
try:
|
try:
|
||||||
database = connect_database()
|
database, path = connect_database()
|
||||||
bot = Bot(token=get_config()["TELEGRAM"]["TOKEN"])
|
database.connect()
|
||||||
|
create_tables(database)
|
||||||
|
|
||||||
dp = Dispatcher()
|
dp = Dispatcher()
|
||||||
|
await include_routers(dp)
|
||||||
await dp.start_polling(bot)
|
await dp.start_polling(bot)
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
@ -21,4 +22,5 @@ async def main():
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
run(main())
|
bot = Bot(token=get_telegram_token())
|
||||||
|
run(main(bot))
|
||||||
|
11
src/core/routers.py
Normal file
11
src/core/routers.py
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
from aiogram import Dispatcher
|
||||||
|
|
||||||
|
from src.modules.standard.admin.routers import router as admin_router
|
||||||
|
|
||||||
|
|
||||||
|
async def include_routers(dp: Dispatcher):
|
||||||
|
"""
|
||||||
|
Подключение роутеров в бота
|
||||||
|
dp.include_router()
|
||||||
|
"""
|
||||||
|
dp.include_router(admin_router)
|
1
src/modules/standard/admin/__init__.py
Normal file
1
src/modules/standard/admin/__init__.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
from . import routers
|
10
src/modules/standard/admin/handlers.py
Normal file
10
src/modules/standard/admin/handlers.py
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
from aiogram import Bot
|
||||||
|
from aiogram.types import Message
|
||||||
|
|
||||||
|
|
||||||
|
async def delete_message(message: Message, bot: Bot):
|
||||||
|
reply_message_id = message.reply_to_message.message_id
|
||||||
|
await bot.delete_message(message.chat.id, reply_message_id)
|
||||||
|
|
||||||
|
async def delete_message_error_access(message: Message, bot: Bot):
|
||||||
|
await message.reply("Вы не админ/модератор")
|
6
src/modules/standard/admin/info.json
Normal file
6
src/modules/standard/admin/info.json
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"name": "Admin",
|
||||||
|
"description": "Модуль для работы с админкой",
|
||||||
|
"author": "OCAB Team",
|
||||||
|
"version": "1.0"
|
||||||
|
}
|
8
src/modules/standard/admin/routers.py
Normal file
8
src/modules/standard/admin/routers.py
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
from aiogram import Router, F
|
||||||
|
|
||||||
|
from src.modules.standard.admin.handlers import delete_message, delete_message_error_access
|
||||||
|
from src.modules.standard.filters.admin import ChatModerOrAdminFilter
|
||||||
|
|
||||||
|
router = Router()
|
||||||
|
router.message.register(delete_message, ChatModerOrAdminFilter(), F.text == '/rm')
|
||||||
|
router.message.register(delete_message_error_access, F.text == '/rm')
|
@ -12,14 +12,18 @@ def get_config(is_test: bool = False) -> dict:
|
|||||||
with open(path, 'r') as file:
|
with open(path, 'r') as file:
|
||||||
return yaml.full_load(file)
|
return yaml.full_load(file)
|
||||||
|
|
||||||
|
config = get_config()
|
||||||
|
|
||||||
|
def get_telegram_token() -> str:
|
||||||
|
return config["TELEGRAM"]["TOKEN"]
|
||||||
|
|
||||||
def get_yandexgpt_token() -> str:
|
def get_yandexgpt_token() -> str:
|
||||||
return get_config()["YANDEX_GPT_TOKEN"]
|
return config["YANDEX_GPT_TOKEN"]
|
||||||
|
|
||||||
def get_yandexgpt_catalog_id() -> str:
|
def get_yandexgpt_catalog_id() -> str:
|
||||||
return get_config()["YANDEX_GPT_CATALOG_ID"]
|
return config["YANDEX_GPT_CATALOG_ID"]
|
||||||
|
|
||||||
def get_yandexgpt_prompt() -> str:
|
def get_yandexgpt_prompt() -> str:
|
||||||
return get_config()["YANDEX_GPT_PROMPT"]
|
return config["YANDEX_GPT_PROMPT"]
|
||||||
|
|
||||||
|
|
||||||
|
@ -22,6 +22,8 @@ def connect_database(is_test: bool = False, module: str | None = None):
|
|||||||
Chats._meta.database = _database
|
Chats._meta.database = _database
|
||||||
Messages._meta.database = _database
|
Messages._meta.database = _database
|
||||||
Users._meta.database = _database
|
Users._meta.database = _database
|
||||||
|
UserStats._meta.database = _database
|
||||||
|
ChatStats._meta.database = _database
|
||||||
|
|
||||||
return _database, f"{db_path}/OCAB.db"
|
return _database, f"{db_path}/OCAB.db"
|
||||||
|
|
||||||
|
0
src/modules/standard/filters/__init__.py
Normal file
0
src/modules/standard/filters/__init__.py
Normal file
11
src/modules/standard/filters/admin.py
Normal file
11
src/modules/standard/filters/admin.py
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
from aiogram.filters import BaseFilter
|
||||||
|
from aiogram.types import Message
|
||||||
|
|
||||||
|
from src.modules.standard.roles.api import Roles
|
||||||
|
|
||||||
|
class ChatModerOrAdminFilter(BaseFilter):
|
||||||
|
async def __call__(self, message: Message) -> bool:
|
||||||
|
user_id = message.from_user.id
|
||||||
|
roles = Roles()
|
||||||
|
return await roles.check_admin_permission(user_id) or \
|
||||||
|
await roles.check_moderator_permission(user_id)
|
6
src/modules/standard/filters/info.json
Normal file
6
src/modules/standard/filters/info.json
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"name": "Filters",
|
||||||
|
"description": "Модуль с фильтрами",
|
||||||
|
"author": "OCAB Team",
|
||||||
|
"version": "1.0"
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user