Giter Club home page Giter Club logo

Comments (9)

GreyElaina avatar GreyElaina commented on August 16, 2024

根据:

class Json(InternalElement, ExternalElement):
    Json: str = Field(..., alias="json")

你需要:

import json

MessageChain.create([
    Json(Json=json.dumps({
        # 你的 json
    }))
])

你自己把这个 issue 关了

from application.

chenshenwei1998 avatar chenshenwei1998 commented on August 16, 2024

根据:

class Json(InternalElement, ExternalElement):
    Json: str = Field(..., alias="json")

你需要:

import json

MessageChain.create([
    Json(Json=json.dumps({
        # 你的 json
    }))
])

你自己把这个 issue 关了

哦哦看懂了,谢谢啦!

from application.

chenshenwei1998 avatar chenshenwei1998 commented on August 16, 2024

根据:

class Json(InternalElement, ExternalElement):
    Json: str = Field(..., alias="json")

你需要:

import json

MessageChain.create([
    Json(Json=json.dumps({
        # 你的 json
    }))
])

你自己把这个 issue 关了

试了一下好像不行欸
如果这么写

from graia.application.entry import Image, Json, MessageChain
import json

music_json = {
	"app": "com.tencent.structmsg",
	"config":
	以下省略n字
}

await app.sendGroupMessage(group, MessageChain.create([Json(Json=json.dumps(music_json))]))

会抛出

Traceback (most recent call last):
  File "bot.py", line 130, in group_message_handler
    await app.sendGroupMessage(group, MessageChain.create([Json(Json=json.dumps(music_json))]))
  File "pydantic\main.py", line 346, in pydantic.main.BaseModel.__init__
pydantic.error_wrappers.ValidationError: 1 validation error for Json
json
  field required (type=value_error.missing)

然后我把Json换成别名json,
await app.sendGroupMessage(group, MessageChain.create([Json(json=json.dumps(music_json))]))

又会抛出

Traceback (most recent call last):
  File "bot.py", line 130, in group_message_handler
    await app.sendGroupMessage(group, MessageChain.create([Json(json=json.dumps(music_json))]))
  File "D:\software\anaconda3\lib\site-packages\graia\application\__init__.py", line 205, in sendGroupMessage
    response.raise_for_status()
  File "D:\software\anaconda3\lib\site-packages\aiohttp\client_reqrep.py", line 946, in raise_for_status
    headers=self.headers)
aiohttp.client_exceptions.ClientResponseError: 400, message='Bad Request', url=URL('http://localhost:8988/sendGroupMessage')

这是怎么回事啊QAQ

from application.

GreyElaina avatar GreyElaina commented on August 16, 2024

附带 mirai-console 输出.

from application.

chenshenwei1998 avatar chenshenwei1998 commented on August 16, 2024

附带 mirai-console 输出.

用的是miraiOK,并没有什么输出TAT

from application.

chenshenwei1998 avatar chenshenwei1998 commented on August 16, 2024

附带 mirai-console 输出.

我在application包里添加了print((await message.build()).dict()['root'])的输出,发现是post的格式问题,应该是build方法实现有bug,导致post出去的消息无效,参数缺少'type: 'json',同样的问题也出现在App等消息中
输出信息如下

# 下面这条是文本的post信息中的messagechain的值,格式是正确的
[{'type': 'Plain', 'text': '你好哇,很开心你能找我聊天。'}]
# 下面这条是json的post信息中的messagechain的值,格式有误
[{'json': '{"app": "com.tencent.structmsg"}'}]
Traceback (most recent call last):
  File "bot.py", line 140, in group_message_handler
    await app.sendGroupMessage(group, MessageChain.create([Json(json=json.dumps(music_json_str))]))
  File "D:\software\anaconda3\lib\site-packages\graia\application\__init__.py", line 207, in sendGroupMessage
    response.raise_for_status()
  File "D:\software\anaconda3\lib\site-packages\aiohttp\client_reqrep.py", line 946, in raise_for_status
    headers=self.headers)
aiohttp.client_exceptions.ClientResponseError: 400, message='Bad Request', url=URL('http://localhost:8988/sendGroupMessage')

from application.

GreyElaina avatar GreyElaina commented on August 16, 2024

已知: FlashImage, Poke 等都有此种bug 需要修复.

from application.

GreyElaina avatar GreyElaina commented on August 16, 2024

更新到 0.1.3 尝试修复该错误

from application.

chenshenwei1998 avatar chenshenwei1998 commented on August 16, 2024

更新到 0.1.3 尝试修复该错误

问题已修复,非常感谢!

from application.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.