예제 #1
0
async def get_song_ordered(keyword: str) -> list:
    """
    Search song from CloudMusic

    Args:
        keyword: Keyword to search

    Examples:
        message = await get_song_ordered("lemon")

    Return:
        [
            str: Auxiliary treatment to be done(Such as add statement),
            MessageChain: Message to be send(MessageChain)
        ]
    """
    song_search_url = "http://music.163.com/api/search/get/web?csrf_token=hlpretag=&hlposttag=&s={%s}&type=1&offset=0&total=true&limit=1" % keyword
    # print(song_search_url)
    async with aiohttp.ClientSession() as session:
        async with session.get(url=song_search_url) as resp:
            data_json = await resp.read()

    data_json = json.loads(data_json)

    song_id = data_json["result"]["songs"][0]["id"]
    detail_url = f"http://musicapi.leanapp.cn/song/detail?ids={song_id}"

    async with aiohttp.ClientSession() as session:
        async with session.get(url=detail_url) as resp:
            data_json = await resp.json()

    song_name = data_json["songs"][0]["name"]
    pic_url = data_json["songs"][0]["al"]["picUrl"]
    desc = data_json["songs"][0]["ar"][0]["name"]
    json_code = {
        "app": "com.tencent.structmsg",
        "desc": "音乐",
        "meta": {
            "music": {
                "action": "",
                "android_pkh_name": "",
                "app_type": 1,
                "appid": 100495085,
                "desc": desc,
                "jumpUrl": f"https://y.music.163.com/m/song/{song_id}",
                "musicUrl":
                f"http://music.163.com/song/media/outer/url?id={song_id}",
                "preview": pic_url,
                "sourceMsgId": 0,
                "source_icon": "",
                "source_url": "",
                "tag": "假装自己是网易云音乐的屑机器人",
                "title": song_name
            }
        },
        "prompt": f"[分享]{song_name}",
        "ver": "0.0.0.1",
        "view": "music"
    }
    return ["None", MessageChain.create([App(content=json.dumps(json_code))])]
예제 #2
0
async def member_join(
        app: GraiaMiraiApplication,
        event: MemberJoinEvent
):
    try:
        await app.sendGroupMessage(
            event.member.group.id, MessageChain.create([
                At(target=event.member.id),
                Plain(text="我是本群小可爱纱雾哟~欢迎呐~一起快活鸭~")
            ])
        )
        # welcome_json = json.dumps(eval(await get_json_code("MemberJoinEvent")))
        # print(welcome_json)
        welcome_json = """{
                    "prompt": "[欢迎入群]",
                    "extraApps": [],
                    "sourceUrl": "",
                    "appID": "",
                    "sourceName": "",
                    "desc": "",
                    "app": "com.tencent.qqpay.qqmp.groupmsg",
                    "ver": "1.0.0.7",
                    "view": "groupPushView",
                    "meta": {
                        "groupPushData": {
                            "fromIcon": "",
                            "fromName": "name",
                            "time": "",
                            "report_url": "http:\\/\\/kf.qq.com\\/faq\\/180522RRRVvE180522NzuuYB.html",
                            "cancel_url": "http:\\/\\/www.baidu.com",
                            "summaryTxt": "",
                            "bannerTxt": "欸嘿~欢迎进群呐~进来了就不许走了哦~",
                            "item1Img": "",
                            "bannerLink": "",
                            "bannerImg": "http:\\/\\/gchat.qpic.cn\\/gchatpic_new\\/12904366\\/1046209507-2584598286-E7FCC807BECA2938EBE5D57E7E4980FF\\/0?term=2"
                        }
                    },
                    "actionData": "",
                    "actionData_A": ""
                }"""
        await app.sendGroupMessage(
            event.member.group.id, MessageChain.create([
                App(content=welcome_json)
            ])
        )
    except AccountMuted:
        pass
async def get_group_announcement(content: str) -> list:
    group_announcement_json = """
                {
                    "app": "com.tencent.mannounce",
                    "config": {
                        "ctime": 1610424762,
                        "forward": 0,
                        "token": "190bcca54b1eb9c543676aa1c82762ab"
                    },
                    "desc": "群公告",
                    "extra": {
                        "app_type": 1,
                        "appid": 1101236949,
                        "uin": 1900384123
                    },
                    "meta": {
                        "mannounce": {
                            "cr": 1,
                            "encode": 1,
                            "fid": "93206d3900000000ba21fd5fa58a0500",
                            "gc": "963453075",
                            "sign": "cbbf90a7cbf1dc938ac5bdb8224fc3cb",
                            "text": "%s",
                            "title": "576k5YWs5ZGK",
                            "tw": 1,
                            "uin": "1900384123"
                        }
                    },
                    "prompt": "[群公告]test",
                    "ver": "1.0.0.43",
                    "view": "main"
                }""" % base64.b64encode(content.encode('utf-8'))
    return [
        "None",
        MessageChain.create([App(content=group_announcement_json)])
    ]
