init🎉: 首次提交

This commit is contained in:
HibiKier
2024-02-04 04:18:54 +08:00
parent a3004438a9
commit 131200a28e
355 changed files with 4826 additions and 53229 deletions
@@ -0,0 +1,5 @@
from pathlib import Path
import nonebot
nonebot.load_plugins(str(Path(__file__).parent.resolve()))
@@ -0,0 +1,59 @@
from nonebot import on_notice
from nonebot.adapters.onebot.v11 import GroupAdminNoticeEvent
from nonebot.plugin import PluginMetadata
from zhenxun.configs.config import Config
from zhenxun.configs.utils import PluginExtraData
from zhenxun.models.group_member_info import GroupInfoUser
from zhenxun.models.level_user import LevelUser
from zhenxun.services.log import logger
from zhenxun.utils.enum import PluginType
__zx_plugin_name__ = "群管理员变动监测 [Hidden]"
__plugin_version__ = 0.1
__plugin_author__ = "HibiKier"
__plugin_meta__ = PluginMetadata(
name="群管理员变动监测",
description="检测群管理员变动, 添加与删除管理员默认权限, 当配置项 ADMIN_DEFAULT_AUTH 为空时, 不会添加管理员权限",
usage="",
extra=PluginExtraData(
author="HibiKier", version="0.1", plugin_type=PluginType.HIDDEN
).dict(),
)
admin_notice = on_notice(priority=5)
base_config = Config.get("admin_bot_manage")
@admin_notice.handle()
async def _(event: GroupAdminNoticeEvent):
nickname = event.user_id
if user := await GroupInfoUser.get_or_none(
user_id=str(event.user_id), group_id=str(event.group_id)
):
nickname = user.user_name
if event.sub_type == "set":
admin_default_auth = base_config.get("ADMIN_DEFAULT_AUTH")
if admin_default_auth is not None:
await LevelUser.set_level(
event.user_id,
event.group_id,
admin_default_auth,
)
logger.info(
f"成为管理员,添加权限: {admin_default_auth}",
"群管理员变动监测",
event.user_id,
event.group_id,
)
else:
logger.warning(
f"配置项 MODULE: [<u><y>admin_bot_manage</y></u>] | KEY: [<u><y>ADMIN_DEFAULT_AUTH</y></u>] 为空"
)
elif event.sub_type == "unset":
await LevelUser.delete_level(event.user_id, event.group_id)
logger.info("撤销群管理员, 取消权限等级", "群管理员变动监测", event.user_id, event.group_id)
@@ -0,0 +1,116 @@
import shutil
from typing import Dict
import ujson as json
from arclet.alconna import Args, Option
from nonebot.plugin import PluginMetadata
from nonebot_plugin_alconna import (
Alconna,
AlconnaMatch,
Arparma,
Match,
on_alconna,
store_true,
)
from nonebot_plugin_alconna.matcher import AlconnaMatcher
from nonebot_plugin_saa import Text
from nonebot_plugin_session import EventSession
from zhenxun.configs.config import Config
from zhenxun.configs.path_config import DATA_PATH
from zhenxun.configs.utils import PluginCdBlock, PluginExtraData, RegisterConfig
from zhenxun.services.log import logger
from zhenxun.utils.enum import PluginType
from zhenxun.utils.rules import admin_check, ensure_group
base_config = Config.get("admin_bot_manage")
__plugin_meta__ = PluginMetadata(
name="自定义群欢迎消息",
description="自定义群欢迎消息",
usage="""
设置欢迎消息 欢迎新人!
设置欢迎消息 欢迎你 -at
""".strip(),
extra=PluginExtraData(
author="HibiKier",
version="0.1",
plugin_type=PluginType.ADMIN,
admin_level=base_config.get("SET_GROUP_WELCOME_MESSAGE_LEVEL", 2),
configs=[
RegisterConfig(
key="SET_GROUP_WELCOME_MESSAGE_LEVEL",
value=2,
help="设置群欢迎消息所需要的管理员权限等级",
default_value=2,
)
],
).dict(),
)
_matcher = on_alconna(
Alconna(
"设置欢迎消息",
Args["message", str],
Option("-at", action=store_true, help_text="是否at新入群用户"),
),
rule=admin_check("admin_bot_manage", "SET_GROUP_WELCOME_MESSAGE_LEVEL")
& ensure_group,
priority=5,
block=True,
)
BASE_PATH = DATA_PATH / "welcome_message"
BASE_PATH.mkdir(parents=True, exist_ok=True)
# 旧数据迁移
old_file = DATA_PATH / "custom_welcome_msg" / "custom_welcome_msg.json"
if old_file.exists():
try:
old_data: Dict[str, str] = json.load(old_file.open(encoding="utf8"))
for group_id, message in old_data.items():
file = BASE_PATH / "qq" / f"{group_id}" / "text.json"
file.parent.mkdir(parents=True, exist_ok=True)
json.dump(
{"at": "[at]" in message, "message": message.replace("[at]", "")},
file.open("w", encoding="utf8"),
ensure_ascii=False,
indent=4,
)
logger.debug("群欢迎消息数据迁移", group_id=group_id)
shutil.rmtree(old_file.parent.absolute())
except Exception as e:
pass
@_matcher.handle()
async def _(
session: EventSession,
matcher: AlconnaMatcher,
arparma: Arparma,
message: str,
):
file = (
BASE_PATH
/ f"{session.platform or session.bot_type}"
/ f"{session.id2}"
/ "text.json"
)
if session.id3:
file = (
BASE_PATH
/ f"{session.platform or session.bot_type}"
/ f"{session.id3}"
/ f"{session.id2}"
/ "text.json"
)
if not file.exists():
file.parent.mkdir(exist_ok=True, parents=True)
json.dump(
{"at": arparma.find("at"), "message": message},
file.open("w"),
ensure_ascii=False,
indent=4,
)
logger.info(f"设置群欢迎消息成功: {message}", arparma.header_result, session=session)
await Text(f"设置欢迎消息成功: \n{message}").send()