add some readme
This commit is contained in:
parent
d10adb381c
commit
b1f6d17b52
17
README.md
17
README.md
@ -1,2 +1,19 @@
|
|||||||
# wechatgpt
|
# wechatgpt
|
||||||

|

|
||||||
|
|
||||||
|
# how to use
|
||||||
|
|
||||||
|
## prepare runtime environment
|
||||||
|
|
||||||
|
```
|
||||||
|
go mod tidy
|
||||||
|
cp config/config.yaml.example local/config.yaml
|
||||||
|
```
|
||||||
|
|
||||||
|
## add your openai token
|
||||||
|
open the [openai](https://beta.openai.com/account/api-keys) and register account, copy your token to config file
|
||||||
|
|
||||||
|
## run app
|
||||||
|
```
|
||||||
|
go run main.go
|
||||||
|
```
|
||||||
|
@ -2,39 +2,33 @@ package handler
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/eatmoreapple/openwechat"
|
"github.com/eatmoreapple/openwechat"
|
||||||
|
"github.com/prometheus/common/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
// MessageHandlerInterface 消息处理接口
|
|
||||||
type MessageHandlerInterface interface {
|
type MessageHandlerInterface interface {
|
||||||
handle(*openwechat.Message) error
|
handle(*openwechat.Message) error
|
||||||
ReplyText(*openwechat.Message) error
|
ReplyText(*openwechat.Message) error
|
||||||
}
|
}
|
||||||
|
|
||||||
type HandlerType string
|
type Type string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
GroupHandler = "group"
|
GroupHandler = "group"
|
||||||
)
|
)
|
||||||
|
|
||||||
var handlers map[HandlerType]MessageHandlerInterface
|
var handlers map[Type]MessageHandlerInterface
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
handlers = make(map[HandlerType]MessageHandlerInterface)
|
handlers = make(map[Type]MessageHandlerInterface)
|
||||||
handlers[GroupHandler] = NewGroupMessageHandler()
|
handlers[GroupHandler] = NewGroupMessageHandler()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handler 全局处理入口
|
|
||||||
func Handler(msg *openwechat.Message) {
|
func Handler(msg *openwechat.Message) {
|
||||||
//if msg.IsSendBySelf() {
|
|
||||||
// return
|
|
||||||
//}
|
|
||||||
//sender, err := msg.Sender()
|
|
||||||
//if err != nil {
|
|
||||||
// log.Println(err)
|
|
||||||
// return
|
|
||||||
//}
|
|
||||||
if msg.IsSendByGroup() {
|
if msg.IsSendByGroup() {
|
||||||
handlers[GroupHandler].handle(msg)
|
err := handlers[GroupHandler].handle(msg)
|
||||||
return
|
if err != nil {
|
||||||
|
log.Errorf("handle error: %s\n", err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user