コード例 #1
0
async def check(bot, ev):
    game = gm.get_game(ev.group_id)
    if game.winner:
        return
    c = chara.fromid(game.answer)
    gm.exit_game(ev.group_id)
    await bot.send(ev, f"正确答案是: {c.name} {c.icon.cqcode}\n很遗憾,没有人答对~")
コード例 #2
0
ファイル: whois.py プロジェクト: Lostdegree/HoshinoBot
async def whois(bot, ev: CQEvent):
    uid = ev.user_id
    if not lmt.check(uid):
        await bot.send(ev,
                       f'兰德索尔花名册冷却中(剩余 {int(lmt.left_time(uid)) + 1}秒)',
                       at_sender=True)
        return
    lmt.start_cd(uid)

    name = ev.message.extract_plain_text().strip()
    if not name:
        await bot.send(ev, '请发送"谁是"+别称,如"谁是霸瞳"')
        return
    id_ = chara.name2id(name)
    confi = 100
    guess = False
    if id_ == chara.UNKNOWN:
        id_, guess_name, confi = chara.guess_id(name)
        guess = True
    c = chara.fromid(id_)

    msg = ''
    if guess:
        lmt.start_cd(uid, 60)
        msg = f'兰德索尔似乎没有叫"{name}"的人...\n角色别称补全计划: github.com/Ice-Cirno/HoshinoBot/issues/5'
        await bot.send(ev, msg)
        msg = f'\n您有{confi}%的可能在找{guess_name} '

    if confi > 60:
        msg += f'{c.icon.cqcode} {c.name}'
        await bot.send(ev, msg, at_sender=True)
コード例 #3
0
ファイル: whois.py プロジェクト: Lostdegree/HoshinoBot
async def ubrec(bot, ev: CQEvent):
    uid = ev.user_id
    if not lmt.check(uid):
        await bot.send(ev,
                       f'您〇太快了,请稍等一会儿(剩余 {int(lmt.left_time(uid)) + 1}秒)',
                       at_sender=True)
        return
    lmt.start_cd(uid, 5)

    name = ev.message.extract_plain_text().strip()
    if not name:
        await bot.send(ev, '请发送"谁是"+别称,如"谁是霸瞳"')
        return
    id_ = chara.name2id(name)
    confi = 100
    guess = False
    if id_ == chara.UNKNOWN:
        id_, guess_name, confi = chara.guess_id(name)
        guess = True
    c = chara.fromid(id_)

    msg = ''
    if guess:
        lmt.start_cd(uid, 60)
        msg = f'兰德索尔似乎没有叫"{name}"的人...\n角色别称补全计划: github.com/Ice-Cirno/HoshinoBot/issues/5 \n您有{confi}%的可能在找{guess_name} '
        await bot.send(ev, msg)
        #msg = f'\n您有{confi}%的可能在找{guess_name} '

    if confi > 60 and R.rec(f'priconne/rec/rec_unit_{id_}_ub.mp3').exist:
        msg = R.rec(f'priconne/rec/rec_unit_{id_}_ub.mp3').cqcode
        await bot.send(ev, msg, at_sender=False)

    else:
        await bot.send(ev, f'暂时未收录对应语音,该宁来表演了~', at_sender=True)
コード例 #4
0
ファイル: voiceguess.py プロジェクト: PaperPig/hoshino_xcw
async def voice_guess(bot, ev: CQEvent):
    if gm.is_playing(ev.group_id):
        await bot.finish(ev, "游戏仍在进行中…")
    with gm.start_game(ev.group_id) as game:
        record_path = os.path.join(HOSHINO_RES_PATH, 'record')
        if not os.path.exists(record_path):
            await cygames_voice_guess(bot, ev)
            return
        file_list = os.listdir(record_path)
        chosen_chara = random.choice(file_list)
        chara_path = os.path.join(HOSHINO_RES_PATH, 'record', chosen_chara)
        chara_list = os.listdir(chara_path)
        chosen_file = random.choice(chara_list)
        file_path = os.path.join(chara_path, chosen_file)
        await bot.send(ev, f'猜猜这段语音来自哪位角色? ({ONE_TURN_TIME}s后公布答案)')
        await bot.send(
            ev, MessageSegment.record(f'file:///{os.path.abspath(file_path)}'))
        #兼容"小仓唯骂我"插件的语音资源
        if chosen_chara == 'mawo':
            game.answer = 1036
        else:
            game.answer = int(chosen_chara)
        #print(chara.fromid(game.answer).name)
        await asyncio.sleep(ONE_TURN_TIME)
        # 结算
        if game.winner:
            return
        c = chara.fromid(game.answer)
    await bot.send(ev, f"正确答案是: {c.name} {c.icon.cqcode}\n很遗憾,没有人答对~")
