mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2025-12-15 06:12:53 +08:00
🎨 notice响应期添加rule (#1682)
* 🎨 notice响应期添加rule
* chore(version): Update version to v0.2.3-f3e5c9e
---------
Co-authored-by: HibiKier <HibiKier@users.noreply.github.com>
This commit is contained in:
parent
3117dc264f
commit
fd90e1ab82
@ -1 +1 @@
|
|||||||
__version__: v0.2.3-5f361ff
|
__version__: v0.2.3-f3e5c9e
|
||||||
|
|||||||
@ -1,16 +1,18 @@
|
|||||||
from nonebot import on_notice
|
from nonebot import on_notice
|
||||||
from nonebot.adapters.onebot.v11 import GroupAdminNoticeEvent
|
|
||||||
from nonebot.plugin import PluginMetadata
|
from nonebot.plugin import PluginMetadata
|
||||||
|
from nonebot.adapters.onebot.v11 import GroupAdminNoticeEvent
|
||||||
|
|
||||||
from zhenxun.configs.config import Config
|
|
||||||
from zhenxun.configs.utils import PluginExtraData, RegisterConfig
|
|
||||||
from zhenxun.models.level_user import LevelUser
|
|
||||||
from zhenxun.services.log import logger
|
from zhenxun.services.log import logger
|
||||||
|
from zhenxun.configs.config import Config
|
||||||
from zhenxun.utils.enum import PluginType
|
from zhenxun.utils.enum import PluginType
|
||||||
|
from zhenxun.utils.rules import notice_rule
|
||||||
|
from zhenxun.models.level_user import LevelUser
|
||||||
|
from zhenxun.configs.utils import RegisterConfig, PluginExtraData
|
||||||
|
|
||||||
__plugin_meta__ = PluginMetadata(
|
__plugin_meta__ = PluginMetadata(
|
||||||
name="群管理员变动监测",
|
name="群管理员变动监测",
|
||||||
description="检测群管理员变动, 添加与删除管理员默认权限, 当配置项 ADMIN_DEFAULT_AUTH 为空时, 不会添加管理员权限",
|
description="""检测群管理员变动, 添加与删除管理员默认权限,
|
||||||
|
当配置项 ADMIN_DEFAULT_AUTH 为空时, 不会添加管理员权限""",
|
||||||
usage="",
|
usage="",
|
||||||
extra=PluginExtraData(
|
extra=PluginExtraData(
|
||||||
author="HibiKier",
|
author="HibiKier",
|
||||||
@ -29,7 +31,7 @@ __plugin_meta__ = PluginMetadata(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
admin_notice = on_notice(priority=5)
|
admin_notice = on_notice(priority=5, rule=notice_rule(GroupAdminNoticeEvent))
|
||||||
|
|
||||||
base_config = Config.get("admin_bot_manage")
|
base_config = Config.get("admin_bot_manage")
|
||||||
|
|
||||||
@ -52,7 +54,8 @@ async def _(event: GroupAdminNoticeEvent):
|
|||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
logger.warning(
|
logger.warning(
|
||||||
f"配置项 MODULE: [<u><y>admin_bot_manage</y></u>] | KEY: [<u><y>ADMIN_DEFAULT_AUTH</y></u>] 为空"
|
"配置项 MODULE: [<u><y>admin_bot_manage</y></u>] |"
|
||||||
|
" KEY: [<u><y>ADMIN_DEFAULT_AUTH</y></u>] 为空"
|
||||||
)
|
)
|
||||||
elif event.sub_type == "unset":
|
elif event.sub_type == "unset":
|
||||||
await LevelUser.delete_level(str(event.user_id), str(event.group_id))
|
await LevelUser.delete_level(str(event.user_id), str(event.group_id))
|
||||||
|
|||||||
@ -1,19 +1,19 @@
|
|||||||
import nonebot
|
import nonebot
|
||||||
from nonebot import on_notice
|
from nonebot import on_notice
|
||||||
from nonebot.adapters import Bot
|
from nonebot.adapters import Bot
|
||||||
from nonebot.adapters.onebot.v11 import GroupIncreaseNoticeEvent
|
|
||||||
from nonebot.plugin import PluginMetadata
|
from nonebot.plugin import PluginMetadata
|
||||||
from nonebot_plugin_alconna import Alconna, Arparma, on_alconna
|
|
||||||
from nonebot_plugin_apscheduler import scheduler
|
|
||||||
from nonebot_plugin_session import EventSession
|
from nonebot_plugin_session import EventSession
|
||||||
|
from nonebot_plugin_apscheduler import scheduler
|
||||||
|
from nonebot_plugin_alconna import Alconna, Arparma, on_alconna
|
||||||
|
from nonebot.adapters.onebot.v11 import GroupIncreaseNoticeEvent
|
||||||
|
|
||||||
from zhenxun.configs.config import BotConfig
|
|
||||||
from zhenxun.configs.utils import PluginExtraData
|
|
||||||
from zhenxun.services.log import logger
|
from zhenxun.services.log import logger
|
||||||
from zhenxun.utils.enum import PluginType
|
from zhenxun.utils.enum import PluginType
|
||||||
|
from zhenxun.configs.config import BotConfig
|
||||||
from zhenxun.utils.message import MessageUtils
|
from zhenxun.utils.message import MessageUtils
|
||||||
from zhenxun.utils.platform import PlatformUtils
|
from zhenxun.utils.platform import PlatformUtils
|
||||||
from zhenxun.utils.rules import admin_check, ensure_group
|
from zhenxun.configs.utils import PluginExtraData
|
||||||
|
from zhenxun.utils.rules import admin_check, notice_rule, ensure_group
|
||||||
|
|
||||||
from ._data_source import MemberUpdateManage
|
from ._data_source import MemberUpdateManage
|
||||||
|
|
||||||
@ -42,7 +42,7 @@ _matcher = on_alconna(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
_notice = on_notice(priority=1, block=False)
|
_notice = on_notice(priority=1, block=False, rule=notice_rule(GroupIncreaseNoticeEvent))
|
||||||
|
|
||||||
|
|
||||||
@_matcher.handle()
|
@_matcher.handle()
|
||||||
|
|||||||
@ -1,19 +1,19 @@
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
from nonebot.adapters import Bot, Event
|
|
||||||
from nonebot.exception import IgnoredException
|
|
||||||
from nonebot.matcher import Matcher
|
|
||||||
from nonebot.message import run_preprocessor
|
|
||||||
from nonebot.typing import T_State
|
from nonebot.typing import T_State
|
||||||
|
from nonebot.matcher import Matcher
|
||||||
from nonebot_plugin_alconna import At
|
from nonebot_plugin_alconna import At
|
||||||
|
from nonebot.adapters import Bot, Event
|
||||||
|
from nonebot.message import run_preprocessor
|
||||||
|
from nonebot.exception import IgnoredException
|
||||||
from nonebot_plugin_session import EventSession
|
from nonebot_plugin_session import EventSession
|
||||||
|
|
||||||
from zhenxun.configs.config import Config
|
from zhenxun.configs.config import Config
|
||||||
|
from zhenxun.utils.enum import PluginType
|
||||||
|
from zhenxun.utils.utils import FreqLimiter
|
||||||
|
from zhenxun.utils.message import MessageUtils
|
||||||
from zhenxun.models.ban_console import BanConsole
|
from zhenxun.models.ban_console import BanConsole
|
||||||
from zhenxun.models.group_console import GroupConsole
|
from zhenxun.models.group_console import GroupConsole
|
||||||
from zhenxun.utils.enum import PluginType
|
|
||||||
from zhenxun.utils.message import MessageUtils
|
|
||||||
from zhenxun.utils.utils import FreqLimiter
|
|
||||||
|
|
||||||
Config.add_plugin_config(
|
Config.add_plugin_config(
|
||||||
"hook",
|
"hook",
|
||||||
@ -58,12 +58,12 @@ async def _(
|
|||||||
else:
|
else:
|
||||||
time = abs(int(time))
|
time = abs(int(time))
|
||||||
if time < 60:
|
if time < 60:
|
||||||
time_str = str(time) + " 秒"
|
time_str = f"{time!s} 秒"
|
||||||
else:
|
else:
|
||||||
minute = int(time / 60)
|
minute = int(time / 60)
|
||||||
if minute > 60:
|
if minute > 60:
|
||||||
hours = int(minute / 60)
|
hours = minute // 60
|
||||||
minute = minute % 60
|
minute %= 60
|
||||||
time_str = f"{hours} 小时 {minute}分钟"
|
time_str = f"{hours} 小时 {minute}分钟"
|
||||||
else:
|
else:
|
||||||
time_str = f"{minute} 分钟"
|
time_str = f"{minute} 分钟"
|
||||||
|
|||||||
@ -18,6 +18,7 @@ from nonebot.adapters.onebot.v12 import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
from zhenxun.services.log import logger
|
from zhenxun.services.log import logger
|
||||||
|
from zhenxun.utils.rules import notice_rule
|
||||||
from zhenxun.utils.utils import FreqLimiter
|
from zhenxun.utils.utils import FreqLimiter
|
||||||
from zhenxun.utils.message import MessageUtils
|
from zhenxun.utils.message import MessageUtils
|
||||||
from zhenxun.models.fg_request import FgRequest
|
from zhenxun.models.fg_request import FgRequest
|
||||||
@ -95,9 +96,17 @@ limit_cd = base_config.get("welcome_msg_cd")
|
|||||||
_flmt = FreqLimiter(limit_cd)
|
_flmt = FreqLimiter(limit_cd)
|
||||||
|
|
||||||
|
|
||||||
group_increase_handle = on_notice(priority=1, block=False)
|
group_increase_handle = on_notice(
|
||||||
|
priority=1,
|
||||||
|
block=False,
|
||||||
|
rule=notice_rule([GroupIncreaseNoticeEvent, GroupMemberIncreaseEvent]),
|
||||||
|
)
|
||||||
"""群员增加处理"""
|
"""群员增加处理"""
|
||||||
group_decrease_handle = on_notice(priority=1, block=False)
|
group_decrease_handle = on_notice(
|
||||||
|
priority=1,
|
||||||
|
block=False,
|
||||||
|
rule=notice_rule([GroupDecreaseNoticeEvent, GroupMemberDecreaseEvent]),
|
||||||
|
)
|
||||||
"""群员减少处理"""
|
"""群员减少处理"""
|
||||||
add_group = on_request(priority=1, block=False)
|
add_group = on_request(priority=1, block=False)
|
||||||
"""加群同意请求"""
|
"""加群同意请求"""
|
||||||
|
|||||||
@ -11,6 +11,7 @@ from nonebot.adapters.onebot.v12 import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
from zhenxun.utils.enum import PluginType
|
from zhenxun.utils.enum import PluginType
|
||||||
|
from zhenxun.utils.rules import notice_rule
|
||||||
from zhenxun.utils.platform import PlatformUtils
|
from zhenxun.utils.platform import PlatformUtils
|
||||||
from zhenxun.utils.common_utils import CommonUtils
|
from zhenxun.utils.common_utils import CommonUtils
|
||||||
from zhenxun.configs.config import Config, BotConfig
|
from zhenxun.configs.config import Config, BotConfig
|
||||||
@ -82,9 +83,17 @@ base_config = Config.get("invite_manager")
|
|||||||
limit_cd = base_config.get("welcome_msg_cd")
|
limit_cd = base_config.get("welcome_msg_cd")
|
||||||
|
|
||||||
|
|
||||||
group_increase_handle = on_notice(priority=1, block=False)
|
group_increase_handle = on_notice(
|
||||||
|
priority=1,
|
||||||
|
block=False,
|
||||||
|
rule=notice_rule([GroupIncreaseNoticeEvent, GroupMemberIncreaseEvent]),
|
||||||
|
)
|
||||||
"""群员增加处理"""
|
"""群员增加处理"""
|
||||||
group_decrease_handle = on_notice(priority=1, block=False)
|
group_decrease_handle = on_notice(
|
||||||
|
priority=1,
|
||||||
|
block=False,
|
||||||
|
rule=notice_rule([GroupMemberDecreaseEvent, GroupMemberIncreaseEvent]),
|
||||||
|
)
|
||||||
"""群员减少处理"""
|
"""群员减少处理"""
|
||||||
add_group = on_request(priority=1, block=False)
|
add_group = on_request(priority=1, block=False)
|
||||||
"""加群同意请求"""
|
"""加群同意请求"""
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
from nonebot.adapters import Bot, Event
|
|
||||||
from nonebot.internal.rule import Rule
|
from nonebot.internal.rule import Rule
|
||||||
|
from nonebot.adapters import Bot, Event
|
||||||
from nonebot.permission import SUPERUSER
|
from nonebot.permission import SUPERUSER
|
||||||
from nonebot_plugin_session import EventSession, SessionLevel
|
from nonebot_plugin_session import EventSession, SessionLevel
|
||||||
|
|
||||||
@ -24,7 +24,7 @@ def admin_check(a: int | str, key: str | None = None) -> Rule:
|
|||||||
return True
|
return True
|
||||||
if session.id1 and session.id2:
|
if session.id1 and session.id2:
|
||||||
level = a
|
level = a
|
||||||
if type(a) == str and key:
|
if isinstance(a, str) and key:
|
||||||
level = Config.get_config(a, key)
|
level = Config.get_config(a, key)
|
||||||
if level is not None:
|
if level is not None:
|
||||||
return bool(
|
return bool(
|
||||||
@ -59,3 +59,26 @@ def ensure_private(session: EventSession) -> bool:
|
|||||||
bool: bool
|
bool: bool
|
||||||
"""
|
"""
|
||||||
return not session.id3 and not session.id2
|
return not session.id3 and not session.id2
|
||||||
|
|
||||||
|
|
||||||
|
def notice_rule(event_type: type | list[type]) -> Rule:
|
||||||
|
"""
|
||||||
|
Notice限制
|
||||||
|
|
||||||
|
参数:
|
||||||
|
event_type: Event类型
|
||||||
|
|
||||||
|
返回:
|
||||||
|
Rule: Rule
|
||||||
|
"""
|
||||||
|
|
||||||
|
async def _rule(event: Event) -> bool:
|
||||||
|
if isinstance(event_type, list):
|
||||||
|
for et in event_type:
|
||||||
|
if isinstance(event, et):
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return isinstance(event, event_type)
|
||||||
|
return False
|
||||||
|
|
||||||
|
return Rule(_rule)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user