def cqcode(self) -> MessageSegment: if hoshino.config.RES_PROTOCOL == 'http': return MessageSegment.record(self.url) elif hoshino.config.RES_PROTOCOL == 'file': return MessageSegment.record(f'file:///{os.path.abspath(self.path)}') else: return MessageSegment.text('[不支持的协议]')
async def xcw_jiaochuan(bot, ev) -> MessageSegment: roll = random.random() if roll <= 0.05: filename = '喘息声.mp3' file = R.get('img/xcw/record', filename) try: rec = MessageSegment.record( f'file:///{os.path.abspath(file.path)}') await bot.send(ev, rec) except CQHttpError: sv.logger.error("发送失败") elif 0.05 < roll <= 0.15: file = get_xcw_biantai() try: rec = MessageSegment.record( f'file:///{os.path.abspath(file.path)}') await bot.send(ev, rec) except CQHttpError: sv.logger.error("发送失败") elif 0.15 < roll <= 0.4: filename = '叹气声.mp3' file = R.get('img/xcw/record', filename) try: rec = MessageSegment.record( f'file:///{os.path.abspath(file.path)}') await bot.send(ev, rec) except CQHttpError: sv.logger.error("发送失败") elif 0.4 < roll <= 0.75: filename = '叹气声2.mp3' file = R.get('img/xcw/record', filename) try: rec = MessageSegment.record( f'file:///{os.path.abspath(file.path)}') await bot.send(ev, rec) except CQHttpError: sv.logger.error("发送失败") elif 0.75 < roll <= 0.95: filename = '叹气声2.mp3' file = R.get('img/xcw/record', filename) try: rec = MessageSegment.record( f'file:///{os.path.abspath(file.path)}') await bot.send(ev, rec) except CQHttpError: sv.logger.error("发送失败") else: await bot.send(ev, '我懂了你是变态吧~', at_sender=True)
async def kkp(bot, ev): file = get_xcw_kkp() try: rec = MessageSegment.record(f'file:///{os.path.abspath(file.path)}') await bot.send(ev, rec) except CQHttpError: sv.logger.error("发送失败")
async def record_send(bot, ev: CQEvent): name = ev.message.extract_plain_text().strip() if not name: await bot.send(ev, '请发送"语音"+角色名,如"语音ue"') return cid = chara.name2id(name) if cid == chara.UNKNOWN: msg = f'兰德索尔似乎没有叫"{name}"的人...' await bot.send(ev, msg) return dir_path = R.get('record', str(cid)).path if not os.path.exists(dir_path): msg = f'未找到"{name}"的语音数据' await bot.send(ev, msg) return file_list = os.listdir(dir_path) file_path = None while not file_path or not os.path.isfile(file_path): filename = random.choice(file_list) file_path = os.path.join(dir_path, filename) if not file_path: msg = f'未找到"{name}"的语音数据' await bot.send(ev, msg) return rec = MessageSegment.record(f'file:///{os.path.abspath(file_path)}') await bot.send(ev, rec)
async def kfc(bot, ev) -> MessageSegment: try: rec = MessageSegment.record( f'file:///{os.path.dirname(__file__)}/record/{get_kfc()}') await bot.send(ev, rec) except CQHttpError: sv.logger.error("发送失败")
async def random_echo(bot, event): echo_folder = R.get('record/echo/').path files = os.listdir(echo_folder) filename = random.choice(files) file = R.get('record/echo/', filename) rec = MessageSegment.record(f'file:///{os.path.abspath(file.path)}') await bot.send(event, rec)
async def xcw(bot, ev) -> MessageSegment: # conditions all ok, send a xcw. file = get_xcw() try: rec = MessageSegment.record(f'file:///{os.path.abspath(file.path)}') await bot.send(ev, rec) except CQHttpError: sv.logger.error("发送失败")
async def cygames_voice_guess(bot, ev: CQEvent): try: if winner_recorder.get_on_off_status(): await bot.send(ev, "此轮游戏还没结束,请勿重复使用指令") return hoshino_res_path = os.path.expanduser(hoshino.config.RES_DIR) dir_path = os.path.join(hoshino_res_path, 'voice_ci') if not os.path.exists(dir_path): os.makedirs(dir_path) file_list = os.listdir(dir_path) if len(file_list) < DOWNLOAD_THRESHOLD: count = 0 await bot.send(ev, '正在下载语音资源,请耐心等待') estertion_id_list = get_estertion_id_list() for eid in estertion_id_list: file_number_list = ['001'] if eid not in MULTIPLE_VOICE_ESTERTION_ID_LIST else ['001', '002'] for file_number in file_number_list: url = f'https://redive.estertion.win/sound/vo_ci/{eid}/vo_ci_1{eid[1:]}01_{file_number}.m4a' file_name = url.split('/')[-1] if file_name not in file_list: file_path = os.path.join(dir_path, file_name) if not download(url, file_path): await bot.send(ev, '下载资源错误,请重试') return else: count = count+1 await bot.send(ev, f'下载完毕,此次下载语音包{count}个,目前共{len(os.listdir(dir_path))}个') file_list = os.listdir(dir_path) random.shuffle(file_list) if len(file_list) != 0: winner_recorder.turn_on() file_path = os.path.join(dir_path, file_list[0]) await bot.send(ev, f'注意:语音听不了请在手机端里听\n猜猜这个“cygames”语音来自哪位角色? ({ONE_TURN_TIME}s后公布答案)') record = MessageSegment.record(f'file:///{os.path.abspath(file_path)}') await bot.send(ev, record) estertion_id = file_list[0][7:10] chara_id = estertion_id2chara_id(int(estertion_id)) winner_recorder.set_correct_chara_id(chara_id) await asyncio.sleep(ONE_TURN_TIME) c = chara.fromid(chara_id) if len(winner_recorder.winner) == 0: msg_part = '很遗憾,没有人答对~' else: user_card_dict = await get_user_card_dict(bot, ev.group_id) msg_part = f'一共{len(winner_recorder.winner)}人答对,真厉害!他们是:\n' + '\n'.join([uid2card(uid, user_card_dict) for uid in winner_recorder.winner]) dir_path = os.path.join(hoshino_res_path, 'img', 'priconne', 'unit') if not os.path.exists(dir_path): os.makedirs(dir_path) cqcode = '' if not c.icon.exist else c.icon.cqcode cqcode = '' msg = f'正确答案是: {c.name}{cqcode}\n{msg_part}' await bot.send(ev, msg) winner_recorder.turn_off() except Exception as e: await bot.send(ev, '错误:\n' + str(e))
async def hour_call(): now = datetime.now(tz) if 2 <= now.hour <= 4: return # 宵禁 免打扰 msg = get_hour_call()[now.hour] chosen_file = random.choice(record_pre) + str(now.hour).zfill(2) + '00.mp3' record_path = os.path.join(record_folder, chosen_file) record = MessageSegment.record(f'file:///{os.path.abspath(record_path)}') await sv.broadcast(msg, 'hourcall', 0) await sv.broadcast(record, 'hourcall_record', 0)
async def sleep(bot, event): if random.random() <= 0.3: voice = R.get('record/echo/', '晚安.mp3') elif random.random() > 0.3 and random.random() <= 0.6: voice = R.get('record/echo/', '不想睡觉.mp3') elif random.random() > 0.6 and random.random() <= 0.8: voice = R.get('record/echo/', '不行不行.mp3') else: voice = R.get('record/echo/', '不想睡觉-n.mp3') rec = MessageSegment.record(f'file:///{os.path.abspath(voice.path)}') await bot.send(event, rec)
async def woaini(bot, event): if random.random() <= 0.3: voice = R.get('record/echo/', 'jiehun.mp3') elif random.random() > 0.3 and random.random() <= 0.6: voice = R.get('record/echo/', 'aini.mp3') elif random.random() > 0.6 and random.random() <= 0.8: voice = R.get('record/echo/', 'woaini.m4a') else: voice = R.get('record/echo/', 'jiehun2.mp3') rec = MessageSegment.record(f'file:///{os.path.abspath(voice.path)}') await bot.send(event, rec)
async def hso(bot, event): if random.random() <= 0.2: voice = R.get('record/echo/', 'hso.mp3') elif random.random() > 0.2 and random.random() <= 0.5: voice = R.get('record/echo/', 'cheche.mp3') elif random.random() > 0.5 and random.random() <= 0.6: voice = R.get('record/echo/', 'echohso.mp3') else: voice = R.get('record/echo/', 'hso.mp3') rec = MessageSegment.record(f'file:///{os.path.abspath(voice.path)}') await bot.send(event, rec)
async def biantai(bot, ev): if random.random() < 0.5: file = get_xcw_biantai() try: rec = MessageSegment.record( f'file:///{os.path.abspath(file.path)}') await bot.send(ev, rec) except CQHttpError: sv.logger.error("发送失败") else: await bot.send(ev, '变态~', at_sender=True)
async def exosend(bot, ev): uid = ev['user_id'] if not _nlmt.check(uid): await bot.send(ev, EXCEED_NOTICE, at_sender=True) return if exo_switch: r = random.choice([a, b, c, d, e, f, g, h, i, j]) print(r) if r == '1': uid = ev['user_id'] _nlmt.increase(uid) path = 'C:/Resources/explorion-voice/explosion/施法吟诵1.mp3' rec1 = MessageSegment.record(f'file:///{path}') await bot.send(ev, rec1) await bot.send(ev, text1) if r == '2': uid = ev['user_id'] _nlmt.increase(uid) path = 'C:/Resources/explorion-voice/explosion/施法吟诵2.mp3' rec2 = MessageSegment.record(f'file:///{path}') await bot.send(ev, rec2) await bot.send(ev, text2) if r == '3': uid = ev['user_id'] _nlmt.increase(uid) path = 'C:/Resources/explorion-voice/explosion/施法吟诵3.mp3' rec3 = MessageSegment.record(f'file:///{path}') await bot.send(ev, rec3) await bot.send(ev, text3) if r == '4': uid = ev['user_id'] _nlmt.increase(uid) path = 'C:/Resources/explorion-voice/explosion/施法吟诵4.mp3' rec4 = MessageSegment.record(f'file:///{path}') await bot.send(ev, rec4) await bot.send(ev, text4) if r == '5': uid = ev['user_id'] _nlmt.increase(uid) path = 'C:/Resources/explorion-voice/explosion/施法吟诵5.mp3' rec5 = MessageSegment.record(f'file:///{path}') await bot.send(ev, rec5) await bot.send(ev, text5) if r == '6': uid = ev['user_id'] _nlmt.increase(uid) path = 'C:/Resources/explorion-voice/explosion/施法吟诵6.mp3' rec6 = MessageSegment.record(f'file:///{path}') await bot.send(ev, rec6) await bot.send(ev, text6) if r == '7': uid = ev['user_id'] _nlmt.increase(uid) path = 'C:/Resources/explorion-voice/explosion/施法吟诵7.mp3' rec7 = MessageSegment.record(f'file:///{path}') await bot.send(ev, rec7) await bot.send(ev, text7) if r == '8': uid = ev['user_id'] _nlmt.increase(uid) path = 'C:/Resources/explorion-voice/explosion/施法吟诵8.mp3' rec8 = MessageSegment.record(f'file:///{path}') await bot.send(ev, rec8) await bot.send(ev, text8) if r == '9': uid = ev['user_id'] _nlmt.increase(uid) path = 'C:/Resources/explorion-voice/explosion/施法吟诵9.mp3' rec9 = MessageSegment.record(f'file:///{path}') await bot.send(ev, rec9) await bot.send(ev, text9) if r == '10': uid = ev['user_id'] _nlmt.increase(uid) path = 'C:/Resources/explorion-voice/explosion/施法吟诵10.mp3' rec10 = MessageSegment.record(f'file:///{path}') await bot.send(ev, rec10) await bot.send(ev, text10)
async def shengrige(bot, event): voice = R.get('record/echo/', 'shengri.mp3') rec = MessageSegment.record(f'file:///{os.path.abspath(voice.path)}') await bot.send(event, rec)
def cqcode(self) -> MessageSegment: if get_bot().config.RESOURCE_URL: return MessageSegment.record(self.url)
def cqcode(self) -> MessageSegment: if hoshino.config.RES_PROTOCOL == 'file': return MessageSegment.record(f'file:///{os.path.abspath(self.path)}')