MCPcopy
hub / github.com/EverythingSuckz/TG-FileStreamBot / sendLink

Function sendLink

internal/commands/stream.go:43–136  ·  view source on GitHub ↗
(ctx *ext.Context, u *ext.Update)

Source from the content-addressed store, hash-verified

41}
42
43func sendLink(ctx *ext.Context, u *ext.Update) error {
44 chatId := u.EffectiveChat().GetID()
45 peerChatId := ctx.PeerStorage.GetPeerById(chatId)
46 if peerChatId.Type != int(storage.TypeUser) {
47 return dispatcher.EndGroups
48 }
49 if len(config.ValueOf.AllowedUsers) != 0 && !utils.Contains(config.ValueOf.AllowedUsers, chatId) {
50 ctx.Reply(u, ext.ReplyTextString("You are not allowed to use this bot."), nil)
51 return dispatcher.EndGroups
52 }
53 supported, err := supportedMediaFilter(u.EffectiveMessage)
54 if err != nil {
55 return err
56 }
57 if !supported {
58 ctx.Reply(u, ext.ReplyTextString("Sorry, this message type is unsupported."), nil)
59 return dispatcher.EndGroups
60 }
61 update, err := utils.ForwardMessages(ctx, chatId, config.ValueOf.LogChannelID, u.EffectiveMessage.ID)
62 if err != nil {
63 utils.Logger.Sugar().Error(err)
64 ctx.Reply(u, ext.ReplyTextString(fmt.Sprintf("Error - %s", err.Error())), nil)
65 return dispatcher.EndGroups
66 }
67 if len(update.Updates) < 2 {
68 ctx.Reply(u, ext.ReplyTextString("Error - unexpected update structure from Telegram"), nil)
69 return dispatcher.EndGroups
70 }
71 msgIDUpdate, ok := update.Updates[0].(*tg.UpdateMessageID)
72 if !ok {
73 ctx.Reply(u, ext.ReplyTextString("Error - unexpected update type"), nil)
74 return dispatcher.EndGroups
75 }
76 messageID := msgIDUpdate.ID
77 newMsg, ok := update.Updates[1].(*tg.UpdateNewChannelMessage)
78 if !ok {
79 ctx.Reply(u, ext.ReplyTextString("Error - unexpected channel message update"), nil)
80 return dispatcher.EndGroups
81 }
82 msg, ok := newMsg.Message.(*tg.Message)
83 if !ok {
84 ctx.Reply(u, ext.ReplyTextString("Error - unexpected message type"), nil)
85 return dispatcher.EndGroups
86 }
87 doc := msg.Media
88 file, err := utils.FileFromMedia(doc)
89 if err != nil {
90 ctx.Reply(u, ext.ReplyTextString(fmt.Sprintf("Error - %s", err.Error())), nil)
91 return dispatcher.EndGroups
92 }
93 fullHash := utils.PackFile(
94 file.FileName,
95 file.FileSize,
96 file.MimeType,
97 file.ID,
98 )
99 hash := utils.GetShortHash(fullHash)
100 link := fmt.Sprintf("%s/stream/%d?hash=%s", config.ValueOf.Host, messageID, hash)

Callers

nothing calls this directly

Calls 6

ContainsFunction · 0.92
ForwardMessagesFunction · 0.92
FileFromMediaFunction · 0.92
PackFileFunction · 0.92
GetShortHashFunction · 0.92
supportedMediaFilterFunction · 0.85

Tested by

no test coverage detected