This commit is contained in:
shoopea 2019-06-09 00:26:13 +08:00
parent 43d99a09ba
commit 205cf0598d
2 changed files with 8 additions and 2 deletions

1
bot.go
View File

@ -196,6 +196,7 @@ func botMsgExportAll(m *tb.Message) {
TGCmdQueue <- c
b, err := zipMessages()
log.Printf("botMsgExportAll : Data returned.\n")
logOnError(err, "botMsgExportAll : exportMessages")
if err != nil {
c := TGCommand{

9
msg.go
View File

@ -278,7 +278,7 @@ func zipMessages() ([]byte, error) {
s := new([]ChatWarsMessage)
msgs := *s
ids := getSQLListID64(`SELECT om.obj_id id FROM obj_msg om;`)
fmt.Printf("zipMessages : Retrieved %d message ids.\n", len(ids))
log.Printf("zipMessages : Retrieved %d message ids.\n", len(ids))
i := 0
for _, id := range ids {
m, err := getMsg(id)
@ -288,18 +288,21 @@ func zipMessages() ([]byte, error) {
}
i = i + 1
if i%10000 == 0 {
fmt.Printf("zipMessages : Exported %d messages.\n", i)
log.Printf("zipMessages : Exported %d messages.\n", i)
}
}
log.Printf("zipMessages : Assigning messages.\n")
bkp.Messages = msgs
log.Printf("zipMessages : Marshalling messages.\n")
b, err := json.Marshal(bkp)
logOnError(err, "exportMessages : Marshal")
if err != nil {
return nil, err
}
log.Printf("zipMessages : Compressing messages.\n")
zbuf := new(bytes.Buffer)
zw := zip.NewWriter(zbuf)
zf, err := zw.Create(`backup.json`)
@ -320,6 +323,8 @@ func zipMessages() ([]byte, error) {
return nil, err
}
log.Printf("zipMessages : Returning messages.\n")
return zbuf.Bytes(), nil
}