* feat: add import command and batch import functionality - Implemented the `/import` command to allow users to import files from storage to Telegram. - Added support for listing files in storage and filtering based on regex patterns. - Created a batch import task to handle multiple file uploads concurrently. - Introduced progress tracking for batch imports, providing real-time updates to users. - Enhanced storage interfaces to support file listing and reading capabilities. - Updated localization files for the new import command and its usage instructions. - Added utility functions for file size formatting and speed calculation. - Refactored Telegram storage handling to support reading from non-seekable streams. * feat: add i18n for import command * feat: implement ListFiles and OpenFile methods for WebDAV and Alist storage * Update common/i18n/locale/zh-Hans.yaml Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update core/tasks/batchimport/progress.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update core/tasks/batchimport/execute.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update storage/alist/alist.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update common/i18n/locale/en.yaml Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update pkg/storagetypes/fileinfo.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update common/i18n/locale/en.yaml Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update core/tasks/batchimport/execute.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update storage/webdav/webdav.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update storage/telegram/telegram.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update core/tasks/batchimport/execute.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update storage/webdav/webdav.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * fix: missing progress stats i18n * refactor: use strutil to parse args * chore: update generated code files for consistency --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
73 lines
3.6 KiB
Go
73 lines
3.6 KiB
Go
package handlers
|
|
|
|
import (
|
|
"regexp"
|
|
|
|
"github.com/celestix/gotgproto/dispatcher"
|
|
"github.com/celestix/gotgproto/dispatcher/handlers"
|
|
"github.com/celestix/gotgproto/dispatcher/handlers/filters"
|
|
"github.com/celestix/gotgproto/ext"
|
|
sabotfilters "github.com/krau/SaveAny-Bot/client/bot/handlers/utils/filters"
|
|
"github.com/krau/SaveAny-Bot/client/bot/handlers/utils/re"
|
|
userclient "github.com/krau/SaveAny-Bot/client/user"
|
|
"github.com/krau/SaveAny-Bot/common/i18n/i18nk"
|
|
"github.com/krau/SaveAny-Bot/config"
|
|
"github.com/krau/SaveAny-Bot/pkg/tcbdata"
|
|
)
|
|
|
|
type DescCommandHandler struct {
|
|
Cmd string
|
|
Desc i18nk.Key
|
|
handler func(ctx *ext.Context, u *ext.Update) error
|
|
}
|
|
|
|
var CommandHandlers = []DescCommandHandler{
|
|
{"start", i18nk.BotMsgCmdStart, handleHelpCmd},
|
|
{"silent", i18nk.BotMsgCmdSilent, handleSilentCmd},
|
|
{"storage", i18nk.BotMsgCmdStorage, handleStorageCmd},
|
|
{"dir", i18nk.BotMsgCmdDir, handleDirCmd},
|
|
{"rule", i18nk.BotMsgCmdRule, handleRuleCmd},
|
|
{"save", i18nk.BotMsgCmdSave, handleSilentMode(handleSaveCmd, handleSilentSaveReplied)},
|
|
{"dl", i18nk.BotMsgCmdDl, handleDlCmd},
|
|
{"aria2dl", i18nk.BotMsgCmdAria2dl, handleAria2DlCmd},
|
|
{"ytdlp", i18nk.BotMsgCmdYtdlp, handleYtdlpCmd},
|
|
{"import", i18nk.BotMsgCmdImport, handleImportCmd},
|
|
{"task", i18nk.BotMsgCmdTask, handleTaskCmd},
|
|
{"cancel", i18nk.BotMsgCmdCancel, handleCancelCmd},
|
|
{"config", i18nk.BotMsgCmdConfig, handleConfigCmd},
|
|
{"fnametmpl", i18nk.BotMsgCmdFnametmpl, handleConfigFnameTmpl},
|
|
{"help", i18nk.BotMsgCmdHelp, handleHelpCmd},
|
|
{"parser", i18nk.BotMsgCmdParser, handleParserCmd},
|
|
{"watch", i18nk.BotMsgCmdWatch, handleWatchCmd},
|
|
{"unwatch", i18nk.BotMsgCmdUnwatch, handleUnwatchCmd},
|
|
{"lswatch", i18nk.BotMsgCmdLswatch, handleLswatchCmd},
|
|
{"syncpeers", i18nk.BotMsgCmdSyncpeers, handleSyncpeersCmd},
|
|
{"update", i18nk.BotMsgCmdUpdate, handleUpdateCmd},
|
|
}
|
|
|
|
func Register(disp dispatcher.Dispatcher) {
|
|
disp.AddHandler(handlers.NewMessage(filters.Message.ChatType(filters.ChatTypeChannel), func(ctx *ext.Context, u *ext.Update) error {
|
|
return dispatcher.EndGroups
|
|
}))
|
|
disp.AddHandler(handlers.NewMessage(filters.Message.ChatType(filters.ChatTypeChat), func(ctx *ext.Context, u *ext.Update) error {
|
|
return dispatcher.EndGroups
|
|
}))
|
|
disp.AddHandler(handlers.NewMessage(filters.Message.All, checkPermission))
|
|
for _, info := range CommandHandlers {
|
|
disp.AddHandler(handlers.NewCommand(info.Cmd, info.handler))
|
|
}
|
|
disp.AddHandler(handlers.NewCallbackQuery(filters.CallbackQuery.Prefix("update"), handleUpdateCallback))
|
|
disp.AddHandler(handlers.NewCallbackQuery(filters.CallbackQuery.Prefix(tcbdata.TypeAdd), handleAddCallback))
|
|
disp.AddHandler(handlers.NewCallbackQuery(filters.CallbackQuery.Prefix(tcbdata.TypeSetDefault), handleSetDefaultCallback))
|
|
disp.AddHandler(handlers.NewCallbackQuery(filters.CallbackQuery.Prefix(tcbdata.TypeCancel), handleCancelCallback))
|
|
disp.AddHandler(handlers.NewCallbackQuery(filters.CallbackQuery.Prefix(tcbdata.TypeConfig), handleConfigCallback))
|
|
disp.AddHandler(handlers.NewMessage(sabotfilters.RegexUrl(regexp.MustCompile(re.TgMessageLinkRegexString)), handleSilentMode(handleMessageLink, handleSilentSaveLink)))
|
|
disp.AddHandler(handlers.NewMessage(sabotfilters.RegexUrl(regexp.MustCompile(re.TelegraphUrlRegexString)), handleSilentMode(handleTelegraphUrlMessage, handleSilentSaveTelegraph)))
|
|
disp.AddHandler(handlers.NewMessage(filters.Message.Media, handleSilentMode(handleMediaMessage, handleSilentSaveMedia)))
|
|
disp.AddHandler(handlers.NewMessage(filters.Message.Text, handleSilentMode(handleTextMessage, handleSilentSaveText)))
|
|
|
|
if config.C().Telegram.Userbot.Enable {
|
|
go listenMediaMessageEvent(userclient.GetMediaMessageCh())
|
|
}
|
|
}
|