|
| 1 | +package commands |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + |
| 6 | + "EverythingSuckz/fsb/config" |
| 7 | + "EverythingSuckz/fsb/utils" |
| 8 | + |
| 9 | + "github.com/celestix/gotgproto/dispatcher" |
| 10 | + "github.com/celestix/gotgproto/dispatcher/handlers" |
| 11 | + "github.com/celestix/gotgproto/dispatcher/handlers/filters" |
| 12 | + "github.com/celestix/gotgproto/ext" |
| 13 | + "github.com/gotd/td/tg" |
| 14 | +) |
| 15 | + |
| 16 | +func (m *command) LoadStream(dispatcher dispatcher.Dispatcher) { |
| 17 | + defer m.log.Sugar().Info("Loaded stream command") |
| 18 | + dispatcher.AddHandler( |
| 19 | + handlers.NewMessage(filters.Message.Media, sendLink), |
| 20 | + ) |
| 21 | +} |
| 22 | + |
| 23 | +func sendLink(ctx *ext.Context, u *ext.Update) error { |
| 24 | + if u.EffectiveMessage.Media == nil { |
| 25 | + return dispatcher.EndGroups |
| 26 | + } |
| 27 | + if len(u.Entities.Chats) != 0 { |
| 28 | + return dispatcher.EndGroups |
| 29 | + } |
| 30 | + chatId := u.EffectiveChat().GetID() |
| 31 | + update, err := ctx.ForwardMessages( |
| 32 | + chatId, |
| 33 | + config.ValueOf.LogChannelID, |
| 34 | + &tg.MessagesForwardMessagesRequest{ |
| 35 | + FromPeer: &tg.InputPeerChat{ChatID: chatId}, |
| 36 | + ID: []int{u.EffectiveMessage.ID}, |
| 37 | + ToPeer: &tg.InputPeerChannel{ChannelID: config.ValueOf.LogChannelID, AccessHash: 0}, |
| 38 | + }, |
| 39 | + ) |
| 40 | + if err != nil { |
| 41 | + utils.Logger.Sugar().Error(err) |
| 42 | + ctx.Reply(u, fmt.Sprintf("Error - %s", err.Error()), nil) |
| 43 | + return dispatcher.EndGroups |
| 44 | + } |
| 45 | + messageID := update.(*tg.Updates).Updates[0].(*tg.UpdateMessageID).ID |
| 46 | + if err != nil { |
| 47 | + utils.Logger.Sugar().Error(err) |
| 48 | + ctx.Reply(u, fmt.Sprintf("Error - %s", err.Error()), nil) |
| 49 | + return dispatcher.EndGroups |
| 50 | + } |
| 51 | + link := fmt.Sprintf("%s/stream/%d", config.ValueOf.Host, messageID) |
| 52 | + ctx.Reply(u, link, nil) |
| 53 | + return dispatcher.EndGroups |
| 54 | +} |
0 commit comments