Skip to content

Commit 2b84179

Browse files
committed
新增b站弹幕监听
1 parent 296a8e9 commit 2b84179

File tree

20 files changed

+3126
-150
lines changed

20 files changed

+3126
-150
lines changed

README.md

Lines changed: 65 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,26 @@
1010

1111
_✨ NoneBot 插件描述 ✨_
1212

13-
这是一个 onebot.v11的词库插件
13+
这是一个 onebot.v11的词库插件,兼b站直播间弹幕监听插件
14+
15+
## 特别鸣谢
16+
17+
- [blivedm](https://github.com/xfgryujk/blivedm)项目的灵感来源以及部分实现的参考
1418

1519
## 📖 介绍
1620

21+
词库插件方面:
22+
1723
面向小白的词库插件,目的是减少编写代码的时间和难度 特点:语言精简 无需重启nb和reload即可实
1824
现功能热重载 缺点:目前仅能实现一些简单的逻辑运行,但随着更新肯定会慢慢削减
1925

2026
支持自开发函数,只要不跳脱当前解析框架一般都能成功解析并做出对应的反馈
2127

28+
b站直播间弹幕监听方面:
29+
30+
通过ws连接b站直播间,监听弹幕
31+
具体使用方法和配置见下面的配置和使用例子
32+
2233
## 💿 安装
2334

2435
<details open>
@@ -70,6 +81,59 @@ help_on_off=1 ##是否开启帮助功能1是开,其他为关闭
7081

7182
allowed_groups=["能触发教程的指令的群号"]
7283

84+
bililiveid=[b站直播间id]
85+
bilitoken= ##这里填一个已登录账号的cookie的SESSDATA字段的值。不填也可以连接,但是收到弹幕的用户名会打码,UID会变成0
86+
bililivedown=on ##是否开启b站直播间弹幕监听功能,on为开启,其他为关闭
87+
bilidmj=on ##是否开启b站直播间弹幕显示器,on为开启,其他为关闭
88+
loadws= ##是否开启websocket功能,默认为ws://127.0.0.1:8000/onebot/v11/ws
89+
90+
```
91+
92+
## 如何使用b站弹幕功能
93+
94+
在.env文件里面配置好之后,在你自己的py文件里面这样使用ws
95+
以默认的ws://127.0.0.1:8000/onebot/v11/ws为例
96+
97+
```bash
98+
from aiohttp import web
99+
import threading
100+
import nonebot
101+
102+
async def websocket_handler(request): ##千万别在这里使用async def websocket_handler(request,bot: Bot):不然会导致报错无法连接
103+
ws = web.WebSocketResponse()
104+
await ws.prepare(request)
105+
106+
async for msg in ws:
107+
reout = msg.data
108+
tes = json.loads(msg.data)
109+
send = tes["message"]
110+
(bot,) = nonebot.get_bots().values()
111+
await bot.send_private_msg(user_id=12335, message=send)
112+
113+
return ws
114+
115+
def run_app():
116+
app = web.Application()
117+
app.router.add_get("/onebot/v11/ws", websocket_handler)
118+
web.run_app(app, host="127.0.0.1", port=8000,print=None)
119+
120+
# 在主线程中创建一个子线程,防止卡住nb进程(或者用py单独运行个.py文件也行)
121+
thread = threading.Thread(target=run_app)
122+
thread.start()
123+
124+
```
125+
126+
参数说明
127+
```bash
128+
{
129+
"user_id": int,
130+
"nickname": str,
131+
"message": str,
132+
"room_id": int,
133+
"type": str, ##仅支持普通消息(message)和醒目留言(super_chat)
134+
"price":int
135+
}
136+
73137
```
74138
75139
| 指令 | 类型 | 别名 | 说明 |
@@ -139,55 +203,3 @@ $senduserimage QQ$
139203
![a4e3e63add3c93dc1fbe12e46aaa63fe](https://github.com/user-attachments/assets/eb4f1192-4434-4cd2-a652-5623b32aa04c)
140204
![194bf3d8414fa72dee372a208ee73b9d](https://github.com/user-attachments/assets/163d704c-243b-4104-a7be-79e7f4a7b4df)
141205
![3d146e4948b16de1cc78f0a0b8859aba](https://github.com/user-attachments/assets/09982c19-6c80-4a25-9023-85fb39b01951)
142-
143-
144-
145-
### 更新日志
146-
0.1.11
147-
- 新增获取随机数的函数
148-
- 优化sendat的范围,参数为all时可艾特全体了
149-
150-
0.1.10
151-
- 修复了在指令为戳.*时会与戳一戳事件标识产生奇妙的化学反应而导致报错的问题
152-
- 新增入群申请的函数
153-
154-
0.1.9
155-
- 新增获取艾特对象的QQ的函数
156-
- 新增戳一戳函数
157-
158-
0.1.8
159-
- 新增了链接获取内容的函数
160-
- 对asif的判断范围进行了一点优化(还是暂不支持and和or)
161-
162-
0.1.7
163-
- 新增获取群昵称和用户昵称的函数
164-
165-
0.1.6
166-
- 重新上传
167-
168-
0.1.5
169-
- 新增获取target_id和self_id的函数
170-
- 修复了0.1.4启动报错的问题(import没删完)
171-
- 新增了戳一戳事件和入群通知事件的响应函数
172-
173-
0.1.4
174-
- 修复了字体文件缺失的bug
175-
- 修复了$sendtext 参数$在发送纯字符串时报错的bug
176-
- 修复了异步函数不完整的bug
177-
- 新增了help和查询指令列表的功能
178-
- 新增了在.env文件中可选择开启或关闭help和教程功能的配置项
179-
180-
0.1.3
181-
- 优化部分日志
182-
- 新增获取消息id的函数
183-
- 优化了部分代码
184-
- 新增通过消息id撤回消息的函数
185-
186-
0.1.2
187-
- 优化了部分传递参数的限制
188-
- 新增教程功能
189-
190-
0.1.1
191-
- 新增私聊消息接收
192-
- 新增人机合一模式
193-
- 优化部分日志

nonebot_plugin_SimpleToWrite/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@
1414
from nonebot.typing import overrides
1515
from nonebot.matcher import current_event, current_bot
1616
from .teach import teach
17+
from .livedm.bllichat import sample
1718
import httpx
1819

1920
__plugin_meta__ = PluginMetadata(
20-
name="简易编写词库",
21-
description="适用于零基础的小白向快速编写功能的词库语言插件",
21+
name="简易编写词库+b站弹幕监控",
22+
description="适用于零基础的小白向快速编写功能的词库语言插件,以及基于ws的b站弹幕监控",
2223
usage="在机器人的项目目录里面新建dicpro.txt,再根据github主页的使用教程进行编写",
2324

2425
type="application",
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
*.egg-info/
24+
.installed.cfg
25+
*.egg
26+
27+
# PyInstaller
28+
# Usually these files are written by a python script from a template
29+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
30+
*.manifest
31+
*.spec
32+
33+
# Installer logs
34+
pip-log.txt
35+
pip-delete-this-directory.txt
36+
37+
# Unit test / coverage reports
38+
htmlcov/
39+
.tox/
40+
.coverage
41+
.coverage.*
42+
.cache
43+
nosetests.xml
44+
coverage.xml
45+
*.cover
46+
.hypothesis/
47+
48+
# Translations
49+
*.mo
50+
*.pot
51+
52+
# Django stuff:
53+
*.log
54+
local_settings.py
55+
56+
# Flask stuff:
57+
instance/
58+
.webassets-cache
59+
60+
# Scrapy stuff:
61+
.scrapy
62+
63+
# Sphinx documentation
64+
docs/_build/
65+
66+
# PyBuilder
67+
target/
68+
69+
# Jupyter Notebook
70+
.ipynb_checkpoints
71+
72+
# pyenv
73+
.python-version
74+
75+
# celery beat schedule file
76+
celerybeat-schedule
77+
78+
# SageMath parsed files
79+
*.sage.py
80+
81+
# Environments
82+
.env
83+
.venv
84+
env/
85+
venv/
86+
ENV/
87+
88+
# Spyder project settings
89+
.spyderproject
90+
.spyproject
91+
92+
# Rope project settings
93+
.ropeproject
94+
95+
# mkdocs documentation
96+
/site
97+
98+
# mypy
99+
.mypy_cache/
100+
101+
102+
.idea/
103+
.pdm-python
104+
pdm.lock
105+
pdm.toml
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# -*- coding: utf-8 -*-
2+
__version__ = '1.0.0'
3+
4+
from .handlers import *
5+
from .clients import *
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# -*- coding: utf-8 -*-
2+
from .web import *
3+
from .open_live import *

0 commit comments

Comments
 (0)