You've already forked XiguaLiveDanmakuHelper
额外更新
This commit is contained in:
40
Struct/Chat.py
Normal file
40
Struct/Chat.py
Normal file
@ -0,0 +1,40 @@
|
||||
from .User import User
|
||||
from .Lottery import Lottery
|
||||
from XiguaMessage_pb2 import ChatMessage
|
||||
|
||||
class Chat:
|
||||
content = ""
|
||||
user = None
|
||||
filterString = ["", ]
|
||||
isFiltered = False
|
||||
|
||||
def __init__(self, json=None, lottery: Lottery = None):
|
||||
if lottery:
|
||||
self.filterString.append(lottery.content)
|
||||
if json:
|
||||
if type(json) == bytes:
|
||||
self.parsePb(json)
|
||||
else:
|
||||
self.parse(json)
|
||||
|
||||
def parsePb(self, raw):
|
||||
_message = ChatMessage()
|
||||
_message.ParseFromString(raw)
|
||||
self.user = User(_message.user)
|
||||
self.content = _message.content
|
||||
if self.content in self.filterString:
|
||||
self.isFiltered = True
|
||||
|
||||
def parse(self, json):
|
||||
self.user = User(json)
|
||||
if "extra" in json:
|
||||
if "content" in json["extra"]:
|
||||
self.content = json["extra"]['content']
|
||||
if self.content in self.filterString:
|
||||
self.isFiltered = True
|
||||
|
||||
def __str__(self):
|
||||
return "{} : {}".format(self.user, self.content)
|
||||
|
||||
def __unicode__(self):
|
||||
return self.__str__()
|
0
Struct/Digg.py
Normal file
0
Struct/Digg.py
Normal file
72
Struct/Gift.py
Normal file
72
Struct/Gift.py
Normal file
@ -0,0 +1,72 @@
|
||||
import requests
|
||||
from .User import User
|
||||
from XiguaMessage_pb2 import GiftMessage
|
||||
|
||||
|
||||
class Gift:
|
||||
giftList = {}
|
||||
|
||||
def __init__(self, json=None):
|
||||
self.ID = 0
|
||||
self.count = 0
|
||||
self.user = None
|
||||
self.isFinished = False
|
||||
self.backupName = None
|
||||
if json:
|
||||
if type(json) == bytes:
|
||||
self.parsePb(json)
|
||||
else:
|
||||
self.parse(json)
|
||||
|
||||
def parsePb(self, raw):
|
||||
_message = GiftMessage()
|
||||
_message.ParseFromString(raw)
|
||||
self.user = User(_message.user)
|
||||
self.ID = _message.giftId
|
||||
self.count = _message.repeated
|
||||
self.isFinished = _message.isFinished
|
||||
self.backupName = _message.commonInfo.displayText.params.gifts.gift.name
|
||||
|
||||
def parse(self, json):
|
||||
self.user = User(json)
|
||||
if "extra" in json and json["extra"] is not None:
|
||||
if "present_info" in json["extra"] and json["extra"]['present_info'] is not None:
|
||||
self.ID = int(json["extra"]['present_info']['id'])
|
||||
self.count = json["extra"]['present_info']['repeat_count']
|
||||
elif "present_end_info" in json["extra"] and json["extra"]['present_end_info'] is not None:
|
||||
self.ID = int(json["extra"]['present_end_info']['id'])
|
||||
self.count = json["extra"]['present_end_info']['count']
|
||||
|
||||
def isAnimate(self):
|
||||
if self.ID != 0 and self.ID in self.giftList:
|
||||
if 'combo' in self.giftList[self.ID]:
|
||||
return self.giftList[self.ID]["combo"] == False
|
||||
elif 'meta' in self.giftList[self.ID] and 'combo' in self.giftList[self.ID]['meta']:
|
||||
return self.giftList[self.ID]['meta']["combo"] == False
|
||||
elif 'type' in self.giftList[self.ID]:
|
||||
return self.giftList[self.ID]["type"] == 2
|
||||
return False
|
||||
|
||||
def _getGiftName(self):
|
||||
if self.ID in self.giftList:
|
||||
return self.giftList[self.ID]["name"]
|
||||
elif self.backupName is not None:
|
||||
return self.backupName
|
||||
else:
|
||||
return "未知礼物[{}]".format(self.ID)
|
||||
|
||||
def __str__(self):
|
||||
return "{user} 送出的 {count} 个 {name}".format(user=self.user, count=self.count, name=self._getGiftName())
|
||||
|
||||
def __unicode__(self):
|
||||
return self.__str__()
|
||||
|
||||
def __repr__(self):
|
||||
return "西瓜礼物【{}(ID:{})】".format(self._getGiftName(), self.ID)
|
||||
|
||||
@classmethod
|
||||
def addGift(cls, _gift):
|
||||
if 'id' not in _gift:
|
||||
return
|
||||
_id = int(_gift["id"])
|
||||
cls.giftList[_id] = _gift
|
71
Struct/Lottery.py
Normal file
71
Struct/Lottery.py
Normal file
@ -0,0 +1,71 @@
|
||||
# coding=utf-8
|
||||
import requests
|
||||
import time
|
||||
from .LuckyUser import LuckyUser
|
||||
|
||||
|
||||
class Lottery:
|
||||
ID = 0
|
||||
isActive = False
|
||||
content = ""
|
||||
isFinished = False
|
||||
luckyUsers = []
|
||||
joinedUserCount = 0
|
||||
prizeName = ""
|
||||
finish = 0
|
||||
|
||||
def __init__(self, json=None):
|
||||
if json:
|
||||
self.parse(json)
|
||||
|
||||
def parse(self, json):
|
||||
if "lottery_info" in json and json["lottery_info"] is not None:
|
||||
self.isActive = int(json["lottery_info"]["status"]) > 0
|
||||
self.ID = json["lottery_info"]["lottery_id"]
|
||||
for i in json["lottery_info"]['conditions']:
|
||||
if i['type'] != 3:
|
||||
continue
|
||||
self.content = i["content"]
|
||||
self.joinedUserCount = int(json["lottery_info"]["candidate_num"])
|
||||
self.prizeName = json["lottery_info"]["prize_info"]["name"]
|
||||
_delta = int(json["lottery_info"]["draw_time"]) - int(json["lottery_info"]["current_time"])
|
||||
self.finish = time.time()+_delta+1
|
||||
elif "extra" in json and json["extra"] is not None:
|
||||
if "lottery_info" in json["extra"] and json["extra"]["lottery_info"] is not None:
|
||||
return self.parse(json["extra"])
|
||||
|
||||
def update(self):
|
||||
if self.isActive:
|
||||
if not self.isFinished and self.finish > time.time():
|
||||
self.checkFinished()
|
||||
return True
|
||||
return False
|
||||
|
||||
def checkFinished(self):
|
||||
p = requests.get("https://i.snssdk.com/videolive/lottery/check_user_right?lottery_id={}"
|
||||
"&version_code=730&device_platform=android".format(
|
||||
self.ID
|
||||
))
|
||||
d = p.json()
|
||||
if d["base_resp"]["status_code"] != 0:
|
||||
self.isActive = False
|
||||
self.isFinished = False
|
||||
return
|
||||
self.isActive = int(d["lottery_info"]["status"]) > 0
|
||||
self.isFinished = int(d["lottery_info"]["status"]) == 2
|
||||
self.joinedUserCount = int(d["lottery_info"]["candidate_num"])
|
||||
if self.isFinished:
|
||||
self.luckyUsers = [ LuckyUser(i) for i in d["lottery_info"]["lucky_users"] ]
|
||||
|
||||
def __str__(self):
|
||||
if self.isFinished:
|
||||
ret = "恭喜以下中奖用户:\n"
|
||||
for i in self.luckyUsers:
|
||||
ret += "> {} {}\n".format(i,self.prizeName)
|
||||
ret += "> 参与人数:{}".format(self.joinedUserCount)
|
||||
return ret
|
||||
elif self.isActive:
|
||||
return "正在抽奖中。。。\n" \
|
||||
"> 参与人数:{}".format(self.joinedUserCount)
|
||||
else:
|
||||
return "抽奖已失效"
|
19
Struct/LuckyUser.py
Normal file
19
Struct/LuckyUser.py
Normal file
@ -0,0 +1,19 @@
|
||||
from .User import User
|
||||
|
||||
class LuckyUser:
|
||||
|
||||
user = None
|
||||
count = 0
|
||||
|
||||
def __init__(self, json=None):
|
||||
if json:
|
||||
self.parse(json)
|
||||
|
||||
def parse(self, json):
|
||||
self.user = User()
|
||||
self.user.ID = json['user_id']
|
||||
self.user.name = json['user_name']
|
||||
self.count = int(json["grant_count"])
|
||||
|
||||
def __str__(self):
|
||||
return "用户 {} 获得了 {} 个".format(self.user,self.count)
|
36
Struct/MemberMsg.py
Normal file
36
Struct/MemberMsg.py
Normal file
@ -0,0 +1,36 @@
|
||||
from .User import User
|
||||
|
||||
|
||||
class MemberMsg:
|
||||
type = 0
|
||||
content = ""
|
||||
user = None
|
||||
|
||||
def __init__(self, json=None):
|
||||
if json:
|
||||
self.parse(json)
|
||||
|
||||
def parse(self, json):
|
||||
self.user = User(json)
|
||||
if "extra" in json:
|
||||
if "action" in json["extra"]:
|
||||
self.type = json["extra"]['action']
|
||||
elif "content" in json["extra"]:
|
||||
self.content = json["extra"]['content']
|
||||
|
||||
def __str__(self):
|
||||
if self.type == 3:
|
||||
return "{} 被禁言了".format(self.user)
|
||||
elif self.type == 4:
|
||||
return "{} 被取消禁言了".format(self.user)
|
||||
elif self.type == 5:
|
||||
return "{} 被任命为房管".format(self.user)
|
||||
elif self.type == 1:
|
||||
return "{} 进入了房间".format(self.user)
|
||||
else:
|
||||
if self.content == "":
|
||||
return "未知消息{} 关于用户 {}".format(self.type, self.user)
|
||||
return self.content.format(self.user)
|
||||
|
||||
def __unicode__(self):
|
||||
return self.__str__()
|
@ -1,15 +1,33 @@
|
||||
class User:
|
||||
ID = 0
|
||||
name = ""
|
||||
brand = ""
|
||||
level = 0
|
||||
type = 0
|
||||
block = False
|
||||
mute = False
|
||||
from XiguaUser_pb2 import User as UserPb
|
||||
|
||||
|
||||
class User:
|
||||
def __init__(self, json=None):
|
||||
self.ID = 0
|
||||
self.name = ""
|
||||
self.brand = ""
|
||||
self.level = 0
|
||||
self.type = 0
|
||||
self.block = False
|
||||
self.mute = False
|
||||
if json:
|
||||
self.parse(json)
|
||||
if type(json) == bytes:
|
||||
self.parsePb(json)
|
||||
elif type(json) == UserPb:
|
||||
self.parseUserPb(json)
|
||||
else:
|
||||
self.parse(json)
|
||||
|
||||
def parseUserPb(self, _user):
|
||||
self.ID = _user.id
|
||||
self.name = _user.nickname
|
||||
self.brand = _user.fansClub.fansClub.title
|
||||
self.level = _user.fansClub.fansClub.level
|
||||
|
||||
def parsePb(self, raw):
|
||||
_user = UserPb()
|
||||
_user.ParseFromString(raw)
|
||||
self.parseUserPb(_user)
|
||||
|
||||
def parse(self, json):
|
||||
if "extra" in json:
|
||||
|
Reference in New Issue
Block a user