This repository has been archived by the owner on Jul 2, 2019. It is now read-only.
forked from Dawnnnnnn/bilibili-live-tools
-
Notifications
You must be signed in to change notification settings - Fork 23
/
Tasks.py
325 lines (288 loc) · 11.3 KB
/
Tasks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
from online_net import OnlineNet
import asyncio
from configloader import ConfigLoader
import utils
import printer
from bilitimer import BiliTimer
import random
import re
import json
# 获取每日包裹奖励
async def Daily_bag():
json_response = await OnlineNet().req('get_dailybag')
# no done code
for i in json_response['data']['bag_list']:
printer.info([f'# 获得包裹 {i["bag_name"]}'])
BiliTimer.call_after(Daily_bag, 21600)
# 签到功能
async def DoSign():
# -500 done
temp = await OnlineNet().req('get_dosign')
printer.info([f'# 签到状态: {temp["msg"]}'])
if temp['code'] == -500 and '已' in temp['msg']:
sleeptime = (utils.seconds_until_tomorrow() + 300)
else:
sleeptime = 350
BiliTimer.call_after(DoSign, sleeptime)
# 领取每日任务奖励
async def Daily_Task():
# -400 done/not yet
json_response2 = await OnlineNet().req('get_dailytask')
printer.info([f'# 双端观看直播: {json_response2["msg"]}'])
if json_response2['code'] == -400 and '已' in json_response2['msg']:
sleeptime = (utils.seconds_until_tomorrow() + 300)
else:
sleeptime = 350
BiliTimer.call_after(Daily_Task, sleeptime)
async def Sign1Group(i1, i2):
json_response = await OnlineNet().req('assign_group', i1, i2)
if not json_response['code']:
data = json_response['data']
if data['status']:
printer.info([f'# 应援团 {i1} 已应援过'])
else:
printer.info([f'# 应援团 {i1} 应援成功,获得{data["add_num"]}点亲密度'])
# 应援团签到
async def link_sign():
json_rsp = await OnlineNet().req('get_grouplist')
list_check = json_rsp['data']['list']
for i in list_check:
asyncio.ensure_future(Sign1Group(i['group_id'], i['owner_uid']))
BiliTimer.call_after(link_sign, 21600)
async def send_expiring_gift():
task_control = ConfigLoader().dic_user['task_control']
if task_control['clean-expiring-gift']:
argvs = await utils.fetch_bag_list(show=False)
roomID = task_control['clean-expiring-gift2room']
time_set = task_control['set-expiring-time']
list_gift = []
for i in argvs:
left_time = i[3]
# 剩余时间少于半天时自动送礼
if left_time is not None and 0 < int(left_time) < time_set:
list_gift.append(i[:3])
if list_gift:
print('发现即将过期的礼物', list_gift)
if task_control['clean_expiring_gift2all_medal']:
print('正在投递其他勋章')
list_medal = await utils.fetch_medal(show=False)
list_gift = await full_intimate(list_gift, list_medal)
print('正在清理过期礼物到指定房间')
for i in list_gift:
giftID = i[0]
giftNum = i[1]
bagID = i[2]
await utils.send_gift_web(roomID, giftNum, bagID, giftID)
else:
print('未发现即将过期的礼物')
async def send_medal_gift():
list_medal = []
task_control = ConfigLoader().dic_user['task_control']
if task_control['send2wearing-medal']:
list_medal = await utils.WearingMedalInfo()
if not list_medal:
print('暂未佩戴任何勋章')
if task_control['send2medal']:
list_medal += await utils.fetch_medal(False, task_control['send2medal'])
# print(list_medal)
print('正在投递勋章')
temp = await utils.fetch_bag_list(show=False)
# print(temp)
list_gift = []
for i in temp:
gift_id = int(i[0])
left_time = i[3]
if (gift_id not in [4, 3, 9, 10]) and left_time is not None:
list_gift.append(i[:3])
await full_intimate(list_gift, list_medal)
async def send_gift():
await send_medal_gift()
await send_expiring_gift()
BiliTimer.call_after(send_gift, 21600)
async def full_intimate(list_gift, list_medal):
json_res = await OnlineNet().req('gift_list')
dic_gift = {j['id']: int(j['price'] / 100) for j in json_res['data']}
for roomid, score_wanted, medal_name in list_medal:
sum_score = 0
for i in list_gift:
gift_id, gift_num, bag_id = i
price = dic_gift[gift_id]
left_score = score_wanted - sum_score
if price * gift_num <= left_score:
num_wanted = gift_num
elif left_score >= price:
num_wanted = int(left_score / price)
else:
num_wanted = 0
await utils.send_gift_web(roomid, num_wanted, bag_id, gift_id)
i[1] -= num_wanted
score = price * num_wanted
sum_score += score
printer.info([f'# 对{medal_name}共送出亲密度为{sum_score}的礼物'])
return [i for i in list_gift if i[1]]
async def doublegain_coin2silver():
if ConfigLoader().dic_user['task_control']['doublegain_coin2silver']:
json_response0 = await OnlineNet().req('request_doublegain_coin2silver')
json_response1 = await OnlineNet().req('request_doublegain_coin2silver')
print(json_response0['msg'], json_response1['msg'])
BiliTimer.call_after(doublegain_coin2silver, 21600)
async def sliver2coin():
if ConfigLoader().dic_user['task_control']['silver2coin']:
# 403 done
# json_response1 = await OnlineNet().req('silver2coin_app')
json_response = await OnlineNet().req('silver2coin_web')
printer.info([f'# {json_response["msg"]}'])
if json_response['code'] == 403 and '最多' in json_response['msg']:
finish_web = True
else:
finish_web = False
if finish_web:
sleeptime = (utils.seconds_until_tomorrow() + 300)
BiliTimer.call_after(sliver2coin, sleeptime)
return
else:
BiliTimer.call_after(sliver2coin, 350)
return
BiliTimer.call_after(sliver2coin, 21600)
async def GetVideoExp(list_topvideo):
print('开始获取视频观看经验')
aid = random.choice(list_topvideo)
cid = await utils.GetVideoCid(aid)
await OnlineNet().req('Heartbeat', aid, cid)
async def GiveCoinTask(coin_remain, list_topvideo):
i = 0
while coin_remain > 0:
i += 1
if i > 20:
print('本次可投票视频获取量不足')
return
aid = random.choice(list_topvideo)
rsp = await utils.GiveCoin2Av(aid, 1)
if rsp is None:
break
elif rsp:
coin_remain -= 1
async def GetVideoShareExp(list_topvideo):
print('开始获取视频分享经验')
aid = random.choice(list_topvideo)
await OnlineNet().req('DailyVideoShare', aid)
async def BiliMainTask():
task_control = ConfigLoader().dic_user['task_control']
login, watch_av, num, share_av = await utils.GetRewardInfo()
if task_control['fetchrule'] == 'bilitop':
list_topvideo = await utils.GetTopVideoList()
else:
list_topvideo = await utils.fetch_uper_video(task_control['mid'])
if (not login) or not watch_av:
await GetVideoExp(list_topvideo)
coin_sent = num / 10
coin_set = min(task_control['givecoin'], 5)
coin_remain = coin_set - coin_sent
await GiveCoinTask(coin_remain, list_topvideo)
if not share_av:
await GetVideoShareExp(list_topvideo)
# b站傻逼有记录延迟,3点左右成功率高一点
BiliTimer.call_after(BiliMainTask, utils.seconds_until_tomorrow() + 10800)
async def check(id):
# 3放弃
# 2 否 voterule
# 4 删除 votedelete
# 1 封杀 votebreak
text_rsp = await OnlineNet().req('req_check_voted', id)
pattern = re.compile(r'\((.+)\)')
match = pattern.findall(text_rsp)
temp = json.loads(match[0])
data = temp['data']
votebreak = data['voteBreak']
voteDelete = data['voteDelete']
voteRule = data['voteRule']
voted = votebreak+voteDelete+voteRule
percent = (voteRule / voted) if voted else 0
print(f'\"{data["originContent"]}\"')
print('该案件目前已投票', voted)
print('认为言论合理比例', percent)
return voted, percent
def judge_case(voted, percent):
vote = None
if voted >= 300:
# 认为这里可能出现了较多分歧,抬一手
if percent >= 0.4:
vote = 2
elif percent <= 0.25:
vote = 4
elif voted >= 150:
if percent >= 0.9:
vote = 2
elif percent <= 0.1:
vote = 4
elif voted >= 50:
if percent >= 0.97:
vote = 2
elif percent <= 0.03:
vote = 4
# 抬一手
if vote is None and voted >= 400:
vote = 2
return vote
async def judge():
num_case = 0
num_voted = 0
while True:
temp = await OnlineNet().req('req_fetch_case')
if not temp['code']:
id = temp['data']['id']
num_case += 1
else:
print('本次未获取到案件')
break
wait_time = 0
min_percent = 1
max_percent = 0
while True:
voted, percent = await check(id)
vote = judge_case(voted, percent)
if voted >= 50:
min_percent = min(min_percent, percent)
max_percent = max(max_percent, percent)
print('统计投票波动情况', max_percent, min_percent)
if vote is not None:
break
elif wait_time >= 1200:
print('进入二次判定')
# 如果case判定中,波动很小,则表示趋势基本一致
if 0 <= max_percent - min_percent <= 0.1 and voted > 200:
future_voted = voted + 100
vote0 = judge_case(future_voted, max_percent)
vote1 = judge_case(future_voted, min_percent)
vote = vote0 if vote0 == vote1 else None
print('二次判定结果', vote)
break
else:
sleep_time = 180 if voted < 300 else 60
printer.info([f'案件{id}暂时无法判定,在{sleep_time}后重新尝试'], True)
await asyncio.sleep(sleep_time)
wait_time += sleep_time
if vote is None:
num_voted -= 1
vote = 3
vote_info = '作废票' if vote == 3 else '有效票'
print('该案件的投票决策', id, vote, vote_info)
json_rsp = await OnlineNet().req('req_vote_case', id, vote)
if not json_rsp['code']:
print('该案件的投票结果', id, '投票成功')
num_voted += 1
else:
print('该案件的投票结果', id, '投票失败,请反馈作者')
print('______________________________________________')
printer.info([f'风纪委员会共获取{num_case}件案例,其中有效投票{num_voted}件'], True)
BiliTimer.call_after(judge, 3600)
def init():
BiliTimer.call_after(sliver2coin, 0)
BiliTimer.call_after(doublegain_coin2silver, 0)
BiliTimer.call_after(DoSign, 0)
BiliTimer.call_after(Daily_bag, 0)
BiliTimer.call_after(Daily_Task, 0)
BiliTimer.call_after(link_sign, 0)
BiliTimer.call_after(send_gift, 0)
BiliTimer.call_after(BiliMainTask, 0)
BiliTimer.call_after(judge, 0)