コード例 #1
0
async def eventChecker60():
    if Universe.get_value("dailyMession")[0] is 1:
        sender = Universe.get_value("dailyMession")[1]
        if type(sender) is Group:
            await app.sendGroupMessage(
                sender,
                MessageChain.create([Plain(f"今日色图更新成功,发送 色图 或者 好图 进行查看")]))
        elif type(sender) is Friend:
            await app.sendFriendMessage(
                sender,
                MessageChain.create([Plain(f"今日色图更新成功,发送 色图 或者 好图 进行查看")]))
        elif type(sender) is list:  # 只会是自动更新
            for ls in sender:
                await app.sendGroupMessage(
                    ls,
                    MessageChain.create([Plain(f"今日色图更新成功,发送 色图 或者 好图 进行查看")]))
                await app.sendGroupMessage(
                    ls,
                    MessageChain.create([
                        Plain("色图一览"),
                        Image.fromLocalFile(Universe.get_value("setuScan"))
                    ]))
                await app.sendGroupMessage(
                    ls,
                    MessageChain.create([
                        Plain("好图一览"),
                        Image.fromLocalFile(Universe.get_value("haotuScan"))
                    ]))

        Universe.set_value("dailyMession", [0, None])
    elif Universe.get_value("dailyMession")[0] is -1:
        sender = Universe.get_value("dailyMession")[1]
        if type(sender) is Group:
            await app.sendGroupMessage(
                sender, MessageChain.create([Plain(f"今日色图更新失败")]))
        elif type(sender) is Friend:
            await app.sendFriendMessage(
                sender, MessageChain.create([Plain(f"今日色图更新失败")]))
        await app.sendFriendMessage(
            775086089, MessageChain.create([Plain(f"今日色图更新失败,请检查网络设置")]))
        Universe.set_value("dailyMession", [0, None])

    global isFresh
    if not isFresh:
        if extraEvent.getDate("%H") == "08":
            isFresh = True
            await app.sendFriendMessage(775086089,
                                        MessageChain.create([Plain(f"开始更新")]))
            for ls in await app.groupList():
                if ls.id in schedulepermission:
                    await app.sendGroupMessage(
                        ls, MessageChain.create([Plain("开始更新每日色图......")]))
            await app.sendFriendMessage(
                775086089, MessageChain.create([Plain(f"群消息发送成功")]))
            threadDaily = threading.Thread(target=extraEvent.DayilyMission,
                                           args=(schedulepermission, 0))
            threadDaily.start()
コード例 #2
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)]))
コード例 #3
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
コード例 #4
0
async def command_ygg_client_refresh(app: GraiaMiraiApplication, group: Group):
    await app.sendGroupMessage(
        group,
        MessageChain.create([
            Image.fromLocalFile('./images/ygg-client-refresh.png'),
            Plain(tF.client_refresh)
        ]))
コード例 #5
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}'
            )
        ]))
コード例 #6
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)
コード例 #7
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
コード例 #8
0
ファイル: __init__.py プロジェクト: kuttakke/CUAVbot
async def sleep_time(app: GraiaMiraiApplication):
    group_list = await app.groupList()
    for group in group_list:
        await app.sendGroupMessage(
            group.id,
            MessageChain.create([
                Plain("到点了到点了,好孩子该睡觉了!"),
                Image.fromLocalFile(_go_to_sleep_img_path)
            ]))
コード例 #9
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)
コード例 #10
0
ファイル: main.py プロジェクト: xfl03/commspt-bot
async def command_ot(app: GraiaMiraiApplication, group: Group,
                     _gm: GroupMessage):
    CP = CommandParser(_gm, settings.commandSymbol)
    atList: List[Optional[At]] = [At(t.target)
                                  for t in CP.at] if CP.at != [] else []
    await app.sendGroupMessage(
        group,
        MessageChain.create([
            *atList,
            Image.fromLocalFile('./images/off-topic.png'),
            *([Plain(tF.ot)] if group.id == settings.specialqq.littleskin_main
              else [])  # 仅在 LittleSkin 主群中启用此文本消息
        ]))
