Skip to content

Commit

Permalink
✨适配插件元数据
Browse files Browse the repository at this point in the history
  • Loading branch information
Reversedeer committed Aug 2, 2024
1 parent 5c2b0e8 commit 53da0c9
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 42 deletions.
33 changes: 15 additions & 18 deletions nonebot_plugin_eventmonitor/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import contextlib
import nonebot

from nonebot.rule import Rule
from nonebot.matcher import Matcher
from nonebot.plugin import on_notice, on_command
from nonebot.permission import SUPERUSER
from nonebot.plugin import PluginMetadata
from nonebot.adapters.onebot.v11.permission import GROUP_OWNER, GROUP_ADMIN
from nonebot.adapters.onebot.v11 import (
Bot, Event, Message,
Expand Down Expand Up @@ -104,7 +104,7 @@ async def _is_red_packet(event: Event) -> bool:
priority=10,
block=True
)

driver = nonebot.get_driver()
#初始化配置配置文件
@driver.on_bot_connect
async def _():
Expand Down Expand Up @@ -221,19 +221,16 @@ async def event_state(event:GroupMessageEvent, matcher: Matcher):
)


with contextlib.suppress(Exception):
from nonebot.plugin import PluginMetadata

__plugin_meta__ = PluginMetadata(
name="eventmonitor",
description="监控群事件的插件,支持戳一戳,成员变动,群荣誉变化等提示的插件",
usage=utils.usage,
type="application",
homepage="https://github.com/Reversedeer/nonebot_plugin_eventmonitor",
supported_adapters={"onebot.v11"},
extra={
"author": "Reversedeer",
"version": "0.2.0",
"priority": 50,
},
)
__plugin_meta__ = PluginMetadata(
name="eventmonitor",
description="监控群事件的插件,支持戳一戳,成员变动,群荣誉变化等提示的插件",
usage=utils.usage,
type="application",
homepage="https://github.com/Reversedeer/nonebot_plugin_eventmonitor",
supported_adapters={"~onebot.v11"},
extra={
"author": "Reversedeer",
"version": "0.2.1",
"priority": 50,
}
)
45 changes: 21 additions & 24 deletions nonebot_plugin_eventmonitor/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,11 @@

config_path = Path() / 'data/eventmonitor'
address = config_path / 'config.json'

driver = nonebot.get_driver()
#从 配置文件中获取SUPERUSER, NICKNAME
config = nonebot.get_driver().config
config = nonebot.get_driver().config #从 配置文件中获取SUPERUSER, NICKNAME
superusers = {int(uid) for uid in config.superusers}
nickname = next(iter(config.nickname))
#戳一戳cd,感觉很鸡肋,自行调整

nickname: str = next(iter(config.nickname), "Bot")
notAllow = "功能未开启"
chuo_cd: int = getattr(config, "chuo_cd", 0) #戳一戳cd默认值


async def init(g_temp):
Expand Down Expand Up @@ -111,64 +107,71 @@ def json_upload(path, dict_content) -> None:
c.write(json.dumps(dict_content, ensure_ascii=False, indent=4))


#写入群配置

def write_group_data(g_temp):
"""写入群配置"""
with open('data/eventmonitor/config.json', 'w', encoding='utf-8') as f:
json.dump(g_temp, f, indent=4, ensure_ascii=False)


#检查戳一戳是否允许
async def check_chuo(g_temp, gid: str) -> bool:
"""检查戳一戳是否允许"""
if gid in g_temp and not g_temp[gid]["chuo"]:
return False
return g_temp[gid]["chuo"]

#检查群荣誉是否允许

async def check_honor(g_temp, gid: str) -> bool:
"""检查群荣誉是否允许"""
if gid in g_temp and not g_temp[gid]["honor"]:
print(g_temp)
return False
return g_temp[gid]["honor"]

#检查群文件是否允许

async def check_file(g_temp, gid: str) -> bool:
"""检查群文件是否允许"""
if gid in g_temp and not g_temp[gid]["files"]:
return False
return g_temp[gid]["files"]

#检查群成员减少是否允许

async def check_del_user(g_temp, gid: str) -> bool:
"""检查群成员减少是否允许 """
if gid in g_temp and not g_temp[gid]["del_user"]:
return False
print(g_temp)
return g_temp[gid]["del_user"]

#检查群成员增加是否允许

async def check_add_user(g_temp, gid: str) -> bool:
"""检查群成员增加是否允许"""
if gid in g_temp and not g_temp[gid]["add_user"]:
return False
print(g_temp)
return g_temp[gid]["add_user"]


#检查管理员是否允许
async def check_admin(g_temp, gid: str) -> bool:
"""检查管理员是否允许"""
if gid in g_temp and not g_temp[gid]["admin"]:
return False
return g_temp[gid]["admin"]

#检查运气王是否允许

async def check_red_package(g_temp, gid: str) -> bool:
"""检查运气王是否允许"""
if gid in g_temp and not g_temp[gid]["red_package"]:
return False
return g_temp[gid]["red_package"]

#根据关键词获取对应功能名称
def get_function_name(key: str) -> str:
"""根据关键词获取对应功能名称"""
return path[key][0]

#根据指令内容获取开关类型

def get_command_type(command: str) -> str:
"""根据指令内容获取开关类型"""
return next(
(
key
Expand All @@ -177,13 +180,7 @@ def get_command_type(command: str) -> str:
),
"",
)

#戳一戳cd默认值
try:
chuo_cd = nonebot.get_driver().config.chuo_cd
except Exception:
chuo_cd = 0



path = {
'chuo': ['戳一戳'],
Expand Down

0 comments on commit 53da0c9

Please sign in to comment.