Esempio n. 1
0
async def handle_city(bot: Bot, event: Event, state: T_State):
    city = state["city"]
    code = await get_weather(city)
    if code['msg'] == "success":
        data = code['data']
        weatherJson = {
            "app": "com.tencent.miniapp",
            "desc": "",
            "view": "notification",
            "ver": "0.0.0.1",
            "prompt": "",
            "appID": "",
            "sourceName": "",
            "actionData": "",
            "actionData_A": "",
            "sourceUrl": "",
            "meta": {
                "notification": {
                    "appInfo": {
                        "appName": f"{data['cityname']}天气",
                        "appType": "",
                        "appid": "",
                        "iconUrl": "https://gitee.com/jxygzzy/filebad/raw/master/icon/20210614-160947-0334.png"
                    },
                    "data": [
                        {
                            "title": "气温:",
                            "value": f"{data['temp']}℃ {data['weather']}"
                        },
                        {
                            "title": "PM2.5:",
                            "value": f"{data['pm25']}μg/m3"
                        }
                    ],
                    "title": "",
                    "button": [
                        {
                            "name": f"最后更新时间:{data['time']}",
                            "action": ""
                        }
                    ],
                    "emphasis_keyword": ""
                }
            },
            "text": "",
            "sourceAd": ""
        }
        await weather.finish(message=MessageSegment.json(data=json.dumps(weatherJson)))
    else:
        msg = code['msg']
        await weather.finish(message=msg)
Esempio n. 2
0
async def handle_songName(bot: Bot, event: Event, state: T_State):
    songName = state["songName"]
    songIdList = await dataget.songIds(songName=songName)
    if not songIdList:
        await songpicker.reject("没有找到这首歌,请发送其它歌名!")
    songInfoList = list()
    for songId in songIdList:
        songInfoDict = await dataget.songInfo(songId)
        songInfoList.append(songInfoDict)
    songInfoMessage = await dataProcess.mergeSongInfo(songInfoList)
    songInfoMessageJson = {
        "app": "com.tencent.miniapp",
        "desc": "",
        "view": "notification",
        "ver": "0.0.0.1",
        "prompt": "",
        "appID": "",
        "sourceName": "",
        "actionData": "",
        "actionData_A": "",
        "sourceUrl": "",
        "meta": {
            "notification": {
                "appInfo": {
                    "appName":
                    f"{songName}结果如下,请输入欲点播歌曲的序号:",
                    "appType":
                    "",
                    "appid":
                    "",
                    "iconUrl":
                    "https://bizaladdin-image.baidu.com/0/pic/67edf360ac5f88826e3d757a5e407579.jpg"
                },
                "data": songInfoMessage,
                "title": "",
                "button": [{
                    "name": "【回复序号可重选】",
                    "action": ""
                }],
                "emphasis_keyword": ""
            }
        },
        "text": "",
        "sourceAd": ""
    }
    await songpicker.send(message=MessageSegment.json(
        data=json.dumps(songInfoMessageJson)))
    state["songIdList"] = songIdList