mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-10-05 03:39:59 +08:00
✨ 指定bot的功能管理 (#1706)
This commit is contained in:
@@ -9,6 +9,8 @@ from nonebot.adapters import Bot
|
||||
from nonebot.drivers import Driver
|
||||
from tortoise.exceptions import OperationalError
|
||||
|
||||
from zhenxun.utils.platform import PlatformUtils
|
||||
|
||||
require("nonebot_plugin_apscheduler")
|
||||
require("nonebot_plugin_alconna")
|
||||
require("nonebot_plugin_session")
|
||||
@@ -19,6 +21,7 @@ require("nonebot_plugin_htmlrender")
|
||||
from zhenxun.services.log import logger
|
||||
from zhenxun.models.sign_user import SignUser
|
||||
from zhenxun.models.goods_info import GoodsInfo
|
||||
from zhenxun.models.bot_console import BotConsole
|
||||
from zhenxun.models.user_console import UserConsole
|
||||
from zhenxun.utils.decorator.shop import shop_register
|
||||
from zhenxun.models.bot_connect_log import BotConnectLog
|
||||
@@ -33,6 +36,10 @@ async def _(bot: Bot):
|
||||
await BotConnectLog.create(
|
||||
bot_id=bot.self_id, platform=bot.adapter, connect_time=datetime.now(), type=1
|
||||
)
|
||||
if not await BotConsole.exists(bot_id=bot.self_id):
|
||||
await BotConsole.create(
|
||||
bot_id=bot.self_id, platform=PlatformUtils.get_platform(bot)
|
||||
)
|
||||
|
||||
|
||||
@driver.on_bot_disconnect
|
||||
|
||||
@@ -11,6 +11,7 @@ from zhenxun.services.log import logger
|
||||
from zhenxun.configs.config import Config
|
||||
from zhenxun.utils.message import MessageUtils
|
||||
from zhenxun.models.level_user import LevelUser
|
||||
from zhenxun.models.bot_console import BotConsole
|
||||
from zhenxun.models.plugin_info import PluginInfo
|
||||
from zhenxun.models.plugin_limit import PluginLimit
|
||||
from zhenxun.models.user_console import UserConsole
|
||||
@@ -244,6 +245,7 @@ class AuthChecker:
|
||||
if not plugin.limit_superuser:
|
||||
cost_gold = 0
|
||||
raise IsSuperuserException()
|
||||
await self.auth_bot(plugin, bot.self_id)
|
||||
await self.auth_group(plugin, session, message)
|
||||
await self.auth_admin(plugin, session)
|
||||
await self.auth_plugin(plugin, session, event)
|
||||
@@ -278,6 +280,16 @@ class AuthChecker:
|
||||
if is_ignore:
|
||||
raise IgnoredException("权限检测 ignore")
|
||||
|
||||
async def auth_bot(self, plugin: PluginInfo, bot_id: str):
|
||||
"""机器人权限
|
||||
|
||||
参数:
|
||||
plugin: PluginInfo
|
||||
bot_id: bot_id
|
||||
"""
|
||||
if await BotConsole.is_block_plugin(plugin.module, bot_id):
|
||||
raise IgnoredException("机器人权限检测 ignore")
|
||||
|
||||
async def auth_limit(self, plugin: PluginInfo, session: EventSession):
|
||||
"""插件限制
|
||||
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
import os
|
||||
import time
|
||||
|
||||
from nonebot.rule import to_me
|
||||
from nonebot.utils import run_sync
|
||||
from nonebot.permission import SUPERUSER
|
||||
from nonebot.plugin import PluginMetadata
|
||||
from nonebot_plugin_session import EventSession
|
||||
from nonebot_plugin_apscheduler import scheduler
|
||||
from nonebot_plugin_alconna import Alconna, on_alconna
|
||||
|
||||
from zhenxun.services.log import logger
|
||||
from zhenxun.utils.enum import PluginType
|
||||
from zhenxun.utils.message import MessageUtils
|
||||
from zhenxun.configs.path_config import TEMP_PATH
|
||||
from zhenxun.configs.utils import PluginExtraData
|
||||
from zhenxun.utils.utils import ResourceDirManager
|
||||
|
||||
__plugin_meta__ = PluginMetadata(
|
||||
name="Bot管理",
|
||||
description="指定bot对象的功能/被动开关和状态",
|
||||
usage="""
|
||||
清理临时数据
|
||||
""".strip(),
|
||||
extra=PluginExtraData(
|
||||
author="",
|
||||
version="0.1",
|
||||
plugin_type=PluginType.SUPERUSER,
|
||||
).dict(),
|
||||
)
|
||||
Reference in New Issue
Block a user