mirror of
https://github.com/krau/SaveAny-Bot.git
synced 2026-05-20 15:49:36 +08:00
refactor: use MTP API
This commit is contained in:
52
bot/utils.go
52
bot/utils.go
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user