Beispiel #1
0
 def icon(self) -> ResImg:
     star = '3' if 1 <= self.star <= 5 else '6'
     res = R.img(f'priconne/unit/icon_unit_{self.id}{star}1.png')
     if not res.exist:
         res = R.img(f'priconne/unit/icon_unit_{self.id}31.png')
     if not res.exist:
         res = R.img(f'priconne/unit/icon_unit_{self.id}11.png')
     if not res.exist:
         res = R.img(f'priconne/unit/icon_unit_{Chara.UNKNOWN}31.png')
     return res
Beispiel #2
0
async def hour_call():
    now = datetime.now(pytz.timezone('Asia/Shanghai'))
    if 2 <= now.hour <= 5:
        return  # 宵禁 免打扰
    h = now.hour
    if (math.fmod(h, 6) == 0):
        pic = R.img(f"buyexp{random.randint(1, 2)}.jpg").cqcode
        msg = [f'{pic} ']
        await sv.broadcast(msg, 'hourcall', 0)
        return
    pic = R.img(f"mmt{random.randint(1, 30)}.jpg").cqcode
    msg = [f'现在是{now.hour}点咯~~\n{pic} ']
    await sv.broadcast(msg, 'hourcall', 0)
Beispiel #3
0
async def update_seeker():
    '''
    轮询官方四格漫画更新
    若有更新则推送至订阅群
    '''
    index_api = 'https://comic.priconne-redive.jp/api/index'
    index = load_index()

    # 获取最新漫画信息
    resp = await aiorequests.get(index_api, timeout=10)
    data = await resp.json()
    id_ = data['latest_cartoon']['id']
    episode = data['latest_cartoon']['episode_num']
    title = data['latest_cartoon']['title']

    # 检查是否已在目录中
    # 同一episode可能会被更新为另一张图片(官方修正),此时episode不变而id改变
    # 所以需要两步判断
    if episode in index:
        qs = urlparse(index[episode]['link']).query
        old_id = parse_qs(qs)['id'][0]
        if id_ == old_id:
            sv.logger.info('未检测到官漫更新')
            return

    # 确定已有更新,下载图片
    sv.logger.info(f'发现更新 id={id_}')
    await download_comic(id_)

    # 推送至各个订阅群
    pic = R.img('priconne/comic', get_pic_name(episode)).cqcode
    msg = f'プリンセスコネクト!Re:Dive公式4コマ更新!\n第{episode}話 {title}\n{pic}'
    await sv.broadcast(msg, 'PCR官方四格', 0.5)
Beispiel #4
0
def download_comic(id_):
    '''
    下载指定id的官方四格漫画,同时更新漫画目录index.json
    episode_num可能会小于id
    '''
    base = 'https://comic.priconne-redive.jp/api/detail/'
    save_dir = R.img('priconne/comic/').path
    index = load_index()

    # 先从api获取detail,其中包含图片真正的链接
    sv.logger.info(f'getting comic {id_} ...')
    url = base + id_
    sv.logger.info(f'url={url}')
    resp = requests.get(url)
    sv.logger.info(f'status_code={resp.status_code}')
    if 200 != resp.status_code:
        return
    data = resp.json()[0]

    episode = data['episode_num']
    title = data['title']
    link = data['cartoon']
    index[episode] = {'title': title, 'link': link}
    sv.logger.info(f'episode={index[episode]}')

    # 下载图片并保存
    download_img(os.path.join(save_dir, get_pic_name(episode)), link)

    # 保存官漫目录信息
    with open(os.path.join(save_dir, 'index.json'), 'w', encoding='utf8') as f:
        json.dump(index, f, ensure_ascii=False)
Beispiel #5
0
async def random_equip(session: CommandSession):
    filelist = os.listdir(equip_folder)
    path = None
    while not path or not os.path.isfile(path):
        filename = random.choice(filelist)
        path = os.path.join(equip_folder, filename)
    pic = R.img('kancolle/equip/', filename).cqcode
    await session.send(pic, at_sender=True)
Beispiel #6
0
def load_data():
    config = util.load_config(__file__)
    db = config["data"]
    rex = re.compile(r"\[CQ:image,file=(.*)\]")
    for k, v in db.items():
        m = rex.search(v)
        if m:
            img = str(R.img('kancolle/', m.group(1)).cqcode)
            db[k] = rex.sub(img, v)
    return db
Beispiel #7
0
async def comic(bot, ctx, match):
    episode = match.group(1)
    if not episode:
        await bot.send(ctx, '请输入漫画集数 如:官漫132', at_sender=True)
        return
    index = load_index()
    if episode not in index:
        await bot.send(ctx, f'未查找到第{episode}话,敬请期待官方更新', at_sender=True)
        return
    title = index[episode]['title']
    pic = R.img('priconne/comic/', get_pic_name(episode)).cqcode
    msg = f'プリンセスコネクト!Re:Dive公式4コマ\n第{episode}話 {title}\n{pic}'
    await bot.send(ctx, msg, at_sender=True)
