Skip to content

Commit

Permalink
Merge pull request #19 from Reversedeer/dev
Browse files Browse the repository at this point in the history
更新v0.1.91
  • Loading branch information
Reversedeer authored Jul 28, 2023
2 parents f2a6002 + 3033bfc commit ff4cab5
Show file tree
Hide file tree
Showing 6 changed files with 155 additions and 70 deletions.
65 changes: 52 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,35 +33,55 @@ _✨ 基于NoneBot2实现的 监测QQ群事件 插件 ✨_
nb plugin install nonebot_plugin_eventmonitor
```

<details><summary><h3>pip</h3></summary>
<details>
<summary><h3>pip</h3></summary>


pip install nonebot-plugin-eventmonitor
在’pyproject.toml‘文件中写入


"nonebot_plugin_eventmonitor"

</details>

<details><summary><h3>git clone</h3></summary>
### 更新:

```
git clone https://github.com/Reversedeer/nonebot_piugin_eventmonitor.git
pip install --upgrade nonebot-plugin-eventmonitor
```

</details>

### 更新
## 配置

| 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 或者是否以机器人昵称开头来判断是否是向机器人发送的消息(必填) |

## 指令帮助

```
pip install --upgrade nonebot-plugin-eventmonitor
User: (戳一戳-> bot)
Bot: "请不要戳AI-Md >_<"
SUPERUSER/GROUP_ADMIN/GROUP_OWNER: "/开启 群荣誉检测"
Bot: "群荣誉检测功能已开启喵"
SUPERUSER/GROUP_ADMIN/GROUP_OWNER: "/event配置"
Bot: "
群114514的Event配置状态:
戳一戳: 开启
群荣誉检测: 开启
群文件检测: 开启
群成员减少检测: 开启
群成员增加检测: 开启
管理员变动检测: 开启
运气王检测: 关闭
"
```

## 配置

| config | type | default | example | usage |
| :-----: | :--: | :-----: | :----------: | :----------------: |
| chuo_cd | int | 0 | chuo_cd = 10 | 戳一戳的cd(选填) |

## 指令结构帮助:

Expand All @@ -75,17 +95,36 @@ usage = """
指令6:管理员变动检测(当新增管理员或取消管理员时发送消息提示,当bot自身被上/下管理时有特殊回复)
指令7:运气王检测(检测抢红包检测后的运气王并发送提示消息)
"""
json结构(默认值):
{
"114514": {
"chuo": true,
"honor": true,
"files": true,
"del_user": true,
"add_user": true,
"admin": true,
"red_package": false
}
}
```

<details>
<summary><h2>更新日志</h2></summary>

- v0.1.9

- v0.2.0

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

- 优化提示

- v0.1.9
- 🚨增加功能开关指令:event状态/event配置
- 🐛修复群文件不能检测bug(少写一个字母qwq)
- 优化目录结构

