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 TGCmdQueue <- c
b, err := zipMessages() b, err := zipMessages()
log.Printf("botMsgExportAll : Data returned.\n")
logOnError(err, "botMsgExportAll : exportMessages") logOnError(err, "botMsgExportAll : exportMessages")
if err != nil { if err != nil {
c := TGCommand{ c := TGCommand{

9
msg.go
View File

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