Skip to content

Commit

Permalink
✨适配插件元数据
Browse files Browse the repository at this point in the history
  • Loading branch information
Reversedeer authored Jan 8, 2024
2 parents 38dd59b + 7d7a430 commit 0f5c101
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 54 deletions.
26 changes: 16 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
</div>

<p align="center">
<a href="https://raw.githubusercontent.com/Mrs4s/go-cqhttp/master/LICENSE">
<img src="https://img.shields.io/github/license/Mrs4s/go-cqhttp" alt="license">
<a href="https://raw.githubusercontent.com/Reversedeer/nonebot_plugin_eventmonitor/main/LICENSE">
<img src="https://img.shields.io/github/license/Reversedeer/nonebot_plugin_eventmonitor" alt="license">
</a>
<a href="https://camo.githubusercontent.com/c5bfbde247cd10e93ff50a518b0f5e441a6e9959495f6bf0f1a1913d2b1b7a8d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f707974686f6e2d332e382b2d626c75652e737667">
<img src="https://img.shields.io/badge/python-3.8+-green.svg" alt="python">
Expand All @@ -26,6 +26,7 @@
</a>
</p>


## 介绍:点点Star✨
> 监测群组的以下变动事件:
>
Expand Down Expand Up @@ -69,11 +70,11 @@ pip install --upgrade nonebot-plugin-eventmonitor

## 配置

| config | type | default | example | usage |
| :--------: | :------: | :-----: | :-------------------: | :----------------------------------------------------------: |
| chuo_cd | int | 0 | chuo_cd = 10 | 戳一戳的cd(选填) |
| SUPERUSERS | set[str] | set() | SUPERUSERS=["114514"] | 机器人超级用户,可以使用权限 [`SUPERUSER`](https://nonebot.dev/docs/2.0.0/api/permission#SUPERUSER)(必填) |
| NICKNAME | set[str] | set() | NICKNAME=["IKun"] | 机器人昵称,通常协议适配器会根据用户是否 @user 或者是否以机器人昵称开头来判断是否是向机器人发送的消息(必填) |
| config | type | default | example | usage |
| :--------: | :------: | :------: | :-------------------: | :----------------------------------------------------------: |
| chuo_cd | int | 0 | chuo_cd = 10 | 戳一戳的cd(选填) |
| SUPERUSERS | set[str] | set() | SUPERUSERS=["114514"] | 机器人超级用户,可以使用权限 [`SUPERUSER`](https://nonebot.dev/docs/2.0.0/api/permission#SUPERUSER)(必填) |
| NICKNAME | set[str] | set(Bot) | NICKNAME=["IKun"] | 机器人昵称,通常协议适配器会根据用户是否 @user 或者是否以机器人昵称开头来判断是否是向机器人发送的消息(必填) |

## 指令帮助

Expand Down Expand Up @@ -135,12 +136,17 @@ json结构(默认值):
<details>
<summary><h2>更新日志</h2></summary>

- v0.2.0
- v0.2.1

- 🐛修复bot加群bug[issue6](https://github.com/Reversedeer/nonebot_plugin_eventmonitor/issues/18)
- 适配插件元数据

- 优化提示
- 🐛修复bug

- v0.2.0
- 🐛修复bot加群bug[issue6](https://github.com/Reversedeer/nonebot_plugin_eventmonitor/issues/18)

- 优化提示

- v0.1.9
- 🚨增加功能开关指令:event状态/event配置
- 🐛修复群文件不能检测bug(少写一个字母qwq)
Expand Down
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
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="nonebot_plugin_eventmonitor",
version="0.2.0",
version="0.2.1",
author="schwarzwald",
description="监控群事件的插件,支持戳一戳,成员变动,群荣誉,运气王变化等提示",
long_description=long_description,
Expand All @@ -23,7 +23,7 @@
python_requires=">=3.8",
install_requires = [
'nonebot2>=2.0.0rc2',
'nonebot-adapter-onebot',
'nonebot-adapter-onebot>=2.1.3',
'requests>=2.28.2'
]
)

0 comments on commit 0f5c101

Please sign in to comment.