-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathget_changelog_update.go
82 lines (80 loc) · 2.13 KB
/
get_changelog_update.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package updates
import (
"OwlGramServer/consts"
"OwlGramServer/http"
"fmt"
"regexp"
"strconv"
"strings"
)
func (ctx *Context) GetChangelogUpdate(version string, lang string, ignoreChecks bool) *string {
langStyle := ""
switch strings.ToUpper(lang) {
case "IT":
langStyle = "IT"
break
default:
langStyle = ""
break
}
linkChannel := fmt.Sprintf("%s%s", consts.OwlGramTGChannelLink, langStyle)
cacheId := "changelogNews"
cacheBetaId := cacheId + "Beta"
resultCache := ""
updatesInfo := ctx.UpdatesDescriptor
testVersion, _ := strconv.Atoi(version)
if !ignoreChecks {
if updatesInfo.Updates == nil {
fmt.Println("CRITICAL ERROR: updatesInfo.Updates is nil")
return nil
}
if updatesInfo.Updates.Beta == nil {
fmt.Println("CRITICAL ERROR: updatesInfo.Updates.Beta is nil")
}
if updatesInfo.Updates.Stable == nil {
fmt.Println("CRITICAL ERROR: updatesInfo.Updates.Stable is nil")
}
if testVersion > updatesInfo.Updates.Beta.VersionCode && testVersion > updatesInfo.Updates.Stable.VersionCode {
return nil
}
}
var cache *string
if !ignoreChecks {
cache = ctx.getCacheContent(cacheId+langStyle, version)
}
if cache == nil {
tmpResult := http.ExecuteRequest(linkChannel).ReadString()
cache = &tmpResult
if !ignoreChecks {
ctx.setCacheContent(cacheId+langStyle, version, tmpResult)
}
}
if cache != nil {
resultCache = *cache
}
var cacheBeta *string
if !ignoreChecks {
cacheBeta = ctx.getCacheContent(cacheBetaId, version)
}
if cacheBeta == nil {
tmpResult := http.ExecuteRequest(consts.OwlGramTGChannelBetaLink).ReadString()
cacheBeta = &tmpResult
if !ignoreChecks {
ctx.setCacheContent(cacheBetaId, version, tmpResult)
}
}
if cacheBeta != nil {
resultCache += "\n" + *cacheBeta
}
if cache != nil || cacheBeta != nil {
r, _ := regexp.Compile(`<div class="tgme_widget_message_text js-message_text" dir="auto">(.*?)</div>`)
for _, match := range r.FindAllSubmatch([]byte(resultCache), -1) {
post := string(match[1])
if strings.Contains(strings.Split(post, "<br/>")[0], version) {
formattedString := getReadableResult(post)
return &formattedString
}
}
}
return nil
}