예제 #4
0
async def member_join(app: GraiaMiraiApplication, event: MemberJoinEvent):
    try:
        await app.sendGroupMessage(
            event.member.group.id,
            MessageChain.create([
                At(target=event.member.id),
                Plain(text="我是本群小可爱纱雾哟~欢迎呐~一起快活鸭~")
            ]))
        # welcome_json = json.dumps(eval(await get_json_code("MemberJoinEvent")))
        # print(welcome_json)
        # welcome_json = """{
        #             "prompt": "[欢迎入群]",
        #             "extraApps": [],
        #             "sourceUrl": "",
        #             "appID": "",
        #             "sourceName": "",
        #             "desc": "",
        #             "app": "com.tencent.qqpay.qqmp.groupmsg",
        #             "ver": "1.0.0.7",
        #             "view": "groupPushView",
        #             "meta": {
        #                 "groupPushData": {
        #                     "fromIcon": "",
        #                     "fromName": "name",
        #                     "time": "",
        #                     "report_url": "http:\\/\\/kf.qq.com\\/faq\\/180522RRRVvE180522NzuuYB.html",
        #                     "cancel_url": "http:\\/\\/www.baidu.com",
        #                     "summaryTxt": "",
        #                     "bannerTxt": "欸嘿~欢迎进群呐~进来了就不许走了哦~",
        #                     "item1Img": "",
        #                     "bannerLink": "",
        #                     "bannerImg": "http:\\/\\/gchat.qpic.cn\\/gchatpic_new\\/12904366\\/1046209507-2584598286-E7FCC807BECA2938EBE5D57E7E4980FF\\/0?term=2"
        #                 }
        #             },
        #             "actionData": "",
        #             "actionData_A": ""
        #         }"""
        welcome_json = """
        {
            "prompt": "SAGIRI",
            "sourceUrl": "",
            "extraApps": [],
            "appID": "",
            "sourceName": "",
            "desc": "",
            "app": "com.tencent.miniapp",
            "config": {
                "forward": true
            },
            "ver": "1.0.0.89",
            "view": "all",
            "meta": {
                "all": {
                    "preview": "http:\/\/gchat.qpic.cn\/gchatpic_new\/12904366\/1030673292-3125245045-E7FCC807BECA2938EBE5D57E7E4980FF\/0?term=2",
                    "title": "欢迎入群",
                    "buttons": [{
                        "name": "---FROM SAGIRI-BOT---",
                        "action": "http:\/\/www.qq.com"
                    }],
                    "jumpUrl": "",
                    "summary": "欢迎进群呐~进群了就不许走了呐~\r\n"
                }
            },
            "actionData": "",
            "actionData_A": ""
        }"""
        test_json = """
            {
                "app": "com.tencent.mannounce",
                "config": {
                    "ctime": 1610424762,
                    "forward": 0,
                    "token": "190bcca54b1eb9c543676aa1c82762ab"
                },
                "desc": "群公告",
                "extra": {
                    "app_type": 1,
                    "appid": 1101236949,
                    "uin": 1900384123
                },
                "meta": {
                    "mannounce": {
                        "cr": 1,
                        "encode": 1,
                        "fid": "93206d3900000000ba21fd5fa58a0500",
                        "gc": "963453075",
                        "sign": "cbbf90a7cbf1dc938ac5bdb8224fc3cb",
                        "text": "dGVzdA==",
                        "title": "576k5YWs5ZGK",
                        "tw": 1,
                        "uin": "1900384123"
                    }
                },
                "prompt": "[群公告]test",
                "ver": "1.0.0.43",
                "view": "main"
            }"""
        await app.sendGroupMessage(
            event.member.group.id,
            MessageChain.create([App(content=welcome_json)]))
    except AccountMuted:
        pass