Beispiel #8
0
async def ban_word(session):
    ctx = session.ctx
    user_id = ctx['user_id']
    msg_from = str(user_id)
    if ctx['message_type'] == 'group':
        msg_from += f'@[群:{ctx["group_id"]}]'
    elif ctx['message_type'] == 'discuss':
        msg_from += f'@[讨论组:{ctx["discuss_id"]}]'
    logger.critical(f'Self: {ctx["self_id"]}, Message {ctx["message_id"]} from {msg_from}: {ctx["message"]}')
    # await session.send(random.choice(BANNED_WORD))
    Service.set_block_user(user_id, timedelta(hours=8))
    pic = R.img(f"chieri{random.randint(1, 4)}.jpg").cqcode
    await session.send(f"不理你啦!バーカー\n{pic}", at_sender=True)
    await util.silence(session.ctx, 8*60*60)
Beispiel #9
0
async def comic(session:NLPSession):
    rex = re.compile(r'[1-9]\d{0,2}')
    arg = session.msg_text.strip()
    match = rex.search(arg)
    if not match:
        await session.send('请输入漫画集数 如:官漫132')
        return
    episode = match.group()
    index = load_index()
    if episode not in index:
        await session.send(f'未查找到第{episode}话,敬请期待官方更新')
        return
    title = index[episode]['title']
    pic = R.img('priconne/comic/', get_pic_name(episode)).cqcode
    msg = f'プリンセスコネクト!Re:Dive公式4コマ\n第{episode}話 {title}\n{pic}'
    await session.send(msg)
Beispiel #10
0
def get_setu():
    try:
        path = None
        filename = None
        filelist = os.listdir(setu_folder)
        filelist = sorted(filelist, key=lambda x: os.path.getmtime(os.path.join(setu_folder, x)), reverse=True)
        while not path or not os.path.isfile(path):
            # i = round(random.expovariate(0.02))  # 期望为 1 / λ
            i = random.randint(0, len(filelist) - 1) # if i >= len(filelist) else i
            filename = filelist[i]
            path = os.path.join(setu_folder, filename)
        return R.img('setu/', filename).cqcode
    except Exception as e:
        sv.logger.exception(e)
        sv.logger.exception(f'f={filename}, x={path}')
        return MessageSegment.text('Error: 挑选涩图时发生异常')
Beispiel #11
0
async def update_seeker(group_list):
    '''
    轮询官方四格漫画更新
    若有更新则推送至订阅群
    '''
    index_api = 'https://comic.priconne-redive.jp/api/index'
    index = load_index()

    # 获取最新漫画信息
    resp = requests.get(index_api, timeout=10)
    data = resp.json()
    id_ = data['latest_cartoon']['id']
    episode = data['latest_cartoon']['episode_num']
    title = data['latest_cartoon']['title']

    # 检查是否已在目录中
    # 同一episode可能会被更新为另一张图片(官方修正),此时episode不变而id改变
    # 所以需要两步判断
    if episode in index:
        qs = urlparse(index[episode]['link']).query
        old_id = parse_qs(qs)['id'][0]
        if id_ == old_id:
            sv.logger.info('未检测到官漫更新')
            return
    
    # 确定已有更新,下载图片
    sv.logger.info(f'发现更新 id={id_}')
    download_comic(id_)

    # 推送至各个订阅群
    pic = R.img('priconne/comic', get_pic_name(episode)).cqcode
    msg = f'プリンセスコネクト!Re:Dive公式4コマ更新!\n第{episode}話 {title}\n{pic}'

    for group, sid in group_list.items():
        await asyncio.sleep(0.5)  # 降低发送频率,避免被腾讯ban
        try:
            await sv.bot.send_group_msg(self_id=random.choice(sid), group_id=group, message=msg)
            sv.logger.info(f'群{group} 投递PCR官漫更新成功')
        except CQHttpError as e:
            sv.logger.error(f'Error:群{group} 投递PCR官漫更新失败 {type(e)}')

    sv.logger.info('计划任务:update_seeker 完成')
