nonebot_plugin_poke 0.1.6__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- nonebot_plugin_poke-0.1.6/LICENSE +21 -0
- nonebot_plugin_poke-0.1.6/PKG-INFO +138 -0
- nonebot_plugin_poke-0.1.6/README.md +113 -0
- nonebot_plugin_poke-0.1.6/nonebot_plugin_poke/__init__.py +106 -0
- nonebot_plugin_poke-0.1.6/nonebot_plugin_poke/config.py +34 -0
- nonebot_plugin_poke-0.1.6/nonebot_plugin_poke/matcher.py +38 -0
- nonebot_plugin_poke-0.1.6/nonebot_plugin_poke/utils.py +152 -0
- nonebot_plugin_poke-0.1.6/pyproject.toml +120 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Agnes Digital
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: nonebot_plugin_poke
|
|
3
|
+
Version: 0.1.6
|
|
4
|
+
Summary: 自定义群聊戳戳事件 plugin for NoneBot2
|
|
5
|
+
Keywords: nonebot2,plugin,poke
|
|
6
|
+
Author-Email: Agnes_Digital <Z735803792@163.com>
|
|
7
|
+
License: MIT
|
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
+
Classifier: Programming Language :: Python
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Requires-Python: <4.0,>=3.9
|
|
18
|
+
Requires-Dist: nonebot2>=2.1.0
|
|
19
|
+
Requires-Dist: nonebot-plugin-alconna>=0.58.5
|
|
20
|
+
Requires-Dist: nonebot-adapter-onebot>=2.1.5
|
|
21
|
+
Requires-Dist: aiofiles>=23.1.0
|
|
22
|
+
Requires-Dist: aiohttp>=3.8.5
|
|
23
|
+
Requires-Dist: pydantic>=2.1.1
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
|
|
26
|
+
<!-- markdownlint-disable MD026 MD031 MD033 MD036 MD041 MD046 -->
|
|
27
|
+
<div align="center">
|
|
28
|
+
<img src="https://raw.githubusercontent.com/Agnes4m/nonebot_plugin_l4d2_server/main/image/logo.png" width="180" height="180" alt="AgnesDigitalLogo">
|
|
29
|
+
<br>
|
|
30
|
+
<p><img src="https://s2.loli.net/2022/06/16/xsVUGRrkbn1ljTD.png" width="240" alt="NoneBotPluginText"></p>
|
|
31
|
+
</div>
|
|
32
|
+
|
|
33
|
+
<div align="center">
|
|
34
|
+
|
|
35
|
+
# nonebot_plugin_poke(仅支持onebotv11)
|
|
36
|
+
|
|
37
|
+
_✨Nonebot & 自定义戳戳群聊事件✨_
|
|
38
|
+
|
|
39
|
+
<a href="https://github.com/Agnes4m/nonebot_plugin_poke/stargazers">
|
|
40
|
+
<img alt="GitHub stars" src="https://img.shields.io/github/stars/Agnes4m/nonebot_plugin_poke" alt="stars">
|
|
41
|
+
</a>
|
|
42
|
+
<a href="https://github.com/Agnes4m/nonebot_plugin_poke/issues">
|
|
43
|
+
<img alt="GitHub issues" src="https://img.shields.io/github/issues/Agnes4m/nonebot_plugin_poke" alt="issues">
|
|
44
|
+
</a>
|
|
45
|
+
<a href="https://jq.qq.com/?_wv=1027&k=HdjoCcAe">
|
|
46
|
+
<img src="https://img.shields.io/badge/QQ%E7%BE%A4-399365126-orange?style=flat-square" alt="QQ Chat Group">
|
|
47
|
+
</a>
|
|
48
|
+
<a href="https://pypi.python.org/pypi/nonebot_plugin_poke">
|
|
49
|
+
<img src="https://img.shields.io/pypi/v/nonebot_plugin_poke.svg" alt="pypi">
|
|
50
|
+
</a>
|
|
51
|
+
<img src="https://img.shields.io/badge/python-3.9+-blue.svg" alt="python">
|
|
52
|
+
<img src="https://img.shields.io/badge/nonebot-2.0.0-red.svg" alt="NoneBot">
|
|
53
|
+
|
|
54
|
+
</div>
|
|
55
|
+
|
|
56
|
+
## 注意事项
|
|
57
|
+
|
|
58
|
+
**如果使用napcat,请将版本更新到1.6.6或者以上,否则这个功能用不了**
|
|
59
|
+
|
|
60
|
+
## 安装
|
|
61
|
+
|
|
62
|
+
方法一 (推荐):
|
|
63
|
+
```bash
|
|
64
|
+
nb plugin install nonebot_plugin_poke
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
方法二:
|
|
68
|
+
```bash
|
|
69
|
+
poetry add nonebot_plugin_poke
|
|
70
|
+
pdm add nonebot_plugin_poke
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
方法三:
|
|
74
|
+
```bash
|
|
75
|
+
pip install nonebot_plugin_poke
|
|
76
|
+
```
|
|
77
|
+
再手动添加`nonebot_plugin_poke`到bot文件下`pyproject.toml`文件中
|
|
78
|
+
|
|
79
|
+
## env配置项:
|
|
80
|
+
|
|
81
|
+
# 在完全不写的情况下,效果是戳戳后反戳戳
|
|
82
|
+
# 机器人名称
|
|
83
|
+
bot_nickname: str = '宁宁'
|
|
84
|
+
# 是否回复图片
|
|
85
|
+
poke_send_pic: bool = False
|
|
86
|
+
# 是否回复戳戳
|
|
87
|
+
poke_send_poke: bool = True
|
|
88
|
+
# 是否回复文字
|
|
89
|
+
poke_send_text: bool = False
|
|
90
|
+
# 是否回复音频
|
|
91
|
+
poke_send_acc: bool = False
|
|
92
|
+
|
|
93
|
+
如果不知道以下配置,默认就可以,只修改上面部分
|
|
94
|
+
|
|
95
|
+
# poke文件夹位置
|
|
96
|
+
poke_path:Path = Path('data/poke')
|
|
97
|
+
# 是否开启黑名单模式(否则是白名单)
|
|
98
|
+
poke_black: bool = True
|
|
99
|
+
# 黑名单屏蔽群组
|
|
100
|
+
poke_ban_group:List[str] = []
|
|
101
|
+
# 白名单允许群组
|
|
102
|
+
poke_allow_group:List[str] = []
|
|
103
|
+
# 戳戳优先级
|
|
104
|
+
poke_priority:int = 1
|
|
105
|
+
# 是否阻断其他指令
|
|
106
|
+
poke_block:bool = True
|
|
107
|
+
|
|
108
|
+
## 指令
|
|
109
|
+
|
|
110
|
+
群里双击bot头像,会依次按照配置文件,逐步检查回复
|
|
111
|
+
|
|
112
|
+
## 数据结构
|
|
113
|
+
|
|
114
|
+
```txt
|
|
115
|
+
举例:
|
|
116
|
+
└── data
|
|
117
|
+
└── poke
|
|
118
|
+
├── poke.txt # 回复文字
|
|
119
|
+
├── pic # 回复图片
|
|
120
|
+
├── 1.png
|
|
121
|
+
├── 2.jpg
|
|
122
|
+
├── 3.jpeg
|
|
123
|
+
└── ...
|
|
124
|
+
└── acc # 回复音频
|
|
125
|
+
├── 1.acc
|
|
126
|
+
├── 2.mp3
|
|
127
|
+
└── ...
|
|
128
|
+
...
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
## 其他
|
|
132
|
+
|
|
133
|
+
- 如果发不出语音,请手动安装ffmpeg
|
|
134
|
+
- 当语音,与图或文都为True的时候,则随机发送一种,防止刷屏刷到风控
|
|
135
|
+
|
|
136
|
+
## 参考
|
|
137
|
+
|
|
138
|
+
- [智障回复](https://github.com/Special-Week/nonebot_plugin_smart_reply)
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
<!-- markdownlint-disable MD026 MD031 MD033 MD036 MD041 MD046 -->
|
|
2
|
+
<div align="center">
|
|
3
|
+
<img src="https://raw.githubusercontent.com/Agnes4m/nonebot_plugin_l4d2_server/main/image/logo.png" width="180" height="180" alt="AgnesDigitalLogo">
|
|
4
|
+
<br>
|
|
5
|
+
<p><img src="https://s2.loli.net/2022/06/16/xsVUGRrkbn1ljTD.png" width="240" alt="NoneBotPluginText"></p>
|
|
6
|
+
</div>
|
|
7
|
+
|
|
8
|
+
<div align="center">
|
|
9
|
+
|
|
10
|
+
# nonebot_plugin_poke(仅支持onebotv11)
|
|
11
|
+
|
|
12
|
+
_✨Nonebot & 自定义戳戳群聊事件✨_
|
|
13
|
+
|
|
14
|
+
<a href="https://github.com/Agnes4m/nonebot_plugin_poke/stargazers">
|
|
15
|
+
<img alt="GitHub stars" src="https://img.shields.io/github/stars/Agnes4m/nonebot_plugin_poke" alt="stars">
|
|
16
|
+
</a>
|
|
17
|
+
<a href="https://github.com/Agnes4m/nonebot_plugin_poke/issues">
|
|
18
|
+
<img alt="GitHub issues" src="https://img.shields.io/github/issues/Agnes4m/nonebot_plugin_poke" alt="issues">
|
|
19
|
+
</a>
|
|
20
|
+
<a href="https://jq.qq.com/?_wv=1027&k=HdjoCcAe">
|
|
21
|
+
<img src="https://img.shields.io/badge/QQ%E7%BE%A4-399365126-orange?style=flat-square" alt="QQ Chat Group">
|
|
22
|
+
</a>
|
|
23
|
+
<a href="https://pypi.python.org/pypi/nonebot_plugin_poke">
|
|
24
|
+
<img src="https://img.shields.io/pypi/v/nonebot_plugin_poke.svg" alt="pypi">
|
|
25
|
+
</a>
|
|
26
|
+
<img src="https://img.shields.io/badge/python-3.9+-blue.svg" alt="python">
|
|
27
|
+
<img src="https://img.shields.io/badge/nonebot-2.0.0-red.svg" alt="NoneBot">
|
|
28
|
+
|
|
29
|
+
</div>
|
|
30
|
+
|
|
31
|
+
## 注意事项
|
|
32
|
+
|
|
33
|
+
**如果使用napcat,请将版本更新到1.6.6或者以上,否则这个功能用不了**
|
|
34
|
+
|
|
35
|
+
## 安装
|
|
36
|
+
|
|
37
|
+
方法一 (推荐):
|
|
38
|
+
```bash
|
|
39
|
+
nb plugin install nonebot_plugin_poke
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
方法二:
|
|
43
|
+
```bash
|
|
44
|
+
poetry add nonebot_plugin_poke
|
|
45
|
+
pdm add nonebot_plugin_poke
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
方法三:
|
|
49
|
+
```bash
|
|
50
|
+
pip install nonebot_plugin_poke
|
|
51
|
+
```
|
|
52
|
+
再手动添加`nonebot_plugin_poke`到bot文件下`pyproject.toml`文件中
|
|
53
|
+
|
|
54
|
+
## env配置项:
|
|
55
|
+
|
|
56
|
+
# 在完全不写的情况下,效果是戳戳后反戳戳
|
|
57
|
+
# 机器人名称
|
|
58
|
+
bot_nickname: str = '宁宁'
|
|
59
|
+
# 是否回复图片
|
|
60
|
+
poke_send_pic: bool = False
|
|
61
|
+
# 是否回复戳戳
|
|
62
|
+
poke_send_poke: bool = True
|
|
63
|
+
# 是否回复文字
|
|
64
|
+
poke_send_text: bool = False
|
|
65
|
+
# 是否回复音频
|
|
66
|
+
poke_send_acc: bool = False
|
|
67
|
+
|
|
68
|
+
如果不知道以下配置,默认就可以,只修改上面部分
|
|
69
|
+
|
|
70
|
+
# poke文件夹位置
|
|
71
|
+
poke_path:Path = Path('data/poke')
|
|
72
|
+
# 是否开启黑名单模式(否则是白名单)
|
|
73
|
+
poke_black: bool = True
|
|
74
|
+
# 黑名单屏蔽群组
|
|
75
|
+
poke_ban_group:List[str] = []
|
|
76
|
+
# 白名单允许群组
|
|
77
|
+
poke_allow_group:List[str] = []
|
|
78
|
+
# 戳戳优先级
|
|
79
|
+
poke_priority:int = 1
|
|
80
|
+
# 是否阻断其他指令
|
|
81
|
+
poke_block:bool = True
|
|
82
|
+
|
|
83
|
+
## 指令
|
|
84
|
+
|
|
85
|
+
群里双击bot头像,会依次按照配置文件,逐步检查回复
|
|
86
|
+
|
|
87
|
+
## 数据结构
|
|
88
|
+
|
|
89
|
+
```txt
|
|
90
|
+
举例:
|
|
91
|
+
└── data
|
|
92
|
+
└── poke
|
|
93
|
+
├── poke.txt # 回复文字
|
|
94
|
+
├── pic # 回复图片
|
|
95
|
+
├── 1.png
|
|
96
|
+
├── 2.jpg
|
|
97
|
+
├── 3.jpeg
|
|
98
|
+
└── ...
|
|
99
|
+
└── acc # 回复音频
|
|
100
|
+
├── 1.acc
|
|
101
|
+
├── 2.mp3
|
|
102
|
+
└── ...
|
|
103
|
+
...
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## 其他
|
|
107
|
+
|
|
108
|
+
- 如果发不出语音,请手动安装ffmpeg
|
|
109
|
+
- 当语音,与图或文都为True的时候,则随机发送一种,防止刷屏刷到风控
|
|
110
|
+
|
|
111
|
+
## 参考
|
|
112
|
+
|
|
113
|
+
- [智障回复](https://github.com/Special-Week/nonebot_plugin_smart_reply)
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import imghdr
|
|
2
|
+
from datetime import datetime
|
|
3
|
+
from typing import List
|
|
4
|
+
|
|
5
|
+
from nonebot.adapters import Message
|
|
6
|
+
from nonebot.adapters.onebot.v11 import MessageEvent, PokeNotifyEvent
|
|
7
|
+
from nonebot.log import logger
|
|
8
|
+
from nonebot.matcher import Matcher
|
|
9
|
+
from nonebot.plugin import PluginMetadata
|
|
10
|
+
from nonebot.plugin.on import on_command, on_notice
|
|
11
|
+
|
|
12
|
+
from .matcher import poke_reply
|
|
13
|
+
from .utils import config, get_data, poke_rule
|
|
14
|
+
|
|
15
|
+
__version__ = "0.1.6"
|
|
16
|
+
__plugin_meta__ = PluginMetadata(
|
|
17
|
+
name="戳一戳事件",
|
|
18
|
+
description="自定义群聊戳一戳事件",
|
|
19
|
+
usage="戳戳",
|
|
20
|
+
type="application",
|
|
21
|
+
homepage="https://github.com/Agnes4m/nonebot_plugin_poke",
|
|
22
|
+
supported_adapters={"~onebot.v11"},
|
|
23
|
+
extra={
|
|
24
|
+
"version": __version__,
|
|
25
|
+
"author": "Agnes4m <Z735803792@163.com>",
|
|
26
|
+
},
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
poke_ = on_notice(block=config.poke_block, priority=config.poke_priority, rule=poke_rule)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
@poke_.handle()
|
|
34
|
+
async def _(event: PokeNotifyEvent, matcher: Matcher):
|
|
35
|
+
logger.info("戳戳触发")
|
|
36
|
+
await poke_reply(event, matcher)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
add_pic = on_command("zq", aliases={"抓图"}, priority=30)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
@add_pic.handle()
|
|
43
|
+
async def _(event: MessageEvent, matcher: Matcher):
|
|
44
|
+
images: List[bytes] = []
|
|
45
|
+
images_name: List[str] = []
|
|
46
|
+
|
|
47
|
+
success: int = 0
|
|
48
|
+
fail: int = 0
|
|
49
|
+
|
|
50
|
+
# 处理回复消息中的图片
|
|
51
|
+
if event.reply:
|
|
52
|
+
for pic in event.reply.message["image"]:
|
|
53
|
+
_img = None
|
|
54
|
+
try:
|
|
55
|
+
_img = await get_data(str(pic.data.get("url", "")))
|
|
56
|
+
if not _img:
|
|
57
|
+
return
|
|
58
|
+
success += 1
|
|
59
|
+
images.append(_img)
|
|
60
|
+
except Exception as e:
|
|
61
|
+
if _img:
|
|
62
|
+
success += 1
|
|
63
|
+
images.append(_img)
|
|
64
|
+
else:
|
|
65
|
+
logger.warning(f"获取图片失败: {e}")
|
|
66
|
+
fail += 1
|
|
67
|
+
|
|
68
|
+
# 处理消息中的图片
|
|
69
|
+
|
|
70
|
+
msg: Message = event.dict()["message"]
|
|
71
|
+
for msg_seg in msg:
|
|
72
|
+
if msg_seg.type == "image":
|
|
73
|
+
try:
|
|
74
|
+
_img = await get_data(str(msg_seg.data.get("url", "")))
|
|
75
|
+
success += 1
|
|
76
|
+
if not _img:
|
|
77
|
+
return
|
|
78
|
+
images.append(_img)
|
|
79
|
+
|
|
80
|
+
except Exception as e:
|
|
81
|
+
if _img:
|
|
82
|
+
success += 1
|
|
83
|
+
images.append(_img)
|
|
84
|
+
else:
|
|
85
|
+
fail += 1
|
|
86
|
+
logger.warning(f"获取图片失败: {e}")
|
|
87
|
+
fail += 1
|
|
88
|
+
|
|
89
|
+
base = 0
|
|
90
|
+
while len(images_name) < len(images):
|
|
91
|
+
images_name.append(str(int(datetime.now().timestamp()) + base))
|
|
92
|
+
base += 1
|
|
93
|
+
images_name = images_name[: len(images)]
|
|
94
|
+
images_name = [
|
|
95
|
+
f"{img_name}.{imghdr.what(None, h=images[i])}"
|
|
96
|
+
for i, img_name in enumerate(images_name)
|
|
97
|
+
]
|
|
98
|
+
|
|
99
|
+
path = config.poke_path.joinpath("pic")
|
|
100
|
+
for i, img in enumerate(images):
|
|
101
|
+
img_path = path / images_name[i]
|
|
102
|
+
with img_path.open("wb+") as f:
|
|
103
|
+
f.write(img)
|
|
104
|
+
|
|
105
|
+
tosend = f"添加完成,成功{success}张,失败{fail}张,可用于戳戳随机图"
|
|
106
|
+
await matcher.send(message=tosend, at_sender=True)
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
from typing import List
|
|
3
|
+
|
|
4
|
+
from nonebot import get_plugin_config
|
|
5
|
+
from pydantic import BaseModel, model_validator
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class ConfigModel(BaseModel):
|
|
9
|
+
bot_nickname: str = "宁宁"
|
|
10
|
+
poke_black: bool = True
|
|
11
|
+
poke_ban_group: List[str] = []
|
|
12
|
+
poke_allow_group: List[str] = []
|
|
13
|
+
poke_send_pic: bool = False
|
|
14
|
+
poke_send_poke: bool = True
|
|
15
|
+
poke_send_text: bool = False
|
|
16
|
+
poke_send_acc: bool = False
|
|
17
|
+
poke_path: Path = Path("data/poke")
|
|
18
|
+
poke_priority: int = 1
|
|
19
|
+
poke_block: bool = True
|
|
20
|
+
|
|
21
|
+
@model_validator(mode="before")
|
|
22
|
+
def ensure_path(self, data: dict):
|
|
23
|
+
if isinstance(data.get("poke_path"), str):
|
|
24
|
+
data["poke_path"] = Path(data["poke_path"])
|
|
25
|
+
return data
|
|
26
|
+
|
|
27
|
+
class Config:
|
|
28
|
+
extra = "ignore"
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
config = get_plugin_config(ConfigModel)
|
|
32
|
+
# 初始化
|
|
33
|
+
Path(config.poke_path.joinpath("pic")).mkdir(parents=True, exist_ok=True)
|
|
34
|
+
Path(config.poke_path.joinpath("acc")).mkdir(parents=True, exist_ok=True)
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import random
|
|
2
|
+
|
|
3
|
+
from nonebot.adapters.onebot.v11 import PokeNotifyEvent
|
|
4
|
+
from nonebot.matcher import Matcher
|
|
5
|
+
|
|
6
|
+
from .config import config
|
|
7
|
+
from .utils import PS
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
async def poke_reply(event: PokeNotifyEvent, matcher: Matcher):
|
|
11
|
+
if config.poke_send_poke:
|
|
12
|
+
await PS.poke_send(event, matcher)
|
|
13
|
+
|
|
14
|
+
if config.poke_send_acc and (config.poke_send_pic or config.poke_send_text):
|
|
15
|
+
roll = random.random()
|
|
16
|
+
if roll > 0.5:
|
|
17
|
+
await PS.acc_send(matcher)
|
|
18
|
+
else:
|
|
19
|
+
await matcher_pic_text(matcher)
|
|
20
|
+
elif config.poke_send_acc and not (config.poke_send_pic or config.poke_send_text):
|
|
21
|
+
await PS.acc_send(matcher)
|
|
22
|
+
elif not config.poke_send_acc and (config.poke_send_pic or config.poke_send_text):
|
|
23
|
+
await matcher_pic_text(matcher)
|
|
24
|
+
else:
|
|
25
|
+
return
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
async def matcher_pic_text(matcher):
|
|
29
|
+
if config.poke_send_pic and config.poke_send_text:
|
|
30
|
+
await PS.pic_or_text(
|
|
31
|
+
await PS.pic_send(),
|
|
32
|
+
await PS.text_send(),
|
|
33
|
+
matcher,
|
|
34
|
+
)
|
|
35
|
+
elif config.poke_send_pic and not config.poke_send_text:
|
|
36
|
+
await PS.pic_or_text(await PS.pic_send(), None, matcher)
|
|
37
|
+
elif not config.poke_send_pic and config.poke_send_text:
|
|
38
|
+
await PS.pic_or_text(None, await PS.text_send(), matcher)
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import random
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
from typing import List, Optional
|
|
4
|
+
|
|
5
|
+
import aiofiles
|
|
6
|
+
import aiohttp
|
|
7
|
+
from nonebot.adapters.onebot.v11 import Message, MessageSegment, PokeNotifyEvent
|
|
8
|
+
from nonebot.log import logger
|
|
9
|
+
from nonebot.matcher import Matcher
|
|
10
|
+
|
|
11
|
+
from .config import config
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
async def get_data(url: str):
|
|
15
|
+
"""获取url内容"""
|
|
16
|
+
headers = {
|
|
17
|
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:107.0) Gecko/20100101 Firefox/107.0",
|
|
18
|
+
}
|
|
19
|
+
async with (
|
|
20
|
+
aiohttp.ClientSession() as session,
|
|
21
|
+
session.get(url, headers=headers, timeout=600) as response,
|
|
22
|
+
):
|
|
23
|
+
if response.status == 200:
|
|
24
|
+
return await response.read()
|
|
25
|
+
return None
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class PokeSender:
|
|
29
|
+
def __init__(self):
|
|
30
|
+
self.poke_path = config.poke_path
|
|
31
|
+
self.bot_nickname = config.bot_nickname
|
|
32
|
+
|
|
33
|
+
async def poke_send(self, event: PokeNotifyEvent, matcher: Matcher):
|
|
34
|
+
if config.poke_send_poke:
|
|
35
|
+
await matcher.send(
|
|
36
|
+
Message([MessageSegment("poke", {"qq": f"{event.user_id}"})]),
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
async def pic_send(self):
|
|
40
|
+
pic_file_path = self.poke_path.joinpath("pic")
|
|
41
|
+
pic_file_path.mkdir(parents=True, exist_ok=True)
|
|
42
|
+
if config.poke_send_pic:
|
|
43
|
+
poke_pic_list = pic_file_path.iterdir()
|
|
44
|
+
pic_file_list = [
|
|
45
|
+
pic_file
|
|
46
|
+
for pic_file in poke_pic_list
|
|
47
|
+
if pic_file.is_file()
|
|
48
|
+
and pic_file.suffix.lower() in [".png", ".jpg", ".jpeg", ".webp", ".gif"]
|
|
49
|
+
]
|
|
50
|
+
return random.choice(pic_file_list) if pic_file_list else None
|
|
51
|
+
return None
|
|
52
|
+
|
|
53
|
+
async def text_send(self):
|
|
54
|
+
pic_file_path = self.poke_path
|
|
55
|
+
|
|
56
|
+
async def _get_random_text() -> str:
|
|
57
|
+
if pic_file_path.joinpath("poke.txt").is_file():
|
|
58
|
+
async with aiofiles.open(
|
|
59
|
+
pic_file_path.joinpath("poke.txt"),
|
|
60
|
+
mode="r",
|
|
61
|
+
encoding="utf-8",
|
|
62
|
+
) as f:
|
|
63
|
+
text_file_list = (await f.read()).split("\n")
|
|
64
|
+
send_text = random.choice(text_file_list)
|
|
65
|
+
else:
|
|
66
|
+
default_texts = [
|
|
67
|
+
"lsp你再戳?",
|
|
68
|
+
"连个可爱美少女都要戳的肥宅真恶心啊。",
|
|
69
|
+
"你再戳!",
|
|
70
|
+
"?再戳试试?",
|
|
71
|
+
"别戳了别戳了再戳就坏了555",
|
|
72
|
+
"我爪巴爪巴,球球别再戳了",
|
|
73
|
+
"你戳你🐎呢?!",
|
|
74
|
+
"请不要戳我 >_<",
|
|
75
|
+
"放手啦,不给戳QAQ",
|
|
76
|
+
"喂(#`O′) 戳我干嘛!",
|
|
77
|
+
"戳坏了,赔钱!",
|
|
78
|
+
"戳坏了",
|
|
79
|
+
"嗯……不可以……啦……不要乱戳",
|
|
80
|
+
"那...那里...那里不能戳...绝对...",
|
|
81
|
+
"(。´・ω・)ん?",
|
|
82
|
+
"有事恁叫我,别天天一个劲戳戳戳!",
|
|
83
|
+
"欸很烦欸!你戳🔨呢",
|
|
84
|
+
"再戳一下试试?",
|
|
85
|
+
"正在关闭对您的所有服务...关闭成功",
|
|
86
|
+
"啊呜,太舒服刚刚竟然睡着了。什么事?",
|
|
87
|
+
"正在定位您的真实地址...定位成功。轰炸机已起飞",
|
|
88
|
+
]
|
|
89
|
+
async with aiofiles.open(
|
|
90
|
+
pic_file_path.joinpath("poke.txt"),
|
|
91
|
+
mode="w",
|
|
92
|
+
encoding="utf-8",
|
|
93
|
+
) as f:
|
|
94
|
+
await f.write("\n".join(default_texts))
|
|
95
|
+
send_text = random.choice(default_texts)
|
|
96
|
+
return send_text
|
|
97
|
+
|
|
98
|
+
def _replace_pronoun(text: str) -> str:
|
|
99
|
+
return text.replace("我", self.bot_nickname)
|
|
100
|
+
|
|
101
|
+
send_text = await _get_random_text()
|
|
102
|
+
return _replace_pronoun(send_text)
|
|
103
|
+
|
|
104
|
+
async def acc_send(self, matcher: Matcher):
|
|
105
|
+
"""语音部分"""
|
|
106
|
+
poke_file_path = config.poke_path
|
|
107
|
+
poke_file_path.joinpath("acc").mkdir(parents=True, exist_ok=True)
|
|
108
|
+
poke_acc_list = poke_file_path.joinpath("acc").iterdir()
|
|
109
|
+
acc_file_list: List[Path] = []
|
|
110
|
+
for acc_file in poke_acc_list:
|
|
111
|
+
if acc_file.is_file() and acc_file.suffix.lower() in [
|
|
112
|
+
".wav",
|
|
113
|
+
".mp3",
|
|
114
|
+
".acc",
|
|
115
|
+
]:
|
|
116
|
+
acc_file_list.append(acc_file)
|
|
117
|
+
send_acc = random.choice(acc_file_list)
|
|
118
|
+
logger.info(f"选择{send_acc}")
|
|
119
|
+
await matcher.send(MessageSegment.record(file=f"file:///{send_acc.resolve()}"))
|
|
120
|
+
|
|
121
|
+
async def pic_or_text(
|
|
122
|
+
self,
|
|
123
|
+
send_pic: Optional[Path],
|
|
124
|
+
send_text: Optional[str],
|
|
125
|
+
matcher: Matcher,
|
|
126
|
+
):
|
|
127
|
+
if send_pic and send_text:
|
|
128
|
+
await matcher.send(
|
|
129
|
+
MessageSegment.image(file=f"file:///{send_pic.resolve()}") + send_text,
|
|
130
|
+
)
|
|
131
|
+
elif send_pic and not send_text:
|
|
132
|
+
await matcher.send(
|
|
133
|
+
MessageSegment.image(file=f"file:///{send_pic.resolve()}"),
|
|
134
|
+
)
|
|
135
|
+
elif not send_pic and send_text:
|
|
136
|
+
await matcher.send(send_text)
|
|
137
|
+
return
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
async def poke_rule(event: PokeNotifyEvent):
|
|
141
|
+
"""黑白名单判断"""
|
|
142
|
+
if isinstance(event, PokeNotifyEvent) and event.target_id == event.self_id:
|
|
143
|
+
group = event.group_id
|
|
144
|
+
return (
|
|
145
|
+
(group not in set(config.poke_ban_group))
|
|
146
|
+
if config.poke_black
|
|
147
|
+
else (group in set(config.poke_allow_group))
|
|
148
|
+
)
|
|
149
|
+
return False
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
PS = PokeSender()
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "nonebot_plugin_poke"
|
|
3
|
+
dynamic = []
|
|
4
|
+
description = "自定义群聊戳戳事件 plugin for NoneBot2"
|
|
5
|
+
authors = [
|
|
6
|
+
{ name = "Agnes_Digital", email = "Z735803792@163.com" },
|
|
7
|
+
]
|
|
8
|
+
requires-python = ">=3.9,<4.0"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
homepage = "https://github.com/Agnes4m/nonebot_plugin_poke"
|
|
11
|
+
repository = "https://github.com/Agnes4m/nonebot_plugin_poke"
|
|
12
|
+
keywords = [
|
|
13
|
+
"nonebot2",
|
|
14
|
+
"plugin",
|
|
15
|
+
"poke",
|
|
16
|
+
]
|
|
17
|
+
classifiers = [
|
|
18
|
+
"License :: OSI Approved :: MIT License",
|
|
19
|
+
"Programming Language :: Python",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Programming Language :: Python :: 3.9",
|
|
22
|
+
"Programming Language :: Python :: 3.10",
|
|
23
|
+
"Programming Language :: Python :: 3.11",
|
|
24
|
+
"Programming Language :: Python :: 3.12",
|
|
25
|
+
"Programming Language :: Python :: 3.13",
|
|
26
|
+
"Operating System :: OS Independent",
|
|
27
|
+
]
|
|
28
|
+
include = [
|
|
29
|
+
"LICENSE",
|
|
30
|
+
"README.md",
|
|
31
|
+
]
|
|
32
|
+
dependencies = [
|
|
33
|
+
"nonebot2>=2.1.0",
|
|
34
|
+
"nonebot-plugin-alconna>=0.58.5",
|
|
35
|
+
"nonebot-adapter-onebot>=2.1.5",
|
|
36
|
+
"aiofiles>=23.1.0",
|
|
37
|
+
"aiohttp>=3.8.5",
|
|
38
|
+
"pydantic>=2.1.1",
|
|
39
|
+
]
|
|
40
|
+
version = "0.1.6"
|
|
41
|
+
|
|
42
|
+
[project.license]
|
|
43
|
+
text = "MIT"
|
|
44
|
+
|
|
45
|
+
[tool.pdm.build]
|
|
46
|
+
includes = []
|
|
47
|
+
|
|
48
|
+
[tool.pdm.version]
|
|
49
|
+
source = "file"
|
|
50
|
+
path = "nonebot_plugin_poke/__init__.py"
|
|
51
|
+
|
|
52
|
+
[tool.pyright]
|
|
53
|
+
pythonVersion = "3.9"
|
|
54
|
+
|
|
55
|
+
[tool.black]
|
|
56
|
+
line-length = 89
|
|
57
|
+
target-version = [
|
|
58
|
+
"py39",
|
|
59
|
+
"py310",
|
|
60
|
+
"py311",
|
|
61
|
+
"py312",
|
|
62
|
+
]
|
|
63
|
+
include = "\\.pyi?$"
|
|
64
|
+
|
|
65
|
+
[tool.ruff.lint]
|
|
66
|
+
ignore = [
|
|
67
|
+
"B008",
|
|
68
|
+
"B905",
|
|
69
|
+
"E402",
|
|
70
|
+
"E501",
|
|
71
|
+
"FBT001",
|
|
72
|
+
"FBT002",
|
|
73
|
+
"FBT003",
|
|
74
|
+
"PGH003",
|
|
75
|
+
"RUF001",
|
|
76
|
+
"RUF002",
|
|
77
|
+
"RUF003",
|
|
78
|
+
"RUF006",
|
|
79
|
+
"RUF100",
|
|
80
|
+
"TRY002",
|
|
81
|
+
"TRY003",
|
|
82
|
+
]
|
|
83
|
+
select = [
|
|
84
|
+
"A",
|
|
85
|
+
"ARG",
|
|
86
|
+
"ASYNC",
|
|
87
|
+
"B",
|
|
88
|
+
"C4",
|
|
89
|
+
"COM",
|
|
90
|
+
"E",
|
|
91
|
+
"F",
|
|
92
|
+
"FBT",
|
|
93
|
+
"FLY",
|
|
94
|
+
"I",
|
|
95
|
+
"ISC",
|
|
96
|
+
"N",
|
|
97
|
+
"PIE",
|
|
98
|
+
"PGH",
|
|
99
|
+
"PTH",
|
|
100
|
+
"PYI",
|
|
101
|
+
"Q",
|
|
102
|
+
"RET",
|
|
103
|
+
"RSE",
|
|
104
|
+
"RUF",
|
|
105
|
+
"SIM",
|
|
106
|
+
"SLF",
|
|
107
|
+
"SLOT",
|
|
108
|
+
"TRY",
|
|
109
|
+
]
|
|
110
|
+
|
|
111
|
+
[tool.ruff.lint.isort]
|
|
112
|
+
extra-standard-library = [
|
|
113
|
+
"typing_extensions",
|
|
114
|
+
]
|
|
115
|
+
|
|
116
|
+
[build-system]
|
|
117
|
+
requires = [
|
|
118
|
+
"pdm-backend",
|
|
119
|
+
]
|
|
120
|
+
build-backend = "pdm.backend"
|