Beispiel #1
0
async def get_key_joke(key: str) -> list:
    sql = "select * from %sJokes order by rand() limit 1" % key
    joke = await execute_sql(sql)
    if joke == (None, ):
        return ["None", MessageChain.create([Plain(text="笑话数据库为空!")])]
    else:
        joke = joke[0][0]
        return ["None", MessageChain.create([Plain(text=joke)])]
Beispiel #2
0
async def get_joke(name: str) -> list:
    sql = "select * from jokes order by rand() limit 1"
    joke = await execute_sql(sql)
    if joke == (None, ):
        return ["None", MessageChain.create([Plain(text="笑话数据库为空!")])]
    else:
        joke = joke[0][0]
        joke = joke.replace("%name%", name).replace("\n", "")
        return ["None", MessageChain.create([Plain(text=joke)])]
Beispiel #3
0
async def phantom_tank(app: GraiaMiraiApplication, message: MessageChain, group: Group):

    message_text = "".join([plain.text for plain in message.get(Plain)]).strip()
    if message_text in ["幻影", "彩色幻影"]:
        if len(message[Image]) != 2:
            try:
                await app.sendGroupMessage(group, MessageChain.create([Plain(text="非预期图片数量!请按 `显示图 隐藏图` 顺序发送,共两张")]))
            except AccountMuted:
                pass
            return None
        if globals()["signal"] >= 2:
            try:
                await app.sendGroupMessage(group, MessageChain.create([Plain(text=f"目前有{signal}个任务正在处理,请稍后再试!")]))
            except AccountMuted:
                pass
            return None

        globals()["signal"] += 1

        try:
            await app.sendGroupMessage(group, MessageChain.create([Plain(text="converting")]))
        except AccountMuted:
            pass

        im_1 = message[Image][0]
        async with aiohttp.ClientSession() as session:
            async with session.get(url=im_1.url) as resp:
                img_content = await resp.read()
        display_img = IMG.open(BytesIO(img_content))

        im_2 = message[Image][1]
        async with aiohttp.ClientSession() as session:
            async with session.get(url=im_2.url) as resp:
                img_content = await resp.read()
        hide_img = IMG.open(BytesIO(img_content))

        try:
            await app.sendGroupMessage(
                group,
                MessageChain.create([
                    Image.fromUnsafeBytes(await make_tank(display_img, hide_img) if message_text == "幻影" else await colorful_tank(display_img, hide_img))
                    # Image.fromUnsafeBytes(await colorful_tank(display_img, hide_img))
                ])
            )
        except AccountMuted:
            pass

        globals()["signal"] -= 1
async def friend_message_process(app: GraiaMiraiApplication, friend: Friend,
                                 message: MessageChain) -> None:
    message_test = message.asDisplay()
    if friend.id == await get_config("HostQQ"):
        if message_test[:5] == "发布消息:":
            msg = MessageChain.create([Plain(text=message_test[5:])])
            group_list = await app.groupList()
            for i in group_list:
                try:
                    await app.sendGroupMessage(i, msg)
                except AccountMuted:
                    pass
        elif message.has(Image):
            imgs = message.get(Image)
            for i in imgs:
                bot_setu_count = await get_total_calls("botSetuCount") + 1
                await update_total_calls(bot_setu_count, "botSetuCount")
                path = "%s%s.png" % (await get_config("listenImagePath"),
                                     bot_setu_count)

                async with aiohttp.ClientSession() as session:
                    async with session.get(url=i.url) as resp:
                        img_content = await resp.read()

                image = IMG.open(BytesIO(img_content))
                image.save(path)

                await insert_image_hash(
                    "%s%d.png" %
                    (await get_config("listenImagePath"), bot_setu_count),
                    await image_hash(path), "tribute")
            await app.sendFriendMessage(
                friend,
                MessageChain.create(
                    [Plain(text="%d Image saved!" % len(imgs))]))
            await write_log("save img from Host", path, await
                            get_config("HostQQ"), 0, True, "img")
