Skip to content

Commit

Permalink
Beta326 (#333)
Browse files Browse the repository at this point in the history
* beta318

* beta319

* beta320

* beata321

* beta322

* beta323

* beta324

* beta325

* beta326
  • Loading branch information
Hoshinonyaruko authored Feb 22, 2024
1 parent 54a77e2 commit 93966fa
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
1 change: 1 addition & 0 deletions handlers/message_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ func transformMessageTextUrl(messageText string, message callapi.ActionMessage,
// 根据配置处理URL
if config.GetLotusValue() {
// 连接到另一个gensokyo
mylog.Printf("转换url:%v", originalURL)
shortURL := url.GenerateShortURL(originalURL)
return shortURL
} else {
Expand Down
25 changes: 23 additions & 2 deletions handlers/send_guild_channel_forum.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/hoshinonyaruko/gensokyo/config"
"github.com/hoshinonyaruko/gensokyo/images"
"github.com/hoshinonyaruko/gensokyo/mylog"
"mvdan.cc/xurls"

"github.com/hoshinonyaruko/gensokyo/echo"

Expand Down Expand Up @@ -165,14 +166,22 @@ func GenerateForumMessage(foundItems map[string][]string, messageText string) (*
} `json:"paragraphs"`
}

// 处理文本消息
// 使用xurls正则表达式查找所有的URL
foundURLs := xurls.Relaxed.FindAllString(messageText, -1)

// 移除文本中的URL
messageText = xurls.Relaxed.ReplaceAllStringFunc(messageText, func(originalURL string) string {
return ""
})

// 处理文本消息,除了URL
if messageText != "" {
richText.Paragraphs = append(richText.Paragraphs, struct {
Elems []interface{} `json:"elems"`
}{
Elems: []interface{}{
map[string]interface{}{
"text": map[string]string{
"text": map[string]interface{}{
"text": messageText,
},
"type": 1,
Expand All @@ -181,12 +190,24 @@ func GenerateForumMessage(foundItems map[string][]string, messageText string) (*
})
}

// 为每个URL创建ELEM_TYPE_URL元素
for _, url := range foundURLs {
richText.Paragraphs[0].Elems = append(richText.Paragraphs[0].Elems, map[string]interface{}{
"url": map[string]interface{}{
"url": url,
"desc": "点我跳转",
},
"type": 4,
})
}

if len(richText.Paragraphs) == 0 {
// 初始化一个空段落
richText.Paragraphs = append(richText.Paragraphs, struct {
Elems []interface{} "json:\"elems\""
}{})
}

// 处理图片链接
for _, url := range foundItems["url_image"] {
richText.Paragraphs[0].Elems = append(richText.Paragraphs[0].Elems, map[string]interface{}{
Expand Down
1 change: 1 addition & 0 deletions url/shorturl.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ func GenerateShortURL(longURL string) string {
// 处理响应
if resp.StatusCode != http.StatusOK {
mylog.Printf("Received non-200 status code: %d from server: %v", resp.StatusCode, requestURL)
mylog.Printf("返回码400请检查lotus密码是否正确!")
return ""
}

Expand Down

0 comments on commit 93966fa

Please sign in to comment.