コード例 #5
0
async def leave_girl(bot, ev: CQEvent):
    args = ev.message.extract_plain_text().split()
    gid = ev.group_id
    uid = ev.user_id
    if not args:
        await bot.send(ev, '请输入分手吧!/丢弃+pcr角色名。', at_sender=True)
        return
    name = args[0]
    cid = chara.name2id(name)
    if cid == 1000:
        await bot.send(ev, '请输入正确的pcr角色名。', at_sender=True)
        return
    duel = DuelCounter()
    score_counter = ScoreCounter2()
    owner = duel._get_card_owner(gid, cid)
    c = chara.fromid(cid)

    if owner == 0 or int(owner) != uid:
        await bot.send(ev,
                       f'[CQ:at,qq={uid}]{c.name}现在还不是你的女友哦。',
                       at_sender=True)
        return
    else:
        if cid > 10000:
            #检查金币是否足够分手
            if score_counter._judge_score(gid, uid, 500) == 0:
                msg = '您的金币不足,抛弃男公主需支付500分手费。'
                await bot.send(ev, msg, at_sender=True)
                return
            score_counter._reduce_score(gid, uid, 500)
            msg = f'[CQ:at,qq={uid}]你抛弃了男公主!支付分手费500金币。\n{c.name}流着眼泪离开了~'
        else:
            msg = f'[CQ:at,qq={uid}]{c.name}流着眼泪离开了~'
        duel._delete_card(gid, uid, cid)
        await bot.send(ev, msg)
コード例 #6
0
def get_cqcode(chara_id):
    dir_path = os.path.join(os.path.expanduser(hoshino.config.RES_DIR), 'img', 'priconne', 'unit')
    if not os.path.exists(dir_path):
        os.makedirs(dir_path)
    c = chara.fromid(chara_id)
    cqcode = '' if not c.icon.exist else c.icon.cqcode
    return c.name, cqcode
コード例 #7
0
async def avatar_guess(bot, ev: CQEvent):
    try:
        if winner_judger.get_on_off_status():
            await bot.send(ev, "此轮游戏还没结束,请勿重复使用指令")
            return
        winner_judger.turn_on()
        chara_id_list = list(_pcr_data.CHARA_NAME.keys())
        while True:
            random.shuffle(chara_id_list)
            if chara_id_list[0] not in BLACKLIST_ID: break
        winner_judger.set_correct_chara_id(chara_id_list[0])
        dir_path = os.path.join(os.path.expanduser(hoshino.config.RES_DIR),
                                'img', 'priconne', 'unit')
        if not os.path.exists(dir_path):
            os.makedirs(dir_path)
        c = chara.fromid(chara_id_list[0])
        img = c.icon.open()
        left = math.floor(random.random() * (129 - PIC_SIDE_LENGTH))
        upper = math.floor(random.random() * (129 - PIC_SIDE_LENGTH))
        cropped = img.crop(
            (left, upper, left + PIC_SIDE_LENGTH, upper + PIC_SIDE_LENGTH))
        file_path = os.path.join(dir_path, 'cropped_avatar.png')
        cropped.save(file_path)
        image = MessageSegment.image(f'file:///{os.path.abspath(file_path)}')
        msg = f'猜猜这个图片是哪位角色头像的一部分?({ONE_TURN_TIME}s后公布答案)'
        await bot.send(ev, msg + image)
        await asyncio.sleep(ONE_TURN_TIME)
        if winner_judger.winner != '':
            winner_judger.turn_off()
            return
        msg = f'正确答案是: {c.name}{c.icon.cqcode}\n很遗憾,没有人答对~'
        winner_judger.turn_off()
        await bot.send(ev, msg)
    except Exception as e:
        await bot.send(ev, '错误:\n' + str(e))
コード例 #8
0
async def avatar_guess(bot, ev: CQEvent):
    if winner_judger.get_on_off_status(ev.group_id):
        await bot.send(ev, "此轮游戏还没结束,请勿重复使用指令")
        return
    winner_judger.turn_on(ev.group_id)
    chara_id_list = list(_pcr_data.CHARA_NAME.keys())
    list_len = len(chara_id_list) - 1
    while True:
        index = random.randint(0, list_len)
        if chara_id_list[index] not in BLACKLIST_ID: break
    winner_judger.set_correct_chara_id(ev.group_id, chara_id_list[index])
    dir_path = os.path.join(os.path.expanduser(hoshino.config.RES_DIR), 'img', 'priconne', 'unit')
    if not os.path.exists(dir_path):
        os.makedirs(dir_path)
    c = chara.fromid(chara_id_list[index])
    img = c.icon.open()
    left = math.floor(random.random()*(129-PIC_SIDE_LENGTH))
    upper = math.floor(random.random()*(129-PIC_SIDE_LENGTH))
    cropped = img.crop((left, upper, left+PIC_SIDE_LENGTH, upper+PIC_SIDE_LENGTH))
    cropped = MessageSegment.image(util.pic2b64(cropped))
    msg = f'猜猜这个图片是哪位角色头像的一部分?({ONE_TURN_TIME}s后公布答案){cropped}'
    await bot.send(ev, msg)
    await asyncio.sleep(ONE_TURN_TIME)
    if winner_judger.get_winner(ev.group_id) != '':
        winner_judger.turn_off(ev.group_id)
        return
    msg =  f'正确答案是: {c.name}{c.icon.cqcode}\n很遗憾,没有人答对~'
    winner_judger.turn_off(ev.group_id)
    await bot.send(ev, msg)
