publish package

This commit is contained in:
Cam 2022-01-09 11:19:51 +08:00
parent 0d95512e3f
commit 101a8ed416
7 changed files with 100 additions and 8 deletions

3
.gitignore vendored
View File

@ -1,3 +1,6 @@
.venv .venv
.vscode .vscode
**/__pycache__ **/__pycache__
dist
build
blive.egg-info

21
LICENSE Normal file
View 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.

View File

@ -11,9 +11,11 @@
## 快速开始 ## 快速开始
1. 创建 app 1. 安装
> 目前请克隆该代码仓库,并执行 pip install -r rquirements.txt `pip install blive`
2. 创建 app
```python ```python
from blive import BLiver from blive import BLiver
@ -21,7 +23,7 @@
app = BLiver(123) #123为房间号 app = BLiver(123) #123为房间号
``` ```
2. 创建处理器 3. 创建处理器
```python ```python
from blive import BLiver, Events, BLiverCtx from blive import BLiver, Events, BLiverCtx
@ -37,7 +39,7 @@
print(danmu.timestamp) print(danmu.timestamp)
``` ```
3. 运行 4. 运行
```python ```python

17
app.py
View File

@ -1,7 +1,13 @@
from blive import BLiver, Events, BLiverCtx 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) @app.on(Events.DANMU_MSG)
@ -24,7 +30,12 @@ async def listen_join(ctx: BLiverCtx):
@app.on(Events.SUPER_CHAT_MESSAGE) @app.on(Events.SUPER_CHAT_MESSAGE)
async def listen_sc(ctx: BLiverCtx): 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) @app.on(Events.SEND_GIFT)

View File

@ -2,12 +2,13 @@ import sys
import json import json
import asyncio import asyncio
from typing import Awaitable, Dict, List, Tuple, Union from typing import Awaitable, Dict, List, Tuple, Union
import loguru
import aiohttp import aiohttp
from aiohttp.client_ws import ClientWebSocketResponse from aiohttp.client_ws import ClientWebSocketResponse
from aiohttp.http_websocket import WSMessage from aiohttp.http_websocket import WSMessage
from apscheduler.schedulers.asyncio import AsyncIOScheduler from apscheduler.schedulers.asyncio import AsyncIOScheduler
import loguru
from apscheduler.util import _Undefined from apscheduler.util import _Undefined
from .core import ( from .core import (
packman, packman,
Events, Events,
@ -43,6 +44,9 @@ class Channel:
def register_handler(self, handler): def register_handler(self, handler):
self.listeners.append(handler) self.listeners.append(handler)
def __getitem__(self, idx):
return self.listeners.__getitem__(idx)
def __iter__(self): def __iter__(self):
return iter(self.listeners) return iter(self.listeners)

View File

@ -136,3 +136,35 @@ class SendGiftMsg(BaseMsg):
"combo_stay_time": self.body["data"]["combo_stay_time"], "combo_stay_time": self.body["data"]["combo_stay_time"],
"combo_total_coin": self.body["data"]["combo_total_coin"], "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
View 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",
],
)