Skip to content

Commit

Permalink
feat(plugin): add dummy stream plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
EverythingSuckz committed Nov 26, 2023
1 parent 6ffbd14 commit a8aab9a
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
54 changes: 54 additions & 0 deletions commands/stream.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package commands

import (
"fmt"

"EverythingSuckz/fsb/config"
"EverythingSuckz/fsb/utils"

"github.com/celestix/gotgproto/dispatcher"
"github.com/celestix/gotgproto/dispatcher/handlers"
"github.com/celestix/gotgproto/dispatcher/handlers/filters"
"github.com/celestix/gotgproto/ext"
"github.com/gotd/td/tg"
)

func (m *command) LoadStream(dispatcher dispatcher.Dispatcher) {
defer m.log.Sugar().Info("Loaded stream command")
dispatcher.AddHandler(
handlers.NewMessage(filters.Message.Media, sendLink),
)
}

func sendLink(ctx *ext.Context, u *ext.Update) error {
if u.EffectiveMessage.Media == nil {
return dispatcher.EndGroups
}
if len(u.Entities.Chats) != 0 {
return dispatcher.EndGroups
}
chatId := u.EffectiveChat().GetID()
update, err := ctx.ForwardMessages(
chatId,
config.ValueOf.LogChannelID,
&tg.MessagesForwardMessagesRequest{
FromPeer: &tg.InputPeerChat{ChatID: chatId},
ID: []int{u.EffectiveMessage.ID},
ToPeer: &tg.InputPeerChannel{ChannelID: config.ValueOf.LogChannelID, AccessHash: 0},
},
)
if err != nil {
utils.Logger.Sugar().Error(err)
ctx.Reply(u, fmt.Sprintf("Error - %s", err.Error()), nil)
return dispatcher.EndGroups
}
messageID := update.(*tg.Updates).Updates[0].(*tg.UpdateMessageID).ID
if err != nil {
utils.Logger.Sugar().Error(err)
ctx.Reply(u, fmt.Sprintf("Error - %s", err.Error()), nil)
return dispatcher.EndGroups
}
link := fmt.Sprintf("%s/stream/%d", config.ValueOf.Host, messageID)
ctx.Reply(u, link, nil)
return dispatcher.EndGroups
}
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type config struct {
LogChannelID int64 `envconfig:"LOG_CHANNEL" required:"false"`
Dev bool `envconfig:"DEV" default:"false"`
Port int `envconfig:"PORT" default:"8080"`
Host string `envconfig:"HOST" default:"http://localhost:8080"`
}

func (c *config) setupEnvVars() {
Expand Down

0 comments on commit a8aab9a

Please sign in to comment.