コード例 #11
0
async def command_ot(app: GraiaMiraiApplication, group: Group,
                     _gm: GroupMessage):
    M = MessagePro(_gm)
    atList: List[Optional[At]] = [At(t.target)
                                  for t in M.at] if M.at != [] else []
    await app.sendGroupMessage(
        group,
        MessageChain.create([
            Image.fromLocalFile('./images/off-topic.png'),
            *atList,
            # 仅在 LittleSkin 主群中启用此文本消息
            *([Plain(tF.ot)] if group.id == qq.littleskin_main else [])
        ]))
コード例 #12
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("输入参数不合法")]))
コード例 #13
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)]))
コード例 #14
0
async def command_faq(app: GraiaMiraiApplication, group: Group):
    await app.sendGroupMessage(
        group,
        MessageChain.create(
            [Image.fromLocalFile('./images/rtfm.png'),
             Plain(tF.faq)]))
コード例 #15
0
async def command_ygg_url(app: GraiaMiraiApplication, group: Group):
    await app.sendGroupMessage(
        group,
        MessageChain.create([Image.fromLocalFile('./images/ygg-url.png')]))
コード例 #16
0
async def friend_message_listener(app: GraiaMiraiApplication,
                                  message: MessageChain, friend: Friend):
    if friend.id in _MANAGER:
        if message.asDisplay() == "UpdateToday":
            await app.sendFriendMessage(
                friend, message.create([Plain("开始更新今日色图......")]))
            thread = threading.Thread(target=extraEvent.DayilyMission,
                                      args=(friend, 0))
            thread.start()
        elif message.asDisplay() == "Init":
            await app.sendFriendMessage(friend,
                                        message.create([Plain("初始化......")]))
            extraEvent.initNow(app, message, friend, loop)
        elif message.asDisplay() == "图裂了":
            await app.sendFriendMessage(
                friend, message.create([Plain("正在想办法处理......")]))
            extraEvent.fixPics(app, message, friend, loop)
        '''if message.asDisplay() == "今日色图":
            try:
                print(Universe.get_value("setuScan"))
                print(os.path.abspath(Universe.get_value("setuScan")))
                await app.sendFriendMessage(friend,
                                            message.create([Image.fromUnsafePath("Pixiv/2020-09-12/day_r18_scan.jpg")]))
            except:
                extraEvent.initNow(app, message, friend, loop)
                await app.sendFriendMessage(friend,
                                            message.create([Image.fromUnsafePath("Pixiv/2020-09-12/day_r18_scan.jpg")]))
        elif message.asDisplay() == "今日好图":
            try:
                await app.sendFriendMessage(friend,
                                            message.create([Image.fromLocalFile(Universe.get_value("haotuScan"))]))
            except:
                extraEvent.initNow(app, message, friend, loop)
                await app.sendFriendMessage(friend,
                                            message.create([Image.fromLocalFile(Universe.get_value("haotuScan"))]))'''  # 错误待解决
        if re.search("色图$", message.asDisplay()):
            setuInd = Universe.get_value("setuInd")
            imgid = await app.sendFriendMessage(
                friend,
                message.create([
                    Image.fromLocalFile(
                        extraEvent.setuList[setuInd %
                                            len(extraEvent.setuList)])
                ]))
            print(imgid)
            await app.sendFriendMessage(
                friend, message.create([Plain("今日发送的第{}份色图".format(setuInd))]))
            setuInd += 1
            Universe.set_value("setuInd", setuInd)
        elif re.search("好图$", message.asDisplay()):
            haotuInd = Universe.get_value("haotuInd")
            await app.sendFriendMessage(
                friend,
                message.create([
                    Image.fromLocalFile(
                        extraEvent.haotuList[haotuInd %
                                             len(extraEvent.haotuList)])
                ]))
            await app.sendFriendMessage(
                friend,
                message.create([Plain("今日发送的第{}份好图".format(haotuInd))]))
            print(extraEvent.haotuList[haotuInd % len(extraEvent.haotuList)])
            haotuInd += 1
            Universe.set_value("haotuInd", haotuInd)
        if message.has(Image):
            savePicLs = message[Image]
            counter = len(savePicLs)
            await app.sendFriendMessage(
                friend, message.create([Plain("{}张".format(counter))]))
            threadPic = threading.Thread(target=extraEvent.savePic,
                                         args=(savePicLs, 3))
            threadPic.start()
コード例 #17
0
async def group_listener(app: GraiaMiraiApplication, group: Group):
    out = table.img_bytes
    await app.sendGroupMessage(
        group, MessageChain.create([Img.fromUnsafeBytes(out.getvalue())]))
