Skip to content
This repository has been archived by the owner on Jun 6, 2023. It is now read-only.

Commit

Permalink
PK lottery
Browse files Browse the repository at this point in the history
增加大乱斗获胜抽奖
其他日常更新
  • Loading branch information
yawwwwwn committed Jun 19, 2019
1 parent 9667120 commit 5b806dd
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 5 deletions.
20 changes: 20 additions & 0 deletions bilibili.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,13 @@ async def get_gift_of_captain(self, roomid, id):
response2 = await self.bili_section_post(join_url, data=payload, headers=self.dic_bilibili['pcheaders'])
return response2

async def get_gift_of_pk(self, roomid, id):
join_url = "https://api.live.bilibili.com/xlive/lottery-interface/v1/pk/join"
payload = {"roomid": roomid, "id": id, "csrf": self.dic_bilibili['csrf'],
"csrf_token": self.dic_bilibili['csrf']}
response2 = await self.bili_section_post(join_url, data=payload, headers=self.dic_bilibili['pcheaders'])
return response2

async def get_giftlist_of_events(self, text1):
headers = {
'Accept': 'application/json, text/plain, */*',
Expand Down Expand Up @@ -323,6 +330,11 @@ async def get_giftlist_of_captain(self, roomid):
response1 = await self.bili_section_get(true_url, headers=headers)
return response1

async def get_lotterylist_of_pk(self, roomid):
url = 'http://api.live.bilibili.com/xlive/lottery-interface/v1/pk/check?roomid=' + str(roomid)
response = await self.bili_section_get(url, headers=self.dic_bilibili['pcheaders'])
return response

def get_giftids_raffle(self, str):
return self.dic_bilibili['giftids_raffle'][str]

Expand Down Expand Up @@ -394,6 +406,14 @@ async def guard_list(self):
response = requests.get(url, headers=headers)
return response

async def pk_list(self):
url = "http://118.25.108.153:8080/pk"
headers = {
"User-Agent": "bilibili-live-tools/" + str(self.dic_bilibili['uid'])
}
response = requests.get(url, headers=headers)
return response

async def get_lotterylist(self, i):
url = "https://api.live.bilibili.com/lottery/v1/box/getStatus?aid=" + \
str(i)
Expand Down
7 changes: 5 additions & 2 deletions bilibiliCilent.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,12 +265,15 @@ async def parseDanMu(self, messages):
# 活动榜单相关 [进入小时榜,未知,获小时榜第一道具奖励]
elif cmd in ["ROOM_RANK", "new_anchor_reward", "HOUR_RANK_AWARDS"]:
pass
# 活动相关 [活动获得的直播间入场特效,活动事件(如充能值信息),以前的高能事件,送礼抽奖活动开奖,LOL竞猜活动]
elif cmd in ["WELCOME_ACTIVITY", "ACTIVITY_EVENT", "EVENT_CMD", "BOX_LOTTERY_WIN", "LOL_ACTIVITY"]:
# 活动相关 [活动获得的直播间入场特效,活动事件(如充能值信息),以前的高能事件,送礼抽奖活动开奖,LOL竞猜活动,LOL助力活动]
elif cmd in ["WELCOME_ACTIVITY", "ACTIVITY_EVENT", "EVENT_CMD", "BOX_LOTTERY_WIN", "LOL_ACTIVITY", "ACTIVITY_MATCH_GIFT"]:
pass
# 直播间信息相关 [直播间更换壁纸,直播间界面皮肤变化,许愿瓶进度变化,关注数变化,实物抽奖宝箱提醒,实物抽奖宝箱开奖]
elif cmd in ["CHANGE_ROOM_INFO", "ROOM_SKIN_MSG", "WISH_BOTTLE", "ROOM_REAL_TIME_MESSAGE_UPDATE", "BOX_ACTIVITY_START", "WIN_ACTIVITY"]:
pass
# 大乱斗活动
elif cmd in ["PK_BATTLE_PRE", "PK_BATTLE_START", "PK_BATTLE_PROCESS", "PK_BATTLE_PRO_TYPE", "PK_BATTLE_END", "PK_BATTLE_SETTLE_USER", "PK_BATTLE_SETTLE", "PK_LOTTERY_START"]:
pass
else:
Printer().printer(f"出现一个未知msg @[{self.area}分区]{self._roomId} {dic}", "Warning", "red")
pass
2 changes: 1 addition & 1 deletion login.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def login(self):
configloader.write2bilibili(dic_saved_session)
Printer().printer(f"登录成功", "Info","green")
except:
Printer().printer(f"登录失败,错误信息为:{response.json()['message']}","Error","red")
Printer().printer(f"登录失败,错误信息为:{response.json()}","Error","red")

async def login_new(self):
if bilibili().dic_bilibili['saved-session']['cookie']:
Expand Down
68 changes: 68 additions & 0 deletions pkLottery.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import traceback
import asyncio

from bilibili import bilibili
from printer import Printer
import utils


class PKLottery:
last_pk_room = 0
had_gotten_pk = []

async def pk_lottery(self):
for _ in range(3):
try:
response = await bilibili().pk_list()
json_response = response.json()
# print(json_response)
break
except Exception:
continue
else:
Printer().printer("连接大乱斗服务器失败", "Error", "red")
return
for i in range(0, len(json_response)):
PKId = json_response[i]['PKId']
if PKId not in PKLottery.had_gotten_pk and PKId != 0:
PKLottery.had_gotten_pk.append(PKId)
OriginRoomId = json_response[i]['OriginRoomId']
if not OriginRoomId == PKLottery.last_pk_room:
result = await utils.check_room_true(OriginRoomId)
if True in result:
Printer().printer(f"检测到房间 {OriginRoomId} 的钓鱼操作", "Warning", "red")
continue
await bilibili().post_watching_history(OriginRoomId)
PKLottery.last_pk_room = OriginRoomId
response2 = await bilibili().get_gift_of_pk(OriginRoomId, PKId)
json_response2 = await response2.json(content_type=None)
# print(json_response2)
# {'code': 0, 'message': '0', 'ttl': 1, 'data': {'id': 343560, 'gift_type': 0, 'award_id': '1', 'award_text': '辣条X1', 'award_image': 'https://i0.hdslb.com/bfs/live/da6656add2b14a93ed9eb55de55d0fd19f0fc7f6.png', 'award_num': 0, 'title': '大乱斗获胜抽奖'}}
# {'code': -1, 'message': '抽奖已结束', 'ttl': 1}
# {'code': -2, 'message': '您已参加过抽奖', 'ttl': 1}
# {"code":-403,"data":null,"message":"访问被拒绝","msg":"访问被拒绝"}
if json_response2['code'] == 0:
Printer().printer(f"参与房间 {OriginRoomId} 编号 {PKId} 的大乱斗获胜抽奖: {json_response2['data']['award_text']}",
"Lottery", "cyan")
elif json_response2['code'] == -2 and json_response2['message'] == "您已参加过抽奖":
Printer().printer(
f"房间 {OriginRoomId} 编号 {PKId} 的大乱斗获胜抽奖已参与过",
"Info", "green")
elif json_response2['code'] == -403 and json_response2['message'] == "访问被拒绝":
Printer().printer(f"参与房间 {OriginRoomId} 编号 {PKId} 的大乱斗获胜抽奖: {json_response2['message']}",
"Lottery", "cyan")
print(json_response2)
else:
Printer().printer(
f"房间 {OriginRoomId} 编号 {PKId} 的大乱斗获胜抽奖参与出错: {json_response2}",
"Error", "red")


async def run(self):
while True:
try:
await self.pk_lottery()
await asyncio.sleep(30)
except Exception:
await asyncio.sleep(10)
Printer().printer(traceback.format_exc(), "Error", "red")
6 changes: 4 additions & 2 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from bilibili import bilibili
import threading
import biliconsole
from pkLottery import PKLottery

loop = asyncio.get_event_loop()
loop1 = asyncio.get_event_loop()
Expand All @@ -25,6 +26,7 @@
task2 = Tasks()
task3 = LotteryResult()
task4 = connect()
task5 = PKLottery()

console_thread = threading.Thread(target=biliconsole.controler)

Expand All @@ -42,8 +44,8 @@
biliconsole.Biliconsole().run(),
task4.create(),
task3.query(),
rafflehandler.run()

rafflehandler.run(),
task5.run()
]

loop.run_until_complete(asyncio.wait(tasks))
Expand Down

0 comments on commit 5b806dd

Please sign in to comment.