- v0.1.7
- 🚨新增所有功能开关[#issue5](https://github.com/Reversedeer/nonebot_plugin_eventmonitor/issues/9)

Expand Down
104 changes: 66 additions & 38 deletions nonebot_plugin_eventmonitor/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import contextlib
import nonebot

from nonebot.rule import Rule
from nonebot.matcher import Matcher
from nonebot.plugin import on_notice, on_command
Expand Down Expand Up @@ -46,31 +47,63 @@ async def _is_red_packet(event: Event) -> bool:
return isinstance(event, LuckyKingNotifyEvent)

# 戳一戳
chuo = on_notice(Rule(_is_poke), priority=50, block=True)
chuo = on_notice(
Rule(_is_poke),
priority=50,
block=True
)
# 群荣誉
qrongyu = on_notice(Rule(_is_rongyu), priority=50, block=True)
qrongyu = on_notice(
Rule(_is_rongyu),
priority=50,
block=True
)
# 群文件
files = on_notice(Rule(_is_checker), priority=50, block=True)
files = on_notice(
Rule(_is_checker),
priority=50,
block=True
)
# 群员减少
del_user = on_notice(Rule(_is_del_user), priority=50, block=True)
del_user = on_notice(
Rule(_is_del_user),
priority=50,
block=True
)
# 群员增加
add_user = on_notice(Rule(_is_add_user), priority=50, block=True)
add_user = on_notice(
Rule(_is_add_user),
priority=50,
block=True
)
# 群管理
group_admin = on_notice(Rule(_is_admin_change), priority=50, block=True)
group_admin = on_notice(
Rule(_is_admin_change),
priority=50,
block=True
)
# 红包
red_packet = on_notice(Rule(_is_red_packet), priority=50, block=True)
red_packet = on_notice(
Rule(_is_red_packet),
priority=50,
block=True
)
# 功能开关
switch_command = on_command("开启", aliases={"关闭"},
permission=SUPERUSER | GROUP_ADMIN | GROUP_OWNER,
priority=10,
block=False
)
switch_command = on_command(
"开启",
aliases={"关闭"},
permission=SUPERUSER | GROUP_ADMIN | GROUP_OWNER,
priority=10,
block=True
)
#功能状态
state = on_command("event配置", aliases={"event状态"},
permission=SUPERUSER | GROUP_ADMIN | GROUP_OWNER,
priority=10,
block=False
)
state = on_command(
"event配置",
aliases={"event状态"},
permission=SUPERUSER | GROUP_ADMIN | GROUP_OWNER,
priority=10,
block=True
)

#初始化配置配置文件
@driver.on_bot_connect
Expand All @@ -97,66 +130,61 @@ async def send_chuo(event: PokeNotifyEvent):
chuo_CD_dir.update({uid: event.time})
rely_msg = await chuo_send_msg()
await chuo.finish(message=Message(rely_msg))

#群荣誉变化
@qrongyu.handle()
async def send_rongyu(event: HonorNotifyEvent, bot: Bot):
if not (await check_honor(g_temp, str(event.group_id))):
await qrongyu.finish(notAllow, at_sender=True)
return
bot_qq = int(bot.self_id)
rely_msg = await monitor_rongyu(event.honor_type, event.user_id, bot_qq)
await qrongyu.finish(message=Message(rely_msg))

#上传群文件
@files.handle()
async def handle_first_receive(event: GroupUploadNoticeEvent):
if not (await check_file(g_temp, str(event.group_id))):
await files.finish(notAllow, at_sender=True)
return
rely = MessageSegment.at(event.user_id) + '\n' + \
MessageSegment.image(f'https://q4.qlogo.cn/headimg_dl?dst_uin={event.user_id}&spec=640') + \
'\n 上传了新文件,感谢你一直为群里做贡献喵~' + MessageSegment.face(175)
await files.finish(message=rely)

#退群事件
@del_user.handle()
async def user_bye(event: GroupDecreaseNoticeEvent):
if not (await check_del_user(g_temp, str(event.group_id))):
await del_user.finish(notAllow, at_sender=True)
return
rely_msg = await del_user_bye(event.time, event.user_id)
await del_user.finish(message=Message(rely_msg))

#入群事件
@add_user.handle()
async def user_welcome(event: GroupIncreaseNoticeEvent, bot: Bot):
await config_check()
if not (await check_add_user(g_temp, str(event.group_id))):
await add_user.finish(notAllow, at_sender=True)
return
bot_qq = int(bot.self_id)
rely_msg = await add_user_wecome(event.time, event.user_id, bot_qq)
await add_user.finish(message=Message(rely_msg))

#管理员变动
@group_admin.handle()
async def admin_chance(event: GroupAdminNoticeEvent, bot: Bot):
if not (await check_admin(g_temp, str(event.group_id))):
await group_admin.finish(notAllow, at_sender=True)
return
bot_qq = int(bot.self_id)
rely_msg = await admin_changer(event.sub_type, event.user_id, bot_qq)
await group_admin.finish(message=Message(rely_msg))

#红包运气王
@red_packet.handle()
async def hongbao(event: LuckyKingNotifyEvent):
if not (await check_red_package(g_temp, str(event.group_id))):
await red_packet.finish(notAllow, at_sender=True)
return
rely_msg = MessageSegment.at(event.user_id) + "\n" + "本次红包运气王为:" + MessageSegment.at(event.target_id)
await red_packet.finish(message=rely_msg)


def get_command_type(command: str) -> str:
"""根据指令内容获取开关类型"""
return next(
(
key
for key, keywords in path.items()
if any(keyword in command for keyword in keywords)
),
"",
)

@switch_command.handle()
async def switch(event: GroupMessageEvent, matcher: Matcher):
# 获取开关指令的参数,即用户输入的指令内容
Expand All @@ -169,13 +197,13 @@ async def switch(event: GroupMessageEvent, matcher: Matcher):
g_temp[gid][key] = True
write_group_data(g_temp)
name = get_function_name(key)
await switch_command.finish(f"{name}功能已开启喵")
await matcher.finish(f"{name}功能已开启喵")
elif "禁止" in command or "关闭" in command:
if key := get_command_type(command):
g_temp[gid][key] = False
write_group_data(g_temp)
name = get_function_name(key)
await switch_command.finish(f"{name}功能已禁用喵")
await matcher.finish(f"{name}功能已禁用喵")

@state.handle()
async def event_state(event:GroupMessageEvent, matcher: Matcher):
Expand Down Expand Up @@ -205,7 +233,7 @@ async def event_state(event:GroupMessageEvent, matcher: Matcher):
supported_adapters={"onebot.v11"},
extra={
"author": "Reversedeer",
"version": "0.1.8",
"version": "0.2.0",
"priority": 50,
},
)
2 changes: 0 additions & 2 deletions nonebot_plugin_eventmonitor/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ async def del_user_bye(add_time, user_id):
if user_id in superusers:
# 如果是超级用户,生成特定的离开消息
del_user_msg = f"⌈{del_time}\n@{user_id}恭送主人离开喵~"
print(superusers)
else:
# 如果不是超级用户,生成通用的离开消息,包含用户的QQ号和头像图片
del_user_msg = f"✈️ 成员变动 ✈️ \n时间: ⌈{del_time}\nQQ号为:{user_id}的小可爱退群喵~" \
Expand All @@ -58,6 +57,5 @@ async def add_user_wecome(add_time, user_id, bot_qq):
# 如果是普通用户加入群组,生成通用的欢迎消息,包含用户ID、加入时间和用户头像图片的链接
add_user_msg = f"✨ 成员变动 ✨\n欢迎@{user_id}的加入喵~\n加入时间:⌈{add_time}⌋,请在群内积极发言喵~" \
f"[CQ:image,file=https://q4.qlogo.cn/headimg_dl?dst_uin={user_id}&spec=640]"

return add_user_msg

4 changes: 2 additions & 2 deletions nonebot_plugin_eventmonitor/honour.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ async def monitor_rongyu(honor_type, user_id, bot_qq):
if honor_type == "emotion":
# 如果用户ID等于机器人的QQ号,不作任何操作
if user_id == bot_qq:
pass
rely = "你们又不行了,本喵喜提快乐源泉🤣~"
# 如果用户ID在superusers列表中,返回特定消息
elif user_id in superusers:
rely = f"@{user_id}恭喜主人荣获快乐源泉🤣标识喵~"
Expand All @@ -18,7 +18,7 @@ async def monitor_rongyu(honor_type, user_id, bot_qq):
elif honor_type == "performer":
# 如果用户ID等于机器人的QQ号,不作任何操作
if user_id == bot_qq:
pass
rely = "你们又不行了,本喵喜提群聊之火🔥~"
# 如果用户ID在superusers列表中,返回特定消息
elif user_id in superusers:
rely = f"@{user_id}恭喜主人荣获群聊之火🔥标识喵~"
Expand Down
Loading

0 comments on commit ff4cab5

Please sign in to comment.