celestix/gotgproto

How I Create Multi Instance

refaldyrk opened this issue · 6 comments

I want to create many clients, and they are in one program, for example I want to create /login then I want to create one more client, and allow for multiple clients.

What's stopping you? Create them then.
Similar to how you create one client, just create multiple clients and setup and start them in separate goroutines so that they don't block each other's execution.

My logic is lacking, can you simulate it simply? Can I create an instance while the program is running?

My logic is lacking, can you simulate it simply? Can I create an instance while the program is running?

Yes, you can create instances while the program is running.

Here is an example of running multiple clients until the first client stops:

apiId := 3
apihash := "apiHash"
numClients := 9
var firstClient *gotgproto.Client
for i := 0; i < numClients; i++ {
	client, err := gotgproto.NewClient(apiId, apihash, gotgproto.ClientType{}, &gotgproto.ClientOpts{
		Session: sessionMaker.SqlSession(sqlite.Open(fmt.Sprintf("client_%d", n))),
	})
	if err != nil {
		log.Fatalln("failed to start client:", err)
		continue
	}
	if firstClient == nil {
		firstClient = client
	}
	// Do something with client
}
firstClient.Idle()

Thank u for the response

but in this bot, i can't login via qr code?

but in this bot, i can't login via qr code?

No, you can't.