This commit is contained in:
shoopea 2019-06-09 21:00:15 +08:00
parent 787a6f04b6
commit 3b2e44c5ec
2 changed files with 34 additions and 6 deletions

29
bot.go
View File

@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"log"
"net/http"
"regexp"
"strconv"
"time"
@ -264,6 +265,34 @@ func botMsgLoad(m *tb.Message) {
if !m.Private() {
return
}
r := regexp.MustCompile("^(http|https)://[a-z0-9./]+.zip$") // https://dump.siteop.biz/20190609163137.backup.zip
if r.MatchString(m.Payload) {
c = TGCommand{
Type: commandReplyMsg,
Text: "Got file",
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
}
TGCmdQueue <- c
resp, err := http.Get(m.Payload)
if err != nil {
return err
}
defer resp.Body.Close()
buf := new(bytes.Buffer)
buf.ReadFrom(resp.Body)
UnzipMessages(buf.Bytes())
} else {
c = TGCommand{
Type: commandReplyMsg,
Text: "No file",
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
}
TGCmdQueue <- c
}
return
}

11
msg.go
View File

@ -278,7 +278,6 @@ func zipMessages() ([]byte, error) {
s := new([]ChatWarsMessage)
msgs := *s
ids := getSQLListID64(`SELECT om.obj_id id FROM obj_msg om;`)
log.Printf("zipMessages : Retrieved %d message ids.\n", len(ids))
i := 0
for _, id := range ids {
m, err := getObjMsg(id)
@ -293,16 +292,13 @@ func zipMessages() ([]byte, error) {
}
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`)
@ -323,8 +319,11 @@ func zipMessages() ([]byte, error) {
return nil, err
}
log.Printf("zipMessages : Returning messages.\n")
return zbuf.Bytes(), nil
}
func UnzipMessages(z []byte) error {
log.Printf("UnzipMessages : %d bytes.\n", len(z))
return nil
}