async def get_group_quotes(group_id: int, app: GraiaMiraiApplication,
                           nickname: str, quote_type: str,
                           source_status: str) -> list:
    member_id = None
    if source_status == "nickname":
        sql = "select memberId from nickname where groupId=%d and nickname='%s'" % (
            group_id, nickname)
        member_id = await execute_sql(sql)
        print(member_id)
        # print(quotes)
        if member_id == ():
            return [
                "None",
                MessageChain.create(
                    [Plain(text="%s是谁我不知道呐~快来添加别名吧~" % nickname)])
            ]
        member_id = member_id[0][0]
    elif source_status == "memberId":
        member_id = int(nickname)
    elif source_status == "None":
        pass

    if quote_type == "random":
        sql = "select * from celebrityQuotes where groupId=%d order by rand() limit 1" % group_id
        quotes = await execute_sql(sql)[0]
        # print(quotes)
        if quotes is None:
            return [
                "None",
                MessageChain.create([Plain(text="本群还没有群语录哟~快来添加吧~")])
            ]
        else:
            member_id = int(quotes[1])  # 说出名言的人
            content = quotes[2]  # 内容,可能为地址/文本
            quote_format = quotes[3]  # 语录形式 img/text
            if quote_format == "text":
                member = await app.getMember(group_id, member_id)
                return [
                    "None",
                    MessageChain.create([
                        Plain(text=content),
                        Plain(text="\n————%s" % member.name)
                    ])
                ]
            elif quote_format == "img":
                return [
                    "None",
                    MessageChain.create([Image.fromLocalFile(content)])
                ]
            else:
                return [
                    "None",
                    MessageChain.create(
                        [Plain(text="quoteFormat error!(%s)" % quote_format)])
                ]
    elif quote_type == "all":
        sql = "select * from celebrityQuotes where groupId=%s and memberId=%s" % (
            group_id, member_id)
        quotes = await execute_sql(sql)
        if quotes is None:
            return [
                "None",
                MessageChain.create(
                    [Plain(text="%s还没有语录哦~快来添加吧~" % nickname[0])])
            ]
        member = await app.getMember(group_id, member_id)
        msg = [Plain(text="%s语录\n" % member.name)]
        index = 1
        for i in quotes:
            # print(i)
            content = i[2]  # 内容,可能为地址/文本
            quote_format = i[3]  # 语录形式 img/text
            if quote_format == "text":
                msg.append(Plain(text="%d.%s\n" % (index, content)))
            elif quote_format == "img":
                msg.append(Plain(text="%d.\n" % index))
                msg.append(Image.fromLocalFile(content))
                msg.append(Plain(text="\n"))
            else:
                return [
                    "None",
                    MessageChain.create(
                        [Plain(text="quoteFormat error!(%s)" % quote_format)])
                ]
            index += 1
        return ["None", MessageChain.create(msg)]
    elif quote_type == "select":
        sql = "select * from celebrityQuotes where groupId=%s and memberId=%s order by rand() limit 1" % (
            group_id, member_id)
        quotes = await execute_sql(sql)
        quotes = quotes[0]
        if quotes is None:
            return [
                "None",
                MessageChain.create(
                    [Plain(text="%s还没有语录哦~快来添加吧~" % nickname[0])])
            ]
        content = quotes[2]  # 内容,可能为地址/文本
        quote_format = quotes[3]  # 语录形式 img/text
        print(group_id, member_id)
        member = await app.getMember(group_id, member_id)
        if quote_format == "text":
            return [
                "None",
                MessageChain.create([
                    Plain(text=content),
                    Plain(text="\n————%s" % member.name)
                ])
            ]
        elif quote_format == "img":
            return [
                "None",
                MessageChain.create([Image.fromLocalFile(content)])
            ]
        else:
            return [
                "None",
                MessageChain.create(
                    [Plain(text="quoteFormat error!(%s)" % quote_format)])
            ]
    else:
        return ["None"]
