Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
Mirai
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
Mirai
Commits
885ae780
Commit
885ae780
authored
Dec 24, 2019
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add wiki
parent
717ef85e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
2 additions
and
79 deletions
+2
-79
README.md
README.md
+2
-79
No files found.
README.md
View file @
885ae780
...
@@ -257,82 +257,5 @@ Mirai 中所有的消息均为对象化的 [Message](mirai-core/src/commonMain/k
...
@@ -257,82 +257,5 @@ Mirai 中所有的消息均为对象化的 [Message](mirai-core/src/commonMain/k
您无需记忆用法.
您无需记忆用法.
在监听事件后的事件处理过程中, 您可调用扩展
`image.send()`
来发送图片. 或是调用
`image.upload()`
来上传并得到一个类型为
`Image`
的
`Message`
以便于发送组合类型的消息
在监听事件后的事件处理过程中, 您可调用扩展
`image.send()`
来发送图片. 或是调用
`image.upload()`
来上传并得到一个类型为
`Image`
的
`Message`
以便于发送组合类型的消息
#### Image JVM
## Wiki
在
[
WiKi
](
https://github.com/mamoe/mirai/wiki/Development-Guide---Kotlin
)
中查看各类帮助
对于 JVM 平台, Mirai 提供额外的足以应对大多数情况的扩展函数:
\ No newline at end of file
[
ExternalImageJvm
](
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/ExternalImageJvm.kt
)
若有必要, 这些函数将会创建临时文件以避免使用内存缓存图片
以下内容中,
`IMAGE`
可替换为
`ExternalImage`
,
`BufferedImage`
,
`File`
,
`InputStream`
,
`URL`
或
`Input`
(来自
`kotlinx.io`
)
转为
`ExternalImage`
-
`suspend IMAGE.toExternalImage():ExternalImage`
直接发送
-
`suspend IMAGE.sendAsImageTo(Contact)`
-
`suspend Contact.sendImage(IMAGE)`
转为 Message
-
`suspend IMAGE.uploadAsImage(Contact)`
-
`suspend Contact.upload(IMAGE)`
### Event
#### Subscription
[
查看相关监听代码
](
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/Subscribers.kt
)
您可以通过顶层 (top-level) 方法
`subscribeXXX`
对某个事件进行监听, 其中
`XXX`
可以是
-
Always (不断监听)
-
Once (一次监听)
-
Until / While (条件监听)
例:
```
kotlin
subscribeAlways
<
FriendMessageEvent
>{
//it: FriendMessageEvent
}
```
#### Message Event
对于消息事件, Mirai 还提供了更强大的 DSL 监听方式.
[
MessageSubscribersBuilder
](
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/MessageSubscribers.kt#L140
)
可用条件方法为:
-
case (内容相等)
-
contains
-
startsWith
-
endsWith
-
sentBy (特定发送者)
```
kotlin
// 监听所有群和好友消息
subscribeMessages
{
// this: MessageSubscribersBuilder
case
(
"你好"
){
// this: SenderAndMessage
// message: MessageChain
// sender: QQ
// it: String (来自 MessageChain.toString)
// group: Group (如果是群消息)
reply
(
"你好!"
)
// reply将发送给这个事件的主体(群消息的群, 好友消息的好友)
}
replyCase
(
"你好"
){
"你好!"
}
// lambda 的返回值将会作为回复消息
"Hello"
reply
"World"
// 收到 "Hello" 回复 "World"
}
```
当然, 您也可以仅监听来自群或好友的消息
```
kotlin
// 监听所有好友消息
subscribeFriendMessages
{
}
//监听所有群消息
subscribeGroupMessages
{
}
```
另外, 由于 Mirai 可同时维护多个机器人账号, Mirai 也提供了对单个机器人的事件的监听.
为了限制只监听来自某个机器人账号的事件, 您只需要在
`subscribeMessages`
前添加
`bot.`
将其修改为调用
`Bot`
下的扩展方法.
例:
```
kotlin
bot
.
subscribeMessages
{
}
```
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment