-
Notifications
You must be signed in to change notification settings - Fork 20
/
main.go
executable file
·59 lines (52 loc) · 958 Bytes
/
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
package main
import (
"fmt"
"github.com/cjongseok/mtproto"
"github.com/cjongseok/slog"
"os"
"sync"
)
func usage() {
fmt.Println("USAGE: ./playdump <AUTH> <DUMP>")
fmt.Println("")
}
func handleError(err error) {
if err != nil {
fmt.Println(err)
usage()
os.Exit(1)
}
}
type callback struct{}
func (cb *callback) OnUpdate(u mtproto.Update) {
fmt.Println("update:", slog.Stringify(u))
}
func main() {
if len(os.Args) != 3 {
usage()
return
}
authFileName := os.Args[1]
dumpFilename := os.Args[2]
slog.SetLogOutputAsFile("dump_" + dumpFilename + "_")
handlerWg := sync.WaitGroup{}
handlerWg.Add(1)
out := make(chan interface{})
go func() {
defer handlerWg.Done()
for {
select {
case u := <-out:
if u == nil {
return
}
fmt.Println("update:", slog.Stringify(u))
}
}
}()
dump, err := mtproto.NewDump(authFileName, dumpFilename, out)
handleError(err)
dump.Play()
dump.Wait()
handlerWg.Wait()
}