Replies: 1 comment
-
Kotlin: suspend fun onMessage(event: MessageEvent) {
// 拿到所有的simbot Image消息对象
event.messageContent.messages.filterIsInstance<Image<*>>().forEach {
// 获取图片资源
val resource = it.resource()
// 直接获取输入流
resource.openStream().use { /* ... */ }
// 或拿url(如果允许的话)
if (resource is URLResource) {
val url = resource.url
println(url)
}
}
} Java: public void handle(MessageEvent event) {
// 拿到图片列表
final Messages messages = event.getMessageContent().getMessages();
for (Message.Element<?> message : messages) {
// 这个 MiraiImage是simbot提供的
if (message instanceof MiraiImage) {
MiraiImage image = (MiraiImage) message;
// 获取原生的Mirai图片对象。
// 这里的Image是Mirai原生的Image对象
final Image originalImage = image.getOriginalImage();
final String url = Image.queryUrl(originalImage);
System.out.println(url);
}
}
} Java中不能直接用 simbot 的 public void handle(MessageEvent event) throws IOException {
// 拿到图片列表
final Messages messages = event.getMessageContent().getMessages();
for (Message.Element<?> message : messages) {
// 这个 MiraiImage是simbot提供的
if (message instanceof Image<?>) {
Image<?> image = (Image<?>) message;
Resource resource = image.getResource();
// 直接获取输入流
try (InputStream stream = resource.openStream()) {
// do...
}
// 或者拿到url(如果允许的话)
if (resource instanceof URLResource) {
final URL url = ((URLResource) resource).getUrl();
System.out.println(url);
}
}
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
在mirai文档找到了这样的方法 simbot3.0要怎么做啊
net.mamoe.mirai.message.data.Image.queryUrl
Beta Was this translation helpful? Give feedback.
All reactions