コード例 #9
0
ファイル: cechara.py プロジェクト: a376148946/pcrduel
async def my_fashion_info(bot, ev: CQEvent):
    args = ev.message.extract_plain_text().split()
    gid = ev.group_id
    uid = ev.user_id
    if not args:
        await bot.send(ev, '请输入我的女友+pcr角色名。', at_sender=True)
        return
    name = args[0]
    cid = chara.name2id(name)
    if cid == 1000:
        await bot.send(ev, '请输入正确的pcr角色名。', at_sender=True)
        return
    duel = DuelCounter()
    score_counter = ScoreCounter2()
    c = chara.fromid(cid)
    nvmes = get_nv_icon(cid)
    lh_msg = ''
    fashioninfo = get_fashion(cid)
    up_icon = ''
    up_info = duel._get_fashionup(gid, uid, cid, 0)
    jishu = 0
    up_name = ''
    if fashioninfo:
        for fashion in fashioninfo:
            buy_info = duel._get_fashionbuy(gid, uid, cid, fashion['fid'])
            if up_info == fashion['fid']:
                up_icon = fashion['icon']
                up_name = fashion['name']
            if buy_info:
                if up_info != fashion['fid']:
                    jishu = jishu + 1
                    if jishu < 3:
                        lh_msg = lh_msg + f"\n{fashion['icon']}\n{fashion['name']}"
    owner = duel._get_card_owner(gid, cid)
    if uid != owner:
        msg = f'{c.name}现在正在\n[CQ:at,qq={owner}]的身边哦,您无法查询哦。'
        await bot.send(ev, msg)
        return
    if owner == 0:
        await bot.send(ev, f'{c.name}现在还是单身哦,快去约到她吧。{nvmes}', at_sender=True)
        return
    if uid == owner:
        queen_msg = ''
        if duel._get_queen_owner(gid, cid) != 0:
            queen_msg = f'现在是您的妻子\n'
        if duel._get_favor(gid, uid, cid) == None:
            duel._set_favor(gid, uid, cid, 0)
        favor = duel._get_favor(gid, uid, cid)
        relationship, text = get_relationship(favor)
        if up_icon:
            nvmes = up_icon
        up_msg = ''
        if up_name:
            up_msg = f"\n目前穿戴的时装是{up_name}\n"
        if lh_msg:
            lh_msg = f"\n您为{c.name}购买的时装有(只显示未穿的2件):" + lh_msg
        msg = f'\n{c.name}{queen_msg}对你的好感是{favor}\n你们的关系是{relationship}\n“{text}”{up_msg}{nvmes}{lh_msg}'
    await bot.send(ev, msg, at_sender=True)
コード例 #10
0
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))
コード例 #11
0
async def select_player(bot, ev: CQEvent):
    global g_result, g_uid
    pkey = ev.message.extract_plain_text().strip()
    id_ = chara.name2id(pkey)
    p = chara.fromid(id_)
    if p.name not in g_result:
        await bot.finish(ev, f'所选角色未在参赛角色中')
    await bot.send(ev, f'已选择{p.name},比赛开始', at_sender=True)
    await compe(bot, ev, p.name)
    g_uid = 0
コード例 #12
0
def get_chara_name(card_id):
    chara_id = card_id % 10000
    if 3000 > chara_id > 2000:
        chara_id -= 1000
        rarity_desc = '【超稀有】的'
    elif 2000 > chara_id > 1000 or chara_id > 3000:
        rarity_desc = '【稀有】的'
    else:
        chara_id += 1000
        rarity_desc = '【普通】的'
    return rarity_desc, chara.fromid(chara_id).name
コード例 #13
0
ファイル: duelconfig.py プロジェクト: a376148946/pcrduel
def get_nv_icon(cid):
    c = chara.fromid(cid)
    mes = c.icon.cqcode
    PIC_PATH = os.path.join(FILE_PATH, 'fullcard')
    path = os.path.join(PIC_PATH, f'{cid}31.png')
    if os.path.exists(path):
        img = Image.open(path)
        bio = BytesIO()
        img.save(bio, format='PNG')
        base64_str = 'base64://' + base64.b64encode(bio.getvalue()).decode()
        mes = f"[CQ:image,file={base64_str}]"
    return mes
コード例 #14
0
async def add_girl(bot, ev: CQEvent):
    gid = ev.group_id
    uid = ev.user_id
    duel = DuelCounter()
    score_counter = ScoreCounter2()

    if duel._get_level(gid, uid) == 0:
        msg = '您还未在本群创建过贵族,请发送 创建贵族 开始您的贵族之旅。'
        duel_judger.turn_off(ev.group_id)

        await bot.send(ev, msg, at_sender=True)
        return
    else:
        # 防止女友数超过上限
        level = duel._get_level(gid, uid)
        noblename = get_noblename(level)
        girlnum = get_girlnum(level)
        cidlist = duel._get_cards(gid, uid)
        cidnum = len(cidlist)
        if cidnum >= girlnum:
            msg = '您的女友已经满了哦,快点发送[升级贵族]进行升级吧。'
            await bot.send(ev, msg, at_sender=True)
            return
        score = score_counter._get_score(gid, uid)
        if score < GACHA_COST:
            msg = f'您的金币不足{GACHA_COST}哦。'
            await bot.send(ev, msg, at_sender=True)
            return
        newgirllist = get_newgirl_list(gid)
        # 判断女友是否被抢没
        if len(newgirllist) == 0:
            await bot.send(ev, '这个群已经没有可以约到的新女友了哦。', at_sender=True)
            return
        score_counter._reduce_score(gid, uid, GACHA_COST)

        # 招募女友失败
        if random.random() < 0.4:
            losetext = random.choice(Addgirlfail)
            msg = f'\n{losetext}\n您花费了{GACHA_COST}金币,但是没有约到新的女友。'
            await bot.send(ev, msg, at_sender=True)
            return

        # 招募女友成功
        cid = random.choice(newgirllist)

        duel._add_card(gid, uid, cid)
        c = chara.fromid(cid)
        wintext = random.choice(Addgirlsuccess)
        msg = f'\n{wintext}\n招募女友成功!\n您花费了{GACHA_COST}金币\n新招募的女友为:{c.name}{c.icon.cqcode}'
        await bot.send(ev, msg, at_sender=True)
