-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
263 lines (260 loc) · 7.39 KB
/
main.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
package main
import (
"TLExtractor/android"
"TLExtractor/appcenter"
"TLExtractor/appcenter/types"
"TLExtractor/consts"
"TLExtractor/debug_menu"
"TLExtractor/environment"
"TLExtractor/github"
"TLExtractor/groq"
"TLExtractor/java/jadx"
"TLExtractor/services"
"TLExtractor/telegram/bot"
"TLExtractor/telegram/scheme"
schemeTypes "TLExtractor/telegram/scheme/types"
"TLExtractor/telegram/telegraph"
"TLExtractor/tui"
"TLExtractor/utils/package_manager"
"errors"
"fmt"
"github.com/GoBotApiOfficial/gobotapi"
"github.com/GoBotApiOfficial/gobotapi/filters"
"github.com/GoBotApiOfficial/gobotapi/methods"
tgTypes "github.com/GoBotApiOfficial/gobotapi/types"
"github.com/Laky-64/gologging"
"slices"
)
func main() {
tui.Run()
if environment.Debug && !debug_menu.ReadyToTest {
return
}
scheme.ListenCoreFork()
package_manager.CheckPackages()
services.Run(run)
}
func run() {
bot.Client.UpdateUptime(true, "")
if !environment.Debug {
defer func() {
if r := recover(); r != nil {
bot.Client.UpdateUptime(false, "panic")
gologging.Fatal(r)
}
}()
}
bot.Client.OnMessage(filters.Filter(func(client *gobotapi.Client, update tgTypes.Message) {
status := environment.IsBuilding()
if !status {
environment.SetPatchStatus(true)
}
_, _ = client.Invoke(&methods.SendMessage{
ChatID: update.Chat.ID,
Text: environment.FormatVar(
"patch_message",
map[string]any{
"is_building": status,
},
),
ParseMode: "HTML",
})
}, filters.And(filters.Command("patch", consts.SupportedBotAliases...), filters.ChatID(environment.LocalStorage.LogChatID))))
appcenter.Listen(func(update types.UpdateInfo) error {
if err := bot.Client.UpdateStatus(
environment.FormatVar(
"message",
map[string]any{
"update": update,
"progress": 0,
"is_patch": environment.IsPatch(),
},
),
false,
false,
nil,
); err != nil {
return err
}
if update.Source == "android" {
if err := jadx.Decompile(func(percentage int64) {
if percentage == 100 {
return
}
if err := bot.Client.UpdateStatus(
environment.FormatVar(
"message",
map[string]any{
"update": update,
"progress": percentage,
"is_patch": environment.IsPatch(),
},
),
false,
false,
nil,
); err != nil {
bot.Client.UpdateUptime(false, "panic")
gologging.Fatal(err)
}
}); err != nil {
return err
}
}
var err error
var fullScheme *schemeTypes.TLFullScheme
previewLayer := environment.LocalStorage.PreviewLayer.Layer
if update.Source == "android" {
fullScheme, err = android.ExtractScheme()
if err != nil {
return err
}
} else if update.Source == "tdesktop" || update.Source == "tdlib" {
var remoteScheme *schemeTypes.TLRemoteScheme
var patchScheme schemeTypes.PatchOS
if update.Source == "tdesktop" {
remoteScheme, err = scheme.GetScheme()
patchScheme = schemeTypes.TDesktopPatch
} else if update.Source == "tdlib" {
remoteScheme, err = scheme.GetTDLibScheme()
patchScheme = schemeTypes.TDLibPatch
} else {
return errors.New("unknown source")
}
err = scheme.UpdateUpstreamCache(update.Source, remoteScheme)
if err != nil {
return err
}
fullScheme, err = scheme.MergeRemote(remoteScheme, patchScheme, remoteScheme.Layer == previewLayer, true, func(isE2E bool) (*schemeTypes.TLRemoteScheme, error) {
var rScheme schemeTypes.TLRemoteScheme
var methodsTemp []*schemeTypes.TLMethod
var constructorsTemp []*schemeTypes.TLConstructor
var layer = environment.LocalStorage.PreviewLayer
if isE2E {
methodsTemp = layer.E2EApi.Methods
constructorsTemp = layer.E2EApi.Constructors
} else {
methodsTemp = layer.MainApi.Methods
constructorsTemp = layer.MainApi.Constructors
}
for _, method := range methodsTemp {
rScheme.Methods = append(rScheme.Methods, &schemeTypes.TLMethod{
TLBase: method.TLBase.Clone(),
Method: method.Method,
})
}
for _, constructor := range constructorsTemp {
rScheme.Constructors = append(rScheme.Constructors, &schemeTypes.TLConstructor{
TLBase: constructor.TLBase.Clone(),
Predicate: constructor.Predicate,
})
}
rScheme.Layer = previewLayer
return &rScheme, nil
})
fullScheme.IsSync = true
} else {
return errors.New("unknown source")
}
if differences := scheme.GetDiffs(environment.LocalStorage.PreviewLayer, fullScheme); differences != nil && fullScheme.Layer >= previewLayer {
stats := scheme.GetStats(differences)
commitMessage := fmt.Sprintf("Updated to Layer %d", fullScheme.Layer)
if environment.IsPatch() {
commitMessage = fmt.Sprintf("Patch %d", fullScheme.Layer)
}
commitInfo, err := github.Client.MakeCommit(
fullScheme,
stats,
commitMessage,
)
if err != nil {
return err
}
var stableScheme *schemeTypes.TLFullScheme
if environment.LocalStorage.StableLayer != nil && slices.Contains(environment.LocalStorage.RecentLayers, fullScheme.Layer) {
stableScheme = environment.LocalStorage.StableLayer
} else {
stableScheme = environment.LocalStorage.PreviewLayer
}
stableDiffs := scheme.GetDiffs(
stableScheme,
fullScheme,
)
pageTitle := fmt.Sprintf("Layer %d", fullScheme.Layer)
if !fullScheme.IsSync {
pageTitle = fmt.Sprintf("%s Preview", pageTitle)
}
groqDescriptions := make(map[string]string)
if stats.MainApi.TotalAdditions > 0 || stats.E2EApi.TotalAdditions > 0 {
groqDescriptions, err = groq.GenerateDescriptions(differences)
if err != nil {
return err
}
}
url, err := telegraph.Client.CreatePage(
pageTitle,
environment.FormatVar(
"changelogs",
map[string]any{
"differences": differences,
"stats": stats,
"commit_urls": commitInfo.FilesLines,
"banner_url": environment.LocalStorage.BannerURL,
"main_scheme": scheme.ToString(stableDiffs.MainApi, fullScheme.Layer, false),
"e2e_scheme": scheme.ToString(stableDiffs.E2EApi, fullScheme.Layer, false),
"groq_descriptions": groqDescriptions,
},
),
)
if err != nil {
return err
}
if err = bot.Client.UpdateStatus(
environment.FormatVar(
"message",
map[string]any{
"update": update,
"layer": fullScheme.Layer,
"stats": stats,
"is_stable": fullScheme.IsSync,
"is_patch": environment.IsPatch(),
},
),
true,
true,
&tgTypes.InlineKeyboardMarkup{
InlineKeyboard: [][]tgTypes.InlineKeyboardButton{
{
{
Text: "Full Changelog",
URL: url,
},
{
Text: "GitHub",
URL: commitInfo.SourceURL,
},
},
},
},
); err != nil {
return err
}
if !environment.Debug {
if !slices.Contains(environment.LocalStorage.RecentLayers, fullScheme.Layer) {
environment.LocalStorage.RecentLayers = append(environment.LocalStorage.RecentLayers, fullScheme.Layer)
}
if len(environment.LocalStorage.RecentLayers) > 1 {
environment.LocalStorage.RecentLayers = environment.LocalStorage.RecentLayers[1:]
environment.LocalStorage.StableLayer = environment.LocalStorage.PreviewLayer
}
environment.LocalStorage.PreviewLayer = fullScheme
environment.LocalStorage.Commit()
}
} else {
if err = bot.Client.UpdateStatus("", false, false, nil); err != nil {
return err
}
}
return nil
})
}