From 1cbe807b057e9a01d068ed17086d5952771cc718 Mon Sep 17 00:00:00 2001 From: HibiKier <775757368@qq.com> Date: Mon, 6 Mar 2023 22:52:15 +0800 Subject: [PATCH] fix bug --- basic_plugins/group_handle/__init__.py | 13 ++++- plugins/open_cases/config.py | 2 +- plugins/open_cases/utils.py | 79 ++++++++++++++------------ 3 files changed, 56 insertions(+), 38 deletions(-) diff --git a/basic_plugins/group_handle/__init__.py b/basic_plugins/group_handle/__init__.py index 45d7cee8..e1dcea0f 100755 --- a/basic_plugins/group_handle/__init__.py +++ b/basic_plugins/group_handle/__init__.py @@ -118,11 +118,20 @@ async def _(bot: Bot, event: GroupIncreaseNoticeEvent): user_info = await bot.get_group_member_info( group_id=event.group_id, user_id=event.user_id ) - await GroupInfoUser.update_or_create( + user, _ = await GroupInfoUser.get_or_create( user_qq=user_info["user_id"], group_id=user_info["group_id"], - defaults={"user_name": user_info["nickname"], "user_join_time": join_time}, + defaults={ + "user_name": user_info["nickname"], + }, ) + user.user_join_time = join_time + await user.save() + # await GroupInfoUser.update_or_create( + # user_qq=user_info["user_id"], + # group_id=user_info["group_id"], + # defaults={"user_name": user_info["nickname"], "user_join_time": join_time}, + # ) logger.info(f"用户{user_info['user_id']} 所属{user_info['group_id']} 更新成功") # 群欢迎消息 diff --git a/plugins/open_cases/config.py b/plugins/open_cases/config.py index b9742a46..36f8cc9b 100755 --- a/plugins/open_cases/config.py +++ b/plugins/open_cases/config.py @@ -53,7 +53,7 @@ CASE2ID = { "光谱": "set_community_16", "手套武器箱": "set_community_15", "伽玛2号": "set_gamma_2", - "伽玛": "set_gamma_1", + "伽玛": "set_community_13", "幻彩3号": "set_community_12", "野火大行动": "set_community_11", "左轮武器箱": "set_community_10", diff --git a/plugins/open_cases/utils.py b/plugins/open_cases/utils.py index 02f0fb15..820d2d51 100755 --- a/plugins/open_cases/utils.py +++ b/plugins/open_cases/utils.py @@ -20,7 +20,7 @@ from .models.open_cases_user import OpenCasesUser URL = "https://buff.163.com/api/market/goods" # proxies = 'http://49.75.59.242:3128' -NAME2COLOR = {"军规级": "BLUE", "受限": "PURPLE", "保密": "PINK", "隐秘": "RED", "非凡": "KNIFE"} +NAME2COLOR = {"消费级": "WHITE", "工业级": "LIGHTBLUE", "军规级": "BLUE", "受限": "PURPLE", "保密": "PINK", "隐秘": "RED", "非凡": "KNIFE"} CURRENT_CASES = [] @@ -207,40 +207,49 @@ async def search_skin_page( for data in data_list: obj = {"case_name": case_name} name = data["name"] - logger.debug( - f"武器箱: [{case_name}] 页数: [{page_index}] 正在收录皮肤: [{name}]...", - "开箱更新", - ) - obj["buy_max_price"] = data["buy_max_price"] # 求购最大金额 - obj["buy_num"] = data["buy_num"] # 当前求购 - goods_info = data["goods_info"] - info = goods_info["info"] - tags = info["tags"] - obj["weapon_type"] = tags["type"]["localized_name"] # 枪械类型 - if obj["weapon_type"] in ["音乐盒", "印花"]: - continue - if obj["weapon_type"] in ["匕首", "手套"]: - obj["color"] = "KNIFE" - obj["name"] = data["short_name"].split("(")[0].strip() # 名称 - if obj["weapon_type"] in ["武器箱"]: - obj["color"] = "CASE" - obj["name"] = data["short_name"] - else: - obj["color"] = NAME2COLOR[tags["rarity"]["localized_name"]] - obj["name"] = tags["weapon"]["localized_name"] # 名称 - if obj["weapon_type"] not in ["武器箱"]: - obj["abrasion"] = tags["exterior"]["localized_name"] # 磨损 - obj["color"] = NAME2COLOR[tags["rarity"]["localized_name"]] # 品质颜色 - obj["is_stattrak"] = "StatTrak" in tags["quality"]["localized_name"] # type: ignore # 是否暗金 - else: - obj["abrasion"] = "CASE" - obj["skin_name"] = data["short_name"].split("|")[-1].strip() # 皮肤名称 - obj["img_url"] = goods_info["original_icon_url"] # 图片url - obj["steam_price"] = goods_info["steam_price_cny"] # steam价格 - obj["sell_min_price"] = data["sell_min_price"] # 售卖最低价格 - obj["sell_num"] = data["sell_num"] # 售卖数量 - obj["sell_reference_price"] = data["sell_reference_price"] # 参考价格 - update_data.append(BuffSkin(**obj)) + try: + logger.debug( + f"武器箱: [{case_name}] 页数: [{page_index}] 正在收录皮肤: [{name}]...", + "开箱更新", + ) + obj["buy_max_price"] = data["buy_max_price"] # 求购最大金额 + obj["buy_num"] = data["buy_num"] # 当前求购 + goods_info = data["goods_info"] + info = goods_info["info"] + tags = info["tags"] + obj["weapon_type"] = tags["type"]["localized_name"] # 枪械类型 + if obj["weapon_type"] in ["音乐盒", "印花", "探员"]: + continue + if obj["weapon_type"] in ["匕首", "手套"]: + obj["color"] = "KNIFE" + obj["name"] = data["short_name"].split("(")[0].strip() # 名称 + if obj["weapon_type"] in ["武器箱"]: + obj["color"] = "CASE" + obj["name"] = data["short_name"] + else: + obj["color"] = NAME2COLOR[tags["rarity"]["localized_name"]] + obj["name"] = tags["weapon"]["localized_name"] # 名称 + if obj["weapon_type"] not in ["武器箱"]: + obj["abrasion"] = tags["exterior"]["localized_name"] # 磨损 + obj["is_stattrak"] = "StatTrak" in tags["quality"]["localized_name"] # type: ignore # 是否暗金 + if not obj["color"]: + obj["color"] = NAME2COLOR[ + tags["rarity"]["localized_name"] + ] # 品质颜色 + else: + obj["abrasion"] = "CASE" + obj["skin_name"] = data["short_name"].split("|")[-1].strip() # 皮肤名称 + obj["img_url"] = goods_info["original_icon_url"] # 图片url + obj["steam_price"] = goods_info["steam_price_cny"] # steam价格 + obj["sell_min_price"] = data["sell_min_price"] # 售卖最低价格 + obj["sell_num"] = data["sell_num"] # 售卖数量 + obj["sell_reference_price"] = data["sell_reference_price"] # 参考价格 + update_data.append(BuffSkin(**obj)) + except Exception as e: + logger.error( + f"更新武器箱: [{case_name}] 皮肤: [{name}] 错误", + e=e, + ) logger.debug( f"访问武器箱: [{case_name}] 页数: [{page_index}] 成功并收录完成", "开箱更新",