Skip to content

Commit

Permalink
Test4 (#34)
Browse files Browse the repository at this point in the history
* Compiled main.go and pushed changes

* test

* 适配了频道私聊,用bolt数据库取代ini

* 适配了nonebot2

* add license

* add a lot

* trss support

* add action

* add action

* add action

* fixbug

* add wss

* bugfix

* fix action

* fix action again

* fa

* fix

* add a lot

* add ws server token

* bugifx

* fixat

* bugfix

* bugfix

* test

* test2

* add url service

* add url service

* bugfix

* fix

* fix

* fix

* bug fix

* fix

* test

* add webui

* add image_compress

* bug fix

* fix cq code
  • Loading branch information
Hoshinonyaruko authored Nov 3, 2023
1 parent b7278ea commit 47d71aa
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions handlers/message_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"path/filepath"
"regexp"
"runtime"
"strconv"
"strings"

"github.com/hoshinonyaruko/gensokyo/callapi"
Expand Down Expand Up @@ -160,15 +161,19 @@ func parseMessageContent(paramsMessage callapi.ParamsContent) (string, map[strin

// at处理和链接处理
func transformMessageText(messageText string) string {
// 首先,将AppID替换为BotID
messageText = strings.ReplaceAll(messageText, AppID, BotID)

// 使用正则表达式来查找所有[CQ:at,qq=数字]的模式
re := regexp.MustCompile(`\[CQ:at,qq=(\d+)\]`)
messageText = re.ReplaceAllStringFunc(messageText, func(m string) string {
submatches := re.FindStringSubmatch(m)
if len(submatches) > 1 {
realUserID, err := idmap.RetrieveRowByIDv2(submatches[1])
if err != nil {
// 如果出错,也替换成相应的格式,但使用原始QQ号
mylog.Printf("Error retrieving user ID: %v", err)
return m // 如果出错,返回原始匹配
return "<@!" + submatches[1] + ">"
}
return "<@!" + realUserID + ">"
}
Expand Down Expand Up @@ -208,11 +213,21 @@ func RevertTransformedText(data interface{}) string {

// 使用正则表达式来查找所有<@!数字>的模式
re := regexp.MustCompile(`<@!(\d+)>`)
// 使用正则表达式来替换找到的模式为[CQ:at,qq=数字]
// 使用正则表达式来替换找到的模式为[CQ:at,qq=用户ID]
messageText = re.ReplaceAllStringFunc(messageText, func(m string) string {
submatches := re.FindStringSubmatch(m)
if len(submatches) > 1 {
return "[CQ:at,qq=" + submatches[1] + "]"
//映射用户id
userID64, err := idmap.StoreIDv2(submatches[1])
if err != nil {
//如果储存失败(数据库损坏)返回原始值
mylog.Printf("Error storing ID: %v", err)
return "[CQ:at,qq=" + submatches[1] + "]"
}
//类型转换
userIDStr := strconv.FormatInt(userID64, 10)
//经过转换的cq码
return "[CQ:at,qq=" + userIDStr + "]"
}
return m
})
Expand Down

0 comments on commit 47d71aa

Please sign in to comment.