Beispiel #12
0
async def gacha_10(session: CommandSession):
    if random.random() < 0.20:
        pic = R.img('gacha.jpg').cqcode
        await session.send(f'\n{pic}', at_sender=True)
        return

    SUPER_LUCKY_LINE = 170

    await check_jewel_num(session)
    uid = session.ctx['user_id']
    jewel_limit.increase(uid, 1500)

    gid = str(session.ctx['group_id'])
    gacha = Gacha(_group_pool[gid])
    result, hiishi = gacha.gacha_ten()
    silence_time = hiishi * 6 if hiishi < SUPER_LUCKY_LINE else hiishi * 60

    if sv.bot.config.IS_CQPRO:
        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}'
    else:
        result = [f'{c.name}{"★"*c.star}' for c in result]
        res1 = ' '.join(result[0:5])
        res2 = ' '.join(result[5:])
        res = f'{res1}\n{res2}'

    if hiishi >= SUPER_LUCKY_LINE:
        await session.send('恭喜海豹!おめでとうございます!')
    await session.send(f'素敵な仲間が増えますよ!\n{res}\n{SWITCH_POOL_TIP}',
                       at_sender=True)
    await silence(session.ctx, silence_time)
Beispiel #13
0
async def gacha_1(session: CommandSession):
    if random.random() < 0.20:
        pic = R.img('gacha.jpg').cqcode
        await session.send(f'\n{pic}', at_sender=True)
        return

    await check_jewel_num(session)
    uid = session.ctx['user_id']
    jewel_limit.increase(uid, 150)

    gid = str(session.ctx['group_id'])
    gacha = Gacha(_group_pool[gid])
    chara, hiishi = gacha.gacha_one(gacha.up_prob, gacha.s3_prob,
                                    gacha.s2_prob)
    silence_time = hiishi * 60

    res = f'{chara.name} {"★"*chara.star}'
    if sv.bot.config.IS_CQPRO:
        res = f'{chara.icon.cqcode} {res}'

    await silence(session.ctx, silence_time)
    await session.send(f'素敵な仲間が増えますよ!\n{res}\n{SWITCH_POOL_TIP}',
                       at_sender=True)
Beispiel #14
0
async def say_sorry(session):
    pic_index = random.randint(1, 2)
    await session.send(R.img(f"sbot{pic_index}.jpg").cqcode)
Beispiel #15
0
async def chat_laogong(session):
    await session.send(R.img('爬.jpg').cqcode, at_sender=True)
Beispiel #16
0
async def seina(session: CommandSession):
    seg_setu = R.img('星奏.png').cqcode
    await session.send(seg_setu)
Beispiel #17
0
async def chat_neigui(bot, ctx):
    await bot.send(ctx, R.img('内鬼.png').cqcode)
Beispiel #18
0
async def chat_clanba(bot, ctx):
    await bot.send(ctx, R.img('我的天啊你看看都几点了.jpg').cqcode)
Beispiel #19
0
async def panci(session):
    if not sv.check_priv(session.ctx, Priv.SUPERUSER):
        await session.send(f'给👴爬', at_sender=True)
    else:
        pic = R.img('胖次.jpg').cqcode
        await session.send(f'耻ずかしい~\n{pic}', at_sender=False)
Beispiel #20
0
async def penshui(session):
    await session.send(R.img('喷水.jpg').cqcode)
Beispiel #21
0
async def chat_waifu(session):
    if not sv.check_priv(session.ctx, Priv.SUPERUSER):
        await session.send(R.img('laopo.jpg').cqcode)
        await session.send('爪巴')
    else:
        await session.send('mua~')
Beispiel #22
0
def get_img_cq(yy, mm, ss):
    img = R.img('kancolle/senka/', rank_filename(yy, mm, ss))
    if os.path.exists(img.path):
        return img.cqcode
    else:
        return ms.image(rank_url(yy, mm, ss))
Beispiel #23
0
async def seina(session):
    await session.send(R.img('purin.jpg').cqcode)
Beispiel #24
0
async def purin(session):
    await session.send(R.img('吃布丁.jpg').cqcode)
Beispiel #25
0
async def question(session):
    await session.send(R.img('问号.jpg').cqcode)
    await util.silence(session.ctx, 30)
Beispiel #26
0
def load_index():
    with open(R.get('img/priconne/comic/index.json').path, encoding='utf8') as f:
        return json.load(f)
Beispiel #27
0
async def bihua(session):
    await session.send(R.img('比划比划.gif').cqcode)
Beispiel #28
0
async def chat_queshi(bot, ctx):
    if random.random() < 0.05:
        await bot.send(ctx, R.img('确实.jpg').cqcode)
Beispiel #29
0
async def chat_clanba(bot, ctx):
    if random.random() < 0.10:
        await bot.send(ctx, R.img('我的天啊你看看都几点了.jpg').cqcode)
Beispiel #30
0
async def ddhaole(session):
    pic = R.img('疑问.jpg').cqcode
    await session.send(f'那个朋友是不是你弟弟?\n{pic}')