コード例 #15
0
async def bot_crazy(bot, ev: CQEvent):
    template_image_name = ''
    for seg in ev.message:
        if (seg.type == 'image'):
            template_image_name = main.download_template_image(seg.data['url'])
            if (template_image_name == ""):
                logger.error(f'Fail to find a image in message [{ev.message}]')
                return
            else:
                break
    result = main.transform_coordinate_to_chara_id(template_image_name)
    if result[0]:
        chara_name = chara.fromid(result[1]).name
        #it could be very hard to answer faster than bot. please add a time.sleep. onegai
        await bot.send(ev, chara_name)
    if not result[0] and result[1] != '':
        await bot.send(ev, result[1])
コード例 #16
0
ファイル: game.py プロジェクト: jyk714017560/HoshinoBot
async def cardguess(bot, ev: CQEvent):

    if ev['message_type'] != 'group':
        await bot.send(ev, '小游戏仅支持群组游玩,好孩子要学会和伙伴一起玩哦~')
        return

    try:
        gid = str(ev.group_id)
        if _group_game[gid]:
            await bot.send(ev, '游戏进行中,好孩子要学会耐心等候哦~')
            return
        _group_game[gid] = 'cardguess'
        card = random.choice(os.listdir(cardpath))
        card_id = int(re.compile(r'^card_(\d{4}).*').match(card).group(1))
        c = chara.fromid(card_id)
        _group_parameter[gid] = card_id

        img = Image.open(os.path.join(cardpath, card))
        h = img.height
        w = img.width
        box = random.choice([(0, 0, 200, 200), (w - 200, 0, w, 200),
                             (0, h - 200, 200, h), (w - 200, h - 200, w, h)])
        res = img.crop(box)
        res = pic2b64(res)
        res = MessageSegment.image(res)

        await bot.send(ev, f'猜猜这张卡面来自哪位角色? ({ONE_TURN_TIME}s后公布答案)\n{res}')
        glmt.start_cd(gid)
        await asyncio.sleep(ONE_TURN_TIME)
        imgcard = R.img(f'priconne/card/{card}').cqcode
        msg = [f'锵锵,正确答案是: \n{imgcard}{c.name}']
        if not _group_winner[gid]:
            msg.append('很遗憾,没有人答对呢~')
            await bot.send(ev, '\n'.join(msg))
        else:
            _group_winner[gid] = list(set(_group_winner[gid]))
            msg.append(f'ヤバイですね!一共有{len(_group_winner[gid])}人答对,他们是:')
            for n in _group_winner[gid]:
                msg.append(str(n))
            await bot.send(ev, '\n'.join(msg))
    except Exception as e:
        logger.error(f'{e}')
        await bot.send(ev, '佩可似乎出错了o(╥﹏╥)o,快联系主人来看看吧~')
    del _group_game[gid]
    del _group_winner[gid]
コード例 #17
0
async def on_input_chara_name(bot, ev: CQEvent):
    try:
        if winner_judger.get_on_off_status(ev.group_id):
            s = ev.message.extract_plain_text()
            cid = chara.name2id(s)
            if cid != chara.UNKNOWN and cid == winner_judger.get_correct_chara_id(ev.group_id) and winner_judger.get_winner(ev.group_id) == '':
                winner_judger.record_winner(ev.group_id, ev.user_id)
                winning_counter = WinningCounter()
                winning_counter._record_winning(ev.group_id, ev.user_id)
                winning_count = winning_counter._get_winning_number(ev.group_id, ev.user_id)
                user_card_dict = await get_user_card_dict(bot, ev.group_id)
                user_card = uid2card(ev.user_id, user_card_dict)
                msg_part = f'{user_card}猜对了,真厉害!TA已经猜对{winning_count}次了~\n(此轮游戏将在时间到后自动结束,请耐心等待)'
                c = chara.fromid(winner_judger.get_correct_chara_id(ev.group_id))
                msg =  f'正确答案是: {c.name}{c.icon.cqcode}\n{msg_part}'
                await bot.send(ev, msg)
    except Exception as e:
        await bot.send(ev, '错误:\n' + str(e))
