Spaces:
Sleeping
Sleeping
Fix gotgbot InputFileByID type in replace plugin
Browse files- plugins/replace.go +33 -33
plugins/replace.go
CHANGED
|
@@ -17,10 +17,10 @@ var (
|
|
| 17 |
tgLinkRegex = regexp.MustCompile(`t\.me/(?:c/)?([^/]+)/(\d+)`)
|
| 18 |
)
|
| 19 |
|
| 20 |
-
func parseTelegramLink(link string) (
|
| 21 |
matches := tgLinkRegex.FindStringSubmatch(link)
|
| 22 |
if len(matches) != 3 {
|
| 23 |
-
return
|
| 24 |
}
|
| 25 |
|
| 26 |
chatStr := matches[1]
|
|
@@ -28,20 +28,20 @@ func parseTelegramLink(link string) (interface{}, int64, error) {
|
|
| 28 |
|
| 29 |
msgID, err := strconv.ParseInt(msgIDStr, 10, 64)
|
| 30 |
if err != nil {
|
| 31 |
-
return
|
| 32 |
}
|
| 33 |
|
| 34 |
-
//
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
|
|
|
| 41 |
}
|
| 42 |
|
| 43 |
-
|
| 44 |
-
return "@" + chatStr, msgID, nil
|
| 45 |
}
|
| 46 |
|
| 47 |
func ReplaceCommand(bot *gotgbot.Bot, ctx *ext.Context) error {
|
|
@@ -75,29 +75,29 @@ func ReplaceCommand(bot *gotgbot.Bot, ctx *ext.Context) error {
|
|
| 75 |
if replyMsg.Document != nil {
|
| 76 |
fileID = replyMsg.Document.FileId
|
| 77 |
inputMedia = gotgbot.InputMediaDocument{
|
| 78 |
-
Media:
|
| 79 |
-
Caption:
|
| 80 |
CaptionEntities: replyMsg.CaptionEntities,
|
| 81 |
}
|
| 82 |
} else if replyMsg.Video != nil {
|
| 83 |
fileID = replyMsg.Video.FileId
|
| 84 |
inputMedia = gotgbot.InputMediaVideo{
|
| 85 |
-
Media:
|
| 86 |
-
Caption:
|
| 87 |
CaptionEntities: replyMsg.CaptionEntities,
|
| 88 |
}
|
| 89 |
} else if replyMsg.Audio != nil {
|
| 90 |
fileID = replyMsg.Audio.FileId
|
| 91 |
inputMedia = gotgbot.InputMediaAudio{
|
| 92 |
-
Media:
|
| 93 |
-
Caption:
|
| 94 |
CaptionEntities: replyMsg.CaptionEntities,
|
| 95 |
}
|
| 96 |
} else if len(replyMsg.Photo) > 0 {
|
| 97 |
fileID = replyMsg.Photo[len(replyMsg.Photo)-1].FileId
|
| 98 |
inputMedia = gotgbot.InputMediaPhoto{
|
| 99 |
-
Media:
|
| 100 |
-
Caption:
|
| 101 |
CaptionEntities: replyMsg.CaptionEntities,
|
| 102 |
}
|
| 103 |
}
|
|
@@ -120,11 +120,11 @@ func ReplaceCommand(bot *gotgbot.Bot, ctx *ext.Context) error {
|
|
| 120 |
var BatchReplaceState = make(map[int64]*BatchState)
|
| 121 |
|
| 122 |
type BatchState struct {
|
| 123 |
-
ChatID
|
| 124 |
-
StartMsgID
|
| 125 |
-
Count
|
| 126 |
-
CurrentIndex
|
| 127 |
-
AdminID
|
| 128 |
}
|
| 129 |
|
| 130 |
func BatchReplaceCommand(bot *gotgbot.Bot, ctx *ext.Context) error {
|
|
@@ -196,29 +196,29 @@ func BatchReplaceHandler(bot *gotgbot.Bot, ctx *ext.Context) error {
|
|
| 196 |
if msg.Document != nil {
|
| 197 |
fileID = msg.Document.FileId
|
| 198 |
inputMedia = gotgbot.InputMediaDocument{
|
| 199 |
-
Media:
|
| 200 |
-
Caption:
|
| 201 |
CaptionEntities: msg.CaptionEntities,
|
| 202 |
}
|
| 203 |
} else if msg.Video != nil {
|
| 204 |
fileID = msg.Video.FileId
|
| 205 |
inputMedia = gotgbot.InputMediaVideo{
|
| 206 |
-
Media:
|
| 207 |
-
Caption:
|
| 208 |
CaptionEntities: msg.CaptionEntities,
|
| 209 |
}
|
| 210 |
} else if msg.Audio != nil {
|
| 211 |
fileID = msg.Audio.FileId
|
| 212 |
inputMedia = gotgbot.InputMediaAudio{
|
| 213 |
-
Media:
|
| 214 |
-
Caption:
|
| 215 |
CaptionEntities: msg.CaptionEntities,
|
| 216 |
}
|
| 217 |
} else if len(msg.Photo) > 0 {
|
| 218 |
fileID = msg.Photo[len(msg.Photo)-1].FileId
|
| 219 |
inputMedia = gotgbot.InputMediaPhoto{
|
| 220 |
-
Media:
|
| 221 |
-
Caption:
|
| 222 |
CaptionEntities: msg.CaptionEntities,
|
| 223 |
}
|
| 224 |
}
|
|
|
|
| 17 |
tgLinkRegex = regexp.MustCompile(`t\.me/(?:c/)?([^/]+)/(\d+)`)
|
| 18 |
)
|
| 19 |
|
| 20 |
+
func parseTelegramLink(link string) (int64, int64, error) {
|
| 21 |
matches := tgLinkRegex.FindStringSubmatch(link)
|
| 22 |
if len(matches) != 3 {
|
| 23 |
+
return 0, 0, fmt.Errorf("invalid telegram link format")
|
| 24 |
}
|
| 25 |
|
| 26 |
chatStr := matches[1]
|
|
|
|
| 28 |
|
| 29 |
msgID, err := strconv.ParseInt(msgIDStr, 10, 64)
|
| 30 |
if err != nil {
|
| 31 |
+
return 0, 0, fmt.Errorf("invalid message ID")
|
| 32 |
}
|
| 33 |
|
| 34 |
+
// Channel ID in t.me/c/123456/789 format
|
| 35 |
+
chatID, err := strconv.ParseInt(chatStr, 10, 64)
|
| 36 |
+
if err != nil {
|
| 37 |
+
return 0, 0, fmt.Errorf("invalid channel ID in link")
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
if chatID > 0 {
|
| 41 |
+
chatID, _ = strconv.ParseInt("-100"+chatStr, 10, 64)
|
| 42 |
}
|
| 43 |
|
| 44 |
+
return chatID, msgID, nil
|
|
|
|
| 45 |
}
|
| 46 |
|
| 47 |
func ReplaceCommand(bot *gotgbot.Bot, ctx *ext.Context) error {
|
|
|
|
| 75 |
if replyMsg.Document != nil {
|
| 76 |
fileID = replyMsg.Document.FileId
|
| 77 |
inputMedia = gotgbot.InputMediaDocument{
|
| 78 |
+
Media: gotgbot.InputFileByID(fileID),
|
| 79 |
+
Caption: replyMsg.Caption,
|
| 80 |
CaptionEntities: replyMsg.CaptionEntities,
|
| 81 |
}
|
| 82 |
} else if replyMsg.Video != nil {
|
| 83 |
fileID = replyMsg.Video.FileId
|
| 84 |
inputMedia = gotgbot.InputMediaVideo{
|
| 85 |
+
Media: gotgbot.InputFileByID(fileID),
|
| 86 |
+
Caption: replyMsg.Caption,
|
| 87 |
CaptionEntities: replyMsg.CaptionEntities,
|
| 88 |
}
|
| 89 |
} else if replyMsg.Audio != nil {
|
| 90 |
fileID = replyMsg.Audio.FileId
|
| 91 |
inputMedia = gotgbot.InputMediaAudio{
|
| 92 |
+
Media: gotgbot.InputFileByID(fileID),
|
| 93 |
+
Caption: replyMsg.Caption,
|
| 94 |
CaptionEntities: replyMsg.CaptionEntities,
|
| 95 |
}
|
| 96 |
} else if len(replyMsg.Photo) > 0 {
|
| 97 |
fileID = replyMsg.Photo[len(replyMsg.Photo)-1].FileId
|
| 98 |
inputMedia = gotgbot.InputMediaPhoto{
|
| 99 |
+
Media: gotgbot.InputFileByID(fileID),
|
| 100 |
+
Caption: replyMsg.Caption,
|
| 101 |
CaptionEntities: replyMsg.CaptionEntities,
|
| 102 |
}
|
| 103 |
}
|
|
|
|
| 120 |
var BatchReplaceState = make(map[int64]*BatchState)
|
| 121 |
|
| 122 |
type BatchState struct {
|
| 123 |
+
ChatID int64
|
| 124 |
+
StartMsgID int64
|
| 125 |
+
Count int
|
| 126 |
+
CurrentIndex int
|
| 127 |
+
AdminID int64
|
| 128 |
}
|
| 129 |
|
| 130 |
func BatchReplaceCommand(bot *gotgbot.Bot, ctx *ext.Context) error {
|
|
|
|
| 196 |
if msg.Document != nil {
|
| 197 |
fileID = msg.Document.FileId
|
| 198 |
inputMedia = gotgbot.InputMediaDocument{
|
| 199 |
+
Media: gotgbot.InputFileByID(fileID),
|
| 200 |
+
Caption: msg.Caption,
|
| 201 |
CaptionEntities: msg.CaptionEntities,
|
| 202 |
}
|
| 203 |
} else if msg.Video != nil {
|
| 204 |
fileID = msg.Video.FileId
|
| 205 |
inputMedia = gotgbot.InputMediaVideo{
|
| 206 |
+
Media: gotgbot.InputFileByID(fileID),
|
| 207 |
+
Caption: msg.Caption,
|
| 208 |
CaptionEntities: msg.CaptionEntities,
|
| 209 |
}
|
| 210 |
} else if msg.Audio != nil {
|
| 211 |
fileID = msg.Audio.FileId
|
| 212 |
inputMedia = gotgbot.InputMediaAudio{
|
| 213 |
+
Media: gotgbot.InputFileByID(fileID),
|
| 214 |
+
Caption: msg.Caption,
|
| 215 |
CaptionEntities: msg.CaptionEntities,
|
| 216 |
}
|
| 217 |
} else if len(msg.Photo) > 0 {
|
| 218 |
fileID = msg.Photo[len(msg.Photo)-1].FileId
|
| 219 |
inputMedia = gotgbot.InputMediaPhoto{
|
| 220 |
+
Media: gotgbot.InputFileByID(fileID),
|
| 221 |
+
Caption: msg.Caption,
|
| 222 |
CaptionEntities: msg.CaptionEntities,
|
| 223 |
}
|
| 224 |
}
|