2024-06-03 21:50:30 +00:00
|
|
|
|
package devianter
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"encoding/json"
|
|
|
|
|
"strconv"
|
|
|
|
|
"strings"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type comments struct {
|
|
|
|
|
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"`
|
|
|
|
|
Parent int `json:"ParrentId"`
|
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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// функция для обработки комментариев поста, пользователя, группы и многого другого
|
|
|
|
|
func Comments(
|
|
|
|
|
postid string,
|
|
|
|
|
cursor string,
|
|
|
|
|
page int,
|
|
|
|
|
typ int, // 1 - комментарии поста; 4 - комментарии на стене группы или пользователя
|
|
|
|
|
) (cmmts comments) {
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
// если начало строки {, а конец }, то срабатывает этот иф
|
|
|
|
|
if m[0] == 123 && m[l-1] == 125 {
|
|
|
|
|
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
|
|
|
|
|
}
|