コード例 #18
0
async def send_girl(bot, ev: CQEvent):
    msg = str(ev.message)
    if not msg:
        await bot.send(ev, '格式错误。', at_sender=True)
        return
    match = re.match(r'(.+)\[CQ:at,qq=(\d+)\]', msg)
    gid = ev.group_id
    uid = ev.user_id
    name = match.group(1)
    accepter = int(match.group(2))
    cid = chara.name2id(name)
    if cid == 1000:
        await bot.send(ev, '请输入正确的pcr角色名。', at_sender=True)
        return
    duel = DuelCounter()
    score_counter = ScoreCounter2()
    owner = duel._get_card_owner(gid, cid)
    c = chara.fromid(cid)

    if owner == 0 or int(owner) != uid:
        await bot.send(ev,
                       f'[CQ:at,qq={uid}]{c.name}现在还不是你的女友哦。',
                       at_sender=True)
        return
    else:
        if send_judger.get_status(gid, uid, accepter):
            await bot.send(ev, f'请勿重复使用指令。', at_sender=True)
            return
        send_judger.accept_on_off(gid, uid, accepter, False)
        send_judger.turn_on_off(gid, uid, accepter, True)
        msg = f'[CQ:at,qq={accepter}]对方向您赠送了女友{c.name},\n{c.icon.cqcode}\n请在{WAIT_TIME}秒内[YES/NO]@xxx。'
        await bot.send(ev, msg)

        await asyncio.sleep(WAIT_TIME)
        status = send_judger.get_accept_status(gid, uid, accepter)
        send_judger.turn_on_off(gid, uid, accepter, False)
        if not status:
            msg = f'对方拒绝了您的赠送请求'
            await bot.send(ev, msg, at_sender=True)
            return
        duel._delete_card(gid, uid, cid)
        duel._add_card(gid, accepter, cid)
        msg = f'[CQ:at,qq={uid}]{c.name}对你依依不舍,但还是投入了[CQ:at,qq={accepter}]的怀抱。'
        await bot.send(ev, msg)
コード例 #19
0
async def description_guess(bot, ev: CQEvent):
    if gm.is_playing(ev.group_id):
        await bot.finish(ev, "游戏仍在进行中…")
    with gm.start_game(ev.group_id) as game:
        game.answer = random.choice(list(_pcr_data.CHARA_PROFILE.keys()))
        profile = _pcr_data.CHARA_PROFILE[game.answer]
        kws = list(profile.keys())
        kws.remove('名字')
        random.shuffle(kws)
        kws = kws[:TURN_NUMBER]
        await bot.send(ev, f"{PREPARE_TIME}秒后每隔{ONE_TURN_TIME}秒我会给出某位角色的一个描述,根据这些描述猜猜她是谁~")
        await asyncio.sleep(PREPARE_TIME)
        for i, k in enumerate(kws):
            await bot.send(ev, f"提示{i + 1}/{len(kws)}:\n她的{k}是 {profile[k]}")
            await asyncio.sleep(ONE_TURN_TIME)
            if game.winner:
                return
        c = chara.fromid(game.answer)
    await bot.send(ev, f"正确答案是:{c.name} {c.icon.cqcode}\n很遗憾,没有人答对~")
コード例 #20
0
ファイル: voiceguess.py プロジェクト: PaperPig/hoshino_xcw
async def cygames_voice_guess(bot, ev: CQEvent):
    if gm.is_playing(ev.group_id):
        await bot.finish(ev, "游戏仍在进行中…")
    with gm.start_game(ev.group_id) as game:
        await download_voice_ci(bot, ev, sv.logger)
        file_list = os.listdir(DIR_PATH)
        chosen_file = random.choice(file_list)
        file_path = os.path.join(DIR_PATH, chosen_file)
        await bot.send(ev, f'猜猜这个“cygames”语音来自哪位角色? ({ONE_TURN_TIME}s后公布答案)')
        await bot.send(
            ev, MessageSegment.record(f'file:///{os.path.abspath(file_path)}'))
        estertion_id = chosen_file[7:10]
        chara_id = estertion_id2chara_id(int(estertion_id))
        game.answer = chara_id
        await asyncio.sleep(ONE_TURN_TIME)
        # 结算
        if game.winner:
            return
        c = chara.fromid(game.answer)
    await bot.send(ev, f"正确答案是: {c.name} {c.icon.cqcode}\n很遗憾,没有人答对~")
コード例 #21
0
ファイル: avatar_guess.py プロジェクト: LHXnois/HoshinoBot
async def avatar_guess(bot, ev: CQEvent):
    if gm.is_playing(ev.group_id):
        await bot.finish(ev, "游戏仍在进行中…")
    with gm.start_game(ev.group_id) as game:
        ids = list(_pcr_data.CHARA_NAME.keys())
        game.answer = random.choice(ids), random.choice((3, 6))
        while chara.is_npc(game.answer[0]):
            game.answer = random.choice(ids), random.choice((3, 6))
        c = chara.fromid(game.answer[0], game.answer[1])
        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 = Seg.image(util.pic2b64(cropped))
        await bot.send(ev, f"猜猜这个图片是哪位角色头像的一部分?({ONE_TURN_TIME}s后公布答案) {cropped}")
        await asyncio.sleep(ONE_TURN_TIME)
        if game.winner:
            return
    await bot.send(ev, f"正确答案是:{c.name} {c.icon.cqcode}\n很遗憾,没有人答对~")