コード例 #18
0
async def friend_listener(app: GraiaMiraiApplication, friend: Friend):
    out = table.img_bytes
    await app.sendFriendMessage(
        friend, MessageChain.create([Img.fromUnsafeBytes(out.getvalue())]))
コード例 #19
0
async def sendstick(bot, group, source, msg_par, id=None):
    # 这该死的路径居然是取的main的路径,草了
    if msg_par.asDisplay() == "报时":
        time_24 = time.strftime("%H:%M", time.localtime(time.time()))
        send_ask = ask(int(time.strftime("%H", time.localtime(time.time()))))
        draw_text_img(time_24, send_ask)

        await bot.sendGroupMessage(
            group,
            msg_par.create([
                Image.fromLocalFile('img/time_cache.jpg'),
                Plain(
                    text=
                    f'\n现在是北京时间=>{time.strftime("%H点%M分%S秒", time.localtime(time.time()))}'
                )
            ]),
            quote=source)
    elif msg_par.asDisplay() == '随机涩图':
        # TODO :偶尔会出现index out,等以后学会py了再修复,下 次 一 定
        # 别问,问就是lambda真好
        # 判定次数
        if id not in SendImgCount.keys():
            # 初次直接发送然后添加
            SendImgCount[id] = []
            SendImgCount[id].append(1)
            imgname = stick_name['随机涩图']()
            await bot.sendGroupMessage(
                group.id,
                msg_par.create([
                    Image.fromLocalFile(f'{AcgImgPath}/%s' %
                                        imgname).asFlash()
                ]))
            await bot.sendGroupMessage(
                group.id,
                msg_par.create([
                    Plain('图片链接:https://www.pixiv.net/artworks/%s' %
                          imgname[0:-7])
                ]))

        elif SendImgCount[id][0] < 3 and len(SendImgCount[id]) == 1:
            # 如果次数少于三次
            SendImgCount[id][0] += 1
            imgname = stick_name['随机涩图']()
            await bot.sendGroupMessage(
                group.id,
                msg_par.create([
                    # 发!
                    Image.fromLocalFile(f'{AcgImgPath}/%s' % imgname
                                        ).asFlash()
                ]))

            await bot.sendGroupMessage(
                group.id,
                msg_par.create([
                    Plain('图片链接:https://www.pixiv.net/artworks/%s' %
                          imgname[0:-7])
                ]))

            # 记一次
        elif len(SendImgCount[id]) == 1 and SendImgCount[id][0] >= 3:
            # 如果超过三次就加上时间
            SendImgCount[id].append(time.time())
            await bot.sendGroupMessage(
                group.id,
                msg_par.create([Plain(text='做人不要太贪心哦,每获取三次需要等待一分钟')]))
        else:
            # 在这里提醒冲过头了
            if int(time.time() - SendImgCount[id][1]) < 60:
                await bot.sendGroupMessage(
                    group.id,
                    msg_par.create([
                        Plain(text='才过去%0.1fs呢' %
                              int(abs(SendImgCount[id][1] - time.time())))
                    ]))
            else:
                del SendImgCount[id]
    elif msg_par.asDisplay() == '贴贴':
        i = random.randrange(0, 2)
        if i:
            await bot.sendGroupMessage(
                group, msg_par.create([Image.fromLocalFile('img/yes.jpg')]))
        else:
            await bot.sendGroupMessage(
                group, msg_par.create([Image.fromLocalFile('img/no.jpg')]))
    else:  # msg_par.asDisplay() in stick_name.keys() and msg_par.asDisplay() != '随机涩图':
        await bot.sendGroupMessage(
            group.id,
            msg_par.create([
                Image.fromLocalFile(f'img/%s' %
                                    stick_name[msg_par.asDisplay()])
            ]))
コード例 #20
0
ファイル: main.py プロジェクト: LittleSkinCommspt/commspt-bot
app = GraiaMiraiApplication(
    broadcast=bcc, connect_info=settings.Connection, enable_chat_log=False)


def SimpleReply(command: str, reply_content: List[GraiaMessageElementType]):
    async def srr_wrapper(app: GraiaMiraiApplication, group: Group):
        await app.sendGroupMessage(group, MessageChain.create(reply_content))
    bcc.receiver(GroupMessage, dispatchers=[Kanata(
        [CommandMatch(command, False)])])(srr_wrapper)


