Skip to content

Commit

Permalink
Merge branch 'cc004:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
666dechaoge authored Jun 14, 2024
2 parents 7837b11 + d17f76b commit ccdcadb
Show file tree
Hide file tree
Showing 10 changed files with 157 additions and 88 deletions.
11 changes: 7 additions & 4 deletions autopcr/bsdk/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ValidateInfo:

async def manualValidator(account, gt, challenge, userid):
id = questutils.create_quest_token()
url = f"/daily/geetest.html?id={id}&captcha_type=1&challenge={challenge}&gt={gt}&userid={userid}&gs=1"
url = f"/daily/validate?id={id}&captcha_type=1&challenge={challenge}&gt={gt}&userid={userid}&gs=1"
validate_dict[account] = ValidateInfo(
id=id,
challenge=challenge,
Expand Down Expand Up @@ -61,7 +61,8 @@ async def autoValidator(account, gt, challenge, userid):
uuid = res["uuid"]
msg = [f"uuid={uuid}"]
ccnt = 0
while ccnt < 10:
up = 5
while ccnt <= up:
ccnt += 1
res = await aiorequests.get(url=f"https://pcrd.tencentbot.top/check/{uuid}", headers=header)
res.raise_for_status()
Expand All @@ -76,6 +77,7 @@ async def autoValidator(account, gt, challenge, userid):
msg = []
print(f'farm: {uuid} in queue, sleep {tim} seconds')
await asyncio.sleep(tim)
if tim >= 30: ccnt += 1
else:
info = res["info"]
if info in ["fail", "url invalid"]:
Expand All @@ -84,8 +86,9 @@ async def autoValidator(account, gt, challenge, userid):
await asyncio.sleep(8)
elif 'validate' in info:
ret = info
if ccnt >= 10:
raise Exception("Captcha failed")
break
else:
raise Exception("Captcha failed")
except:
if not ret: ret = await manualValidator(account, gt, challenge, userid)

Expand Down
2 changes: 1 addition & 1 deletion autopcr/core/sessionmgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ async def _login(self, next: RequestHandler):
req.tips_id_list = []
resp = await next.request(req)

if resp.quest_list and any(1 for quest in resp.quest_list if quest.quest_id == 11003005 and quest.result_type == eMissionStatusType.AlreadyReceive): # clear normal 3-5 and unlock daily task
if resp.quest_list and any(1 for quest in resp.quest_list if quest.quest_id == 11008001 and quest.result_type == eMissionStatusType.AlreadyReceive): # clear normal 8-1 and unlock daily task
req = DailyTaskTopRequest()
req.setting_alchemy_count = 1
req.is_check_by_term_normal_gacha = 0
Expand Down
7 changes: 5 additions & 2 deletions autopcr/module/crons.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@
CRONLOG_PATH = os.path.join(CACHE_DIR, "http_server", "cron_log.txt")

async def _cron(task):
last = datetime.datetime.now() - datetime.timedelta(minutes=1)
while True:
await asyncio.sleep(60)
await asyncio.sleep(30)
cur = datetime.datetime.now()
if cur.minute == last.minute: continue
last = cur
asyncio.get_event_loop().create_task(task(cur))

async def task(qid, account):
Expand All @@ -32,7 +35,7 @@ async def _run_crons(cur):
await cron_log_buffer.put(f"{db.format_time(cur)}: doing cron for {qid} {account}")

async def cron_log():
if not os.path.exists(CRONLOG_PATH):
if not os.path.exists(os.path.dirname(CRONLOG_PATH)):
os.mkdir(os.path.dirname(CRONLOG_PATH))
fp = open(CRONLOG_PATH, "a")
while True:
Expand Down
5 changes: 3 additions & 2 deletions autopcr/module/modulebase.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,9 @@ def get_config(self, key):
value = self._parent.get_config(key, default)
if key in self.config and self.config[key].config_type == "multi":
if not isinstance(value, list):
value = [value]
value = [v for v in value if v in self.config[key].candidates]
value = default
else:
value = [v for v in value if v in self.config[key].candidates]
if key != self.key and self.config[key].candidates and (
not isinstance(value, list) and (
value not in self.config[key].candidates or
Expand Down
91 changes: 64 additions & 27 deletions autopcr/module/modules/autosweep.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,59 @@
from ...model.custom import ItemType
from ...db.models import QuestDatum, ShioriQuest
from typing import List, Dict, Tuple
import typing
from ...model.error import *
from ...db.database import db
from ...model.enums import *
from collections import Counter
import datetime

@conditional_execution("normal_sweep_run_time", ["n庆典"])
@singlechoice("normal_sweep_consider_unit", "需求角色", "favorite", ["all", "max_rank", "max_rank-1", "max_rank-2", 'favorite'])
@description('根据【刷图推荐】结果刷n图')
@singlechoice("normal_sweep_strategy", "刷取策略", "刷最缺", ["刷最缺", "均匀刷"])
@booltype("normal_sweep_equip_ok_to_full", "刷满则考虑所有角色", False)
@singlechoice("normal_sweep_consider_unit", "起始品级", "所有", ["所有", "最高", "次高", "次次高"])
@booltype("normal_sweep_consider_unit_fav", "收藏角色", True)
@description('根据【刷图推荐】结果刷n图,均匀刷指每次刷取的图覆盖所缺的需求装备,若无缺装备则刷取推荐的第一张图')
@name('智能刷n图')
@default(False)
@stamina_relative
class smart_normal_sweep(Module):

async def get_quests(self, quest_list: List[int], strategy: str, gap: typing.Counter[ItemType]) -> List[int]:
ret = []
lack = set(item for item, need in gap.items() if need > 0)
if not lack or strategy == "刷最缺":
ret.append(quest_list[0])
elif strategy == "均匀刷":
uncover = lack
ret = []
for quest in quest_list:
if any(item in uncover for item in db.normal_quest_rewards[quest]):
ret.append(quest)
uncover -= set(db.normal_quest_rewards[quest])
if not uncover:
break
else:
raise ValueError(f"未知策略{strategy}")

if not ret:
self._log("无需刷取的图,这不太可能")
return ret

async def do_task(self, client: pcrclient):

if self.get_config('normal_sweep_consider_unit') == 'favorite':
demand = client.data.get_equip_demand(like_unit_only = True)
else:
opt: Dict[Union[int, str], int] = {
'all': 1,
'max_rank': db.equip_max_rank,
'max_rank-1': db.equip_max_rank - 1,
'max_rank-2': db.equip_max_rank - 2,
}
demand = client.data.get_equip_demand(start_rank = opt[self.get_config('normal_sweep_consider_unit')])
like_unit_only: bool = self.get_config('normal_sweep_consider_unit_fav')
rank: str = self.get_config('normal_sweep_consider_unit')
strategy: str = self.get_config('normal_sweep_strategy')
full2all: bool = self.get_config('normal_sweep_equip_ok_to_full')
opt: Dict[Union[int, str], int] = {
'所有': 1,
'最高': db.equip_max_rank,
'次高': db.equip_max_rank - 1,
'次次高': db.equip_max_rank - 2,
}
demand = client.data.get_equip_demand(like_unit_only=like_unit_only, start_rank = opt[rank])
all_demand = client.data.get_equip_demand()

clean_cnt = Counter()
quest_id = []
Expand All @@ -38,28 +65,36 @@ async def do_task(self, client: pcrclient):
stop: bool = False

try:
target_quest = []
for i in range(10000):

if i % 3 == 0:

gap = client.data.get_demand_gap(demand, lambda x: db.is_equip(x))
if all(gap[item] <= 0 for item in gap):
self._log("需求装备均已盈余")
if full2all:
gap = client.data.get_demand_gap(all_demand, lambda x: db.is_equip(x))
self._log("考虑所有角色的需求装备")

quest_weight = client.data.get_quest_weght(gap)
quest_id = sorted(quest_list, key = lambda x: quest_weight[x], reverse = True)
target_quest = await self.get_quests(quest_id, strategy, gap)

target_id = quest_id[0]
try:
resp = await client.quest_skip_aware(target_id, 3)
tmp.extend([item for item in resp if db.is_equip((item.type, item.id))])
clean_cnt[target_id] += 3
except SkipError:
pass
except AbortError as e:
stop = True
if str(e).endswith("体力不足"):
if not tmp and not self.log: self._log(str(e))
else:
raise e
break
for target_id in target_quest:
try:
resp = await client.quest_skip_aware(target_id, 3)
tmp.extend([item for item in resp if db.is_equip((item.type, item.id))])
clean_cnt[target_id] += 3
except SkipError:
pass
except AbortError as e:
stop = True
if str(e).endswith("体力不足"):
if not tmp and not self.log: self._log(str(e))
else:
raise e
break
if stop:
break
except:
Expand Down Expand Up @@ -183,7 +218,7 @@ def get_max_times(self, client: pcrclient, quest_id: int) -> int:
(32046, 1), # 水猫剑
(32048, 1), # 水子龙
(32060, 1), # 黑猫
(32016, 1), # 暴击弓
(32016, 2), # 暴击弓,水爆
(32031, 1), # 万圣忍
(32050, 1), # 万圣大眼
(32007, 1), # 万圣布丁
Expand All @@ -199,6 +234,8 @@ def get_max_times(self, client: pcrclient, quest_id: int) -> int:
(32030, 1), # 忍扇
(32040, 1), # 生菜
(32013, 1), # 七七香
(32028, 1), # 水电
(32018, 1), # 老师
]
@conditional_execution("very_hard_sweep_run_time", ["vh庆典"])
@description('储备专二需求的150碎片,包括' + ','.join(db.get_item_name(item_id) for item_id, _ in unique_equip_2_pure_memory_id))
Expand Down
15 changes: 12 additions & 3 deletions autopcr/module/modules/clan.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ async def do_task(self, client: pcrclient):
@description('对某颜色缺口数量最多的装备发起请求')
@name("装备请求")
@singlechoice("clan_equip_request_color", "装备颜色", "all", ["all", "Silver", "Gold", "Purple", 'Red', 'Green'])
@singlechoice("clan_equip_request_consider_unit", "需求角色", "all", ["all", 'favorite'])
@singlechoice("clan_equip_request_consider_unit_rank", "起始品级", "所有", ["所有", '最高', '次高', '次次高'])
@booltype("clan_equip_request_consider_unit_fav", "收藏角色", False)
@default(False)
class clan_equip_request(Module):
color_to_promotion = {
Expand All @@ -52,8 +53,16 @@ async def do_task(self, client: pcrclient):
msg = f"收到{db.get_equip_name(res.request.equip_id)}x{res.request.donation_num}:" + ' '.join(f"{user.name}x{user.num}" for user in res.request.history)
self._log(msg.strip(":"))

fav = (self.get_config('clan_equip_request_consider_unit') == 'favorite')
demand = client.data.get_equip_demand_gap(like_unit_only=fav)
opt: Dict[Union[int, str], int] = {
'所有': 1,
'最高': db.equip_max_rank,
'次高': db.equip_max_rank - 1,
'次次高': db.equip_max_rank - 2,
}

fav: bool = self.get_config('clan_equip_request_consider_unit_fav')
start_rank: int = opt[self.get_config('clan_equip_request_consider_unit_rank')]
demand = client.data.get_equip_demand_gap(like_unit_only=fav, start_rank=start_rank)
config_color: str = self.get_config('clan_equip_request_color')
target_level = self.color_to_promotion[config_color]

Expand Down
14 changes: 9 additions & 5 deletions autopcr/module/modules/hatsune.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,16 @@ async def do_task(self, client: pcrclient):
if is_abort: raise AbortError("")
if is_skip: raise SkipError("")

@singlechoice("hatsune_hboss_strategy", "扫荡策略", "保留当日vh份", ["保留当日vh份", "保留当日及未来vh份"])
@description('未打今日vh保留30+未打sp保留90')
@multichoice("hatsune_hboss_strategy", "扫荡策略", ["保留今日vh", "保留未来vh","保留sp"], ["保留今日vh", "保留未来vh","保留sp"])
@description('vh保留30,sp保留90,若无通关则会保留')
@name('扫荡活动h本boss')
@default("none")
class hatsune_hboss_sweep(Module):
async def do_task(self, client: pcrclient):
strategy: List[str] = self.get_config('hatsune_hboss_strategy')
today_vh: bool = "保留今日vh" in strategy
future_vh: bool = "保留未来vh" in strategy
today_sp: bool = "保留sp" in strategy
is_error = False
is_abort = False
is_skip = True
Expand All @@ -85,13 +89,13 @@ async def do_task(self, client: pcrclient):
raise AbortError(f"h本boss未解锁")
if not boss_info[hboss_id].kill_num:
raise AbortError(f"h本boss未首通")
if not boss_info[spboss_id].kill_num:
if today_sp and not boss_info[spboss_id].kill_num:
self._log("sp未通关,保留90张")
times -= 3
if not boss_info[vhboss_id].daily_kill_count:
if today_vh and not boss_info[vhboss_id].daily_kill_count:
self._log("今日vh未通关,保留30张")
times -= 1
if self.get_config('hatsune_hboss_strategy') == "保留当日及未来vh份":
if future_vh:
left_day = (db.get_start_time(db.parse_time(event.end_time)) - db.get_today_start_time()).days
self._log(f"距离活动结束还有{left_day}天,保留{left_day * 30}张")
times -= left_day
Expand Down
Loading

0 comments on commit ccdcadb

Please sign in to comment.