2024-06-03 21:50:30 +00:00
|
|
|
|
package devianter
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"encoding/json"
|
|
|
|
|
"strconv"
|
|
|
|
|
"strings"
|
|
|
|
|
)
|
|
|
|
|
|
2024-06-13 21:05:21 +00:00
|
|
|
|
type Comments struct {
|
2024-06-03 21:50:30 +00:00
|
|
|
|
Cursor string
|
|
|
|
|
PrevOffset int
|
|
|
|
|
HasMore, HasLess bool
|
|
|
|
|
|
|
|
|
|
Total int
|
|
|
|
|
Thread []struct {
|
2024-06-05 11:32:40 +00:00
|
|
|
|
Replies, Likes int
|
|
|
|
|
ID int `json:"commentId"`
|
2024-06-14 17:05:21 +00:00
|
|
|
|
Parent int `json:"parentId"`
|
2024-06-03 21:50:30 +00:00
|
|
|
|
|
2024-06-05 11:32:40 +00:00
|
|
|
|
Posted time
|
|
|
|
|
Author bool `json:"isAuthorHighlited"`
|
2024-06-03 21:50:30 +00:00
|
|
|
|
|
2024-06-05 11:32:40 +00:00
|
|
|
|
Desctiption string
|
|
|
|
|
Comment string
|
2024-06-03 21:50:30 +00:00
|
|
|
|
|
2024-06-05 11:32:40 +00:00
|
|
|
|
TextContent text
|
2024-06-03 21:50:30 +00:00
|
|
|
|
|
|
|
|
|
User struct {
|
|
|
|
|
Username string
|
2024-06-05 11:32:40 +00:00
|
|
|
|
Banned bool `json:"isBanned"`
|
2024-06-03 21:50:30 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// функция для обработки комментариев поста, пользователя, группы и многого другого
|
2024-06-13 21:05:21 +00:00
|
|
|
|
func CommentsFunc(
|
2024-06-03 21:50:30 +00:00
|
|
|
|
postid string,
|
|
|
|
|
cursor string,
|
|
|
|
|
page int,
|
|
|
|
|
typ int, // 1 - комментарии поста; 4 - комментарии на стене группы или пользователя
|
2024-06-13 21:05:21 +00:00
|
|
|
|
) (cmmts Comments) {
|
2024-06-03 21:50:30 +00:00
|
|
|
|
for x := 0; x <= page; x++ {
|
|
|
|
|
ujson(
|
|
|
|
|
"dashared/comments/thread?typeid="+strconv.Itoa(typ)+
|
|
|
|
|
"&itemid="+postid+"&maxdepth=1000&order=newest"+
|
|
|
|
|
"&limit=50&cursor="+strings.ReplaceAll(cursor, "+", `%2B`),
|
|
|
|
|
&cmmts,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
cursor = cmmts.Cursor
|
|
|
|
|
|
|
|
|
|
// парсинг json внутри json
|
|
|
|
|
for i := 0; i < len(cmmts.Thread); i++ {
|
|
|
|
|
m, l := cmmts.Thread[i].TextContent.Html.Markup, len(cmmts.Thread[i].TextContent.Html.Markup)
|
|
|
|
|
cmmts.Thread[i].Comment = m
|
|
|
|
|
|
|
|
|
|
// если начало строки {, а конец }, то срабатывает этот иф
|
2024-06-13 21:05:21 +00:00
|
|
|
|
if m[0] == '{' && m[l-1] == '}' {
|
2024-06-03 21:50:30 +00:00
|
|
|
|
var content struct {
|
|
|
|
|
Blocks []struct {
|
|
|
|
|
Text string
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
e := json.Unmarshal([]byte(m), &content)
|
|
|
|
|
err(e)
|
|
|
|
|
|
|
|
|
|
for _, a := range content.Blocks {
|
|
|
|
|
cmmts.Thread[i].Comment = a.Text
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
}
|