async def gacha_jyu(bot: Bot, event: CQEvent, state: T_State): if isinstance(event, PrivateMessageEvent): name = util.normalize_str(state['name']) SUPER_LUCKY_LINE = 170 if name in ('国', '国服', 'cn'): await gacha_10.finish('请选择详细区服\n※例:"来发十连b服"或"来发十连台服"') elif name in ('b', 'b服', 'bl', 'bilibili', '陆', '陆服'): name = 'BL' elif name in ('台', '台服', 'tw', 'sonet'): name = 'TW' elif name in ('日', '日服', 'jp', 'cy', 'cygames'): name = 'JP' elif name in ('混', '混合', 'mix'): name = 'MIX' else: await gacha_10.finish('未知区服,请接区服简称\n※例:"来发十连jp"') gacha = Gacha(name) result, hiishi = gacha.gacha_ten() res1 = chara.gen_team_pic(result[:5], star_slot_verbose=False) res2 = chara.gen_team_pic(result[5:], star_slot_verbose=False) res = concat_pic([res1, res2]) res = pic2b64(res) res = MessageSegment.image(res) result = [f'{c.name}{"★"*c.star}' for c in result] res1 = ' '.join(result[0:5]) res2 = ' '.join(result[5:]) res = f'{res}\n{res1}\n{res2}' if hiishi >= SUPER_LUCKY_LINE: await bot.send(event, '恭喜海豹!おめでとうございます!') await gacha_10.finish(Message(f'素敵な仲間が増えますよ!\n{res}'))
async def jyu_rec(bot: Bot, event: CQEvent, state: T_State): SUPER_LUCKY_LINE = 170 await check_jewel_num(bot, event) uid = event.user_id user_info = await bot.get_stranger_info(user_id=uid) nickname = user_info.get('nickname', '未知用户') jewel_limit.increase(uid, 1500) if isinstance(event, GroupMessageEvent): gid = event.group_id gacha = Gacha(_group_pool[gid]) result, hiishi = gacha.gacha_ten() res1 = chara.gen_team_pic(result[:5], star_slot_verbose=False) res2 = chara.gen_team_pic(result[5:], star_slot_verbose=False) res = concat_pic([res1, res2]) res = pic2b64(res) res = MessageSegment.image(res) result = [f'{c.name}{"★"*c.star}' for c in result] res1 = ' '.join(result[0:5]) res2 = ' '.join(result[5:]) res = f'{res}\n{res1}\n{res2}' if hiishi >= SUPER_LUCKY_LINE: await bot.send(event, '恭喜海豹!おめでとうございます!') await gacha_10.finish(Message(f'>{nickname}\n素敵な仲間が増えますよ!\n{res}')) elif isinstance(event, PrivateMessageEvent): args = util.normalize_str(event.get_plaintext().strip()) if args: state['name'] = args
async def ag(bot: Bot, event: CQEvent): if isinstance(event, PrivateMessageEvent): await avatar_guess.finish('本功能仅支持群聊') elif isinstance(event, GroupMessageEvent): if gma.is_playing(event.group_id): await avatar_guess.finish('游戏仍在进行中…') with gma.start_game(event.group_id) as game1: ids = list(_pcr_data.CHARA_NAME.keys()) game1.answer = random.choice(ids) while chara.is_npc(game1.answer): game1.answer = random.choice(ids) c = chara.fromid(game1.answer) img = c.icon.open() w, h = img.size l = random.randint(0, w - PATCH_SIZE) u = random.randint(0, h - PATCH_SIZE) cropped = img.crop((l, u, l + PATCH_SIZE, u + PATCH_SIZE)) cropped = MessageSegment.image(util.pic2b64(cropped)) await bot.send( event, Message(f"猜猜这个图片是哪位角色头像的一部分?({A_TURN_TIME}s后公布答案) {cropped}")) await asyncio.sleep(A_TURN_TIME) if game1.winner: return await bot.send(event, Message(f"正确答案是:{c.name} {c.icon.cqcode}\n很遗憾,没有人答对~"))
def cqcode(self) -> MessageSegment: if salmon.configs.RES_PROTOCOL == 'http': return MessageSegment.image(self.url) elif salmon.configs.RES_PROTOCOL == 'file': return MessageSegment.image( f'file:///{os.path.abspath(self.path)}') else: try: return MessageSegment.image(util.pic2b64(self.open())) except Exception as e: salmon.logger.exception(e) return MessageSegment.text('[图片出错]')
async def get_view(self, sauce) -> str: sauces = self.get_sauce(sauce) repass = "" simimax = 0 for sauce in sauces['results']: try: url = sauce['data']['ext_urls'][0].replace( "\\", "").strip() if 'ext_urls' in sauce['data'] else "no link" similarity = sauce['header']['similarity'] if not similarity.replace(".", "").isdigit(): #print(sauce) similarity = 0 simimax = float( similarity) if float(similarity) > simimax else simimax thumbnail_url = sauce['header']['thumbnail'] if THUMB_ON: try: thumbnail_image = str( MessageSegment.image( pic2b64( ats_pic( Image.open( BytesIO( await get_pic(thumbnail_url))))))) except Exception: salmon.logger.error(f"预览图下载失败:{format_exc()}") thumbnail_image = "[预览图下载失败]" else: thumbnail_image = "" service_name, info = sauces_info(sauce) putline = f"{thumbnail_image}\n[{service_name}][{url}] 相似度:{similarity}%\n{info}" if repass: repass = "******".join([repass, putline]) else: repass = putline except Exception: print(format_exc()) #print(sauce) pass return [repass, simimax]
async def add_repass(self, tag: str, data): po = "——{}——".format(tag) for line in data: if THUMB_ON: try: thumbnail_image = str( MessageSegment.image( pic2b64( ats_pic( Image.open(BytesIO(await get_pic(line[2]))))))) except Exception: salmon.logger.error(f"预览图下载失败:{format_exc()}") thumbnail_image = "[预览图下载失败]" else: thumbnail_image = "" putline = f"{thumbnail_image}\n[{line[1]}][{line[0]}]\n{line[3]}" po = "\n".join([po, putline]) return po
async def gacha_nibyaku(bot: Bot, event: CQEvent, state: T_State): if isinstance(event, PrivateMessageEvent): name = util.normalize_str(state['name']) if name in ('国', '国服', 'cn'): await gacha_200.finish('请选择详细区服\n※例:"来一井b服"或"来一井台服"') elif name in ('b', 'b服', 'bl', 'bilibili', '陆', '陆服'): name = 'BL' elif name in ('台', '台服', 'tw', 'sonet'): name = 'TW' elif name in ('日', '日服', 'jp', 'cy', 'cygames'): name = 'JP' elif name in ('混', '混合', 'mix'): name = 'MIX' else: await gacha_200.finish('未知区服,请接区服简称\n※例:"来一井jp"') gacha = Gacha(name) result = gacha.gacha_tenjou() up = len(result['up']) s3 = len(result['s3']) s2 = len(result['s2']) s1 = len(result['s1']) res = [*(result['up']), *(result['s3'])] random.shuffle(res) lenth = len(res) if lenth <= 0: res = "竟...竟然没有3★?!" else: step = 4 pics = [] for i in range(0, lenth, step): j = min(lenth, i + step) pics.append( chara.gen_team_pic(res[i:j], star_slot_verbose=False)) res = concat_pic(pics) res = pic2b64(res) res = MessageSegment.image(res) msg = [ f"素敵な仲間が増えますよ! {res}", f"★★★×{up+s3} ★★×{s2} ★×{s1}", f"获得记忆碎片×{100*up}与女神秘石×{50*(up+s3) + 10*s2 + s1}!\n第{result['first_up_pos']}抽首次获得up角色" if up else f"获得女神秘石{50*(up+s3) + 10*s2 + s1}个!" ] if up == 0 and s3 == 0: msg.append("太惨了,咱们还是退款删游吧...") elif up == 0 and s3 > 5: msg.append("up呢?我的up呢?") elif up == 0 and s3 <= 2: msg.append("这位酋长,梦幻包考虑一下?") elif up == 0: msg.append("据说天井的概率只有12.16%") elif up <= 2: if result['first_up_pos'] < 50: msg.append("你的喜悦我收到了,滚去喂鲨鱼吧!") elif result['first_up_pos'] < 100: msg.append("已经可以了,您已经很欧了") elif result['first_up_pos'] > 190: msg.append("标 准 结 局") elif result['first_up_pos'] > 150: msg.append("补井还是不补井,这是一个问题...") else: msg.append("期望之内,亚洲水平") elif up == 3: msg.append("抽井母五一气呵成!多出30等专武~") elif up >= 4: msg.append("记忆碎片一大堆!您是托吧?") msg = Message('\n'.join(msg)) await gacha_200.finish(msg)
async def nibyaku_rec(bot: Bot, event: CQEvent, state: T_State): await check_tenjo_num(bot, event) uid = event.user_id user_info = await bot.get_stranger_info(user_id=uid) nickname = user_info.get('nickname', '未知用户') tenjo_limit.increase(uid) if isinstance(event, GroupMessageEvent): gid = event.group_id gacha = Gacha(_group_pool[gid]) result = gacha.gacha_tenjou() up = len(result['up']) s3 = len(result['s3']) s2 = len(result['s2']) s1 = len(result['s1']) res = [*(result['up']), *(result['s3'])] random.shuffle(res) lenth = len(res) if lenth <= 0: res = "竟...竟然没有3★?!" else: step = 4 pics = [] for i in range(0, lenth, step): j = min(lenth, i + step) pics.append( chara.gen_team_pic(res[i:j], star_slot_verbose=False)) res = concat_pic(pics) res = pic2b64(res) res = MessageSegment.image(res) msg = [ f">{nickname}\n" f"素敵な仲間が増えますよ! {res}", f"★★★×{up+s3} ★★×{s2} ★×{s1}", f"获得记忆碎片×{100*up}与女神秘石×{50*(up+s3) + 10*s2 + s1}!\n第{result['first_up_pos']}抽首次获得up角色" if up else f"获得女神秘石{50*(up+s3) + 10*s2 + s1}个!" ] if up == 0 and s3 == 0: msg.append("太惨了,咱们还是退款删游吧...") elif up == 0 and s3 > 5: msg.append("up呢?我的up呢?") elif up == 0 and s3 <= 2: msg.append("这位酋长,梦幻包考虑一下?") elif up == 0: msg.append("据说天井的概率只有12.16%") elif up <= 2: if result['first_up_pos'] < 50: msg.append("你的喜悦我收到了,滚去喂鲨鱼吧!") elif result['first_up_pos'] < 100: msg.append("已经可以了,您已经很欧了") elif result['first_up_pos'] > 190: msg.append("标 准 结 局") elif result['first_up_pos'] > 150: msg.append("补井还是不补井,这是一个问题...") else: msg.append("期望之内,亚洲水平") elif up == 3: msg.append("抽井母五一气呵成!多出30等专武~") elif up >= 4: msg.append("记忆碎片一大堆!您是托吧?") msg = Message('\n'.join(msg)) await gacha_200.finish(msg) elif isinstance(event, PrivateMessageEvent): args = util.normalize_str(event.get_plaintext().strip()) if args: state['name'] = args
async def _arena_query(bot: Bot, event: CQEvent, state: T_State, region: int): uid = event.user_id user_info = await bot.get_stranger_info(user_id=uid) nickname = user_info.get('nickname', '未知用户') sender = f'>{nickname}\n' if isinstance(event, PrivateMessageEvent): if uid not in salmon.configs.SUPERUSERS: await bot.send(event, '非维护组请在群聊中查询') raise FinishedException refresh_quick_key_dic() if not lmt.check(uid): msg = '您查询得过于频繁,请稍等片刻' if isinstance(event, GroupMessageEvent): await bot.send(event, sender + msg) elif isinstance(event, PrivateMessageEvent): await bot.send(event, msg) raise FinishedException lmt.start_cd(uid) # 处理输入数据 defen = state['defen'] defen = re.sub(r'[??,,_]', '', defen) defen, unknown = chara.roster.parse_team(defen) if unknown: _, name, score = chara.guess_id(unknown) if score < 70 and not defen: return # 忽略无关对话 msg = f'无法识别"{unknown}"' if score < 70 else f'无法识别"{unknown}" 您说的有{score}%可能是{name}' await bot.send(event, msg) raise FinishedException if not defen: msg = '查询请发送"怎么拆+防守队伍"(无需+号)' if isinstance(event, GroupMessageEvent): await bot.send(event, sender + msg) elif isinstance(event, PrivateMessageEvent): await bot.send(event, msg) raise FinishedException if len(defen) > 5: msg = '编队不能多于5名角色' if isinstance(event, GroupMessageEvent): await bot.send(event, sender + msg) elif isinstance(event, PrivateMessageEvent): await bot.send(event, msg) raise FinishedException if len(defen) < 5: msg = '由于数据库限制,少于5名角色的检索条件请移步pcrdfans.com进行查询' if isinstance(event, GroupMessageEvent): await bot.send(event, sender + msg) elif isinstance(event, PrivateMessageEvent): await bot.send(event, msg) raise FinishedException if len(defen) != len(set(defen)): msg = '编队中含重复角色' if isinstance(event, GroupMessageEvent): await bot.send(event, sender + msg) elif isinstance(event, PrivateMessageEvent): await bot.send(event, msg) raise FinishedException if any(chara.is_npc(i) for i in defen): msg = '编队中含未实装角色' if isinstance(event, GroupMessageEvent): await bot.send(event, sender + msg) elif isinstance(event, PrivateMessageEvent): await bot.send(event, msg) raise FinishedException if 1004 in defen: msg = '\n⚠️您正在查询普通版炸弹人\n※万圣版可用万圣炸弹人/瓜炸等别称' if isinstance(event, GroupMessageEvent): await bot.send(event, sender + msg) elif isinstance(event, PrivateMessageEvent): await bot.send(event, msg) raise FinishedException # 执行查询 salmon.logger.info('Doing query...') res = None try: res = await do_query(defen, uid, region) except salmon.aiohttpx.HTTPError as e: code = e.response["code"] if code == 117: await bot.send(event, "高峰期服务器限流!请前往pcrdfans.com/battle查询") else: await bot.send(event, f'CODE{code} 查询出错,请联系维护组调教\n请先前往pcrdfans.com进行查询') raise FinishedException salmon.logger.info('Got response!') # 处理查询结果 if res is None: msg = '数据库未返回数据,请再次尝试查询或前往pcrdfans.com' if isinstance(event, GroupMessageEvent): await bot.send(event, sender + msg) elif isinstance(event, PrivateMessageEvent): await bot.send(event, msg) raise FinishedException if not len(res): msg = '抱歉没有查询到解法\n※没有作业说明随便拆 发挥你的想象力~★\n作业上传请前往pcrdfans.com' if isinstance(event, GroupMessageEvent): await bot.send(event, sender + msg) elif isinstance(event, PrivateMessageEvent): await bot.send(event, msg) raise FinishedException res = res[:min(6, len(res))] # 限制显示数量,截断结果 # 发送回复 salmon.logger.info('Arena generating picture...') teams = render_atk_def_teams(res) teams = pic2b64(teams) teams = MessageSegment.image(teams) salmon.logger.info('Arena picture ready!') # 纯文字版 # atk_team = '\n'.join(map(lambda entry: ' '.join(map(lambda x: f"{x.name}{x.star if x.star else ''}{'专' if x.equip else ''}" , entry['atk'])) , res)) # details = [" ".join([ # f"赞{e['up']}+{e['my_up']}" if e['my_up'] else f"赞{e['up']}", # f"踩{e['down']}+{e['my_down']}" if e['my_down'] else f"踩{e['down']}", # e['qkey'], # "你赞过" if e['user_like'] > 0 else "你踩过" if e['user_like'] < 0 else "" # ]) for e in res] # defen = [ chara.fromid(x).name for x in defen ] # defen = f"防守方【{' '.join(defen)}】" at = str(MessageSegment.at(event.user_id)) msg = [ # defen, f'已为骑士{at}查询到以下进攻方案:', str(teams), # '作业评价:', # *details, # '※发送"点赞/点踩"可进行评价' ] if region == 1: msg.append('※使用"b怎么拆"或"台怎么拆"可按服过滤') msg.append('Support by pcrdfans_com') salmon.logger.debug('Arena sending result...') await bot.send(event, '\n'.join(msg)) salmon.logger.debug('Arena result sent!') raise FinishedException