async def look_pool(bot: Bot, event: CQEvent): if isinstance(event, GroupMessageEvent): gid = str(event.group_id) gacha = Gacha(_group_pool[gid]) elif isinstance(event, PrivateMessageEvent): name = util.normalize_str(event.get_plaintext().strip()) if not name: await gacha_pool.finish('请后接区服简称\n※例:"查看卡池jp"') elif name in ('国', '国服', 'cn'): await gacha_pool.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_pool.finish('未知区服,请接区服简称\n※例:"查看卡池jp"') gacha = Gacha(name) up_chara = gacha.up up_chara = map(lambda x: str(chara.fromname(x, star=3).icon.cqcode) + x, up_chara) up_chara = '\n'.join(up_chara) await gacha_pool.finish( Message( f"本期卡池主打的角色:\n{up_chara}\nUP概率合计={(gacha.up_prob/10):.1f}%\n3★出率={(gacha.s3_prob)/10:.1f}%" ))
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 update_pcrdata(): ''' 对比本地和远程的_pcr_data.py, 自动补充本地没有的角色信息, 已有角色信息进行补全 ''' online_pcrdata = await get_online_pcrdata() salmon.logger.info('开始对比角色数据') if online_pcrdata == {}: return -1 for id in online_pcrdata: # 增加对只有一个key的名字的检查,从而更新之前检查所添加的没有别称的新角色 if (id not in _pcr_data.CHARA_NAME or len(_pcr_data.CHARA_NAME[id]) == 1) and id != 9401: salmon.logger.info(f'已开始更新角色{id}的数据和图标') # 由于返回数据可能出现全半角重复, 做一定程度的兼容性处理, 会将所有全角替换为半角, 并移除重复别称 for i, name in enumerate(online_pcrdata[id]): name_format = name.replace('(', '(') name_format = name_format.replace(')', ')') name_format = util.normalize_str(name_format) online_pcrdata[id][i] = name_format if len(online_pcrdata[id]) != 1: n = online_pcrdata[id][1] else: n = online_pcrdata[id][0] group = {f'{n}'} # 转集合再转列表, 移除重复元素, 按中文原名优先顺序排列 m = list(set(online_pcrdata[id])) sort_priority(m, group) _pcr_data.chara_master.add_chara(id, m) download_chara_icon(id, 6) download_chara_icon(id, 3) download_chara_icon(id, 1) # 重载花名册(不会引起全局reload) roster.update()
async def switch_pool(bot: Bot, event: CQEvent, state: T_State): if isinstance(event, GroupMessageEvent): user_info = await bot.get_stranger_info(user_id=event.user_id) nickname = user_info.get('nickname', '未知用户') if not priv.check_priv(bot, event, priv.ADMIN): await gacha_switch.finish(f'>{nickname}\n只有群管理才能切换卡池') name = util.normalize_str(state['name']) if name in ('国', '国服', 'cn'): await gacha_pool.finish(f'>{nickname}\n请选择以下卡池\n> 选择卡池b服\n> 选择卡池台服' ) 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_pool.finish(f'>{nickname}\n未知区服,{POOL_NAME_TIP}') gid = str(event.group_id) _group_pool[gid] = name dump_pool_config() await bot.send(event, f'>{nickname}\n卡池已切换为{name}池') await look_pool(bot, event)
async def _keyword(bot: Bot, event: CQEvent, state: T_State) -> bool: if event.get_type() != "message": return False text = event.get_plaintext() if normal: text = normalize_str(text) return bool(text and any(kw in text for kw in keywords))
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 rank_rec(bot: Bot, event: CQEvent, state: T_State): user_info = await bot.get_stranger_info(user_id=event.user_id) nickname = user_info.get('nickname', '未知用户') if isinstance(event, GroupMessageEvent): state['prompt'] = f'>{nickname}\n请发送需要查询rank表的区服' elif isinstance(event, PrivateMessageEvent): state['prompt'] = '请发送需要查询rank表的区服' args = util.normalize_str(event.get_plaintext().strip()) if args: state['name'] = args
async def group_set(bot: Bot, event: CQEvent): if isinstance(event, GroupMessageEvent): gid = event.group_id is_su = priv.check_priv(event, priv.SUPERUSER) args = util.normalize_str(event.get_plaintext()).split() msg = '' if not is_su: msg = '权限不足' elif len(args) == 0: msg = '请后接参数(空格隔开)\n支持的指令如下:\n[setu set r18/withdraw on/off (group_id)]\n[setu status (group_id)]\n[setu fetch]\n[setu warehouse]' elif args[0] == 'set' and len(args) >= 3: if len(args) >= 4 and args[3].isdigit(): gid = int(args[3]) elif args[1] == 'r18': key = 'lolicon_r18' elif args[1] == 'withdraw': key = 'withdraw' else: key = None if args[2] == 'on' or args[2] == '启用': value = True elif args[2] == 'off' or args[2] == '禁用': value = False elif args[2].isdigit(): value = int(args[2]) else: value = None if key and (not value is None): set_group_config(gid, key, value) msg = '设置成功!当前设置值如下:\n' msg += f'群/{gid} : 设置项/{key} = 值/{value}' else: msg = '无效参数\n支持的指令如下:\n[setu set r18/withdraw on/off (group_id)]\n[setu status (group_id)]\n[setu fetch]\n[setu warehouse]' elif args[0] == 'status': if len(args) >= 2 and args[1].isdigit(): gid = int(args[1]) withdraw_status = "Off" if get_group_config( gid, "withdraw") == 0 else f'{get_group_config(gid, "withdraw")}s' lolicon_status = "R18" if get_group_config(gid, "lolicon_r18") else "Normal" msg = f'Group: {gid} :' msg += f'\nWithdraw: {withdraw_status}' msg += f'\nSetu: {lolicon_status}' elif args[0] == 'fetch': await bot.send(event, '开始缓存图片') await lolicon_fetch_process() msg = '缓存进程结束' elif args[0] == 'warehouse': msg = 'Warehouse:' state = check_path() for k, v in state.items(): msg += f'\n{k} : {v}' else: msg = '无效参数\n支持的指令如下:\n[setu set r18/withdraw on/off (group_id)]\n[setu status (group_id)]\n[setu fetch]\n[setu warehouse]' await bot.send(event, msg)
async def switch_recg(bot: Bot, event: CQEvent, state: T_State): user_info = await bot.get_stranger_info(user_id=event.user_id) nickname = user_info.get('nickname', '未知用户') if isinstance(event, PrivateMessageEvent): await gacha_switch.finish('请在群聊内切换卡池') elif isinstance(event, GroupMessageEvent): args = util.normalize_str(event.get_plaintext().strip()) if args: state['name'] = args message = f'>{nickname}\n请发送需要切换的卡池的区服' state['prompt'] = message
def update(self): importlib.reload(_pcr_data) self._roster.clear() for idx, names in _pcr_data.CHARA_NAME.items(): for n in names: n = util.normalize_str(n) if n not in self._roster: self._roster[n] = idx else: salmon.logger.warning( f'priconne.chara.Roster: 出现重名{n}于id{idx}与id{self._roster[n]}' ) self._all_name_list = self._roster.keys()
def parse_team(self, namestr): """@return: List[ids], unknown_namestr""" namestr = util.normalize_str(namestr.strip()) team = [] unknown = [] while namestr: item = self._roster.longest_prefix(namestr) if not item: unknown.append(namestr[0]) namestr = namestr[1:].lstrip() else: team.append(item.value) namestr = namestr[len(item.key):].lstrip() return team, ''.join(unknown)
async def _regex(bot: Bot, event: CQEvent, state: T_State) -> bool: if event.get_type() != "message": return False text = str(event.get_message()) if normal: text = normalize_str(text) matched = pattern.search(text) if matched: state['match'] = matched state["_matched"] = matched.group() state["_matched_groups"] = matched.groups() state["_matched_dict"] = matched.groupdict() return True else: return False
async def ichi_rec(bot: Bot, event: CQEvent, state: T_State): await check_jewel_num(bot, event) uid = event.user_id jewel_limit.increase(uid, 150) user_info = await bot.get_stranger_info(user_id=uid) nickname = user_info.get('nickname', '未知用户') if isinstance(event, GroupMessageEvent): gid = event.group_id gacha = Gacha(_group_pool[gid]) chara, _ = gacha.gacha_one(gacha.up_prob, gacha.s3_prob, gacha.s2_prob) res = f'{chara.icon.cqcode} {chara.name} {"★"*chara.star}' await gacha_1.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 gacha_ichi(bot: Bot, event: CQEvent, state: T_State): if isinstance(event, PrivateMessageEvent): name = util.normalize_str(state['name']) if name in ('国', '国服', 'cn'): await gacha_1.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_1.finish('未知区服,请接区服简称\n※例:"来发单抽jp"') gacha = Gacha(name) chara, _ = gacha.gacha_one(gacha.up_prob, gacha.s3_prob, gacha.s2_prob) res = f'{chara.icon.cqcode} {chara.name} {"★"*chara.star}' await gacha_1.finish(Message(f'素敵な仲間が増えますよ!\n{res}'))
async def rank_sheet(bot: Bot, event: CQEvent, state: T_State): user_info = await bot.get_stranger_info(user_id=event.user_id) nickname = user_info.get('nickname', '未知用户') name = util.normalize_str(state['name']) if name in ('国', '国服', 'cn'): if isinstance(event, GroupMessageEvent): await rank.finish(f'>{nickname}\n请选择详细区服\n※例:"rank表b服"或"rank表台服"') elif isinstance(event, PrivateMessageEvent): await rank.finish('请选择详细区服\n※例:"rank表b服"或"rank表台服"') elif name in ('b', 'b服', 'bl', 'bilibili', '陆', '陆服'): name = 'BL' elif name in ('台', '台服', 'tw', 'sonet'): name = 'TW' elif name in ('日', '日服', 'jp', 'cy', 'cygames'): name = 'JP' else: if isinstance(event, GroupMessageEvent): await rank.finish(f'>{nickname}\n未知区服,请重新选择\n*rank表日服\n*rank表台服\n*rank表b服') elif isinstance(event, PrivateMessageEvent): await rank.finish('未知区服,请重新选择\n*rank表日服\n*rank表台服\n*rank表b服') if isinstance(event, GroupMessageEvent): msg = [f'>{nickname}\n表格仅供参考'] elif isinstance(event, PrivateMessageEvent): msg = ['表格仅供参考'] if name == 'JP': msg.append(f'※不定期搬运自图中Q群\n※广告为原作者推广,与本bot无关\nR{rank_jp} rank表:\n{pjp}') # pos = match.group(3) # if not pos or '前' in pos: # msg.append(str(p4)) # if not pos or '中' in pos: # msg.append(str(p5)) # if not pos or '后' in pos: # msg.append(str(p6)) await bot.send(event, Message('\n'.join(msg))) elif name == 'TW': msg.append(f'※不定期搬运自漪夢奈特\n※详见油管频道\nR{rank_tw} rank表:\n{ptw}') await bot.send(event, Message('\n'.join(msg))) elif name == 'BL': msg.append(f'※不定期搬运自B站专栏\n※制作by席巴鸽\nR{rank_cn} rank表:\n{pcn}') await bot.send(event, Message('\n'.join(msg)))
def get_id(self, name): name = util.normalize_str(name) return self._roster[name] if name in self._roster else UNKNOWN
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