Skip to content

Commit

Permalink
buy medal
Browse files Browse the repository at this point in the history
  • Loading branch information
yjqiang committed Apr 22, 2019
1 parent e31d7b7 commit 5001748
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
7 changes: 6 additions & 1 deletion bili_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from cmd import Cmd
import getopt
from tasks.utils import UtilsTask
from tasks.custom import SendLatiaoTask, BuyLatiaoTask
from tasks.custom import SendLatiaoTask, BuyLatiaoTask, BuyMedalTask
from tasks.main_daily_job import JudgeCaseTask


Expand Down Expand Up @@ -39,6 +39,7 @@ def guide_of_console(self):

print('|21 赠指定总数的辣条到房间    |')
print('|22 银瓜子全部购买辣条并送到房间 |')
print('|23 购买勋章(使用银瓜子或者硬币)|')
print('  ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ')

def default(self, line):
Expand Down Expand Up @@ -151,6 +152,10 @@ def do_21(self, arg):
def do_22(self, arg):
id, real_roomid = self.parse(arg, '-u:-p:')
self.exec_notifier_func_threads(id, BuyLatiaoTask.clean_latiao, [real_roomid])

def do_23(self, arg):
id, coin_type, real_roomid = self.parse(arg, '-u:-c:-p:')
self.exec_notifier_func_threads(id, BuyMedalTask.buy_medal, [real_roomid, coin_type])

def fetch_real_roomid(self, room_id):
real_roomid = [-1, UtilsTask.get_real_roomid, room_id]
Expand Down
9 changes: 9 additions & 0 deletions reqs/custom.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
import utils
from bili_global import API_LIVE


class BuyLatiaoReq:
# 其实与utils部分差不多,怀疑可能是新旧api
@staticmethod
async def fetch_livebili_userinfo_pc(user):
url = f'{API_LIVE}/xlive/web-ucenter/user/get_user_info'
json_rsp = await user.bililive_session.request_json('GET', url, headers=user.dict_bili['pcheaders'])
return json_rsp


class BuyMedalReq:
@staticmethod
async def buy_medal(user, uid, coin_type):
url = f'https://api.vc.bilibili.com/link_group/v1/member/buy_medal?coin_type={coin_type}&master_uid={uid}&platform=android'
json_rsp = await user.other_session.request_json('GET', url, headers=user.dict_bili['pcheaders'])
return json_rsp
13 changes: 11 additions & 2 deletions tasks/custom.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# 理论上项目已有的task不要相互引用,只能引用utils的东西,防止交叉,但是自定义的无所谓,因为绝对不可能交叉
from tasks.live_daily_job import SendGiftTask
from tasks.utils import UtilsTask
from reqs.custom import BuyLatiaoReq
from reqs.custom import BuyLatiaoReq, BuyMedalReq


class SendLatiaoTask:
Expand Down Expand Up @@ -46,7 +46,6 @@ async def fetch_silver(user):
if not json_rsp['code']:
silver = json_rsp['data']['silver']
return silver


@staticmethod
async def clean_latiao(user, room_id):
Expand All @@ -55,4 +54,14 @@ async def clean_latiao(user, room_id):
coin_type = 'silver'
num_sent = int((await BuyLatiaoTask.fetch_silver(user)) / 100)
await UtilsTask.buy_gift(user, room_id, num_sent, coin_type, gift_id)


class BuyMedalTask:
@staticmethod
async def buy_medal(user, room_id, coin_type):
if coin_type == 'metal' or coin_type == 'silver':
uid = await UtilsTask.check_uid_by_roomid(user, room_id)
if uid is not None:
json_rsp = await BuyMedalReq.buy_medal(user, uid, coin_type)
user.info(json_rsp['msg'])
user.info('请重新检查填写coin_type或者房间号')
9 changes: 9 additions & 0 deletions tasks/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,15 @@ async def get_real_roomid(user, room_id):
elif json_rsp['code'] == 60004:
print(json_rsp['msg'])

@staticmethod
async def check_uid_by_roomid(user, room_id):
json_rsp = await user.req_s(UtilsReq.init_room, user, room_id)
if not json_rsp['code']:
uid = json_rsp['data']['uid']
print(f'房间号{room_id}对应的UID为{uid}')
return int(uid)
return None

@staticmethod
async def send_danmu(user, msg, room_id):
json_rsp = await user.req_s(UtilsReq.send_danmu, user, msg, room_id)
Expand Down

0 comments on commit 5001748

Please sign in to comment.