Skip to content

Commit

Permalink
新增b站弹幕监听
Browse files Browse the repository at this point in the history
  • Loading branch information
STESmly committed Oct 26, 2024
1 parent 296a8e9 commit 2b84179
Show file tree
Hide file tree
Showing 20 changed files with 3,126 additions and 150 deletions.
118 changes: 65 additions & 53 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,26 @@

_✨ NoneBot 插件描述 ✨_

这是一个 onebot.v11的词库插件
这是一个 onebot.v11的词库插件,兼b站直播间弹幕监听插件

## 特别鸣谢

- [blivedm](https://github.com/xfgryujk/blivedm)项目的灵感来源以及部分实现的参考

## 📖 介绍

词库插件方面:

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

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

b站直播间弹幕监听方面:

通过ws连接b站直播间,监听弹幕
具体使用方法和配置见下面的配置和使用例子

## 💿 安装

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

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

bililiveid=[b站直播间id]
bilitoken= ##这里填一个已登录账号的cookie的SESSDATA字段的值。不填也可以连接,但是收到弹幕的用户名会打码,UID会变成0
bililivedown=on ##是否开启b站直播间弹幕监听功能,on为开启,其他为关闭
bilidmj=on ##是否开启b站直播间弹幕显示器,on为开启,其他为关闭
loadws= ##是否开启websocket功能,默认为ws://127.0.0.1:8000/onebot/v11/ws

```

## 如何使用b站弹幕功能

在.env文件里面配置好之后,在你自己的py文件里面这样使用ws
以默认的ws://127.0.0.1:8000/onebot/v11/ws为例

```bash
from aiohttp import web
import threading
import nonebot

async def websocket_handler(request): ##千万别在这里使用async def websocket_handler(request,bot: Bot):不然会导致报错无法连接
ws = web.WebSocketResponse()
await ws.prepare(request)

async for msg in ws:
reout = msg.data
tes = json.loads(msg.data)
send = tes["message"]
(bot,) = nonebot.get_bots().values()
await bot.send_private_msg(user_id=12335, message=send)

return ws

def run_app():
app = web.Application()
app.router.add_get("/onebot/v11/ws", websocket_handler)
web.run_app(app, host="127.0.0.1", port=8000,print=None)

# 在主线程中创建一个子线程,防止卡住nb进程(或者用py单独运行个.py文件也行)
thread = threading.Thread(target=run_app)
thread.start()

```
参数说明
```bash
{
"user_id": int,
"nickname": str,
"message": str,
"room_id": int,
"type": str, ##仅支持普通消息(message)和醒目留言(super_chat)
"price":int
}

```
| 指令 | 类型 | 别名 | 说明 |
Expand Down Expand Up @@ -139,55 +203,3 @@ $senduserimage QQ$
![a4e3e63add3c93dc1fbe12e46aaa63fe](https://github.com/user-attachments/assets/eb4f1192-4434-4cd2-a652-5623b32aa04c)
![194bf3d8414fa72dee372a208ee73b9d](https://github.com/user-attachments/assets/163d704c-243b-4104-a7be-79e7f4a7b4df)
![3d146e4948b16de1cc78f0a0b8859aba](https://github.com/user-attachments/assets/09982c19-6c80-4a25-9023-85fb39b01951)



### 更新日志
0.1.11
- 新增获取随机数的函数
- 优化sendat的范围,参数为all时可艾特全体了

0.1.10
- 修复了在指令为戳.*时会与戳一戳事件标识产生奇妙的化学反应而导致报错的问题
- 新增入群申请的函数

0.1.9
- 新增获取艾特对象的QQ的函数
- 新增戳一戳函数

0.1.8
- 新增了链接获取内容的函数
- 对asif的判断范围进行了一点优化(还是暂不支持and和or)

0.1.7
- 新增获取群昵称和用户昵称的函数

0.1.6
- 重新上传

0.1.5
- 新增获取target_id和self_id的函数
- 修复了0.1.4启动报错的问题(import没删完)
- 新增了戳一戳事件和入群通知事件的响应函数

0.1.4
- 修复了字体文件缺失的bug
- 修复了$sendtext 参数$在发送纯字符串时报错的bug
- 修复了异步函数不完整的bug
- 新增了help和查询指令列表的功能
- 新增了在.env文件中可选择开启或关闭help和教程功能的配置项

0.1.3
- 优化部分日志
- 新增获取消息id的函数
- 优化了部分代码
- 新增通过消息id撤回消息的函数

0.1.2
- 优化了部分传递参数的限制
- 新增教程功能

0.1.1
- 新增私聊消息接收
- 新增人机合一模式
- 优化部分日志
5 changes: 3 additions & 2 deletions nonebot_plugin_SimpleToWrite/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
from nonebot.typing import overrides
from nonebot.matcher import current_event, current_bot
from .teach import teach
from .livedm.bllichat import sample
import httpx

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

type="application",
Expand Down
2 changes: 2 additions & 0 deletions nonebot_plugin_SimpleToWrite/livedm/bllichat/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
105 changes: 105 additions & 0 deletions nonebot_plugin_SimpleToWrite/livedm/bllichat/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/


.idea/
.pdm-python
pdm.lock
pdm.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
__version__ = '1.0.0'

from .handlers import *
from .clients import *
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-
from .web import *
from .open_live import *
Loading

0 comments on commit 2b84179

Please sign in to comment.