예제 #5
0
async def group_message_listener(app: GraiaMiraiApplication, group: Group,
                                 message: MessageChain,
                                 message_info: GroupMessage):
    program_start = time.time()

    print("接收到组%s中来自%s的消息:%s" %
          (group.name, message_info.sender.name, message.asDisplay()))

    message_serialization = message.asSerializationString()
    message_serialization = message_serialization.replace(
        "[mirai:source:" +
        re.findall(r'\[mirai:source:(.*?)]', message_serialization, re.S)[0] +
        "]", "")
    # print(message_serialization)
    # 复读
    # lock.acquire()
    group_repeat[group.id]["lastMsg"] = group_repeat[group.id]["thisMsg"]
    group_repeat[group.id]["thisMsg"] = message_serialization
    # print(group_repeat[group.id])
    if group_repeat[group.id]["lastMsg"] != group_repeat[group.id]["thisMsg"]:
        group_repeat[group.id]["stopMsg"] = ""
    if await get_setting(group.id, "repeat"):
        if group_repeat[group.id]["lastMsg"] == group_repeat[
                group.id]["thisMsg"]:
            if group_repeat[group.id]["thisMsg"] != group_repeat[
                    group.id]["stopMsg"]:
                group_repeat[group.id]["stopMsg"] = group_repeat[
                    group.id]["thisMsg"]
                try:
                    await app.sendGroupMessage(group, message.asSendable())
                except AccountMuted:
                    pass
    # lock.release()

    if message.asDisplay(
    ) == "start old version" and message_info.sender.id == await get_config(
            "HostQQ"):
        await app.sendGroupMessage(group,
                                   message.create([Plain(text="即将切换至旧版本...")]))
        await app.sendGroupMessage(group,
                                   message.create([Plain(text="切换成功!")]))
        os.system(
            "%s \"%s\"" %
            (await get_config("environment"), await get_config("oldVersion")))

    if message.asDisplay(
    ) == "bot restart" and message_info.sender.id == await get_config("HostQQ"
                                                                      ):
        await app.sendGroupMessage(group,
                                   message.create([Plain(text="即将重启机器人...")]))
        await app.sendGroupMessage(group,
                                   message.create([Plain(text="重启成功!")]))
        os.system(
            "%s \"%s\"" %
            (await get_config("environment"), await get_config("newVersion")))

    if message.asDisplay(
    ) == "bot shutdown" and message_info.sender.id == await get_config("HostQQ"
                                                                       ):
        await app.sendGroupMessage(group,
                                   message.create([Plain(text="即将退出机器人...")]))
        exit(0)

    if message.asDisplay(
    ) == "pc shutdown" and message_info.sender.id == await get_config("HostQQ"
                                                                      ):
        await app.sendGroupMessage(group,
                                   message.create([Plain(text="即将关机...")]))
        os.system("shutdown -s")

    if message.asDisplay(
    ) == "test" and message_info.sender.id == await get_config("HostQQ"):
        msg = await daily_chat_rank(group.id, app)
        await app.sendGroupMessage(group, msg[1])
    if message.asDisplay(
    ) == "test1" and message_info.sender.id == await get_config("HostQQ"):
        # msg = await get_time()
        # msg = await get_group_announcement("测试")\
        # path = await save_img(message.get(Image)[0])
        # msg = await porn_identification(path)
        msg = await get_douban_new_books()
        await app.sendGroupMessage(group, msg[1])
    if message.asDisplay(
    ) == "test2" and message_info.sender.id == await get_config("HostQQ"):
        welcome_json = """
                {
                    "prompt": "欢迎入群",
                    "sourceUrl": "",
                    "extraApps": [],
                    "appID": "",
                    "sourceName": "",
                    "desc": "",
                    "app": "com.tencent.miniapp",
                    "config": {
                        "forward": true
                    },
                    "ver": "1.0.0.89",
                    "view": "all",
                    "meta": {
                        "all": {
                            "preview": "http:/gchat.qpic.cn/gchatpic_new/12904366/1030673292-3125245045-E7FCC807BECA2938EBE5D57E7E4980FF/0?term=2",
                            "title": "欢迎入群",
                            "buttons": [{
                                "name": "---FROM SAGIRI-BOT---",
                                "action": "http://www.qq.com"
                            }],
                            "jumpUrl": "",
                            "summary": "欢迎进群呐~进群了就不许走了呐~\r\n"
                        }
                    },
                    "actionData": "",
                    "actionData_A": ""
                }"""
        print(("test2"))
        await app.sendGroupMessage(
            group.id, MessageChain.create([App(content=welcome_json)]))
    if message.asDisplay(
    )[:4] == "sql:" and message_info.sender.id == await get_config("HostQQ"):
        result = await execute_sql(message.asDisplay()[4:])
        print(result)
        if type(result) != bool:
            if len(result) > 30:
                await app.sendGroupMessage(
                    group, MessageChain.create([Plain(text="数据过长!自动中止发送!")]))
            else:
                await app.sendGroupMessage(
                    group, MessageChain.create([Plain(text=str(result))]))
        else:
            await app.sendGroupMessage(
                group, MessageChain.create([Plain(text=str(result))]))

    switch = await get_setting(group.id, "switch")
    if switch == "online":
        try:
            message_send = await group_message_process(message, message_info,
                                                       app,
                                                       frequency_limit_dict)
        except Exception as e:
            if await get_setting(group.id, "debug"):
                message_send = [
                    "quoteSource",
                    MessageChain.create([Plain(text=str(e))])
                ]
            else:
                message_send = [
                    "quoteSource",
                    MessageChain.create([Plain(text="出错了呐~呜呜呜")])
                ]
    elif switch == "offline" and message_info.sender.id != await get_config(
            "HostQQ"):
        message_send = ["None"]
    elif message_info.sender.id == await get_config("HostQQ"):
        try:
            message_send = await group_message_process(message, message_info,
                                                       app,
                                                       frequency_limit_dict)
        except Exception as e:
            traceback.print_exc()
            message_send = [
                "quoteSource",
                MessageChain.create([Plain(text=str(e))])
            ]
    else:
        message_send = [
            "quoteSource",
            MessageChain.create([Plain(text="数据项switch错误!请检查数据库!")])
        ]

    # if len(message_send) >= 2 and message_send[1].has(Image):
    #     message_send.append(group)
    #     tasks.put(message_send)
    # else:
    await group_assist_process(message, message_info, message_send, group,
                               program_start)