diff --git a/autopcr/db/database.py b/autopcr/db/database.py index cf5c2da3..1939f848 100644 --- a/autopcr/db/database.py +++ b/autopcr/db/database.py @@ -981,9 +981,9 @@ def get_rank_promote_equip_demand(self, unit_id: int, start_rank: int, start_ran (flow(self.unit_promotion_equip_count[unit_id].items()) .where(lambda x: x[0] >= start_rank and x[0] < target_rank) .select(lambda x: x[1]) - .sum(seed=Counter())) - - Counter((eInventoryType(eInventoryType.Equip), int(getattr(self.unit_promotion[unit_id][start_rank], f"equip_slot_{i}"))) for i in range(1, 7) if start_rank_equip_slot[i - 1]) + - Counter((eInventoryType(eInventoryType.Equip), int(getattr(self.unit_promotion[unit_id][target_rank], f"equip_slot_{i}"))) for i in range(1, 7) if target_rank_equip_slot[i - 1]) + .sum(seed=Counter())) + + Counter((eInventoryType(eInventoryType.Equip), int(getattr(self.unit_promotion[unit_id][target_rank], f"equip_slot_{i}"))) for i in range(1, 7) if target_rank_equip_slot[i - 1]) - + Counter((eInventoryType(eInventoryType.Equip), int(getattr(self.unit_promotion[unit_id][start_rank], f"equip_slot_{i}"))) for i in range(1, 7) if start_rank_equip_slot[i - 1]) ) return ret diff --git a/autopcr/http_server/httpserver.py b/autopcr/http_server/httpserver.py index cb32139e..ca43173c 100644 --- a/autopcr/http_server/httpserver.py +++ b/autopcr/http_server/httpserver.py @@ -25,6 +25,8 @@ def __init__(self, host = '0.0.0.0', port = 2, qq_mod = False): self.web = Blueprint('web', __name__, static_folder=static_path) + # version check & rate limit + self.api_limit = Blueprint('api_limit', __name__, url_prefix = "/api") self.api = Blueprint('api', __name__, url_prefix = "/api") self.app = Blueprint('app', __name__, url_prefix = "/daily") @@ -37,6 +39,7 @@ def __init__(self, host = '0.0.0.0', port = 2, qq_mod = False): self.app.register_blueprint(self.web) self.app.register_blueprint(self.api) + self.app.register_blueprint(self.api_limit) self.host = host self.port = port @@ -76,16 +79,15 @@ async def inner(*args, **kwargs): def configure_routes(self): - @self.api.before_request + @self.api_limit.before_request async def check_app_version(): - return None version = request.headers.get('X-App-Version', None) if version != APP_VERSION: return f"后端期望前端版本为{APP_VERSION},请更新", 400 else: return None - @self.api.errorhandler(RateLimitExceeded) + @self.api_limit.errorhandler(RateLimitExceeded) async def handle_rate_limit_exceeded_error(error): return "您冲得太快了,休息一下吧", 429 @@ -391,7 +393,7 @@ async def validate(): # TODO think to check login or not validate_ok_dict[id] = ValidateInfo.from_dict(data) return "", 200 - @self.api.route('/login/qq', methods = ['POST']) + @self.api_limit.route('/login/qq', methods = ['POST']) @rate_limit(1, timedelta(seconds=1)) @rate_limit(3, timedelta(minutes=1)) async def login_qq(): @@ -408,7 +410,7 @@ async def login_qq(): else: return "无效的QQ或密码", 400 - @self.api.route('/register', methods = ['POST']) + @self.api_limit.route('/register', methods = ['POST']) @rate_limit(1, timedelta(minutes=1)) async def register(): data = await request.get_json() diff --git a/autopcr/module/modules/gacha.py b/autopcr/module/modules/gacha.py index f398d3fd..b355fcca 100644 --- a/autopcr/module/modules/gacha.py +++ b/autopcr/module/modules/gacha.py @@ -85,7 +85,7 @@ async def do_task(self, client: pcrclient): if res.campaign_info.fg10_exec_cnt == 0: raise SkipError("今日份免费十连已使用") cnt = res.campaign_info.fg10_exec_cnt - free_gacha_ids = set(gacha.gacha_id for gacha in gacha_list) + free_gacha_ids = set(gacha.gacha_id for gacha in gacha_list) & set(db.gacha_data) open_gacha_ids = set(gacha.id for gacha in res.gacha_info) open_free_gacha_ids = free_gacha_ids & open_gacha_ids close_free_gacha_ids = free_gacha_ids - open_gacha_ids