mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2025-06-06 03:46:10 +08:00
Update bilibili.py
This commit is contained in:
parent
d0f56e76cd
commit
840519baa1
@ -5,7 +5,7 @@ import httpx
|
||||
|
||||
from ..post import Post
|
||||
from ..types import Category, RawPost, Tag, Target
|
||||
from .platform import CategoryNotSupport, NewMessage
|
||||
from .platform import CategoryNotSupport, NewMessage,StatusChange
|
||||
|
||||
|
||||
class Bilibili(NewMessage):
|
||||
@ -144,3 +144,62 @@ class Bilibili(NewMessage):
|
||||
else:
|
||||
raise CategoryNotSupport(post_type)
|
||||
return Post("bilibili", text=text, url=url, pics=pic, target_name=target_name)
|
||||
|
||||
class Bilibililive(StatusChange):
|
||||
# Author : Sichongzou
|
||||
# Date : 2022-5-18 8:54
|
||||
# Description : bilibili开播提醒
|
||||
# E-mail : 1557157806@qq.com
|
||||
categories = {}
|
||||
platform_name = "bilibililive"
|
||||
enable_tag = True
|
||||
enabled = True
|
||||
is_common = True
|
||||
schedule_type = "interval"
|
||||
schedule_kw = {"seconds": 10}
|
||||
name = "B站直播"
|
||||
has_target = True
|
||||
|
||||
async def get_target_name(self, target: Target) -> Optional[str]:
|
||||
async with httpx.AsyncClient() as client:
|
||||
res = await client.get(
|
||||
"https://api.bilibili.com/x/space/acc/info", params={"mid": target}
|
||||
)
|
||||
res_data = json.loads(res.text)
|
||||
if res_data["code"]:
|
||||
return None
|
||||
return res_data["data"]["name"]
|
||||
|
||||
async def get_status(self, target: Target):
|
||||
async with httpx.AsyncClient() as client:
|
||||
params = {"mid": target}
|
||||
res = await client.get(
|
||||
"https://api.bilibili.com/x/space/acc/info",
|
||||
params=params,
|
||||
timeout=4.0,
|
||||
)
|
||||
res_dict = json.loads(res.text)
|
||||
if res_dict["code"] == 0:
|
||||
info={}
|
||||
info["uid"]=res_dict["data"]["mid"]
|
||||
info["uname"]=res_dict["data"]["name"]
|
||||
info["live_state"]=res_dict["data"]["live_room"]["liveStatus"]
|
||||
info["url"]=res_dict["data"]["live_room"]["url"]
|
||||
info["title"]=res_dict["data"]["live_room"]["title"]
|
||||
info["cover"]=res_dict["data"]["live_room"]["cover"]
|
||||
return info
|
||||
else:
|
||||
return []
|
||||
|
||||
def compare_status(self, target: Target, old_status, new_status) -> list[RawPost]:
|
||||
if(new_status["live_state"]!=old_status["live_state"] and new_status["live_state"]==1):
|
||||
return [new_status]
|
||||
else:
|
||||
return[]
|
||||
|
||||
async def parse(self, raw_post: RawPost) -> Post:
|
||||
url=raw_post["url"]
|
||||
pic=[raw_post["cover"]]
|
||||
target_name=raw_post["uname"]
|
||||
text=target_name+"老师的直播 开播啦!小伙伴们请务必速速来围观!"
|
||||
return Post("bilibililive", text=text, url=url, pics=pic, target_name=target_name)
|
||||
|
Loading…
x
Reference in New Issue
Block a user