Deprecated public copy media feat

This commit is contained in:
krau
2025-06-09 15:50:53 +08:00
parent 56ea1d6f36
commit 693e20b066
2 changed files with 1 additions and 41 deletions

View File

@@ -9,7 +9,6 @@ import (
"github.com/gotd/contrib/middleware/floodwait"
"github.com/gotd/contrib/middleware/ratelimit"
"github.com/gotd/td/telegram"
"github.com/krau/SaveAny-Bot/common"
"github.com/krau/SaveAny-Bot/config"
"golang.org/x/time/rate"
)
@@ -31,44 +30,8 @@ const noPermissionText string = `
func checkPermission(ctx *ext.Context, update *ext.Update) error {
userID := update.GetUserChat().GetID()
if !slice.Contain(config.Cfg.GetUsersID(), userID) {
if config.Cfg.AsPublicCopyMediaBot {
tryCopyMedia(ctx, update)
return dispatcher.EndGroups
}
ctx.Reply(update, ext.ReplyTextString(noPermissionText), nil)
return dispatcher.EndGroups
}
return dispatcher.ContinueGroups
}
func tryCopyMedia(ctx *ext.Context, update *ext.Update) {
if !config.Cfg.AsPublicCopyMediaBot {
return
}
if update.EffectiveMessage == nil || update.EffectiveMessage.Message == nil {
return
}
msg := update.EffectiveMessage.Message
if link := linkRegex.FindString(update.EffectiveMessage.Text); link != "" {
linkChatID, messageID, err := parseLink(ctx, link)
if err != nil {
return
}
fileMessage, err := GetTGMessage(ctx, linkChatID, messageID)
if err != nil {
return
}
if fileMessage == nil || fileMessage.Media == nil {
return
}
msg = fileMessage
}
if _, ok := msg.GetMedia(); !ok || msg.Media == nil {
ctx.Reply(update, ext.ReplyTextString("消息中没有文件或媒体"), nil)
return
}
common.Log.Tracef("Got copy media request from %d", update.EffectiveChat().GetID())
if _, err := copyMediaToChat(ctx, msg, update.EffectiveChat().GetID()); err != nil {
common.Log.Errorf("Failed to copy media: %v", err)
}
}
}

View File

@@ -21,9 +21,6 @@ type Config struct {
Threads int `toml:"threads" mapstructure:"threads" json:"threads"`
Stream bool `toml:"stream" mapstructure:"stream" json:"stream"`
// Experimental: 将拷贝媒体文件的功能设为公开可用
AsPublicCopyMediaBot bool `toml:"as_public_copy_media_bot" mapstructure:"as_public_copy_media_bot" json:"as_public_copy_media_bot"`
Users []userConfig `toml:"users" mapstructure:"users" json:"users"`
Temp tempConfig `toml:"temp" mapstructure:"temp"`