def checks_achieve(user_id): """ 由多个卡牌名检查是否需要更新成就 :param user_id: :param card_names: 新获取到的卡牌内容 :return: """ achievement_list1 = select_u(user_id, 'achievement')[0].split(' ') achievement_list2 = [] str_return = '' for k, v in achieve_list.items(): res = select_card(user_id, *v) if not is_have_zero(res): achievement_list2.append(k) achievement_set1 = set(achievement_list1) achievement_set1.remove('') achievement_set2 = set(achievement_list2) get_achieve = achievement_set2 - achievement_set1 lose_achieve = achievement_set1 - achievement_set2 is_change = False if get_achieve: str_return += f'恭喜获得新成就{",".join(get_achieve)}' is_change = True if lose_achieve: str_return += f'失去成就{",".join(lose_achieve)}' is_change = True if is_change: update_u(user_id, {'achievement': ' '.join(achievement_list2)})
def daily_score(user_id): """ 签到,检查是否已签到,未签到则产生随机积分,并将积分赋给该用户,更改该用户的"score"积分字段以及"da"签到日期字段 :param user_id: :return: """ score, da = select_u(user_id, 'score', 'da') today = str(datetime.date.today()) if da == today: return get_return('您已签到!', 1) a = random.randint(20, 50) score += a change_score(user_id, score, today) str1 = f'获得:{a}积分!总积分:{score}' # if a <= 24: # str2 = '不会真有人觉得自己签个到就能欧皇吧?不会吧不会吧?\n非酋签个到也才' # elif a >= 41: # str2 = '欧皇ohhh!!\n签到居然有' # else: # str2 = '...\n获得:' # # if score >= 500: # # a = int(a*0.1) # # str1 = '\n积分超过五百,签到积分减少90%,' # # elif score >= 400: # # a = int(a*0.6) # # str1 = '\n积分超过四百,签到积分减少60%,' # # elif score >= 300: # # a = int(a*0.5) # # str1 = '\n积分超过三百,签到积分减少50%,' # # elif score >= 200: # # a = int(a*0.6) # # str1 = '\n积分超过二百,签到积分减少40%,' # # return get_return(str2 + f'') return get_return(str1)
def select_score(user_id): """ 查询积分, 调用sql模块方法 :param user_id: :return: """ score = select_u(user_id, 'score')[0] return score
def search_card(user_id): """ 查询用户拥有的卡牌 :param user_id: :return: """ res = select_u(user_id, 'N', 'R', 'SR', "SSR", 'UR') str1 = f'N:{res[0]} R:{res[1]} SR:{res[2]} SSR:{res[3]} UR:{res[4]}' return get_return(str1)
def select_achievement(user_id): """ 查询用户成就 :param user_id: :return: """ achievement = select_u(user_id, 'achievement')[0] achievement_num = len(achievement.split(' ')) - 1 str1 = f'您的成就有:{achievement}, 共{achievement_num}个' return get_return(str1)
def inner(user_id, *args, **kwargs): """ 查询数据库中"u"库,是否包含该用户信息,若无,则返回需要注册,有则代表已注册,执行被装饰的方法,返回其返回结果 :param user_id: :param args: :param kwargs: :return: """ if not select_u(user_id, 'id'): return get_return('您还没有注册,请先注册', code=1) return func(user_id, *args, **kwargs)
def inner(user_id, *args, **kwargs): """ 类似,检查"u"表中用户的"permission"字段,若为"admin"则放行,不然返回pa, :param user_id: :param args: :param kwargs: :return: """ permission = select_u(user_id, 'permission') if not permission or permission != ('admin', ): return pa return func(user_id, *args, **kwargs)
def archive_card(user_id, img, lv, num=1): """ 存储抽卡获得的卡牌 :param user_id: :param img: 卡牌名称 :param lv: 卡牌等级 :param num: 获得的卡牌数量 :return: """ if '.jpg' in img: img = img[:-4] img_num = select_card(user_id, img)[0] lv_num = select_u(user_id, lv)[0] update_card({"id": user_id}, {img: img_num + num}) update_u(user_id, {lv: lv_num + num})
def archive_cards(user_id, imgs: dict, lvs: dict): """ 存储十连或者是百连获取的卡牌,一次性存储 :param user_id: :param imgs: 卡牌字典,{卡牌名:卡牌数量} :param lvs: 卡牌等级,{卡牌等级: 数量} :return: """ img_list = list(imgs.keys()) lv_list = list(lvs.keys()) img_num = select_card(user_id, *img_list) lv_num = select_u(user_id, *lv_list) for i, _ in enumerate(img_list): imgs[_] += img_num[i] for i, _ in enumerate(lv_list): lvs[_] += lv_num[i] update_card({"id": user_id}, imgs) update_u(user_id, lvs)