コード例 #1
0
ファイル: DailyNews.py プロジェクト: kuttakke/CUAVbot
async def auto_send_news(app: GraiaMiraiApplication):
    await news.update()
    if news.is_update:
        group_list = await app.groupList()
        for group in group_list:
            await app.sendGroupMessage(
                group.id,
                MessageChain.create([Image.fromUnsafeBytes(news.img_bytes)]))
        await app.sendFriendMessage(
            master_id,
            MessageChain.create([Image.fromUnsafeBytes(news.img_bytes)]))
コード例 #2
0
ファイル: pixiv.py プロジェクト: kuttakke/CUAVbot
 def _creat_msg_chain(self, pid_list: List[str], pages_num: List[int],
                      img_bytes: List[BytesIO]):
     """
     进行消息链构造
     :param pid_list: List[str]
     :param pages_num: List[int]
     :param img_bytes: List[BytesIO]
     :return: List[List[MessageChain], ...]
     """
     page_count = 0
     msg_img_limit = 2
     limit_count = 0
     out_msg_list = [[
         Plain("又到了涩图时间!此次共有{}张图!".format(str(len(img_bytes))))
     ]]
     for i in range(len(pid_list)):
         out_msg = []
         for n in range(pages_num[i]):
             out_msg.append(
                 Image.fromUnsafeBytes(img_bytes[page_count].getvalue()))
             page_count += 1
             limit_count += 1
             if limit_count >= msg_img_limit:
                 limit_count = 0
                 out_msg_list.extend([out_msg])
                 out_msg = []
         if out_msg:
             out_msg_list.extend([out_msg])
             limit_count = 0
     self.logger.info("消息链构建成功")
     return out_msg_list
コード例 #3
0
async def command_csl(app: GraiaMiraiApplication, group: Group,
                      params: MessageChain):
    player_name = params.asDisplay()
    result = await apis.CustomSkinLoaderApi.get(
        'https://mcskin.littleservice.cn/csl', player_name)
    if not result.existed:
        await app.sendGroupMessage(
            group, MessageChain.create([Plain(f'「{player_name}」不存在')]))
    else:
        skin_hash = result.skins.slim or result.skins.default
        cape_hash = result.cape
        littleskin_root = 'https://mcskin.littleservice.cn'
        preview_images: List[Image] = list()
        for texture in [skin_hash, cape_hash]:
            if skin_hash:
                preview_images.append(
                    Image.fromUnsafeBytes(await apis.getTexturePreview(
                        littleskin_root, texture)))
    await app.sendGroupMessage(
        group,
        MessageChain.create([
            *preview_images,
            Plain(
                f'Skin: {skin_hash[:7] if skin_hash else None} [{result.skin_type}]\nCape: {cape_hash[:7] if cape_hash else None}'
            )
        ]))
コード例 #4
0
ファイル: DailyNews.py プロジェクト: kuttakke/CUAVbot
async def send_news(app: GraiaMiraiApplication, group: Group):
    if not news.is_update:
        await news.update()
    out_msg = MessageChain.create(
        [Plain("每日新闻每天九点半更新哦~"),
         Image.fromUnsafeBytes(news.img_bytes)])
    await app.sendGroupMessage(group.id, out_msg)
コード例 #5
0
 def getPreviewByHash(texture_hash: str) -> Image:
     '''通过 hash 获取 Image 对象'''
     r = requests.get(
         f'https://mcskin.littleservice.cn/preview/hash/{texture_hash}?png')
     if r.status_code == 200:
         return Image.fromUnsafeBytes(r.content)
     else:
         return None
コード例 #6
0
ファイル: DailyNews.py プロジェクト: kuttakke/CUAVbot
async def check_news_update(app: GraiaMiraiApplication):
    if not news.is_update:
        await news.update()
        if news.is_update:
            out_msg = MessageChain.create(
                [Image.fromUnsafeBytes(news.img_bytes)])
            group_list = await app.groupList()
            for group in group_list:
                await app.sendGroupMessage(group.id, out_msg)
            await app.sendFriendMessage(master_id, out_msg)
コード例 #7
0
ファイル: Choyen5000.py プロジェクト: kuttakke/CUAVbot
async def send_img(app: GraiaMiraiApplication, group: Group,
                   text: MessageChain):
    text_list = text.asDisplay().strip().split()
    logger.info(text_list)
    if len(text_list) == 2:
        logger.info(f"触发cy5:[{text_list[0]},{text_list[1]}]")
        url = f"https://api.dihe.moe/5000choyen/?upper={text_list[0]}&lower={text_list[1]}"
        async with aiohttp.request("GET", url) as res:
            img_bytes = await res.read()
        await app.sendGroupMessage(
            group.id, MessageChain.create([Image.fromUnsafeBytes(img_bytes)]))
    else:
        await app.sendGroupMessage(group.id,
                                   MessageChain.create([Plain("输入参数不合法")]))
コード例 #8
0
async def friend_setu_handler(app: GraiaMiraiApplication, group: Group,
                              keyword: MessageChain):
    if keyword is None:
        keyword_str = ""
    else:
        keyword_str = keyword.asDisplay().strip()
    res = await setu.get_setu_with_keyword(False, keyword_str)
    if res is None:
        await app.sendGroupMessage(
            group, MessageChain.create([Plain("没有找到这个tag...")]))
    elif res is False:
        await app.sendGroupMessage(group,
                                   MessageChain.create([Plain("请求好像失败了QAQ")]))
    else:
        pid = "pid:" + res[0]
        out = res[1]
        await app.sendGroupMessage(
            group,
            MessageChain.create([Plain(pid),
                                 Image.fromUnsafeBytes(out)]))
コード例 #9
0
async def group_listener(app: GraiaMiraiApplication, group: Group):
    out = table.img_bytes
    await app.sendGroupMessage(
        group, MessageChain.create([Img.fromUnsafeBytes(out.getvalue())]))
コード例 #10
0
async def friend_listener(app: GraiaMiraiApplication, friend: Friend):
    out = table.img_bytes
    await app.sendFriendMessage(
        friend, MessageChain.create([Img.fromUnsafeBytes(out.getvalue())]))