mirror of
https://github.com/yulinfeng000/blive.git
synced 2025-03-13 18:50:58 +08:00
publish package
This commit is contained in:
parent
0d95512e3f
commit
101a8ed416
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,3 +1,6 @@
|
||||
.venv
|
||||
.vscode
|
||||
**/__pycache__
|
||||
dist
|
||||
build
|
||||
blive.egg-info
|
21
LICENSE
Normal file
21
LICENSE
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) [2020] [yulinfeng]
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
10
README.md
10
README.md
@ -11,9 +11,11 @@
|
||||
|
||||
## 快速开始
|
||||
|
||||
1. 创建 app
|
||||
1. 安装
|
||||
|
||||
> 目前请克隆该代码仓库,并执行 pip install -r rquirements.txt
|
||||
`pip install blive`
|
||||
|
||||
2. 创建 app
|
||||
|
||||
```python
|
||||
from blive import BLiver
|
||||
@ -21,7 +23,7 @@
|
||||
app = BLiver(123) #123为房间号
|
||||
```
|
||||
|
||||
2. 创建处理器
|
||||
3. 创建处理器
|
||||
|
||||
```python
|
||||
from blive import BLiver, Events, BLiverCtx
|
||||
@ -37,7 +39,7 @@
|
||||
print(danmu.timestamp)
|
||||
```
|
||||
|
||||
3. 运行
|
||||
4. 运行
|
||||
|
||||
```python
|
||||
|
||||
|
17
app.py
17
app.py
@ -1,7 +1,13 @@
|
||||
from blive import BLiver, Events, BLiverCtx
|
||||
from blive.msg import DanMuMsg, HotRankChangeV2Msg, InteractWordMsg, SendGiftMsg
|
||||
from blive.msg import (
|
||||
DanMuMsg,
|
||||
HotRankChangeV2Msg,
|
||||
InteractWordMsg,
|
||||
SendGiftMsg,
|
||||
SuperChatMsg,
|
||||
)
|
||||
|
||||
app = BLiver(510)
|
||||
app = BLiver(605)
|
||||
|
||||
|
||||
@app.on(Events.DANMU_MSG)
|
||||
@ -24,7 +30,12 @@ async def listen_join(ctx: BLiverCtx):
|
||||
|
||||
@app.on(Events.SUPER_CHAT_MESSAGE)
|
||||
async def listen_sc(ctx: BLiverCtx):
|
||||
print(ctx.body)
|
||||
msg = SuperChatMsg(ctx.body)
|
||||
print(msg.sender)
|
||||
print(msg.content)
|
||||
print(msg.start_time)
|
||||
print(msg.time)
|
||||
print(msg.price)
|
||||
|
||||
|
||||
@app.on(Events.SEND_GIFT)
|
||||
|
@ -2,12 +2,13 @@ import sys
|
||||
import json
|
||||
import asyncio
|
||||
from typing import Awaitable, Dict, List, Tuple, Union
|
||||
import loguru
|
||||
import aiohttp
|
||||
from aiohttp.client_ws import ClientWebSocketResponse
|
||||
from aiohttp.http_websocket import WSMessage
|
||||
from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
||||
import loguru
|
||||
from apscheduler.util import _Undefined
|
||||
|
||||
from .core import (
|
||||
packman,
|
||||
Events,
|
||||
@ -43,6 +44,9 @@ class Channel:
|
||||
def register_handler(self, handler):
|
||||
self.listeners.append(handler)
|
||||
|
||||
def __getitem__(self, idx):
|
||||
return self.listeners.__getitem__(idx)
|
||||
|
||||
def __iter__(self):
|
||||
return iter(self.listeners)
|
||||
|
||||
|
32
blive/msg.py
32
blive/msg.py
@ -136,3 +136,35 @@ class SendGiftMsg(BaseMsg):
|
||||
"combo_stay_time": self.body["data"]["combo_stay_time"],
|
||||
"combo_total_coin": self.body["data"]["combo_total_coin"],
|
||||
}
|
||||
|
||||
|
||||
class SuperChatMsg(BaseMsg):
|
||||
def __init__(self, body) -> None:
|
||||
super().__init__(body)
|
||||
|
||||
@property
|
||||
def content(self):
|
||||
return self.body["data"]["message"]
|
||||
|
||||
@property
|
||||
def sender(self):
|
||||
return {
|
||||
"id": self.body["data"]["user_info"]["uname"],
|
||||
"name": self.body["data"]["uid"],
|
||||
"medal": {
|
||||
"medal_name": self.body["data"]["medal_info"]["medal_name"],
|
||||
"medal_level": self.body["data"]["medal_info"]["medal_level"],
|
||||
},
|
||||
}
|
||||
|
||||
@property
|
||||
def price(self):
|
||||
return self.body["data"]["price"]
|
||||
|
||||
@property
|
||||
def start_time(self):
|
||||
return self.body["data"]["start_time"]
|
||||
|
||||
@property
|
||||
def time(self):
|
||||
return self.body["data"]["time"]
|
||||
|
19
setup.py
Normal file
19
setup.py
Normal file
@ -0,0 +1,19 @@
|
||||
import setuptools
|
||||
|
||||
with open("./README.md", "r") as f:
|
||||
description = f.read()
|
||||
|
||||
setuptools.setup(
|
||||
name="blive",
|
||||
version="0.0.1",
|
||||
author="cam",
|
||||
author_email="yulinfeng000@gmail.com",
|
||||
long_description=description,
|
||||
long_description_content_type="text/markdown",
|
||||
url="https://github.com/yulinfeng000/blive",
|
||||
packages=setuptools.find_packages(),
|
||||
classifiers=[
|
||||
"Programming Language :: Python :: 3",
|
||||
"License :: OSI Approved :: MIT License",
|
||||
],
|
||||
)
|
Loading…
Reference in New Issue
Block a user