Deprecated public copy media feat
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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"`
|
||||
|
||||
Reference in New Issue
Block a user