Skip to content

Commit a8aab9a

Browse files
feat(plugin): add dummy stream plugin
1 parent 6ffbd14 commit a8aab9a

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

commands/stream.go

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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+
}

config/config.go

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ type config struct {
1818
LogChannelID int64 `envconfig:"LOG_CHANNEL" required:"false"`
1919
Dev bool `envconfig:"DEV" default:"false"`
2020
Port int `envconfig:"PORT" default:"8080"`
21+
Host string `envconfig:"HOST" default:"http://localhost:8080"`
2122
}
2223

2324
func (c *config) setupEnvVars() {

0 commit comments

Comments
 (0)