You've already forked XiguaLiveDanmakuHelper
改进部分代码,增加Linux可运行的版本,可自己选择想要进入的房间
Signed-off-by: Jerry Yan <792602257@qq.com>
This commit is contained in:
48
Gift.py
Normal file
48
Gift.py
Normal file
@@ -0,0 +1,48 @@
|
||||
import requests
|
||||
from User import User
|
||||
|
||||
|
||||
class Gift:
|
||||
ID:int = 0
|
||||
count:int = 0
|
||||
roomID:int = 0
|
||||
giftList:dict = {10001: {"Name": "西瓜", "Price": 0}}
|
||||
amount:int = 0
|
||||
user:User = None
|
||||
|
||||
def __init__(self, json=None):
|
||||
if json:
|
||||
self.parse(json)
|
||||
|
||||
def parse(self, json):
|
||||
self.user = User(json)
|
||||
if "Msg" in json:
|
||||
if "present_end_info" in json["Msg"]:
|
||||
self.ID = json["Msg"]['present_end_info']['id']
|
||||
self.count = json["Msg"]['present_end_info']['count']
|
||||
elif "present_info" in json["Msg"]:
|
||||
self.ID = json["Msg"]['present_info']['id']
|
||||
self.count = json["Msg"]['present_info']['repeat_count']
|
||||
if self.ID in self.giftList:
|
||||
self.amount = self.giftList[self.ID]["Price"] * self.count
|
||||
|
||||
@staticmethod
|
||||
def update(roomID):
|
||||
Gift.roomID = roomID
|
||||
p = requests.get("https://live.ixigua.com/api/gifts/{roomID}".format(roomID= roomID))
|
||||
d = p.json()
|
||||
if isinstance(d, int) or "data" not in d:
|
||||
print("错误:礼物更新失败")
|
||||
else:
|
||||
for i in d["data"]:
|
||||
Gift.giftList[i["ID"]] = {"Name": i["Name"], "Price": i["DiamondCount"]}
|
||||
|
||||
def __str__(self):
|
||||
if self.ID in self.giftList:
|
||||
giftN = self.giftList[self.ID]["Name"]
|
||||
else:
|
||||
giftN = "未知礼物[{}]".format(self.ID)
|
||||
return "感谢 {user} 送出的 {count} 个 {name}".format(user= self.user, count= self.count, name= giftN)
|
||||
|
||||
def __unicode__(self):
|
||||
return self.__str__()
|
||||
Reference in New Issue
Block a user