mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-10-21 04:00:04 +08:00
🐛 优化功能开关管理 (#1679)
This commit is contained in:
@@ -23,7 +23,7 @@ class GroupInfo(Model):
|
||||
platform = fields.CharField(255, default="qq", description="所属平台")
|
||||
"""所属平台"""
|
||||
|
||||
class Meta:
|
||||
class Meta: # type: ignore
|
||||
table = "group_info"
|
||||
table_description = "群聊信息表"
|
||||
|
||||
@@ -40,12 +40,81 @@ class GroupInfo(Model):
|
||||
"""
|
||||
return await cls.exists(group_id=group_id, block_task__contains=f"{task},")
|
||||
|
||||
@classmethod
|
||||
async def is_block_plugin(cls, group_id: str, module: str) -> bool:
|
||||
"""查看群组是否禁用插件
|
||||
|
||||
参数:
|
||||
group_id: 群组id
|
||||
plugin: 插件名称
|
||||
|
||||
返回:
|
||||
bool: 是否禁用插件
|
||||
"""
|
||||
return await cls.exists(
|
||||
group_id=group_id, block_plugin__contains=f"{module},"
|
||||
) or await cls.exists(
|
||||
group_id=group_id, superuser_block_plugin__contains=f"{module},"
|
||||
)
|
||||
|
||||
@classmethod
|
||||
async def set_block_plugin(
|
||||
cls,
|
||||
group_id: str,
|
||||
module: str,
|
||||
is_superuser: bool = False,
|
||||
platform: str | None = None,
|
||||
):
|
||||
"""禁用群组插件
|
||||
|
||||
参数:
|
||||
group_id: 群组id
|
||||
task: 任务模块
|
||||
"""
|
||||
group, _ = await cls.get_or_create(
|
||||
group_id=group_id, defaults={"platform": platform}
|
||||
)
|
||||
if is_superuser:
|
||||
if "module," not in group.superuser_block_plugin:
|
||||
group.superuser_block_plugin += f"{module},"
|
||||
elif "module," not in group.block_plugin:
|
||||
group.block_plugin += f"{module},"
|
||||
await group.save(update_fields=["block_plugin", "superuser_block_plugin"])
|
||||
|
||||
@classmethod
|
||||
async def set_unblock_plugin(
|
||||
cls,
|
||||
group_id: str,
|
||||
module: str,
|
||||
is_superuser: bool = False,
|
||||
platform: str | None = None,
|
||||
):
|
||||
"""禁用群组插件
|
||||
|
||||
参数:
|
||||
group_id: 群组id
|
||||
task: 任务模块
|
||||
"""
|
||||
group, _ = await cls.get_or_create(
|
||||
group_id=group_id, defaults={"platform": platform}
|
||||
)
|
||||
if is_superuser:
|
||||
if "module," in group.superuser_block_plugin:
|
||||
group.superuser_block_plugin = group.superuser_block_plugin.replace(
|
||||
f"{module},", ""
|
||||
)
|
||||
elif "module," in group.block_plugin:
|
||||
group.block_plugin = group.block_plugin.replace(f"{module},", "")
|
||||
await group.save(update_fields=["block_plugin", "superuser_block_plugin"])
|
||||
|
||||
@classmethod
|
||||
def _run_script(cls):
|
||||
return [
|
||||
"ALTER TABLE group_info ADD group_flag Integer NOT NULL DEFAULT 0;", # group_info表添加一个group_flag
|
||||
"ALTER TABLE group_info ADD group_flag Integer NOT NULL DEFAULT 0;",
|
||||
# group_info表添加一个group_flag
|
||||
"ALTER TABLE group_info ALTER COLUMN group_id TYPE character varying(255);",
|
||||
"ALTER TABLE group_info ADD block_plugin Text NOT NULL DEFAULT '';",
|
||||
"ALTER TABLE group_info ADD block_task Text NOT NULL DEFAULT '';",
|
||||
"ALTER TABLE group_info ADD platform character varying(255) NOT NULL DEFAULT 'qq';",
|
||||
"ALTER TABLE group_info ADD platform character varying(255) NOT NULL"
|
||||
" DEFAULT 'qq';",
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user