async def head_splicer(app: GraiaMiraiApplication, message: MessageChain, member: Member, group: Group):
    print(globals()["signal"])
    if not os.path.exists("./modules/HeadSplicer/temp/"):
        os.mkdir("./modules/HeadSplicer/temp/")
    if "".join([plain.text for plain in message.get(Plain)]).strip() == "接头":
        if globals()["signal"] >= 2:
            try:
                await app.sendGroupMessage(group, MessageChain.create([Plain(text=f"目前有{signal}个任务正在处理,请稍后再试!")]))
            except AccountMuted:
                pass
            return None

        globals()["signal"] += 1

        if message.get(Image):
            image = message[Image][0]
            img_url = image.url
            async with aiohttp.ClientSession() as session:
                async with session.get(url=img_url) as resp:
                    img_content = await resp.read()
            image = IMG.open(BytesIO(img_content))
            image.save(f"./modules/HeadSplicer/temp/temp-{group.id}-{member.id}.png")
            try:
                try:
                    splicing_result = await process(
                        f"./modules/HeadSplicer/temp/temp-{group.id}-{member.id}.png",
                        f"./modules/HeadSplicer/temp/tempResult-{group.id}-{member.id}.png"
                    )
                except TooManyFacesDetected:
                    globals()["signal"] -= 1
                    await app.sendGroupMessage(
                        group,
                        MessageChain.create([Plain(text="脸太tm多了!说!你是不是故意欺负我!爪巴啊啊啊啊啊啊!")])
                    )
                    return None
                except Exception:
                    globals()["signal"] -= 1
                    await app.sendGroupMessage(
                        group,
                        MessageChain.create([Image.fromLocalFile("./modules/HeadSplicer/statics/接头失败.png")])
                    )
                    return None
                if splicing_result:
                    globals()["signal"] -= 1
                    await app.sendGroupMessage(
                        group,
                        MessageChain.create([
                            Image.fromLocalFile(f"./modules/HeadSplicer/temp/tempResult-{group.id}-{member.id}.png")
                        ])
                    )
                else:
                    globals()["signal"] -= 1
                    await app.sendGroupMessage(
                        group,
                        MessageChain.create([Image.fromLocalFile("./modules/HeadSplicer/statics/没找到头.png")])
                    )
            except AccountMuted:
                return None
        else:
            globals()["signal"] -= 1
            try:
                await app.sendGroupMessage(group, MessageChain.create([Plain(text="请附带图片!")]))
            except AccountMuted:
                pass
Beispiel #7
0
async def get_group_quotes(group_id: int, memberList, nickname, Type,
                           status) -> list:
    if status == "nickname":
        sql = "select memberId from nickname where groupId=%d and nickname='%s'" % (
            group_id, nickname[0])
        member_id = await execute_sql(sql)
        member_id = member_id[0][0]
        # print(quotes)
        if member_id is None:
            return [
                "None",
                MessageChain.create(
                    [Plain(text="%s是谁我不知道呐~快来添加别名吧~" % nickname[0])])
            ]
    elif status == "memberId":
        member_id = nickname
    elif status == "none":
        pass
    if Type == "random":
        sql = "select * from celebrityQuotes where groupId=%d order by rand() limit 1" % group_id
        quotes = await execute_sql(sql)[0]
        # print(quotes)
        if quotes is None:
            return [
                "None",
                MessageChain.create([Plain(text="本群还没有群语录哟~快来添加吧~")])
            ]
        else:
            member_id = quotes[1]  # 说出名言的人
            content = quotes[2]  # 内容,可能为地址/文本
            quote_format = quotes[3]  # 语录形式 img/text
            if quote_format == "text":
                return [
                    Plain(text=content),
                    Plain(text="\n————%s" % qq2name(memberList, member_id))
                ]
            elif quote_format == "img":
                return [
                    # At(target=memberId),
                    Image.fromFileSystem(content)
                    # Plain(text="\n————%s"%qq2name(memberList,memberId))
                ]
            else:
                return [Plain(text="quoteFormat error!(%s)" % quote_format)]
    elif Type == "all":
        sql = "select * from celebrityQuotes where groupId=%s and memberId=%s" % (
            group_id, member_id[0])
        quotes = await execute_sql(sql)
        if quotes is None:
            return [Plain(text="%s还没有语录哦~快来添加吧~" % nickname[0])]
        msg = [Plain(text="%s语录\n" % nickname[0])]
        index = 1
        for i in quotes:
            # print(i)
            content = i[2]  # 内容,可能为地址/文本
            quote_format = i[3]  # 语录形式 img/text
            if quote_format == "text":
                msg.append(Plain(text="%d.%s\n" % (index, content)))
            elif quote_format == "img":
                msg.append(Plain(text="%d.\n" % index))
                msg.append(Image.fromFileSystem(content))
                msg.append(Plain(text="\n"))
            else:
                return [Plain(text="quoteFormat error!(%s)" % quote_format)]
            index += 1
        return msg
    else:
        sql = "select * from celebrityQuotes where groupId=%s and memberId=%s order by rand() limit 1" % (
            group_id, member_id[0])
        quotes = await execute_sql(sql)
        if quotes is None:
            return [Plain(text="%s还没有语录哦~快来添加吧~" % nickname[0])]
        content = quotes[2]  # 内容,可能为地址/文本
        quote_format = quotes[3]  # 语录形式 img/text
        if quote_format == "text":
            return [Plain(text=content), Plain(text="\n————%s" % nickname[0])]
        elif quote_format == "img":
            return [
                # At(target=memberId),
                Image.fromFileSystem(content)
                # Plain(text="\n————%s"%qq2name(memberList,memberId))
            ]
        else:
            return [Plain(text="quoteFormat error!(%s)" % quote_format)]