SimpleReply('ping', [Plain('Pong!')])

SimpleReply('help', [Plain(tF.help)])
SimpleReply('ot', [
    Image.fromLocalFile('./images/off-topic.png'),
    Plain(tF.ot)
])
SimpleReply('manual', [
    Image.fromLocalFile('./images/rtfm.png'),
    Plain(tF.manual)
])
SimpleReply('ygg.server.jvm', [Plain(tF.ygg_server_jvm)])
SimpleReply('csl.gui', [Plain(tF.csl_gui)])
SimpleReply('domain', [
    Image.fromLocalFile('./images/r-search.jpg'),
    Plain(tF.domain)
])
SimpleReply('mail', [Plain(tF.mail)])
SimpleReply('csl.log', [Plain(tF.csl_log)])
SimpleReply('ygg.nsis', [Plain(tF.ygg_nsis)])
コード例 #21
0
async def group_message_handler(app: GraiaMiraiApplication,
                                message: MessageChain, group: Group,
                                member: Member):
    if message.asDisplay().startswith("复读"):
        await app.sendGroupMessage(
            group,
            message.create(
                [At(member.id),
                 Plain(message.exclude(Image).asDisplay())]),
            quote=message.__root__[0].id)

    if re.search(r"色图 \d", message.asDisplay()) and (group.id
                                                     in schedulepermission):
        setuInd = Universe.get_value("setuInd")
        setuId = message.asDisplay().split(" ")[1]
        setuId = eval(setuId) - 1
        await app.sendGroupMessage(
            group,
            message.create([
                Image.fromLocalFile(
                    extraEvent.setuList[setuId % len(extraEvent.setuList)])
            ]))
        await app.sendGroupMessage(
            group, message.create([Plain("今日发送的第{}份色图".format(setuInd))]))
        print(extraEvent.setuList[setuInd % len(extraEvent.setuList)])
        setuInd += 1
        Universe.set_value("setuInd", setuInd)
    elif re.search(r"好图 \d", message.asDisplay()) and (group.id
                                                       in schedulepermission):
        haotuInd = Universe.get_value("haotuInd")
        haotuId = message.asDisplay().split(" ")[1]
        haotuId = eval(haotuId) - 1
        await app.sendGroupMessage(
            group,
            message.create([
                Image.fromLocalFile(
                    extraEvent.haotuList[haotuId % len(extraEvent.haotuList)])
            ]))
        await app.sendGroupMessage(
            group, message.create([Plain("今日发送的第{}份好图".format(haotuInd))]))
        print(extraEvent.haotuList[haotuInd % len(extraEvent.haotuList)])
        haotuInd += 1
        Universe.set_value("haotuInd", haotuInd)

    if message.asDisplay() == "色图一览":
        print(Universe.get_value("setuScan"))
        print(os.path.abspath(Universe.get_value("setuScan")))
        await app.sendGroupMessage(
            group,
            message.create(
                [Image.fromLocalFile(Universe.get_value("setuScan"))]))
    elif message.asDisplay() == "好图一览":
        await app.sendGroupMessage(
            group,
            message.create(
                [Image.fromLocalFile(Universe.get_value("haotuScan"))]))

    if member.permission is MemberPerm.Owner:
        if message.asDisplay().startswith("Update"):
            await app.sendGroupMessage(
                group, message.create([Plain("开始更新今日色图......")]))
            threadDaily = threading.Thread(target=extraEvent.DayilyMission,
                                           args=(group, 0))
            threadDaily.start()
        elif message.asDisplay().startswith("Init"):
            await app.sendGroupMessage(group,
                                       message.create([Plain("初始化......")]))
            extraEvent.initNow(app, message, group, loop)
        elif message.asDisplay() == "图裂了":
            await app.sendFriendMessage(
                group, message.create([Plain("正在想办法处理......")]))
            extraEvent.fixPics(app, message, group, loop)

    if message.has(Image):  #图片保存
        # 日常收集图片
        savePicLs = message[Image]
        counter = len(savePicLs)
        sourceid = message.__root__[0].id
        #await app.sendGroupMessage(group, message.create([Plain("{}张".format(counter))]))
        threadPic = threading.Thread(target=extraEvent.savePic,
                                     args=(savePicLs, counter, app, sourceid,
                                           group, loop))
        threadPic.start()