refactor: use MTP API

This commit is contained in:
krau
2024-10-12 12:47:33 +08:00
parent 5ef7c5ce60
commit 5d6b1003e9
13 changed files with 183 additions and 357 deletions

View File

@@ -4,22 +4,10 @@ import (
"fmt"
"regexp"
"github.com/amarnathcjd/gogram/telegram"
"github.com/krau/SaveAny-Bot/storage"
"github.com/mymmrac/telego"
"github.com/mymmrac/telego/telegoutil"
)
func FileDownloadURL(filePath string) string {
return Bot.FileDownloadURL(filePath)
}
func ReplyMessage(replyTo telego.Message, format string, args ...any) (*telego.Message, error) {
return Bot.SendMessage(telegoutil.Messagef(replyTo.Chat.ChatID(), format, args...).
WithReplyParameters(&telego.ReplyParameters{
MessageID: replyTo.MessageID,
}))
}
var StorageDisplayNames = map[string]string{
"all": "全部",
"local": "服务器磁盘",
@@ -27,20 +15,42 @@ var StorageDisplayNames = map[string]string{
"webdav": "WebDAV",
}
func AddTaskReplyMarkup(messageID int) *telego.InlineKeyboardMarkup {
storageButtons := make([]telego.InlineKeyboardButton, 0)
func AddTaskReplyMarkup(messageID int32) telegram.ReplyMarkup {
// TODO: sort storage buttons
storageButtons := make([]telegram.KeyboardButton, 0)
for name := range storage.Storages {
storageButtons = append(storageButtons, telegoutil.InlineKeyboardButton(StorageDisplayNames[string(name)]).
WithCallbackData(fmt.Sprintf("add %d %s", messageID, name)))
storageButtons = append(storageButtons, &telegram.KeyboardButtonCallback{
Text: StorageDisplayNames[string(name)],
Data: []byte(fmt.Sprintf("add %d %s", messageID, name)),
})
}
if len(storageButtons) > 1 {
return telegoutil.InlineKeyboard(storageButtons, []telego.InlineKeyboardButton{
telegoutil.InlineKeyboardButton("全部").WithCallbackData(fmt.Sprintf("add %d all", messageID)),
})
return &telegram.ReplyInlineMarkup{
Rows: []*telegram.KeyboardButtonRow{
{
Buttons: storageButtons,
},
{
Buttons: []telegram.KeyboardButton{
&telegram.KeyboardButtonCallback{
Text: "全部",
Data: []byte(fmt.Sprintf("add %d all", messageID)),
},
},
},
},
}
}
if len(storageButtons) == 1 {
return telegoutil.InlineKeyboard(storageButtons)
return &telegram.ReplyInlineMarkup{
Rows: []*telegram.KeyboardButtonRow{
{
Buttons: storageButtons,
},
},
}
}
return nil
}