更新文档和readme.md

This commit is contained in:
eatMoreApple 2021-05-18 00:42:20 +08:00
parent 8a963e98f9
commit 7d2fd2fe33
2 changed files with 72 additions and 12 deletions

View File

@ -19,8 +19,6 @@
### 安装
`go get`
@ -83,15 +81,10 @@ func main() {
### 支持功能
> 消息回复、给指定对象好友、群组发送文本、图片、文件、emoji表情等消息
>
> 热登陆(无需重复扫码登录)、自定义消息处理、文件下载、消息防撤回
>
> 获取对象信息、设置好友备注、拉好友进群等
**更多功能请查看文档**
* 消息回复、给指定对象好友、群组发送文本、图片、文件、emoji表情等消息
* 热登陆(无需重复扫码登录)、自定义消息处理、文件下载、消息防撤回
* 获取对象信息、设置好友备注、拉好友进群等
* 更多功能请查看文档
@ -107,7 +100,9 @@ func main() {
## Thanks
<a href="https://www.jetbrains.com/?from=openwechat"><img src="https://goframe.org/download/thumbnails/1114119/jetbrains.png" height="200" alt="JetBrains"/></a>
<a href="https://www.jetbrains.com/?from=openwechat"><img src="https://account.jetbrains.com/static/images/jetbrains-logo-inv.svg" height="200" alt="JetBrains"/></a>

View File

@ -219,6 +219,71 @@ value, exist := msg.Get("hello")
#### 消息分发
```go
type MessageDispatcher interface {
Dispatch(msg *Message)
}
func DispatchMessage(dispatcher MessageDispatcher) func(msg *Message) {
return func(msg *Message) { dispatcher.Dispatch(msg) }
}
```
消息分发处理接口跟 DispatchMessage 结合封装成 MessageHandler
##### MessageMatchDispatcher
> MessageMatchDispatcher impl MessageDispatcher interface
###### example
```go
dispatcher := NewMessageMatchDispatcher()
dispatcher.OnText(func(msg *Message){
msg.ReplyText("hello")
})
bot := DefaultBot()
bot.MessageHandler = DispatchMessage(dispatcher)
```
###### 注册消息处理函数
```go
dispatcher.RegisterHandler(matchFunc matchFunc, handlers ...MessageContextHandler)
```
`matchFunc`为匹配函数,返回为`true`代表执行对应的`MessageContextHandler`
###### 注册文本消息处理函数
```go
dispatcher.OnText(handlers ...MessageContextHandler)
```
###### 注册图片消息的处理函数
```go
dispatcher.OnImage(handlers ...MessageContextHandler)
```
###### 注册语音消息的处理函数
```go
dispatcher.OnVoice(handlers ...MessageContextHandler)
```
### 登陆用户