Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

支持 dicecollapse #101

Open
wants to merge 2 commits into
base: neo
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions nga/nga.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ func (tiezi *Tiezi) page(page int) {
}
code, _ := jsonparser.GetInt(resp.Bytes(), "code")
if code != 0 {
log.Fatalln("nga 返回代码不为0:", code)
msg, _ := jsonparser.GetString(resp.Bytes(), "msg")
log.Fatalln("nga 返回代码不为0:", code, msg)
} else {
tiezi.Timestamp = ts()

Expand Down Expand Up @@ -366,6 +367,26 @@ func (tiezi *Tiezi) fixContent(floor_i int) {
cont = strings.ReplaceAll(cont, it, anony(it))
}

//ROLL DICE
//<div class='dice'><b>ROLL : 1d100</b>=d100(32)=<b>32</b></div>
re = regexp.MustCompile(`<div class='dice'><b>ROLL : (.+?)</b>=(.+?)=<b>(.+?)</b></div>`)
for _, it := range re.FindAllStringSubmatch(cont, -1) {
rollSrc := it[1]
rollRt := it[3]
cont = strings.ReplaceAll(cont, it[0], fmt.Sprintf(" **【ROLL** : %s= **%s】** ", rollSrc, rollRt))
}

//collapse 折叠
//<div class="foldBox no"><div class="collapse_btn"><a href="javascript:;" onclick="collapse(this);">+</a>外层看到的 ...</div><span class="collapse_content" id="foldCnt">里面</span></div>
re = regexp.MustCompile(`<div class="foldBox no"><div class="collapse_btn"><a href="javascript:;" onclick="collapse\(this\);">\+</a>(.+?) ...</div><span class="collapse_content" id="foldCnt">(.+?)</span></div>`)
for _, it := range re.FindAllStringSubmatch(cont, -1) {
outTxt := it[1]
inTxt := it[2]
rt := fmt.Sprintf("<details>\n <summary>%s</summary>\n <pre>%s</pre>\n</details>", outTxt, strings.ReplaceAll(inTxt, "\n", "<br>"))

cont = strings.ReplaceAll(cont, it[0], rt)
}

//图片
re = regexp.MustCompile(`\[img\](.+?)\[/img\]`)
for _, it := range re.FindAllStringSubmatch(cont, -1) {
Expand Down Expand Up @@ -612,11 +633,10 @@ func (tiezi *Tiezi) genMarkdown(localMaxFloor int) {
}

f, err := os.OpenFile(mdFilePath, os.O_APPEND|os.O_WRONLY, 0666)
defer f.Close()
if err != nil {
log.Fatalf("创建或打开 .md 文件失败:%v", err)
}

defer f.Close()
for i := localMaxFloor; i < len(tiezi.Floors); i++ {
floor := &tiezi.Floors[i]
if floor.Lou == -1 {
Expand Down