コード例 #22
0
async def add_noble(bot, ev: CQEvent):
    try:
        gid = ev.group_id
        uid = ev.user_id
        duel = DuelCounter()
        if duel._get_level(gid, uid) != 0:
            msg = '您已经在本群创建过贵族了,请发送 查询贵族 查询。'
            await bot.send(ev, msg, at_sender=True)
            return
        else:
            cid = get_pcr_id()
            # 防止情人重复
            while duel._get_card_owner(gid, cid) != 0:
                cid = get_pcr_id()
            duel._add_card(gid, uid, cid)
            c = chara.fromid(cid)
            duel._set_level(gid, uid, 1)
            msg = f'\n创建贵族成功!\n您的初始爵位是男爵\n可以拥有3名女友。\n为您分配的初始女友为:{c.name}{c.icon.cqcode}'
            await bot.send(ev, msg, at_sender=True)
    except Exception as e:
        await bot.send(ev, '错误:\n' + str(e))
コード例 #23
0
async def search_girl(bot, ev: CQEvent):
    args = ev.message.extract_plain_text().split()
    gid = ev.group_id
    if not args:
        await bot.send(ev, '请输入查女友+pcr角色名。', at_sender=True)
        return
    name = args[0]
    cid = chara.name2id(name)
    if cid == 1000:
        await bot.send(ev, '请输入正确的pcr角色名。', at_sender=True)
        return
    duel = DuelCounter()
    owner = duel._get_card_owner(gid, cid)
    c = chara.fromid(cid)

    if owner == 0:
        await bot.send(ev, f'{c.name}现在还是单身哦,快去约到她吧。', at_sender=True)
        return
    else:
        msg = f'{c.name}现在正在\n[CQ:at,qq={owner}]的身边哦。{c.icon.cqcode}'
        await bot.send(ev, msg)
コード例 #24
0
ファイル: game.py プロジェクト: jyk714017560/HoshinoBot
async def voiceguess(bot, ev: CQEvent):

    if ev['message_type'] != 'group':
        await bot.send(ev, '小游戏仅支持群组游玩,好孩子要学会和伙伴一起玩哦~')
        return

    try:
        gid = str(ev.group_id)
        if _group_game[gid]:
            await bot.send(ev, '游戏进行中,好孩子要学会耐心等候哦~')
            return
        _group_game[gid] = 'voiceguess'
        voice = random.choice(os.listdir(voicepath))
        voice_id = int('1' + re.compile(
            r'^vo_title_(customize_)?(\d{4}).*').match(voice).group(2)[-3:])
        c = chara.fromid(voice_id)
        _group_parameter[gid] = voice_id

        await bot.send(ev, f'猜猜这个语音来自哪位角色? ({ONE_TURN_TIME}s后公布答案)')
        await bot.send(ev, R.record(f"title_silk/{voice}").cqcode)
        glmt.start_cd(gid)
        await asyncio.sleep(ONE_TURN_TIME)
        msg = [f'锵锵,正确答案是: \n{c.icon.cqcode}{c.name}']
        if not _group_winner[gid]:
            msg.append('很遗憾,没有人答对呢~')
            await bot.send(ev, '\n'.join(msg))
        else:
            _group_winner[gid] = list(set(_group_winner[gid]))
            msg.append(f'ヤバイですね!一共有{len(_group_winner[gid])}人答对,他们是:')
            for n in _group_winner[gid]:
                msg.append(str(n))
            await bot.send(ev, '\n'.join(msg))
    except Exception as e:
        logger.error(f'{e}')
        await bot.send(ev, '佩可似乎出错了o(╥﹏╥)o,快联系主人来看看吧~')
    del _group_game[gid]
    del _group_winner[gid]
