replyContent
continuous-integration/drone/push Build is passing Details

master
dustoair 3 years ago
parent aeb45db68e
commit 2818784c9f

@ -0,0 +1,24 @@
package api
import (
"WechatGateWay/global"
"github.com/jinzhu/gorm"
)
/**
@author: sre
@date: 2022/9/12 0012
@desc: todo
**/
type BinancePrice struct {
gorm.Model
Symbol string
Price float64
}
func GetBinanceLatestPrice(symbol string) float64 {
var binancePrice BinancePrice
global.DB.Where("symbol = ?", symbol).Last(&binancePrice)
return binancePrice.Price
}

@ -1,16 +1,19 @@
package handle
import (
"WechatGateWay/api"
"WechatGateWay/global"
"WechatGateWay/third_part"
"WechatGateWay/utils"
"encoding/xml"
"fmt"
"log"
"net/http"
)
// cmdExec 根据白名单命令来执行
func cmdExec(msgContent MsgContent) (cmdString string) {
func cmdExec(msgContent MsgContent) (replyContent string) {
var cmdString string
switch msgContent.Content {
case "last":
cmdString = global.HistoryCmds[len(global.HistoryCmds)-1]
@ -34,9 +37,13 @@ func cmdExec(msgContent MsgContent) (cmdString string) {
go RecordWechatBlockWords(lastText.Content, textMd5, msgContent.FromUsername)
return
case "eth", "btc", "虚拟货币":
cmdString = "cmdString"
priceBTC := api.GetBinanceLatestPrice("BTCUSDT")
priceETH := api.GetBinanceLatestPrice("ETHUSDT")
replyContent = fmt.Sprintf("BTC: %f \n ETH: %f", priceBTC, priceETH)
return
case "gold", "黄金":
cmdString = "cmdString"
replyContent = "黄金黄金黄金黄金黄金"
default:
cmdString = msgContent.Content
}
@ -49,14 +56,31 @@ func cmdExec(msgContent MsgContent) (cmdString string) {
//aiAnswer = "执行命令:" + msgContent.Content
}
return cmdString
return
}
func aiReply(msgContent MsgContent) (replyContent string) {
var replyContentAi string
if _, ok := global.EmojMap[msgContent.Content]; ok {
//系统表情消息 取字典意思丢ai回复
replyContentAi = third_part.AiChat(global.EmojMap[msgContent.Content])
} else {
//普通文本消息直接丢ai
replyContentAi = third_part.AiChat(msgContent.Content)
}
//对ai结果 有表情包的上表情包
if emoj, ok := utils.MapKey(global.EmojMap, replyContentAi); ok {
replyContent = emoj + replyContentAi
} else {
replyContent = replyContentAi
}
return
}
func replyText(msgContent MsgContent, timestamp, nonce string, w http.ResponseWriter) {
var replyContent string
if global.EnableCmdExec && utils.SliceContain(global.CMDList, msgContent.Content) && msgContent.FromUsername == "QiaoYang" {
//开启了命令执行功能,并且消息内容包含了命令
log.Println("收到命令消息")
cmdExec(msgContent)
replyContent = cmdExec(msgContent)
//cmdString := cmdExec(msgContent)
//var cmdString string
//if msgContent.Content == "last" {
@ -94,20 +118,8 @@ func replyText(msgContent MsgContent, timestamp, nonce string, w http.ResponseWr
// //aiAnswer = "执行命令:" + msgContent.Content
//}
} else {
var replyContentAi string
if _, ok := global.EmojMap[msgContent.Content]; ok {
//系统表情消息 取字典意思丢ai回复
replyContentAi = third_part.AiChat(global.EmojMap[msgContent.Content])
} else {
//普通文本消息直接丢ai
replyContentAi = third_part.AiChat(msgContent.Content)
}
//对ai结果 有表情包的上表情包
if emoj, ok := utils.MapKey(global.EmojMap, replyContentAi); ok {
replyContent = emoj + replyContentAi
} else {
replyContent = replyContentAi
}
log.Println("ai msg")
replyContent = aiReply(msgContent)
}
//文本消息审核

@ -1,6 +1,7 @@
package main
import (
"WechatGateWay/api"
"WechatGateWay/global"
"WechatGateWay/handle"
"WechatGateWay/third_part"
@ -68,6 +69,7 @@ func InitDB() *gorm.DB {
//自动建表
db.AutoMigrate(&handle.WechatLog{})
db.AutoMigrate(&handle.WechatBlockWords{})
db.AutoMigrate(&api.BinancePrice{})
global.DB = db
return db

Loading…
Cancel
Save