test
This commit is contained in:
parent
7d4ae4b668
commit
2a53fa5d22
109
bot.go
109
bot.go
@ -162,6 +162,16 @@ func botMsgRescan(m *tb.Message) {
|
|||||||
if !m.Private() {
|
if !m.Private() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if _, ok := clientsKeepAlive[m.Chat.ID]; !ok && m.Chat.ID != cfg.Bot.Admin {
|
||||||
|
c := TGCommand{
|
||||||
|
Type: commandReplyMsg,
|
||||||
|
Text: "Client not registered",
|
||||||
|
FromMsgID64: int64(m.ID),
|
||||||
|
FromChatID64: m.Chat.ID,
|
||||||
|
}
|
||||||
|
TGCmdQueue <- c
|
||||||
|
return
|
||||||
|
}
|
||||||
r := regexp.MustCompile("^[0-9]+$")
|
r := regexp.MustCompile("^[0-9]+$")
|
||||||
if r.MatchString(m.Payload) {
|
if r.MatchString(m.Payload) {
|
||||||
p := JobPayloadRescanMsg{
|
p := JobPayloadRescanMsg{
|
||||||
@ -202,6 +212,16 @@ func botMsgRescanAll(m *tb.Message) {
|
|||||||
if !m.Private() {
|
if !m.Private() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if _, ok := clientsKeepAlive[m.Chat.ID]; !ok && m.Chat.ID != cfg.Bot.Admin {
|
||||||
|
c := TGCommand{
|
||||||
|
Type: commandReplyMsg,
|
||||||
|
Text: "Client not registered",
|
||||||
|
FromMsgID64: int64(m.ID),
|
||||||
|
FromChatID64: m.Chat.ID,
|
||||||
|
}
|
||||||
|
TGCmdQueue <- c
|
||||||
|
return
|
||||||
|
}
|
||||||
p := JobPayloadRescanMsg{
|
p := JobPayloadRescanMsg{
|
||||||
Query: fmt.Sprintf("SELECT o.id FROM obj o WHERE o.obj_type_id = %d AND o.obj_sub_type_id = %d ORDER BY id ASC;", objTypeMessage, objSubTypeMessageUnknown),
|
Query: fmt.Sprintf("SELECT o.id FROM obj o WHERE o.obj_type_id = %d AND o.obj_sub_type_id = %d ORDER BY id ASC;", objTypeMessage, objSubTypeMessageUnknown),
|
||||||
MsgID64: int64(m.ID),
|
MsgID64: int64(m.ID),
|
||||||
@ -231,103 +251,68 @@ func botMsgRescanAll(m *tb.Message) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func botMsgExport(m *tb.Message) {
|
func botBackupExport(m *tb.Message) {
|
||||||
if !m.Private() {
|
if !m.Private() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if _, ok := clientsKeepAlive[m.Chat.ID]; !ok && m.Chat.ID != cfg.Bot.Admin {
|
||||||
c := TGCommand{
|
|
||||||
Type: commandReplyMsg,
|
|
||||||
Text: `Starting messages export`,
|
|
||||||
FromMsgID64: int64(m.ID),
|
|
||||||
FromChatID64: m.Chat.ID,
|
|
||||||
}
|
|
||||||
TGCmdQueue <- c
|
|
||||||
|
|
||||||
b, err := zipMessages()
|
|
||||||
log.Printf("botMsgExportAll : Data returned.\n")
|
|
||||||
logOnError(err, "botMsgExportAll : exportMessages")
|
|
||||||
if err != nil {
|
|
||||||
c := TGCommand{
|
c := TGCommand{
|
||||||
Type: commandReplyMsg,
|
Type: commandReplyMsg,
|
||||||
Text: `Error exporting messages`,
|
Text: "Client not registered",
|
||||||
FromMsgID64: int64(m.ID),
|
FromMsgID64: int64(m.ID),
|
||||||
FromChatID64: m.Chat.ID,
|
FromChatID64: m.Chat.ID,
|
||||||
}
|
}
|
||||||
TGCmdQueue <- c
|
TGCmdQueue <- c
|
||||||
|
|
||||||
return
|
return
|
||||||
} else {
|
|
||||||
text := fmt.Sprintf("Document size : %d bytes.", len(b))
|
|
||||||
c := TGCommand{
|
|
||||||
Type: commandReplyMsg,
|
|
||||||
Text: text,
|
|
||||||
FromMsgID64: int64(m.ID),
|
|
||||||
FromChatID64: m.Chat.ID,
|
|
||||||
}
|
|
||||||
TGCmdQueue <- c
|
|
||||||
}
|
}
|
||||||
|
|
||||||
d := tb.Document{}
|
p := JobPayloadBackupExport{
|
||||||
d.File = tb.FromReader(bytes.NewReader(b))
|
MsgID64: int64(m.ID),
|
||||||
d.FileName = fmt.Sprintf("%s.backup.zip", time.Now().Format("20060102150405"))
|
ChatID64: m.Chat.ID,
|
||||||
d.Caption = d.FileName
|
|
||||||
d.MIME = `application/zip`
|
|
||||||
|
|
||||||
c = TGCommand{
|
|
||||||
Type: commandSendDocument,
|
|
||||||
Document: d,
|
|
||||||
ToChatID64: m.Chat.ID,
|
|
||||||
}
|
}
|
||||||
TGCmdQueue <- c
|
b, _ := json.Marshal(p)
|
||||||
|
_, err := createJob(objSubTypeJobBackupExport, objJobPriorityBackup, int64(m.Sender.ID), time.Now(), b)
|
||||||
|
logOnError(err, "botBackupExport : createJob(objSubTypeJobBackupExport)")
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func botMsgLoad(m *tb.Message) {
|
func botBackupImport(m *tb.Message) {
|
||||||
if !m.Private() {
|
if !m.Private() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
r := regexp.MustCompile("^(http|https)://[a-z0-9./]+.zip$") // https://dump.siteop.biz/20190609163137.backup.zip
|
if _, ok := clientsKeepAlive[m.Chat.ID]; !ok && m.Chat.ID != cfg.Bot.Admin {
|
||||||
if r.MatchString(m.Payload) {
|
|
||||||
|
|
||||||
resp, err := http.Get(m.Payload)
|
|
||||||
logOnError(err, "botMsgLoad : Get")
|
|
||||||
defer resp.Body.Close()
|
|
||||||
|
|
||||||
buf := new(bytes.Buffer)
|
|
||||||
buf.ReadFrom(resp.Body)
|
|
||||||
|
|
||||||
c := TGCommand{
|
c := TGCommand{
|
||||||
Type: commandReplyMsg,
|
Type: commandReplyMsg,
|
||||||
Text: "File downloaded.",
|
Text: "Client not registered",
|
||||||
FromMsgID64: int64(m.ID),
|
FromMsgID64: int64(m.ID),
|
||||||
FromChatID64: m.Chat.ID,
|
FromChatID64: m.Chat.ID,
|
||||||
}
|
}
|
||||||
TGCmdQueue <- c
|
TGCmdQueue <- c
|
||||||
|
return
|
||||||
err = UnzipMessages(buf.Bytes())
|
}
|
||||||
logOnError(err, "botMsgLoad : UnzipMessages")
|
r := regexp.MustCompile(`^((http[s]?\:)\/\/)?([^\?\:\/#]+)(\:([0-9]+))?(\/[^\?\#]*)?(\?([^#]*))?(#.*)?.zip$`)
|
||||||
|
if !r.MatchString(m.Payload) {
|
||||||
c = TGCommand{
|
|
||||||
Type: commandReplyMsg,
|
|
||||||
Text: "Messages injected.",
|
|
||||||
FromMsgID64: int64(m.ID),
|
|
||||||
FromChatID64: m.Chat.ID,
|
|
||||||
}
|
|
||||||
TGCmdQueue <- c
|
|
||||||
|
|
||||||
} else {
|
|
||||||
c := TGCommand{
|
c := TGCommand{
|
||||||
Type: commandReplyMsg,
|
Type: commandReplyMsg,
|
||||||
Text: "No file",
|
Text: "URL not valid.",
|
||||||
FromMsgID64: int64(m.ID),
|
FromMsgID64: int64(m.ID),
|
||||||
FromChatID64: m.Chat.ID,
|
FromChatID64: m.Chat.ID,
|
||||||
}
|
}
|
||||||
TGCmdQueue <- c
|
TGCmdQueue <- c
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
p := JobPayloadBackupExport{
|
||||||
|
URL: m.Payload,
|
||||||
|
MsgID64: int64(m.ID),
|
||||||
|
ChatID64: m.Chat.ID,
|
||||||
|
}
|
||||||
|
b, _ := json.Marshal(p)
|
||||||
|
_, err := createJob(objSubTypeJobBackupImport, objJobPriorityBackup, int64(m.Sender.ID), time.Now(), b)
|
||||||
|
logOnError(err, "botBackupImport : createJob(objSubTypeJobBackupImport)")
|
||||||
return
|
return
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func botMsgDump(m *tb.Message) {
|
func botMsgDump(m *tb.Message) {
|
||||||
|
3
job.go
3
job.go
@ -1,8 +1,11 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"archive/zip"
|
||||||
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
Loading…
Reference in New Issue
Block a user