コード例 #25
0
async def on_sended_chara_info(bot, ev: CQEvent):
    global BLOOD_TYPE, ANSWERS_DIC_CACHE
    try:
        if game_status.get_on_off_status(ev.group_id):
            s = ev.message.extract_plain_text()
            if '提示' and '她的' in s:
                chara_info = s.replace('提示', '').replace('/5:', '').replace(
                    '\n', ' ').replace('她的', '').replace('是', '')
                chara_info_list = chara_info.split()
                #print(chara_info_list)
                if not len(ANSWERS_DIC_CACHE) == 0:
                    if chara_info_list[0] == 5 and BLOOD_TYPE != '':
                        answers = {}
                        for cache_chara_id in ANSWERS_DIC_CACHE.keys():
                            if ANSWERS_DIC_CACHE[cache_chara_id][
                                    '血型'] == BLOOD_TYPE:
                                answers[cache_chara_id] = ANSWERS_DIC_CACHE[
                                    cache_chara_id]
                        ANSWERS_DIC_CACHE = answers
                    if chara_info_list[1] == '血型':
                        BLOOD_TYPE = chara_info_list[2]
                    else:
                        answers = {}
                        for chara_id in ANSWERS_DIC_CACHE.keys():
                            chara_properties = ANSWERS_DIC_CACHE[chara_id][
                                chara_info_list[1]]
                            if chara_properties == chara_info_list[2]:
                                answers[chara_id] = ANSWERS_DIC_CACHE[chara_id]
                        ANSWERS_DIC_CACHE = answers
                else:
                    if chara_info_list[1] == '血型':
                        BLOOD_TYPE = chara_info_list[2]
                    else:
                        for chara_id in _pcr_data.CHARA_PROFILE.keys():
                            chara_properties = _pcr_data.CHARA_PROFILE[
                                chara_id][chara_info_list[1]]
                            if chara_properties == chara_info_list[2]:
                                ANSWERS_DIC_CACHE[
                                    chara_id] = _pcr_data.CHARA_PROFILE[
                                        chara_id]
                if len(ANSWERS_DIC_CACHE) < 4 and len(ANSWERS_DIC_CACHE) != 0:
                    answers = {}
                    if not BLOOD_TYPE == '':
                        for cache_chara_id in ANSWERS_DIC_CACHE.keys():
                            if ANSWERS_DIC_CACHE[cache_chara_id][
                                    '血型'] == BLOOD_TYPE:
                                answers[cache_chara_id] = ANSWERS_DIC_CACHE[
                                    cache_chara_id]
                        ANSWERS_DIC_CACHE = answers
                    print(ANSWERS_DIC_CACHE)
                    for cache_chara_id in ANSWERS_DIC_CACHE.keys():
                        chara_name = chara.fromid(cache_chara_id).name
                        await bot.send(ev, chara_name)
                    game_status.turn_off(ev.group_id)
                #print(ANSWERS_DIC_CACHE)
            elif '猜对了,真厉害!' in s:
                game_status.turn_off(ev.group_id)
            elif '很遗憾,没有人答对~' in s:
                game_status.turn_off(ev.group_id)
    except Exception as e:
        await bot.send(ev, '错误:\n' + str(e))
