-
Notifications
You must be signed in to change notification settings - Fork 607
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
111 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(), | ||
) |
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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
from tortoise import fields | ||
|
||
from zhenxun.services.db_context import Model | ||
|
||
|
||
class BotConsole(Model): | ||
id = fields.IntField(pk=True, generated=True, auto_increment=True) | ||
"""自增id""" | ||
bot_id = fields.CharField(255, unique=True, description="bot_id") | ||
"""bot_id""" | ||
status = fields.BooleanField(default=True, description="Bot状态") | ||
"""Bot状态""" | ||
block_plugin = fields.TextField(default="", description="禁用插件") | ||
"""禁用插件""" | ||
block_task = fields.TextField(default="", description="禁用被动技能") | ||
"""禁用被动技能""" | ||
create_time = fields.DatetimeField(auto_now_add=True, description="创建时间") | ||
"""创建时间""" | ||
platform = fields.CharField(255, null=True, description="平台") | ||
"""平台""" | ||
|
||
class Meta: # type: ignore | ||
table = "bot_console" | ||
table_description = "Bot数据表" | ||
|
||
@classmethod | ||
async def get_bot_status(cls, bot_id: str) -> bool: | ||
result = await cls.get_or_none(bot_id=bot_id) | ||
return result.status if result else False | ||
|
||
@classmethod | ||
async def set_block_plugin(cls, bot_id: str, module: str): | ||
bot_data, _ = await cls.get_or_create(bot_id=bot_id) | ||
if f"<{module}," not in bot_data.block_plugin: | ||
bot_data.block_plugin += f"<{module}," | ||
await bot_data.save(update_fields=["block_plugin"]) | ||
|
||
@classmethod | ||
async def set_unblock_plugin(cls, bot_id: str, module: str): | ||
bot_data, _ = await cls.get_or_create(bot_id=bot_id) | ||
if f"<{module}," in bot_data.block_plugin: | ||
bot_data.block_plugin = bot_data.block_plugin.replace(f"<{module},", "") | ||
await bot_data.save(update_fields=["block_plugin"]) | ||
|
||
@classmethod | ||
async def set_block_task(cls, bot_id: str, task: str): | ||
bot_data, _ = await cls.get_or_create(bot_id=bot_id) | ||
if f"<{task}," not in bot_data.block_task: | ||
bot_data.block_plugin += f"<{task}," | ||
await bot_data.save(update_fields=["block_task"]) | ||
|
||
@classmethod | ||
async def is_block_plugin(cls, bot_id: str, task: str) -> bool: | ||
bot_data, _ = await cls.get_or_create(bot_id=bot_id) | ||
return f"<{task}," in bot_data.block_plugin | ||
|
||
@classmethod | ||
async def is_block_task(cls, bot_id: str, task: str) -> bool: | ||
bot_data, _ = await cls.get_or_create(bot_id=bot_id) | ||
return f"<{task}," in bot_data.block_task |
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