You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

85 lines
2.4 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package handle
import (
"WechatGateWay/global"
"WechatGateWay/third_part"
"WechatGateWay/utils"
"encoding/xml"
"log"
"net/http"
)
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("收到命令消息")
var cmdString string
if msgContent.Content == "last" {
cmdString = global.HistoryCmds[len(global.HistoryCmds)-1]
} else if msgContent.Content == "history" {
cmdString = utils.SlicePrint(global.HistoryCmds)
} else if msgContent.Content == "删除图片" {
lastImg := GetLastWechatLog(msgContent.FromUsername, "image")
err := utils.DeleteFile(lastImg.Content)
if err != nil {
log.Println("删除图片失败")
return
} else {
log.Println("删除图片")
return
}
} else {
cmdString = msgContent.Content
}
global.HistoryCmds = append(global.HistoryCmds, msgContent.Content)
replyContent, err := utils.CMDShellTrick(cmdString)
if err != nil {
replyContent = "/:,@!执行失败:\n" + msgContent.Content
} else {
replyContent = "/::D执行成功\n" + replyContent
//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
}
}
//构造回复消息
replyMsg, _ := xml.Marshal(ReplyTextMsg{
ToUsername: msgContent.FromUsername,
FromUsername: msgContent.ToUsername,
CreateTime: msgContent.CreateTime,
MsgType: "text",
Content: replyContent,
})
encryptMsg, cryptErr := global.WxCrypt.EncryptMsg(string(replyMsg), timestamp, nonce)
if cryptErr != nil {
log.Println("回复加密出错", cryptErr)
return
} else {
log.Println(string(encryptMsg))
l, err := w.Write(encryptMsg)
if err != nil {
log.Println("返回消息失败")
return
} else {
log.Println("成功写入", l)
}
}
}