コード例 #26
0
async def nobleduel(bot, ev: CQEvent):
    if ev.message[0].type == 'at':
        id2 = int(ev.message[0].data['qq'])
    else:
        await bot.finish(ev, '参数格式错误, 请重试')
    if duel_judger.get_on_off_status(ev.group_id):
        await bot.send(ev, "此轮决斗还没结束,请勿重复使用指令。")
        return
    gid = ev.group_id
    duel_judger.turn_on(gid)
    id1 = ev.user_id
    duel = DuelCounter()

    if duel._get_level(gid, id1) == 0:
        msg = f'[CQ:at,qq={id1}]决斗发起者还未在创建过贵族\n请发送 创建贵族 开始您的贵族之旅。'
        duel_judger.turn_off(ev.group_id)
        await bot.send(ev, msg)
        return
    if duel._get_cards(gid, id1) == {}:
        msg = f'[CQ:at,qq={id1}]您没有女友,不能参与决斗哦。'
        duel_judger.turn_off(ev.group_id)
        await bot.send(ev, msg)
        return

    if duel._get_level(gid, id2) == 0:
        msg = f'[CQ:at,qq={id2}]被决斗者还未在本群创建过贵族\n请发送 创建贵族 开始您的贵族之旅。'
        duel_judger.turn_off(ev.group_id)
        await bot.send(ev, msg)
        return
    if duel._get_cards(gid, id2) == {}:
        msg = f'[CQ:at,qq={id2}]您没有女友,不能参与决斗哦。'
        duel_judger.turn_off(ev.group_id)
        await bot.send(ev, msg)
        return

        # 判定双方的女友是否已经超过上限
    level_1 = duel._get_level(gid, id1)
    noblename_1 = get_noblename(level_1)
    girlnum_1 = get_girlnum(level_1)
    cidlist_1 = duel._get_cards(gid, id1)
    cidnum_1 = len(cidlist_1)
    # 这里设定大于才会提醒,就是可以超上限1名,可以自己改成大于等于。
    if cidnum_1 > girlnum_1:
        msg = f'[CQ:at,qq={id1}]您的女友超过了爵位上限,先去升级爵位吧。'
        duel_judger.turn_off(ev.group_id)
        await bot.send(ev, msg)
        return
    level_2 = duel._get_level(gid, id2)
    noblename_2 = get_noblename(level_2)
    girlnum_2 = get_girlnum(level_2)
    cidlist_2 = duel._get_cards(gid, id2)
    cidnum_2 = len(cidlist_2)
    if cidnum_2 > girlnum_2:
        msg = f'[CQ:at,qq={id2}]您的女友超过了爵位上限,先去升级爵位吧。'
        duel_judger.turn_off(ev.group_id)
        await bot.send(ev, msg)
        return

    duel_judger.init_isaccept(gid)
    duel_judger.set_duelid(gid, id1, id2)
    duel_judger.turn_on_accept(gid)
    msg = f'[CQ:at,qq={id2}]对方向您发起了优雅的贵族决斗,请在{WAIT_TIME}秒内[接受/拒绝]。'
    await bot.send(ev, msg)

    await asyncio.sleep(WAIT_TIME)
    duel_judger.turn_off_accept(gid)
    if duel_judger.get_isaccept(gid) is False:
        msg = '决斗被拒绝。'
        await bot.send(ev, msg, at_sender=True)
        duel_judger.turn_off(gid)
        return
    duel = DuelCounter()
    level1 = duel._get_level(gid, id1)
    noblename1 = get_noblename(level1)
    level2 = duel._get_level(gid, id2)
    noblename2 = get_noblename(level2)
    msg = f'''对方接受了决斗!    
1号:[CQ:at,qq={id1}]
爵位为:{noblename1}
2号:[CQ:at,qq={id2}]
爵位为:{noblename2}
其他人请在{DUEL_SUPPORT_TIME}秒选择支持的对象。
[支持1/2号xxx金币]'''

    await bot.send(ev, msg)
    duel_judger.turn_on_support(gid)
    await asyncio.sleep(DUEL_SUPPORT_TIME)
    duel_judger.turn_off_support(gid)
    deadnum = random.randint(1, 6)
    duel_judger.set_deadnum(gid, deadnum)
    duel_judger.init_turn(gid)
    duel_judger.turn_on_fire(gid)
    duel_judger.turn_off_hasfired(gid)
    msg = f'支持环节结束,下面请决斗双方轮流[开枪]。\n[CQ:at,qq={id1}]先开枪,30秒未开枪自动认输'

    await bot.send(ev, msg)
    n = 1
    while (n <= 6):
        wait_n = 0
        while (wait_n < 30):
            if duel_judger.get_on_off_hasfired_status(gid):
                break

            wait_n += 1
            await asyncio.sleep(1)
        if wait_n >= 30:
            # 超时未开枪的胜负判定
            loser = duel_judger.get_duelid(gid)[duel_judger.get_turn(gid) - 1]
            winner = duel_judger.get_duelid(gid)[2 - duel_judger.get_turn(gid)]
            msg = f'[CQ:at,qq={loser}]\n你明智的选择了认输。'
            await bot.send(ev, msg)
            break
        else:
            if n == duel_judger.get_deadnum(gid):
                # 被子弹打到的胜负判定
                loser = duel_judger.get_duelid(gid)[duel_judger.get_turn(gid) -
                                                    1]
                winner = duel_judger.get_duelid(gid)[2 -
                                                     duel_judger.get_turn(gid)]
                msg = f'[CQ:at,qq={loser}]\n砰!你死了。'
                await bot.send(ev, msg)
                break
            else:
                id = duel_judger.get_duelid(gid)[duel_judger.get_turn(gid) - 1]
                id2 = duel_judger.get_duelid(gid)[2 -
                                                  duel_judger.get_turn(gid)]
                msg = f'[CQ:at,qq={id}]\n砰!松了一口气,你并没有死。\n[CQ:at,qq={id2}]\n轮到你开枪了哦。'
                await bot.send(ev, msg)
                n += 1
                duel_judger.change_turn(gid)
                duel_judger.turn_off_hasfired(gid)
                duel_judger.turn_on_fire(gid)

    cidlist = duel._get_cards(gid, loser)
    selected_girl = random.choice(cidlist)
    duel._delete_card(gid, loser, selected_girl)
    duel._add_card(gid, winner, selected_girl)
    c = chara.fromid(selected_girl)
    msg = f'[CQ:at,qq={loser}]您输掉了贵族决斗,您被抢走了女友\n{c.name}{c.icon.cqcode}'
    await bot.send(ev, msg)

    # 判定是否掉爵位
    level_loser = duel._get_level(gid, loser)
    if level_loser > 1:
        noblename_loser = get_noblename(level_loser)
        girlnum_loser = get_girlnum(level_loser - 1)
        cidlist_loser = duel._get_cards(gid, loser)
        cidnum_loser = len(cidlist_loser)
        if cidnum_loser < girlnum_loser:
            duel._reduce_level(gid, loser)
            new_noblename = get_noblename(level_loser - 1)
            msg = f'[CQ:at,qq={loser}]\n您的女友数为{cidnum_loser}名\n小于爵位需要的女友数{girlnum_loser}名\n您的爵位下降了到了{new_noblename}'
            await bot.send(ev, msg)

    # 结算下注金币
    score_counter = ScoreCounter2()
    support = duel_judger.get_support(gid)
    winuid = []
    supportmsg = '金币结算:\n'
    winnum = duel_judger.get_duelnum(gid, winner)

    if support != 0:
        for uid in support:
            support_id = support[uid][0]
            support_score = support[uid][1]
            if support_id == winnum:
                winuid.append(uid)
                winscore = support_score * 2
                score_counter._add_score(gid, uid, winscore)
                supportmsg += f'[CQ:at,qq={uid}]+{winscore}金币\n'
            else:
                score_counter._reduce_score(gid, uid, support_score)
                supportmsg += f'[CQ:at,qq={uid}]-{support_score}金币\n'
    await bot.send(ev, supportmsg)
    duel_judger.set_support(ev.group_id)
    duel_judger.turn_off(ev.group_id)
    return
コード例 #27
0
def get_chara_name(card_id):
    chara_id = card_id % 10000
    rarity = 1 if chara_id > 2000 else 0
    chara_id -= rarity * 1000
    return rarity, chara.fromid(chara_id).name