-
Notifications
You must be signed in to change notification settings - Fork 87
/
main_def.py
2392 lines (1925 loc) · 98.3 KB
/
main_def.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 __future__ import annotations
import datetime
import json
import os
import platform
import random
import shutil
import subprocess
import sys
import threading
import time
from multiprocessing import cpu_count, freeze_support
from typing import Callable
import requests
from alist import download_from_alist
from config import AccountConfig, CommonConfig, Config, config, load_config
from config_cloud import config_cloud, try_update_config_cloud
from const import downloads_dir
from dao import BuyInfo, BuyRecord
from db import DnfHelperChronicleUserActivityTopInfoDB, UserBuyInfoDB
from djc_helper import DjcHelper, get_prize_names, notify_same_account_try_login_at_multiple_threads, run_act
from exceptions_def import ArkLotteryTargetQQSendByRequestReachMaxCount, SameAccountTryLoginAtMultipleThreadsException
from first_run import is_daily_first_run, is_first_run, is_monthly_first_run, is_weekly_first_run
from log import asciiReset, color, logger
from notice import NoticeManager
from pool import get_pool, get_pool_size, init_pool
from qq_login import QQLogin
from server import get_pay_server_addr
from show_usage import (
global_usage_counter_name,
my_active_monthly_pay_usage_counter_name,
my_auto_updater_usage_counter_name,
my_usage_counter_name,
this_version_global_usage_counter_name,
this_version_my_usage_counter_name,
)
from update import check_update_on_start, get_update_info
from upload_lanzouyun import Uploader
from urls import Urls, get_not_ams_act_desc
from usage_count import get_count, increase_counter
from util import (
MB_ICONINFORMATION,
MiB,
append_if_not_in,
async_call,
async_message_box,
auto_updater_latest_path,
auto_updater_path,
bypass_proxy,
cache_name_user_buy_info,
change_title,
clean_dir_to_size,
clear_login_status,
exists_auto_updater_dlc,
exists_auto_updater_dlc_and_not_empty,
exists_flag_file,
format_now,
format_time,
get_act_name_and_next_expect_time_list,
get_appdata_dir,
get_next_regular_activity_desc,
get_next_regular_activity_name_and_expected_datetime,
get_now,
get_time_since_last_update,
is_run_in_github_action,
is_windows,
make_sure_dir_exists,
md5_file,
message_box,
open_with_default_app,
padLeftRight,
parse_time,
parse_timestamp,
pause,
pause_and_exit,
printed_width,
range_from_one,
remove_none_from_list,
run_from_src,
show_act_not_enable_warning,
show_head_line,
show_quick_edit_mode_tip,
sync_configs,
tableify,
time_less,
try_except,
uin2qq,
use_by_myself,
wait_a_while,
with_cache,
)
from version import author, now_version, ver_time
if is_windows():
import win32api
import win32con
def has_any_account_in_normal_run(cfg: Config):
for _idx, account_config in enumerate(cfg.account_configs):
if not account_config.is_enabled():
# 未启用的账户的账户不走该流程
continue
return True
return False
def _show_head_line(msg):
show_head_line(msg, color("fg_bold_yellow"))
def check_djc_role_binding():
load_config("config.toml", "config.toml.local")
cfg = config()
if not has_any_account_in_normal_run(cfg):
logger.warning("未发现任何有效的账户配置,请检查配置文件")
pause_and_exit(-1)
_show_head_line("启动时检查各账号是否在道聚城绑定了dnf账号和任意手游账号")
while True:
all_binded = True
not_binded_accounts = []
for _idx, account_config in enumerate(cfg.account_configs):
idx = _idx + 1
if not account_config.is_enabled():
# 未启用的账户的账户不走该流程
continue
logger.warning(color("fg_bold_yellow") + f"------------检查第{idx}个账户({account_config.name}------------")
# 如果配置为无法绑定道聚城,则提示将无法领取任何奖励
if account_config.cannot_bind_dnf_v2:
async_message_box(
(
f"账号 {account_config.name} 目前配置为 【无法在道聚城绑定dnf】,将产生下列后果:\n"
"1. 将跳过检查dnf角色绑定流程,在未绑定道聚城的情况下可以继续使用\n"
"2. 如果真的没用在道聚城中绑定dnf的角色,将导致后续流程中无法获取角色绑定信息,因此将无法完成自动绑定活动角色以及领取奖励\n"
"\n"
"这个开关主要用于小号,被风控不能注册dnf账号,但是不影响用来当抽卡等活动的工具人\n"
"请确定你打开这个开关的目的是这样,如果仅仅是不想领取道聚城的奖励,其他奖励想正常使用,请勿打开本开关,请单独修改【道聚城兑换】相关的配置\n"
),
f"禁用道聚城绑定后果提示_{account_config.name}",
show_once=True,
color_name="yellow",
)
djcHelper = DjcHelper(account_config, cfg.common)
if not djcHelper.check_djc_role_binding():
all_binded = False
not_binded_accounts.append((account_config.name, account_config.qq()))
if all_binded:
break
else:
_show_head_line("0. 以上是问题描述")
_show_head_line("1. 解决方案")
logger.warning(
color("bold_cyan")
+ "请前往道聚城(未安装的话,手机上应用商城搜索 道聚城 下载安装就行)将上述提示的未绑定【dnf】或【任意手游】的账号进行绑定(就是去道聚城对应游戏页面把领奖角色给选好)"
)
logger.info(color("bold_cyan") + "相关账号如下:")
heads, colSizes = zip(
("序号", 4),
("账号名", 12),
("QQ", 10),
)
logger.info(color("bold_cyan") + tableify(heads, colSizes))
for idx, info in enumerate(not_binded_accounts):
name, qq = info
row = [idx + 1, name, qq]
logger.info(color("bold_cyan") + tableify(row, colSizes))
_show_head_line("2. 详细教程")
logger.warning(
color("bold_cyan")
+ (
"具体操作流程可以参考一下教程信息:\n"
"1. 使用教程/使用文档.docx 【设置领奖角色】章节和【设置道聚城手游角色】章节\n"
"2. 使用教程/道聚城自动化助手使用视频教程 中 DNF蚊子腿小助手4.1.1版本简要&完整视频教程 中 3:17 位置 关于绑定的介绍\n"
)
)
_show_head_line("3. 跳过方式")
logger.warning(
color("bold_yellow")
+ (
"如果本账号不需要道聚城相关操作,请按下列步骤操作\n"
"1. 可以打开配置工具,点开对应账号的tab\n"
"2. 将该账号的【道聚城配置】中的【无法在道聚城绑定dnf】勾选上\n"
"3. 并将【完成礼包达人任务的手游名称】选择为最上方的【无】\n"
"4. 保存配置\n"
"5. 回到这个页面按任意键继续\n"
"\n"
"PS:\n"
"勾选【无法在道聚城绑定dnf】后将无法领取任何奖励,主要用于小号,被风控不能注册dnf账号,但是不影响用来当抽卡等活动的工具人\n"
"勾选【完成礼包达人任务的手游名称】后道聚城的每日手游活动将不会完成,活跃度会低于领取金宝箱所需\n"
"\n"
"由于现在道聚城没有什么可以兑换的,以前每天兑换的10个调整箱也已经挪到助手app的编年史中了,如果没有玩任何手游的话,可以放心地将手游名称设置为 无\n"
)
)
_show_head_line("4. 请完成上述操作,然后按任意键再次进行检查")
logger.warning(
color("bold_red")
+ "如果你真的无法看懂上面到底在说什么,请加群私聊我支付宝账号进行退款,然后手动领取吧-。-"
)
logger.warning(
color("bold_yellow")
+ "如果你真的无法看懂上面到底在说什么,请加群私聊我支付宝账号进行退款,然后手动领取吧-。-"
)
logger.warning(
color("bold_blue")
+ "如果你真的无法看懂上面到底在说什么,请加群私聊我支付宝账号进行退款,然后手动领取吧-。-"
)
_show_head_line("5. 异常状态")
logger.warning(
color("bold_yellow")
+ "如果之前曾设置过,但最近突然开始一直弹这个,而且去道聚城app里看确实已经绑定。那么大概率是道聚城修改了接口,这种情况下,请在qq群私聊我的小号告知我,我会尽快尝试修复~"
)
logger.warning(
color("bold_cyan")
+ "也可以尝试通过 配置工具/账号配置/角色绑定 来本地配置领奖角色,避免因为道聚城的改动而影响领奖"
)
logger.info("\n\n")
pause()
# 这时候重新读取一遍用户修改过后的配置文件(比如把手游设为了 无 )
load_config("config.toml", "config.toml.local")
cfg = config()
def check_all_skey_and_pskey(cfg: Config, check_skey_only=False):
if not has_any_account_in_normal_run(cfg):
return
_show_head_line("启动时检查各账号skey/pskey/openid是否过期")
QQLogin(cfg.common).check_and_download_chrome_ahead()
if (
cfg.common.enable_multiprocessing
and cfg.common.enable_multiprocessing_login
and cfg.is_all_account_auto_login()
):
# 并行登陆
logger.info(
color("bold_yellow")
+ f"已开启多进程模式({get_pool_size()}),并检测到所有账号均使用自动登录模式,将开启并行登录模式"
)
get_pool().starmap(
do_check_all_skey_and_pskey,
[
(_idx + 1, _idx + 1, account_config, cfg.common, check_skey_only)
for _idx, account_config in enumerate(cfg.account_configs)
if account_config.is_enabled()
],
)
logger.info(color("bold_green") + "并行登陆完毕,串行加载缓存的登录信息到cfg变量中")
check_all_skey_and_pskey_silently_sync(cfg)
else:
# 串行登录
qq2index: dict[str, int] = {}
for _idx, account_config in enumerate(cfg.account_configs):
idx = _idx + 1
djcHelper = do_check_all_skey_and_pskey(idx, 1, account_config, cfg.common, check_skey_only)
if djcHelper is None:
continue
qq = uin2qq(djcHelper.cfg.account_info.uin)
if qq in qq2index:
if not cfg.common.disable_clear_login_status_when_duplicate_login:
msg = (
f"第{idx}个账号的实际登录QQ {qq} 与第{qq2index[qq]}个账号的qq重复,是否重复扫描了?\n"
"\n"
"点击确认后,程序将清除本地登录记录,并退出运行。请重新运行并按顺序登录正确的账号~\n"
"\n"
"若不想启用该功能,请在 配置工具/公共配置/其他 中找到禁用重复登录时清空状态的选项,勾选上即可\n"
)
message_box(msg, "重复登录", color_name="fg_bold_red")
clear_login_status()
sys.exit(-1)
else:
msg = (
f"第{idx}个账号的实际登录QQ {qq} 与第{qq2index[qq]}个账号的qq重复,是否重复扫描了?\n"
"\n"
"由于当前禁用了重复登录时清空状态的功能,将不会清除登录状态,仅提示告知\n"
"若需单独手动去清除重复登录的账号,请在.cached目录中找到重复账号对应的两个文件,形如 .saved_pskey.你的账号名字.json .saved_skey.你的账号名字.json ,将其删除后再运行即可\n"
"\n"
"若想启用该功能,请在 配置工具/公共配置/其他 中找到禁用重复登录时清空状态的选项,取消勾选即可\n"
)
async_message_box(
msg,
"账号登录串号提醒",
)
qq2index[qq] = idx
logger.info("全部账号检查完毕")
def do_check_all_skey_and_pskey(
idx: int, window_index: int, account_config: AccountConfig, common_config: CommonConfig, check_skey_only: bool
) -> DjcHelper | None:
while True:
try:
wait_a_while(idx)
logger.warning(
color("fg_bold_yellow") + f"------------检查第{idx}个账户({account_config.name})------------"
)
return _do_check_all_skey_and_pskey(window_index, account_config, common_config, check_skey_only)
except SameAccountTryLoginAtMultipleThreadsException:
notify_same_account_try_login_at_multiple_threads(account_config.name)
def check_all_skey_and_pskey_silently_sync(cfg: Config):
for account_config in cfg.account_configs:
_do_check_all_skey_and_pskey(1, account_config, cfg.common, False)
def _do_check_all_skey_and_pskey(
window_index: int, account_config: AccountConfig, common_config: CommonConfig, check_skey_only: bool
) -> DjcHelper | None:
if not account_config.is_enabled():
# 未启用的账户的账户不走该流程
return None
djcHelper = DjcHelper(account_config, common_config)
djcHelper.fetch_pskey(window_index=window_index)
djcHelper.check_skey_expired(window_index=window_index)
if not check_skey_only:
djcHelper.get_bind_role_list(print_warning=False)
# djcHelper.fetch_guanjia_openid(print_warning=False)
return djcHelper
@try_except()
def auto_send_cards(cfg: Config):
if not has_any_account_in_normal_run(cfg):
return
_show_head_line("运行完毕自动赠送卡片")
target_qqs = cfg.common.auto_send_card_target_qqs
if len(target_qqs) == 0:
logger.warning("未定义自动赠送卡片的对象QQ数组,将跳过本阶段")
return
# 统计各账号卡片数目
logger.info("拉取各账号的卡片数据中,请耐心等待...")
account_data = []
if cfg.common.enable_multiprocessing:
logger.info(f"已开启多进程模式({get_pool_size()}),将并行拉取数据~")
for data in get_pool().starmap(
query_account_ark_lottery_info,
[
(_idx + 1, len(cfg.account_configs), account_config, cfg.common)
for _idx, account_config in enumerate(cfg.account_configs)
if account_config.is_enabled()
],
):
account_data.append(data)
else:
for _idx, account_config in enumerate(cfg.account_configs):
idx = _idx + 1
if not account_config.is_enabled():
# 未启用的账户的账户不走该流程
continue
account_data.append(
query_account_ark_lottery_info(idx, len(cfg.account_configs), account_config, cfg.common)
)
account_data = remove_none_from_list(account_data)
qq_to_card_name_to_counts = {}
qq_to_prize_counts = {}
qq_to_djcHelper = {}
for card_name_to_counts, prize_counts, djcHelper in account_data:
qq = uin2qq(djcHelper.cfg.account_info.uin)
qq_to_card_name_to_counts[qq] = card_name_to_counts
qq_to_prize_counts[qq] = prize_counts
qq_to_djcHelper[qq] = djcHelper
# 赠送卡片
for idx, target_qq in enumerate(target_qqs):
if target_qq in qq_to_djcHelper:
# 新版本里似乎没有查询接口,先随便写一个固定值
left_times = 4 * len(cfg.account_configs)
extra_message = "(这个数字是4*账号数,新版集卡查询不到实际数值)"
name = qq_to_djcHelper[target_qq].cfg.name
logger.warning(
color("fg_bold_green")
+ f"第{idx + 1}/{len(target_qqs)}个赠送目标账号 {name}({target_qq}) 今日仍可被赠送 {left_times} 次卡片{extra_message}"
)
# 最多赠送目标账号今日仍可接收的卡片数
try:
for send_idx in range_from_one(left_times):
logger.info(
color("bold_yellow") + f"尝试第 [{send_idx}/{left_times}] 次赠送卡片给 {name}({target_qq})"
)
other_account_has_card = send_card(
target_qq, qq_to_card_name_to_counts, qq_to_prize_counts, qq_to_djcHelper, target_qqs
)
if not other_account_has_card:
logger.warning(f"第 {send_idx} 次赠送时其他账号已经没有任何卡片,跳过后续尝试")
break
except ArkLotteryTargetQQSendByRequestReachMaxCount as e:
logger.warning(
color("bold_yellow")
+ f"{name}({target_qq}) 今日被赠送和通过索取来赠送均已达上限,将跳过尝试后续赠送尝试。具体结果为:{e}"
)
# 赠送卡片完毕后尝试领取奖励和抽奖
djcHelper = qq_to_djcHelper[target_qq]
lr = djcHelper.fetch_pskey()
if lr is not None:
logger.info("赠送完毕,尝试领取奖励和抽奖")
# if is_new_version_ark_lottery():
# try_copy_cards(djcHelper)
djcHelper.dnf_ark_lottery_take_ark_lottery_awards()
djcHelper.dnf_ark_lottery_try_lottery_using_cards()
def try_copy_cards(djcHelper: DjcHelper):
if not use_by_myself():
return
# 目前似乎可以赠送给自己,先自己测试几天
logger.warning(color("bold_yellow") + "仅本号测试:尝试额外赠送给自己(复制卡片)")
card_name_to_counts = djcHelper.dnf_ark_lottery_get_card_counts()
logger.warning(color("bold_green") + f"尝试额外赠送给自己(复制卡片),最新卡片信息为:{card_name_to_counts}")
# 尝试复制四次
for _copy_idx in range_from_one(4):
# 当前账号的卡牌按照卡牌数升序排列,取出其中为正数的部分来尝试进行复制卡片(赠送给自己)
owned_card_infos = get_owned_card_infos_sort_by_count(card_name_to_counts)
if len(owned_card_infos) == 0:
# 没有任何卡片,不尝试复制
break
# 复制拥有的卡片中最少的那张
least_card_info = owned_card_infos[0]
card_name, card_count = least_card_info
send_ok = djcHelper.dnf_ark_lottery_send_card(card_name, djcHelper.qq())
name = djcHelper.cfg.name
index = new_ark_lottery_parse_index_from_card_id(card_name)
logger.warning(color("thin_cyan") + f"账号 {name} 尝试复制一张 {index}({card_name}),结果为 {send_ok}")
card_name_to_counts[card_name] += 1
def get_owned_card_infos_sort_by_count(card_name_to_counts: dict[str, int]) -> list[tuple[str, int]]:
owned_card_infos = []
for card_name, card_count in card_name_to_counts.items():
if card_count == 0:
continue
owned_card_infos.append((card_name, card_count))
owned_card_infos.sort(key=lambda card: card[1])
return owned_card_infos
def query_account_ark_lottery_info(
idx: int, total_account: int, account_config: AccountConfig, common_config: CommonConfig
) -> tuple[dict[str, int], dict[str, int], DjcHelper] | None:
djcHelper = DjcHelper(account_config, common_config)
lr = djcHelper.fetch_pskey()
if lr is None:
return None
djcHelper.check_skey_expired()
djcHelper.get_bind_role_list(print_warning=False)
card_name_to_counts = djcHelper.dnf_ark_lottery_get_card_counts()
prize_counts = djcHelper.dnf_ark_lottery_get_prize_counts()
logger.info(f"{idx:2d}/{total_account} 账号 {padLeftRight(account_config.name, 12)} 的数据拉取完毕")
return card_name_to_counts, prize_counts, djcHelper
def send_card(
target_qq: str,
qq_to_card_name_to_counts: dict[str, dict[str, int]],
qq_to_prize_counts: dict[str, dict[str, int]],
qq_to_djcHelper: dict[str, DjcHelper],
target_qqs: list[str],
) -> bool:
"""
返回 是否有其他账号有可以赠送的卡片
"""
# 检查目标账号是否有可剩余的兑换奖励次数
has_any_left_gift = False
for _name, count in qq_to_prize_counts[target_qq].items():
if count > 0:
has_any_left_gift = True
break
target_card_infos = []
if has_any_left_gift:
logger.debug("仍有可兑换奖励,将赠送目标QQ最需要的卡片")
# 当前账号的卡牌按照卡牌数升序排列
for card_name, card_count in qq_to_card_name_to_counts[target_qq].items():
target_card_infos.append((card_name, card_count))
target_card_infos.sort(key=lambda card: card[1])
else:
logger.debug("所有奖励都已兑换,将赠送目标QQ其他QQ最富余的卡片")
# 统计其余账号的各卡牌总数
merged_card_name_to_count: dict[str, int] = {}
for _qq, card_name_to_count in qq_to_card_name_to_counts.items():
for card_name, card_count in card_name_to_count.items():
merged_card_name_to_count[card_name] = merged_card_name_to_count.get(card_name, 0) + card_count
# 降序排列
for card_name, card_count in merged_card_name_to_count.items():
target_card_infos.append((card_name, card_count))
target_card_infos.sort(key=lambda card: -card[1])
# 升序遍历
for card_name, _card_count in target_card_infos:
# 找到任意一个拥有卡片的其他账号,让他送给目标账户。默认越靠前的号越重要,因此从后面的号开始查
for qq, card_name_to_count in reverse_map(qq_to_card_name_to_counts):
if qq in target_qqs:
continue
# 如果某账户有这个卡,则赠送该当前玩家,并结束本回合赠卡
if card_name_to_count[card_name] > 0:
send_ok = qq_to_djcHelper[qq].dnf_ark_lottery_send_card(
card_name, target_qq, target_djc_helper=qq_to_djcHelper[target_qq]
)
index = new_ark_lottery_parse_index_from_card_id(card_name)
card_name_to_count[card_name] -= 1
qq_to_card_name_to_counts[target_qq][card_name] += 1
name = qq_to_djcHelper[qq].cfg.name
target_name = qq_to_djcHelper[target_qq].cfg.name
logger.warning(
color("fg_bold_cyan")
+ f"账号 {name} 赠送一张 {index}({card_name}) 给 {target_name}, 结果为 {send_ok}"
)
return True
return False
def new_ark_lottery_parse_index_from_card_id(card_id_str: str) -> str:
"""
将 卡片id 转换为 坐标,如 7 -> 2-3
"""
card_id = int(card_id_str)
row = (card_id + 3) // 4
col = (card_id - 1) % 4 + 1
index = f"{row}-{col}"
return index
def new_ark_lottery_parse_card_id_from_index(index: str) -> str:
"""
将 坐标 转换为 卡片id,如 2-3 -> 7
"""
row, col = index.split("-")
return str(4 * (int(row) - 1) + int(col))
def reverse_map(map):
kvs = list(map.items())
kvs.reverse()
return kvs
@try_except()
def show_lottery_status(ctx, cfg: Config, need_show_tips=False):
if not has_any_account_in_normal_run(cfg):
return
_show_head_line(ctx)
logger.info(get_not_ams_act_desc("集卡"))
order_map, prizeDisplayTitles = make_ark_lottery_card_and_award_info()
# 定义表格标题栏
heads = []
colSizes = []
baseHeads = ["序号", "账号名"]
baseColSizes = [4, 12]
heads.extend(baseHeads)
colSizes.extend(baseColSizes)
card_indexes = ["1-1", "1-2", "1-3", "1-4", "2-1", "2-2", "2-3", "2-4", "3-1", "3-2", "3-3", "3-4"]
card_width = 3
heads.extend(card_indexes)
colSizes.extend([card_width for i in card_indexes])
prize_indexes = [*prizeDisplayTitles]
heads.extend(prize_indexes)
colSizes.extend([printed_width(name) for name in prize_indexes])
# 获取数据
logger.warning("开始获取数据,请耐心等待~")
rows = []
if cfg.common.enable_multiprocessing:
logger.info(f"已开启多进程模式({get_pool_size()}),将并行拉取数据~")
for row in get_pool().starmap(
query_lottery_status,
[
(_idx + 1, account_config, cfg.common, card_indexes, prize_indexes, order_map)
for _idx, account_config in enumerate(cfg.account_configs)
if account_config.is_enabled()
],
):
rows.append(row)
else:
for _idx, account_config in enumerate(cfg.account_configs):
idx = _idx + 1
if not account_config.is_enabled():
# 未启用的账户的账户不走该流程
continue
rows.append(query_lottery_status(idx, account_config, cfg.common, card_indexes, prize_indexes, order_map))
rows = remove_none_from_list(rows)
# 计算概览
summaryCols = [
1,
"总计",
*[0 for card in card_indexes],
*[count_with_color(0, "bold_green", show_width=printed_width(prize_index)) for prize_index in prize_indexes],
]
for row in rows:
summaryCols[0] += 1
for i in range(2, 2 + 12):
summaryCols[i] += row[i]
for cardIdx in range(len(card_indexes)):
idx = len(baseHeads) + cardIdx
summaryCols[idx] = colored_count(
len(cfg.account_configs), summaryCols[idx], cfg.common.ark_lottery_summary_show_color or "fg_thin_cyan"
)
# 计算可以开启抽奖卡片的账号
accounts_that_should_enable_cost_card_to_lottery = []
for row in rows:
has_any_card = False
has_any_left_gift = False
for i in range(2, 2 + 12):
if row[i] > 0:
has_any_card = True
for i in range(14, 14 + 4):
if row[i] > 0:
has_any_left_gift = True
if has_any_card and not has_any_left_gift:
accounts_that_should_enable_cost_card_to_lottery.append(row[1])
# 给每一行上色
for row in rows:
idx = row[0]
name = row[1]
for i in range(2, 2 + 12):
row[i] = colored_count(idx, row[i], cfg.get_account_config_by_name(name).ark_lottery.show_color)
for i in range(14, 14 + 4):
row[i] = count_with_color(row[i], "bold_green", show_width=printed_width(prize_indexes[i - 14]))
# 打印卡片情况
logger.info(tableify(heads, colSizes))
for row in rows:
logger.info(tableify(row, colSizes))
logger.info(tableify(summaryCols, colSizes))
logger.info("")
logger.info("新版集卡不再可以查询剩余领奖次数,上面右侧四个值没有实际含义,望周知")
# 打印提示
if need_show_tips and len(accounts_that_should_enable_cost_card_to_lottery) > 0:
accounts = ", ".join(accounts_that_should_enable_cost_card_to_lottery)
msg = f"账户({accounts})仍有剩余卡片,但已无任何可领取礼包,建议开启消耗卡片来抽奖的功能"
logger.warning(color("fg_bold_yellow") + msg)
def make_ark_lottery_card_and_award_info():
# 构建各个卡片和奖励名称的映射关系
# card index => name(旧版), id(新版)
order_map = {}
# 奖励名称列表
prizeDisplayTitles = []
for row in range_from_one(3):
for col in range_from_one(4):
index = f"{row}-{col}"
card_id = str(4 * (row - 1) + col)
order_map[index] = card_id
for title in get_prize_names():
order_map[title] = title
prizeDisplayTitles.append(title)
return order_map, prizeDisplayTitles
def query_lottery_status(
idx: int,
account_config: AccountConfig,
common_config: CommonConfig,
card_indexes: list[str],
prize_indexes: list[str],
order_map: dict[str, str],
) -> list | None:
if not account_config.ark_lottery.show_status:
return None
djcHelper = DjcHelper(account_config, common_config)
lr = djcHelper.fetch_pskey()
if lr is None:
return None
djcHelper.check_skey_expired()
djcHelper.get_bind_role_list(print_warning=False)
# 获取卡片和奖励数目,其中新版本卡片为 id=>count ,旧版本卡片为 name=>count
card_counts = djcHelper.dnf_ark_lottery_get_card_counts()
prize_counts = djcHelper.dnf_ark_lottery_get_prize_counts()
# 构建本行数据
cols = [idx, account_config.name]
# 处理各个卡片数目
for _card_position, card_index in enumerate(card_indexes):
card_count = card_counts[order_map[card_index]]
cols.append(card_count)
# 处理各个奖励剩余领取次数
for prize_index in prize_indexes:
prize_count = prize_counts[order_map[prize_index]]
cols.append(prize_count)
return cols
def colored_count(accountIdx, card_count, show_color=""):
# 特殊处理色彩
if card_count == 0:
if accountIdx == 1:
# 突出显示大号没有的卡片
show_count = count_with_color(card_count, "fg_bold_cyan")
else:
# 小号没有的卡片直接不显示,避免信息干扰
show_count = ""
else:
if accountIdx == 1:
if card_count == 1:
# 大号只有一张的卡片也特殊处理
show_count = count_with_color(card_count, "fg_bold_blue")
else:
# 大号其余卡片亮绿色
show_count = count_with_color(card_count, "fg_bold_green")
else:
# 小号拥有的卡片淡化处理,方便辨识
show_color = show_color or "fg_bold_black"
show_count = count_with_color(card_count, show_color)
return show_count
def count_with_color(card_count, show_color, show_width=3):
return color(show_color) + padLeftRight(card_count, show_width) + asciiReset + color("INFO")
@try_except()
def show_extra_infos(cfg: Config):
show_activity_info(cfg)
show_following_regular_activity_expected_info()
show_tips(cfg)
@try_except()
def show_pay_info(cfg):
logger.info("")
_show_head_line("付费相关信息")
user_buy_info = get_user_buy_info(cfg.get_qq_accounts())
show_buy_info(user_buy_info, cfg)
@try_except()
def show_activity_info(cfg: Config):
logger.info("")
_show_head_line("部分活动信息")
logger.warning("如果一直卡在这一步,请在小助手目录下创建一个空文件:不查询活动.txt")
Urls().show_current_valid_act_infos()
user_buy_info = get_user_buy_info(cfg.get_qq_accounts(), show_dlc_info=False)
show_activities_summary(cfg, user_buy_info)
def show_following_regular_activity_expected_info():
logger.info("")
_show_head_line("未来一年常规活动周期的预估信息")
lines = []
heads, colSizes = zip(
("序号", 4),
("常规活动周期", 12),
("预估开始时间", 12),
("距今天数", 12),
)
lines.append(color("bold_green") + tableify(heads, colSizes))
now = get_now()
next_year_act_list = get_act_name_and_next_expect_time_list()
for idx, name_and_time in enumerate(next_year_act_list):
act_name, act_time = name_and_time
act_time_str = format_time(act_time, "%Y-%m-%d")
expected_days = (act_time - now).days
f"{expected_days}天后"
lines.append(
color("bold_yellow")
+ tableify(
[idx + 1, act_name, act_time_str, expected_days],
colSizes,
need_truncate=False,
)
)
logger.info("\n" + "\n".join(lines))
if is_first_run("常规活动周期预估信息"):
async_message_box(
"在运行结束的活动链接与小提示中间新增了一个常规活动周期预估信息,可以查看未来一年内的一些常规活动周期的预估时间点,方便大家知晓大概什么时候会有新活动",
"常规活动周期预估",
)
@try_except()
# show_accounts_status 展示个人概览
def sas(cfg: Config, ctx: str, user_buy_info: BuyInfo):
if not has_any_account_in_normal_run(cfg):
return
_show_head_line(ctx)
# 获取数据
rows = []
if cfg.common.enable_multiprocessing:
logger.warning(f"已开启多进程模式({get_pool_size()}),将开始并行拉取数据,请稍后")
for row in get_pool().starmap(
get_account_status,
[
(_idx + 1, account_config, cfg.common, user_buy_info)
for _idx, account_config in enumerate(cfg.account_configs)
if account_config.is_enabled()
],
):
rows.append(row)
else:
logger.warning("拉取数据中,请稍候")
for _idx, account_config in enumerate(cfg.account_configs):
idx = _idx + 1
if not account_config.is_enabled():
# 未启用的账户的账户不走该流程
continue
rows.append(get_account_status(idx, account_config, cfg.common, user_buy_info))
# 打印结果
heads, colSizes = zip(
("序号", 4),
("账号名", 12),
("聚豆余额", 8),
("心悦类型", 10),
("成就点", 6),
("勇士币", 6),
("心悦组队", 16),
("前两周心悦", 10),
("自动组队", 8),
("编年史", 14),
("年史碎片", 8),
("搭档", 14),
("上月", 4),
("自动匹配", 8),
("论坛代币券", 10),
("漫画星星", 8),
)
logger.info(tableify(heads, colSizes))
for row in rows:
logger.info(color("fg_bold_green") + tableify(row, colSizes, need_truncate=True))
# # 展示本周闪光杯爆装
# DjcHelper(cfg.account_configs[0], cfg.common).dnf_shanguang_show_equipments()
def get_account_status(idx: int, account_config: AccountConfig, common_config: CommonConfig, user_buy_info: BuyInfo):
djcHelper = DjcHelper(account_config, common_config)
djcHelper.check_skey_expired()
djcHelper.get_bind_role_list(print_warning=False)
_, djc_balance = djcHelper.query_balance("查询聚豆概览", print_res=False)
xinyue_info = djcHelper.query_xinyue_info("查询心悦成就点概览", print_res=False)
teaminfo = djcHelper.query_xinyue_teaminfo()
team_award_summary = "无队伍"
if teaminfo.is_team_full():
team_award_summary = djcHelper.query_xinyue_team_this_week_award_summary()
last_two_week_xinyue_take_award_count = djcHelper.query_last_two_week_xinyue_team_take_award_count()
can_auto_match_xinyue_team = ""
if djcHelper.can_auto_match_xinyue_team(user_buy_info, print_waring=False):
if teaminfo.is_team_full():
can_auto_match_xinyue_team = "匹配成功"
else:
can_auto_match_xinyue_team = "等待匹配"
elif xinyue_info.is_xinyue_or_special_member() and not account_config.enable_auto_match_xinyue_team:
can_auto_match_xinyue_team = "未开启"
levelInfo, chronicle_points = djcHelper.query_dnf_helper_chronicle_info().get_level_info_and_points_to_show()
partner_levelInfo = ""
user_task_info = djcHelper.query_dnf_helper_chronicle_user_task_list()
if user_task_info.hasPartner:
partner_levelInfo, _ = djcHelper.query_dnf_helper_chronicle_info(
user_task_info.pUserId
).get_level_info_and_points_to_show()
user_info_db = (
DnfHelperChronicleUserActivityTopInfoDB().with_context(djcHelper.get_dnf_helper_chronicle_db_key()).load()
)
last_month_user_task_info = user_info_db.get_last_month_user_info()
last_month_level = last_month_user_task_info.level
can_auto_match_dnf_helper_chronicle = ""
if djcHelper.check_dnf_helper_chronicle_auto_match(user_buy_info, print_waring=False):
if user_task_info.hasPartner:
can_auto_match_dnf_helper_chronicle = "匹配成功"
else:
can_auto_match_dnf_helper_chronicle = "等待匹配"
elif not account_config.dnf_helper_info.enable_auto_match_dnf_chronicle:
can_auto_match_dnf_helper_chronicle = "未开启"
# majieluo_stone = djcHelper.query_stone_count()
# time.sleep(1) # 避免查询下面的次数时提示 速度过快
# majieluo_invite_count = f"{djcHelper.query_invite_count()}/30"
dbq = djcHelper.query_dnf_bbs_dbq()
comic_start_count = djcHelper.query_dnf_comic_star_count()
return [
idx,
account_config.name,
djc_balance,
xinyue_info.xytype_str,
xinyue_info.score,
xinyue_info.ysb,
team_award_summary,
last_two_week_xinyue_take_award_count,
can_auto_match_xinyue_team,
levelInfo,
chronicle_points,
partner_levelInfo,
last_month_level,
can_auto_match_dnf_helper_chronicle,
# majieluo_stone, majieluo_invite_count,
dbq,
comic_start_count,
]