forked from AddOneSecondL/pcrjjc2-clanbattle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
__init__.py
1885 lines (1721 loc) · 82.5 KB
/
__init__.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
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
from json import load, dump, loads
from io import BytesIO
import json
import requests
import base64
import random
from nonebot import get_bot, on_command
from hoshino import priv, R
from hoshino.typing import NoticeSession, MessageSegment, CQHttpError
from .pcrclient import pcrclient, ApiException, bsdkclient
from asyncio import Lock, sleep
from os.path import dirname, join, exists
from copy import deepcopy
from traceback import format_exc
from .safeservice import SafeService
from hoshino.util import pic2b64
from random import randint
import re
import time
import os
from time import gmtime
from hoshino.modules.priconne import chara
from hoshino.modules.priconne._pcr_data import CHARA_NAME
from PIL import Image, ImageDraw, ImageFont, ImageChops, ImageFilter, ImageOps, ImageEnhance
from hoshino import util
import datetime
import sqlite3
from .aiorequests import get
from .yobot import generate_name2qq, report_process
sv_help = '''
[游戏内会战推送] 无描述
'''.strip()
sv = SafeService('会战推送', help_=sv_help, bundle='pcr查询')
curpath = dirname(__file__)
##############################下面这个框填要推送的群
forward_group_list = []
yobot_dir = ''
##############################
current_folder = os.path.dirname(__file__)
img_file = os.path.join(current_folder, 'img')
cache = {}
client = None
lck = Lock()
captcha_lck = Lock()
with open(join(curpath, 'account.json')) as fp:
acinfo = load(fp)
experimental = acinfo["experimental_options"]
if acinfo["push_group"] != []:
forward_group_list = acinfo["push_group"]
bot = get_bot()
validate = None
validating = False
acfirst = False
#同步pcrjjc2自动过码
async def captchaVerifierV2(gt, challenge, userid):
global validating
validating = True
captcha_cnt = 0
while captcha_cnt < 5:
captcha_cnt += 1
#try:
sv.logger.info(f'测试新版自动过码中,当前尝试第{captcha_cnt}次。')
await sleep(1)
url = f"https://pcrd.tencentbot.top/geetest_renew?captcha_type=1&challenge={challenge}>={gt}&userid={userid}&gs=1"
header = {"Content-Type": "application/json", "User-Agent": "pcrjjc2/1.0.0"}
# uuid = loads(await (await get(url="https://pcrd.tencentbot.top/geetest")).content)["uuid"]
# print(f'uuid={uuid}')
res = await (await aiorequests.get(url=url, headers=header)).content
res = loads(res)
uuid = res["uuid"]
msg = [f"uuid={uuid}"]
ccnt = 0
while ccnt < 10:
ccnt += 1
res = await (await aiorequests.get(url=f"https://pcrd.tencentbot.top/check/{uuid}", headers=header)).content
#if str(res.status_code) != "200":
# continue
# print(res)
res = loads(res)
if "queue_num" in res:
nu = res["queue_num"]
msg.append(f"queue_num={nu}")
tim = min(int(nu), 3) * 10
msg.append(f"sleep={tim}")
#await bot.send_private_msg(user_id=acinfo['admin'], message=f"thread{ordd}: \n" + "\n".join(msg))
# print(f"pcrjjc2:\n" + "\n".join(msg))
msg = []
# print(f'farm: {uuid} in queue, sleep {tim} seconds')
await sleep(tim)
else:
info = res["info"]
if info in ["fail", "url invalid"]:
break
elif info == "in running":
await sleep(5)
elif 'validate' in info:
print(f'info={info}')
validating = False
return (info["challenge"], info["gt_user_id"], info["validate"])
if ccnt >= 10:
raise Exception("Captcha failed")
# ccnt = 0
# while ccnt < 3:
# ccnt += 1
# await sleep(5)
# res = await (await get(url=f"https://pcrd.tencentbot.top/check/{uuid}")).content
# res = loads(res)
# if "queue_num" in res:
# nu = res["queue_num"]
# print(f"queue_num={nu}")
# tim = min(int(nu), 3) * 5
# print(f"sleep={tim}")
# await sleep(tim)
# else:
# info = res["info"]
# if info in ["fail", "url invalid"]:
# break
# elif info == "in running":
# await sleep(5)
# else:
# print(f'info={info}')
# validating = False
# return info["challenge"], info["gt_user_id"], info["validate"]
# except:
# pass
# await sendToAdmin(
# f'自动过码多次尝试失败,可能为服务器错误,自动切换为手动。\n确实服务器无误后,可发送/pcrval重新触发自动过码。')
validate = await captchaVerifier(gt, challenge, userid)
validating = False
return challenge, userid, validate
async def captchaVerifier(gt, challenge, userid):
global acfirst, validating
if not acfirst:
await captcha_lck.acquire()
acfirst = True
if acinfo['admin'] == 0:
bot.logger.error('captcha is required while admin qq is not set, so the login can\'t continue')
else:
# url = f"链接头:https://cc004.github.io/geetest/geetest.html\n链接:?captcha_type=1&challenge={challenge}>={gt}&userid={userid}&gs=1"
url = f"https://cc004.github.io/geetest/geetest.html?captcha_type=1&challenge={challenge}>={gt}&userid={userid}&gs=1"
if int(acinfo["captcha_group"]) != 0:
await bot.send_group_msg(group_id = acinfo["captcha_group"],message = f'pcr账号登录需要验证码,请完成以下链接中的验证内容后将第一行validate=后面的内容复制,并用指令/pcrvalclan xxxx将内容发送给机器人完成验证\n为避免tx网页安全验证使验证码过期,请手动拼接链接头和链接:{url}\n※注意:请私聊BOT发送')
else:
await bot.send_private_msg(
user_id = acinfo['admin'],
message = f'pcr账号登录需要验证码,请完成以下链接中的验证内容后将第一行validate=后面的内容复制,并用指令/pcrvalclan xxxx将内容发送给机器人完成验证\n为避免tx网页安全验证使验证码过期,请手动拼接链接头和链接:{url}'
)
validating = True
await captcha_lck.acquire()
validating = False
return validate
async def errlogger(msg):
await bot.send_private_msg(
user_id = acinfo['admin'],
message = f'pcrjjc2登录错误:{msg}'
)
clients = {}
for account_info in acinfo["account_list"]:
account = account_info["account"]
password = account_info["password"]
bClient = bsdkclient(acinfo, captchaVerifierV2, errlogger, account, password)
clients[account] = pcrclient(bClient)
define_account = acinfo["account_list"][0]["account"]
client:pcrclient = clients[define_account]
qlck = Lock()
async def verify(): #验证登录状态
if validating:
raise ApiException('账号被风控,请联系管理员输入验证码并重新登录', -1)
async with qlck:
while client.shouldLogin:
await client.login()
time.sleep(3)
return
@on_command(f'/pcrvalclan') #原手动验证
async def validate(session):
global binds, lck, validate
if session.ctx['user_id'] == acinfo['admin']:
validate = session.ctx['message'].extract_plain_text().strip()[12:]
captcha_lck.release()
#本人编程初学者,以下答辩代码警告
boss_icon_list = []
swa = 0 #初始化出刀开关
boss_status = [0,0,0,0,0]
in_game = [0,0,0,0,0]
in_game_old = [0,0,0,0,0] #实战中
pre_push = [[],[],[],[],[]] #预约组
coin = 0 #会战币
arrow = 0 #出刀ID
tvid = 0 #玩家ID
sw = 0 #会战推送开关
fnum = 0 #实战人数
arrow_rec = 0 #出刀记录
renew_coin = True
side = {
1: 'A',
4: 'B',
11: 'C',
31: 'D',
41: 'E'
} #阶段数
phase = {
1: 1,
4: 2,
11: 3,
31: 4,
41: 5
} #阶段周目
curr_side = '_'
max_chat_list = 20
health_list = [[6000000,8000000,10000000,12000000,15000000],[6000000,8000000,10000000,12000000,15000000],[12000000,14000000,17000000,19000000,22000000],[19000000,20000000,23000000,25000000,27000000],[85000000,90000000,95000000,100000000,110000000]]
@sv.scheduled_job('interval', seconds=60)
async def teafak():
global coin,arrow_rec,side,curr_side,arrow,sw,pre_push,fnum,forward_group_list,boss_status,in_game,tvid,experimental,renew_coin
try:
load_index = 0
if sw == 0: #会战推送开关
return
if coin == 0 or renew_coin > 0: #初始化获取硬币数/检测到boss状态发生变化后更新会战币
item_list = {}
await verify()
load_index = await client.callapi('/load/index', {'carrier': 'OPPO'}) #获取会战币api
if tvid == 0:
tvid =load_index['user_info']['viewer_id']
for item in load_index["item_list"]:
item_list[item["id"]] = item["stock"]
coin = item_list[90006]
msg = ''
ref = 0
res = 0
while(ref == 0):
try:
await verify()
clan_info = await client.callapi('/clan/info', {'clan_id': 0, 'get_user_equip': 0})
clan_id = clan_info['clan']['detail']['clan_id']
res = await client.callapi('/clan_battle/top', {'clan_id': clan_id, 'is_first': 1, 'current_clan_battle_coin': coin})
ref = 1
if renew_coin > 0:
renew_coin -= 1
except Exception as e:
if ('连接中断' or '发生了错误(E)') in str(e):
for forward_group in forward_group_list:
await bot.send_group_msg(group_id = forward_group,message = '连接中断,可能顶号,已自动关闭推送,请重新开启会战推送')
sw = 0
return
await verify()
load_index = await client.callapi('/load/index', {'carrier': 'OPPO'}) #击败BOSS时会战币会变动
item_list = {}
for item in load_index["item_list"]:
item_list[item["id"]] = item["stock"]
coin = item_list[90006]
pass
#判定是否处于会战期间
if load_index != 0:
is_interval = load_index['clan_battle']['is_interval']
if is_interval == 1:
mode_change_open = load_index['clan_battle']['mode_change_limit_start_time']
mode_change_open = time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(mode_change_open))
mode_change_limit = load_index['clan_battle']['mode_change_limit_time']
mode_change_limit = time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(mode_change_limit))
msg = f'当前会战未开放,请在会战前一天初始化会战推送\n会战模式可切换时间{mode_change_open}-{mode_change_limit}'
sw = 0
for forward_group in forward_group_list:
await bot.send_group_msg(group_id = forward_group,message = msg)
return
#判定各BOSS圈数并获取预约表推送
num = 0
for boss_info in res['boss_info']:
lap_num = boss_info['lap_num']
if lap_num != boss_status[num]:
boss_status[num] = lap_num
#msg += f'全新的{lap_num}周目{num+1}王来了!'
push_list = pre_push[num]
if push_list != []: #预约后群内和行会内提醒
chat_content = f'{lap_num}周目{num+1}王已被预约,请耐心等候!'
try:
await verify()
await client.callapi('/clan/chat', {'clan_id': clan_id, 'type': 0, 'message': chat_content})
except:
pass
warn = ''
for pu in push_list:
pu = pu.split('|')
uid = int(pu[0])
gid = int(pu[1])
atmsg = f'提醒:已到{lap_num}周目 {num+1} 王!请注意沟通上一尾刀~\n[CQ:at,qq={uid}]'
await bot.send_group_msg(group_id = gid,message = atmsg)
pre_push[num] = []
num += 1
#获取出刀记录并推送最新的出刀
if res != 0:
history = reversed(res['damage_history']) #从返回的出刀记录刀的状态
clan_info = await client.callapi('/clan/info', {'clan_id': 0, 'get_user_equip': 0})
clan_id = clan_info['clan']['detail']['clan_id']
pre_clan_battle_id = await client.callapi('/clan_battle/top', {'clan_id': clan_id, 'is_first': 1, 'current_clan_battle_coin': coin})
#print(res)
if arrow == 0:
for line in open(current_folder + "/Output.txt",encoding='utf-8'):
if line != '':
line = line.split(',')
if line[0] != 'SL':
arrow = int(line[4])
# print(arrow)
#file.close()
clan_battle_id = pre_clan_battle_id['clan_battle_id']
in_battle = []
for hst in history:
if ((arrow != 0) and (int(hst['history_id']) > int(arrow))) or (arrow == 0): #记录刀ID防止重复
name = hst['name'] #名字
vid = hst['viewer_id'] #13位ID
kill = hst['kill'] #是否击杀
damage = hst['damage'] #伤害
lap = hst['lap_num'] #圈数
boss = int(hst['order_num']) #几号boss
ctime = hst['create_time'] #出刀时间
real_time = time.localtime(ctime)
day = real_time[2] #垃圾代码
hour = real_time[3]
minu = real_time[4]
seconds = real_time[5]
arrow = hst['history_id'] #记录指针
enemy_id = hst['enemy_id'] #BOSSID,暂时没找到用处
is_auto = hst['is_auto']
if is_auto == 1:
is_auto_r = '自动刀'
else:
is_auto_r = '手动刀'
ifkill = '' #击杀变成可读
if kill == 1:
ifkill = '并击破'
in_game_old[boss-1] = 0
#push = True
renew_coin = 2 #第二次获取时顺带刷新会战币数量
for st in phase:
if lap >= st:
phases = st
phases = phase[phases]
timeline = await client.callapi('/clan_battle/battle_log_list', {'clan_battle_id': clan_battle_id, 'order_num': boss, 'phases': [phases], 'report_types': [1], 'hide_same_units': 0, 'favorite_ids': [], 'sort_type': 3, 'page': 1})
timeline_list = timeline['battle_list']
#print(timeline_list)
start_time = 0
used_time = 0
for tl in timeline_list:
if tl['battle_end_time'] == ctime:
blid1 = tl['battle_log_id']
tvid = tl['target_viewer_id']
# print(blid1)
blid = await client.callapi('/clan_battle/timeline_report', {'target_viewer_id': tvid, 'clan_battle_id': clan_battle_id, 'battle_log_id': int(blid1)})
start_time = blid['start_remain_time']
used_time = blid['battle_time']
if start_time == 90:
battle_type = f'初始刀{used_time}s'
else:
battle_type = f'补偿刀{used_time}s'
for st in side:
if lap >= st:
cur_side = st
cur_side = side[cur_side]
msg += f'[{cur_side}-{battle_type}]{name} 对 {lap} 周目 {boss} 王造成了 {damage} 伤害{ifkill}({is_auto_r})\n'
in_battle.append([boss,kill])
output = f'{day},{hour},{minu},{seconds},{arrow},{name},{vid},{lap},{boss},{damage},{kill},{enemy_id},{clan_battle_id},{is_auto},{start_time},{used_time},{ctime},' #记录出刀,后面要用
with open(current_folder+"/Output.txt","a",encoding='utf-8') as file:
file.write(str(output)+'\n')
file.close()
challenge_item = {}
if name in name2qq:
challenge_item['qqid'] = name2qq[name]
else:
msg = f'找不到以下游戏成员对应的QQ号码:\n{name}'
await bot.send_group_msg(group_id = forward_group_list[0], message = msg)
sw = 0
return
challenge_item['lap_num'] = lap
challenge_item['boss'] = boss - 1
challenge_item['damage'] = damage
challenge_item['kill'] = kill
challenge_item['datetime'] = ctime
if start_time == 90:
challenge_item['reimburse'] = 0
else:
challenge_item['reimburse'] = 1
ret = await report_process(bot, str(forward_group_list[0]), challenge_item)
if ret != 0:
sw = 0
arrow = 0
return
challenge_item['finish'] = 1
ret = await report_process(bot, str(forward_group_list[0]), challenge_item)
if ret != 0:
sw = 0
arrow = 0
return
#记录实战人数变动并推送
change = False
for num in range(0,5):
boss_info2 = await client.callapi('/clan_battle/boss_info', {'clan_id': clan_id, 'clan_battle_id': clan_battle_id, 'lap_num': boss_status[num], 'order_num': num+1})
fnum = boss_info2['fighter_num']
if in_game[num] != fnum:
if fnum > in_game[num]:
diff = fnum - in_game[num]
in_game_old[num] += diff
in_game[num] = fnum
change = True
if in_battle != []:
change = True
for ib in in_battle:
if in_game_old[ib[0]-1] > 0:
in_game_old[ib[0]-1] -= 1
if ib[1] == 1:
in_game_old[ib[0]-1] = 0
if change == True:
renew_coin = 15
if acinfo['ingame_calc_mode'] == 1:
msg += f'当前实战人数发生变化:\n[{in_game_old[0]}][{in_game_old[1]}][{in_game_old[2]}][{in_game_old[3]}][{in_game_old[4]}]'
else:
msg += f'当前90s内实战人数发生变化:\n[{in_game[0]}][{in_game[1]}][{in_game[2]}][{in_game[3]}][{in_game[4]}]'
if msg != '':
if len(msg)>200:
msg = '...\n' + msg[-200:]
# for forward_group in forward_group_list:
# await bot.send_group_msg(group_id = forward_group,message = msg)
else:
print('error')
except Exception as e:
if ('连接中断' or '发生了错误(E)') in str(e):
for forward_group in forward_group_list:
await bot.send_group_msg(group_id = forward_group,message = '连接中断,可能顶号,已自动关闭推送,请重新开启会战推送')
sw = 0
elif '发生了错误' in str(e):
print('发生错误,下次重试')
return
@sv.on_fullmatch('切换会战推送') #这个给要出刀的号准备的
async def sw_pus(bot , ev):
global sw
u_priv = priv.get_user_priv(ev)
if u_priv < sv.manage_priv and acinfo["only_admin"] == 1:
await bot.send(ev,'权限不足,当前指令仅管理员可用!')
return
if sw == 0:
sw = 1
if boss_icon_list == []:
try:
date = datetime.date.today()
dyear = date.year
dmonth = date.month
await get_boss_icon(dyear,dmonth)
except:
await bot.send(ev,'获取当期BOSS头像失败')
pass
await bot.send(ev,'已开启会战推送')
else:
sw = 0
await bot.send(ev,'已关闭会战推送')
@sv.on_fullmatch('初始化会战推送') #会战前一天输入这个
async def sw_pus(bot , ev):
global swa,name2qq,forward_group_list
ret, name2qq = await generate_name2qq(str(forward_group_list[0]))
date = datetime.date.today()
dyear = date.year
dmonth = date.month
try:
await get_boss_icon(dyear,dmonth)
except:
await bot.send(ev,'获取当期BOSS头像失败')
pass
swa = 1
await bot.send(ev,'初始化完成')
async def get_boss_icon(dyear,dmonth):
global boss_icon_list
'''proxies = {
'http': 'http://127.0.0.1:4780',
'https': 'http://127.0.0.1:4780',
} '''
url = 'https://pcr.satroki.tech/api/Quest/GetClanBattleInfos?s=cn'
#res = requests.get(url,proxies=proxies).json()
res = requests.get(url).json()#必须考虑代理问题,可能需要改成设置,暂时搁置
for cres in res:
if cres["year"] == dyear and cres["month"] == dmonth:
battle_title = cres["title"]
boss_icon_list = []
boss_phase = cres["phases"][0]["bosses"]
print(boss_phase)
for bp in boss_phase:
boss_icon_list.append(bp["unitId"])
base = 'https://redive.estertion.win/icon/unit/'
save_dir = current_folder
print(boss_icon_list)
for i in boss_icon_list:
#res = requests.get(base+str(i)+'.webp',proxies=proxies)
res = requests.get(base+str(i)+'.webp')
with open(current_folder + f'/{i}.png', 'wb') as img:
img.write(res.content)
img.close()
@sv.on_prefix('会战预约') #会战预约5
async def preload(bot , ev):
global pre_push,sw
if sw == 0:
await bot.send(ev,'未开启会战推送')
return
num = ev.message.extract_plain_text().strip()
try:
if int(num) not in [1,2,3,4,5]:
await bot.send(ev,'点炒饭是吧,爬!')
return
else:
num = int(num)
qid = str(ev.user_id) + '|' + str(ev.group_id)
pus = pre_push[num-1]
warn = ''
clan_info = await client.callapi('/clan/info', {'clan_id': 0, 'get_user_equip': 0})
clan_id = clan_info['clan']['detail']['clan_id']
if pus != []:
warn = f'注意:多于1人同时预约了{num}王,请注意出刀情况!'
if qid not in pus:
pus.append(qid)
await bot.send(ev,f'预约{num}王成功!\n{warn}',at_sender=True)
if sw == 1:
pp1 = ev.user_id
name = ''
try:
info = await bot.get_group_member_info(group_id=ev.group_id, user_id=pp1)
name = info['card'] or pp1
except CQHttpError as e:
print('error name')
pass
await verify()
chat_content = f'一位行会成员({name})预约了{num}王,请注意出(撞)刀情况。{warn}'
await client.callapi('/clan/chat', {'clan_id': clan_id, 'type': 0, 'message': chat_content})
else:
pus.remove(qid)
await bot.send(ev,f'你取消预约了{num}王!',at_sender=True)
if sw == 1:
chat_content = f'一位行会成员取消预约了{num}王!'
await client.callapi('/clan/chat', {'clan_id': clan_id, 'type': 0, 'message': chat_content})
except:
await bot.send(ev,'点炒饭是吧,爬!')
pass
@sv.on_fullmatch('会战表') #预约列表
async def sw_plist(bot , ev):
num = 0
msg = ''
for p in pre_push:
num += 1
msg += f'{num}王预约列表\n'
for pp in p:
pp = pp.split('|')
# print(pp)
pp1 = int(pp[0])
pp2 = int(pp[1])
try:
info = await bot.get_group_member_info(group_id=pp2, user_id=pp1)
name = info['card'] or pp1
except CQHttpError as e:
print('error name')
pass
msg += f'+{name}\n'
await bot.send(ev,msg)
@sv.on_fullmatch('清空预约表')
async def cle(bot , ev):
global pre_push
u_priv = priv.get_user_priv(ev)
if u_priv < sv.manage_priv and acinfo["only_admin"] == 1:
await bot.send(ev,'权限不足,当前指令仅管理员可用!')
return
pre_push = pre_push = [[],[],[],[],[]]
await bot.send(ev,'已全部清空')
@sv.on_fullmatch('会战帮助')
async def chelp(bot , ev):
# msg = '[查轴[A/B/C/D/E][S/T/TS][1/2/3/4/5][ID]]:查轴,中括号内为选填项,可叠加使用。*S/T/TS分别表示手动/自动/半自动*\n[分刀[A/B/C/D/E][毛分/毛伤][S/T/TS][1/2/3/4/5]]:根据box分刀,中括号内为选填项,可叠加使用。*可选择限定boss,如123代表限定123王*\n[(添加/删除)(角色/作业)黑名单 + 名称或ID]:支持多角色,例如春环环奈,无空格。作业序号:花舞作业的序号,如‘A101’\n[(添加/删除)角色缺失 + 角色名称]:支持多角色,例如春环环奈,无空格\n[查看(作业黑名单/角色缺失/角色黑名单)]\n[清空(作业黑名单/角色缺失/角色黑名单)]\n[切换会战推送]:打开/关闭会战推送\n[会战预约(1/2/3/4/5)]:预约提醒\n[会战表]:查看所有预约\n[编写中...][会战查刀(ID)]:查看出刀详情\n[查档线]:若参数为空,则输出10000名内各档档线;若有多个参数,请使用英文逗号隔开。\n[清空预约表]:(仅SU可用)\n'
msg = '[查档线]:若参数为空,则输出10000名内各档档线;若有多个参数,请使用英文逗号隔开。新增按照关键词查档线。结算期间数据为空\n[初始化会战推送]:会战前一天输入这个,记得清空Output.txt内的内容,不要删除Output.txt\n[切换会战推送]:打开/关闭会战推送\n[会战预约(1/2/3/4/5)]:预约提醒\n[会战表]:查看所有预约\n[清空预约表]:(仅SU可用)\nsl + 关键ID:为玩家打上SL标记'
await bot.send(ev,msg)
def rounded_rectangle(size, radius, color): #ChatGPT帮我写的,我也不会
width, height = size
rectangle = Image.new("RGBA", size, color)
corner = Image.new("RGBA", (radius, radius), (0, 0, 0, 0))
filled_corner = Image.new("RGBA", (radius, radius), (0, 0, 0, 255))
mask = Image.new("L", (radius, radius), 0)
mask_draw = ImageDraw.Draw(mask)
mask_draw.ellipse((0, 0, radius * 2, radius * 2), fill=255)
corner.paste(filled_corner, (0, 0), mask)
rectangle.paste(corner, (0, 0))
rectangle.paste(corner.rotate(90), (0, height - radius))
rectangle.paste(corner.rotate(180), (width - radius, height - radius))
rectangle.paste(corner.rotate(270), (width - radius, 0))
return rectangle
def format_number_with_commas(number): #这个也是他帮我写的
return '{:,}'.format(number)
#@sv.on_fullmatch('输出会战日志') #服务器不同
async def cout(bot , ev):
cfile = current_folder+ '/Output.txt'
now = time.strftime("%Y-%m-%d %H:%M:%S",time.localtime())
name = f'Output - Log {now}'
await bot.upload_group_file(group_id = ev.group_id, file = cfile, name = name)
await bot.send(ev, '上传完成')
@sv.on_rex(r'^切换账号(?: |)([\s\S]*)')
async def status(bot, ev):
match = ev['match']
if not match : return
account = match.group(1)
if account not in clients: return await bot.send(ev, '不存在该账号')
global client
client = clients[account]
await bot.send(ev, '切换成功')
@sv.on_prefix('会战状态') #这个更是重量级
async def status(bot,ev):
global sw,health_list,phase,chat_list
u_priv = priv.get_user_priv(ev)
if u_priv < sv.manage_priv and acinfo["only_admin"] == 1:
await bot.send(ev,'权限不足,当前指令仅管理员可用!')
return
status = ev.message.extract_plain_text().strip()
if sw == 0 and status != '1':
await bot.send(ev,'现在会战推送状态为关闭,请确认是否有人上号,如果仍然需要查看状态,请输入 会战状态1 来确认')
return
#try:
if acinfo["statu_text_mode"] == 1:
msg = ''
load_index = await client.callapi('/load/index', {'carrier': 'OPPO'})
clan_info = await client.callapi('/clan/info', {'clan_id': 0, 'get_user_equip': 0})
clan_id = clan_info['clan']['detail']['clan_id']
item_list = {}
for item in load_index["item_list"]:
item_list[item["id"]] = item["stock"]
coin = item_list[90006]
res = await client.callapi('/clan_battle/top', {'clan_id': clan_id, 'is_first': 1, 'current_clan_battle_coin': coin})
clan_battle_id = res['clan_battle_id']
clan_name = res['user_clan']['clan_name']
rank = res['period_rank']
lap = res['lap_num']
msg += f'{clan_name}[{rank}名]--{lap}周目\n※实战人数指90秒内人数\n'
for boss in res['boss_info']:
boss_num = boss['order_num']
boss_id = boss['enemy_id']
boss_lap_num = boss['lap_num']
mhp = boss['max_hp']
hp = boss['current_hp']
hp_percentage = int((hp / mhp)*100) # 计算血量百分比
boss_info2 = await client.callapi('/clan_battle/boss_info', {'clan_id': clan_id, 'clan_battle_id': clan_battle_id, 'lap_num': boss_lap_num, 'order_num': boss_num})
fnum = boss_info2['fighter_num']
msg += f'{boss_lap_num}周目{boss_num}王 剩余{hp}血({hp_percentage}%)|{fnum}人实战\n'
await bot.send(ev,msg)
else:
await bot.send(ev,'生成中...')
##第一部分:验证
img = Image.open(img_file+'/hz/bg.png') #背景图片
draw = ImageDraw.Draw(img)
await verify()
load_index = await client.callapi('/load/index', {'carrier': 'OPPO'})
clan_info = await client.callapi('/clan/info', {'clan_id': 0, 'get_user_equip': 0})
'''with open(os.path.join(os.path.dirname(__file__),f"load_index.json"), "w", encoding='utf-8') as f:
f.write(json.dumps(load_index, indent=4,ensure_ascii=False))''' #保存json,用于测试,轮询太久了
'''with open(os.path.join(os.path.dirname(__file__),f"load_index.json"), "r", encoding='utf-8') as f:
load_index=json.load(f)''' #仅用于读取json测试
try:
clan_id = clan_info['clan']['detail']['clan_id'] #报错 KeyError: 'clan'
except:
return await bot.send(ev, "报错了,请重试")
item_list = {}
try:
for item in load_index["item_list"]: #报错 KeyError: 'item_list'
item_list[item["id"]] = item["stock"]
except:
return await bot.send(ev, "报错了,请重试")
coin = item_list[90006]
res = await client.callapi('/clan_battle/top', {'clan_id': clan_id, 'is_first': 1, 'current_clan_battle_coin': coin})
clan_battle_id = res['clan_battle_id']
clan_name = res['user_clan']['clan_name']
setFont = ImageFont.truetype(img_file+'//084.ttf', 45)
draw.text((5,1582), f'{clan_name}', font=setFont, fill="#367cf7")
rank = res['period_rank']
setFont = ImageFont.truetype(img_file+'//084.ttf', 85)
draw.text((10,1786), f'{rank}', font=setFont, fill="#367cf7")
###第一部分:如果当前boss有人出刀,将boss血条变色
try:
shape_image = Image.open(img_file+'/hz/h01.png') #导入遮罩
original_image = Image.open(img_file+"/hz/1.png")
result_image = Image.new("RGBA", original_image.size, (0, 0, 0, 0))
for num in range(0,5):
boss_info2 = await client.callapi('/clan_battle/boss_info', {'clan_id': clan_id, 'clan_battle_id': clan_battle_id, 'lap_num': boss_status[num], 'order_num': num+1})
fnum = boss_info2['fighter_num']
circlelist = [59,365,671,977,1283]
if fnum!=0:
result_image.paste(shape_image, (324,circlelist[num]), mask=shape_image)
result_image.paste(original_image, (0, 0), mask=result_image)
except:
pass
img.paste(result_image, (0, 0), mask=result_image)
###第二部分:计算血量百分比,改变boss血量进度条
lap = res['lap_num']
img_num = 0
for boss in res['boss_info']:
boss_num = boss['order_num']
boss_id = boss['enemy_id']
boss_lap_num = boss['lap_num']
mhp = boss['max_hp']
hp = boss['current_hp']
hp_percentage = hp / mhp # 计算血量百分比
img=drawjingdutiao(hp_percentage,img,boss_num)# 根据血量百分比设置血条颜色
draw = ImageDraw.Draw(img)
### 第三部分:输出boss头像
try:
try:
img2 = Image.open(current_folder+f'/{boss_icon_list[img_num]}.png')
except:
img2 = R.img(f'priconne/unit/icon_unit_100131.png').open()
img_num += 1
fanglist =[49,350,656,962,1268] #boss图片的位置
shape2_image = Image.open(img_file+'/hz/h02.png') #导入遮罩
m2 = Image.new('RGBA', shape2_image.size)
img3=img2.resize(shape2_image.size,Image.LANCZOS) #boss图片改大小
m2.paste(img3, mask=shape2_image)
img.paste(m2, (17, fanglist[boss_num-1]),mask=m2)
except Exception as e:
print(e)
pass
###第四部分输出血量,输出周目,输出abcde阶段
for st in side:
if boss_lap_num >= st:
cur_stage = st
cur_stage = side[cur_stage]
boss_lap_num_list =[84, 390, 696, 1002, 1308]
bosshplist = [69, 375, 681, 987, 1293]
setFont = ImageFont.truetype(img_file+'//027.ttf', 68)
list =[49,350,656,962,1268]
draw.text((510, bosshplist[boss_num-1]), f'{format_number_with_commas(hp)}/{format_number_with_commas(mhp)}', font=setFont, fill="#4662ec")
setFont = ImageFont.truetype(img_file+'//MiSans-Demibold.ttf', 125)
draw.text((319, boss_lap_num_list[boss_num-1]), f'{boss_lap_num}', font=setFont, fill="#229d9c")
setFont = ImageFont.truetype(img_file+'//MiSans-Demibold.ttf', 40)
draw.text((290, boss_lap_num_list[boss_num-1]+170), f'{cur_stage}', font=setFont, fill="#ffffff")
###第五部分:输出当前预约情况
pre = pre_push[boss_num-1]
all_name = ''
if pre != []:
for pu in pre:
pu = pu.split('|')
uid = int(pu[0])
gid = int(pu[1])
pp1 = uid
name = ''
try:
info = await bot.get_stranger_info(self_id=ev.self_id, user_id=pp1)
name = info['nickname'] or pp1
name = util.filt_message(name)
all_name += f'{name} '
except CQHttpError as e:
print('error name')
pass
yuyuelist=[139, 455, 761, 1067, 1373]
setFont = ImageFont.truetype(img_file+'//027.ttf', 50)
if all_name != '':
all_name+='已预约'
all_name=line_break(all_name)
draw.text((515, yuyuelist[boss_num-1]), f'{all_name}', font=setFont, fill="#030852")
else:
draw.text((515, yuyuelist[boss_num-1]), f'无人预约', font=setFont, fill="#030852")
###第六部分:输出公会头像,出刀情况(这部分没动过)
res2 = await client.callapi('/clan/info', {'clan_id': 0, 'get_user_equip': 1})
row = 0
width = 0
setFont = ImageFont.truetype(img_file+'//084.ttf', 85)
last_rank = res2['last_total_ranking']
draw.text((210, 1786), f'{last_rank}', font=setFont, fill="#367cf7")
all_battle_count = 0
for members in res2['clan']['members']:
vid = members['viewer_id']
name = members['name']
favor = members['favorite_unit']
favorid = str(favor['id'])[:-2]
stars = 3 if members['favorite_unit']['unit_rarity'] != 6 else 6
try:
img2 = R.img(f'priconne/unit/icon_unit_{favorid}{stars}1.png').open()
img2 = img2.resize((48,48),Image.ANTIALIAS)
img.paste(img2, (435+int(149.5*width), 1630+int(59.8*row)), img2)
except:
pass
kill_sign = 0
kill_acc = 0
todayt = time.localtime()
hourh = todayt[3]
today = 0
if hourh < 5:
today = todayt[2]-1
else:
today = todayt[2]
#today = 26
#实用性存疑,不如改成输出第几天,暂时不管
setFont = ImageFont.truetype(img_file+'//pcrcnfont.ttf', 15)
#draw.text((1000,760), f'{today}日', font=setFont, fill="#A020F0")
img3 = Image.new('RGB', (25, 17), "white")
img4 = Image.new('RGB', (12, 17), "red")
#img5 = Image.new('RGB', (25, 17), "green")
time_sign = 0
half_sign = 0
sl_sign = 0
for line in open(current_folder + "/Output.txt",encoding='utf-8'):
if line != '':
line = line.split(',')
# print(line[0])
if line[0] == 'SL':
mode = 1
re_vid = int(line[2])
day = int(line[3])
hour = int(line[4])
else:
mode = 2
day = int(line[0])
hour = int(line[1])
re_battle_id = int(line[4])
re_name = line[5]
re_vid = line[6]
re_lap = int(line[7])
re_boss = int(line[8])
re_dmg = int(line[9])
re_kill = int(line[10])
re_boss_id = int(line[11])
re_clan_battle_id = int(line[12])
re_is_auto = int(line[13])
re_start_time = int(line[14])
re_battle_time = int(line[15])
if_today = False
if ((day == today and hour >= 5) or (day == today + 1 and hour < 5)) and (re_clan_battle_id == clan_battle_id) and mode == 2:
if_today = True
if ((day == today and hour >= 5) or (day == today + 1 and hour < 5)) and mode == 1:
if_today = True
if if_today == True and mode == 1 and int(vid) == int(re_vid):
sl_sign = 1
if int(vid) == int(re_vid) and if_today == True and mode == 2:
full_check = 0
if re_start_time == 90 and re_kill == 1:
if time_sign >= 1:
time_sign -= 1
half_sign -= 0.5
kill_acc += 0.5
continue
if re_battle_time <= 20 and re_battle_time != 0:
time_sign += 1
dmgcheck = 0
for check in open(current_folder + "/Output.txt",encoding='utf-8'):
if check != '':
check = check.split(',')
if check[0] != 'SL' and (check[7] == re_lap and check[8] == re_boss):
dmgcheck += check[9]
for st in phase:
if re_lap >= st:
phases = st
phases = phase[phases]
if dmgcheck > health_list[phases-1][re_boss-1]: #总伤害大于BOSS血量,判定为满补
full_check += 1
kill_acc += 0.5
half_sign += 0.5
elif re_start_time == 90 and re_kill == 0:
if time_sign >= 1:
kill_acc += 0.5
time_sign -= 1
half_sign -= 0.5
continue
kill_acc += 1
else:
kill_acc += 0.5
half_sign -= 0.5
# if full_check != 0:
# kill_acc -= 0.5*full_check
if kill_acc > 3: #对满补刀无从下手,先限定三刀补一下
kill_acc = 3
half_sogn = 0
all_battle_count += kill_acc
if kill_acc == 0:
draw.text((483+149*width, 1630+60*row), f'{name}', font=setFont, fill="#FF0000")
elif 0< kill_acc < 3:
draw.text((483+149*width, 1630+60*row), f'{name}', font=setFont, fill="#FF00FF")
elif kill_acc == 3:
draw.text((483+149*width, 1630+60*row), f'{name}', font=setFont, fill="#FFFF00")
width2 = 0
kill_acc = kill_acc - half_sign
while kill_acc-1 >=0:
img.paste(img3, (480+int(149.5*width)+30*width2, 1654+60*row))
kill_acc -= 1
width2 += 1
while half_sign-0.5 >=0:
img.paste(img4, (480+int(149.5*width)+30*width2, 1654+60*row))
half_sign -= 0.5
width2 += 1
if sl_sign == 1:
draw.text((433+int(149.5*width), 1654+60*row), f'SL', font=setFont, fill="black")
width += 1
if width == 5:
width = 0
row += 1
###第七部分:输出今日已出xx刀/90刀
count_m = len(res2['clan']['members'])*3
setFont = ImageFont.truetype(img_file+'//084.ttf', 45)
draw.text((20,2000), f'{all_battle_count}刀/{count_m}刀', font=setFont, fill="#367cf7")
###第八部分:输出最近出刀战绩(这部分没动过)
if res != 0:
info = res['boss_info'] #BOSS
next_lap_1 = res['lap_num'] #周目
next_boss = 1
msg = ''
history = res['damage_history']
order = 0
for hst in history:
order += 1
if order < 21:
name = hst['name']
vid = hst['viewer_id']
kill = hst['kill']
damage = hst['damage']
lap = hst['lap_num']
boss = int(hst['order_num'])
ctime = hst['create_time']
real_time = time.localtime(ctime)
day = real_time[2]
hour = real_time[3]
minu = real_time[4]
seconds = real_time[5]
arrow = hst['history_id']
#real_time = time.strftime('%d - %H:%M:%S', time.localtime(ctime))
enemy_id = hst['enemy_id']
if boss == 5: