Skip to content

Commit

Permalink
v2.8 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
houko committed Dec 15, 2022
1 parent 64462d2 commit 833ce00
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 12 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,28 @@ xiaomoinfo/wechatgpt-amd64:latest
```


如果运行`telegram`智能机器人时希望在群里回复别人消息,可以指定一个关键字触发

```
# apple silicon
docker run -d \
--name wechatgpt \
-e apiKey="你的chatgpt apiKey" \
-e telegram="你的telegram token" \
-e tg_keyword="小莫" \
xiaomoinfo/wechatgpt:latest
# linux amd64
docker run -d \
--name wechatgpt \
-e apiKey="你的chatgpt apiKey" \
-e telegram="你的telegram token" \
-e tg_keyword="小莫" \
xiaomoinfo/wechatgpt-amd64:latest
```



<img src="screenshots/docker部署.png" alt="drawing" style="width:450px;"/>

Expand Down
8 changes: 4 additions & 4 deletions Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ tasks:

version:
cmds:
- docker build --platform linux/amd64 -t xiaomoinfo/wechatgpt-amd64:2.6 .
- docker push xiaomoinfo/wechatgpt-amd64:2.6
- docker build -t xiaomoinfo/wechatgpt:2.6 .
- docker push xiaomoinfo/wechatgpt:2.6
- docker build --platform linux/amd64 -t xiaomoinfo/wechatgpt-amd64:2.8.0 .
- docker push xiaomoinfo/wechatgpt-amd64:2.8.0
- docker build -t xiaomoinfo/wechatgpt:2.8.0 .
- docker push xiaomoinfo/wechatgpt:2.8.0
32 changes: 24 additions & 8 deletions bootstrap/telegram.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
log "github.com/sirupsen/logrus"
"github.com/wechatgpt/wechatbot/config"
"github.com/wechatgpt/wechatbot/handler/telegram"
"github.com/wechatgpt/wechatbot/utils"
"os"
"strings"
"time"
Expand Down Expand Up @@ -51,10 +52,8 @@ func StartTelegramBot() {
chatUserName := update.Message.Chat.UserName

tgUserNameStr := os.Getenv("tg_whitelist")

tgUserNames := strings.Split(tgUserNameStr, ",")

if len(tgUserNames) > 0 {
if len(tgUserNames) > 0 && len(tgUserNameStr) > 0 {
found := false
for _, name := range tgUserNames {
if name == chatUserName {
Expand All @@ -65,19 +64,36 @@ func StartTelegramBot() {

if !found {
log.Error("用户设置了私人私用,白名单以外的人不生效: ", chatUserName)
return
continue
}
}

responseMsg := telegram.Handle(text)
if responseMsg == nil {
tgKeyWord := os.Getenv("tg_keyword")
var reply *string
// 如果设置了关键字就以关键字为准,没设置就所有消息都监听
if len(tgKeyWord) > 0 {
content, key := utils.ContainsI(text, tgKeyWord)
if len(key) == 0 {
continue
}
splitItems := strings.Split(content, key)
if len(splitItems) < 2 {
continue
}
requestText := strings.TrimSpace(splitItems[1])
log.Println("问题:", requestText)
reply = telegram.Handle(requestText)
} else {
reply = telegram.Handle(text)
}
if reply == nil {
continue
}
msg := tgbotapi.NewMessage(chatID, *responseMsg)
msg := tgbotapi.NewMessage(chatID, *reply)
send, err := bot.Send(msg)
if err != nil {
log.Errorf("发送消息出错:%s", err.Error())
return
continue
}
fmt.Println(send.Text)
}
Expand Down

0 comments on commit 833ce00

Please sign in to comment.