Skip to content

Commit 9c48430

Browse files
feat(bot): add user sessions
1 parent fa27487 commit 9c48430

File tree

4 files changed

+48
-0
lines changed

4 files changed

+48
-0
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@ In addition to the mandatory variables, you can also set the following optional
188188

189189
- `USE_SESSION_FILE` : Use session files for worker client(s). This speeds up the worker bot startups. (default: `false`)
190190

191+
- `USER_SESSION` : A pyrogram session string for the user bot. (default: `null`)
192+
191193
<hr>
192194

193195
### Use Multiple Bots to speed up

cmd/fsb/main.go

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ func main() {
3434
}
3535
cache.InitCache(log)
3636
bot.StartWorkers(log)
37+
bot.StartUserBot(log)
3738
mainLogger.Info("Server started", zap.Int("port", config.ValueOf.Port))
3839
mainLogger.Info("File Stream Bot", zap.String("version", versionString))
3940
err = router.Run(fmt.Sprintf(":%d", config.ValueOf.Port))

config/config.go

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ type config struct {
2525
Host string `envconfig:"HOST" default:"http://localhost:8080"`
2626
HashLength int `envconfig:"HASH_LENGTH" default:"6"`
2727
UseSessionFile bool `envconfig:"USE_SESSION_FILE" default:"true"`
28+
UserSession string `envconfig:"USER_SESSION"`
2829
MultiTokens []string
2930
}
3031

internal/bot/userbot.go

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package bot
2+
3+
import (
4+
"EverythingSuckz/fsb/config"
5+
6+
"github.com/celestix/gotgproto"
7+
"github.com/celestix/gotgproto/sessionMaker"
8+
"go.uber.org/zap"
9+
)
10+
11+
type UserBotStruct struct {
12+
log *zap.Logger
13+
client *gotgproto.Client
14+
}
15+
16+
var UserBot *UserBotStruct = &UserBotStruct{}
17+
18+
func StartUserBot(l *zap.Logger) {
19+
log := l.Named("USERBOT")
20+
if config.ValueOf.UserSession == "" {
21+
log.Warn("User session is empty")
22+
return
23+
}
24+
log.Sugar().Infoln("Starting userbot")
25+
client, err := gotgproto.NewClient(
26+
int(config.ValueOf.ApiID),
27+
config.ValueOf.ApiHash,
28+
gotgproto.ClientType{
29+
Phone: "",
30+
},
31+
&gotgproto.ClientOpts{
32+
Session: sessionMaker.PyrogramSession(config.ValueOf.UserSession),
33+
DisableCopyright: true,
34+
},
35+
)
36+
if err != nil {
37+
log.Error("Failed to start userbot", zap.Error(err))
38+
return
39+
}
40+
UserBot.log = log
41+
UserBot.client = client
42+
log.Info("Userbot started", zap.String("username", client.Self.Username), zap.String("FirstName", client.Self.FirstName), zap.String("LastName", client.Self.LastName))
43+
44+
}

0 commit comments

Comments
 (0)