Skip to content

Commit

Permalink
Add support for pyrogram native session based login
Browse files Browse the repository at this point in the history
  • Loading branch information
celestix committed Aug 13, 2022
1 parent 0d5bc0f commit 8d36231
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 12 deletions.
14 changes: 14 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import (
"encoding/json"
"io/ioutil"
"os"
"strings"

"github.com/anonyindian/gotgproto/sessionMaker"
"github.com/anonyindian/logger"
)

Expand All @@ -19,6 +21,7 @@ type config struct {
RedisPass string `json:"redis_pass"`
TestSessionString string `json:"test_session_string"`
SessionString string `json:"session_string"`
SessionType string `json:"session_type,omitempty"`
HerokuApiKey string `json:"heroku_api_key,omitempty"`
HerokuAppName string `json:"heroku_app_name,omitempty"`
TestServer bool `json:"test_mode,omitempty"`
Expand Down Expand Up @@ -50,3 +53,14 @@ func GetSessionString() string {
}
return ValueOf.SessionString
}

func GetSessionType() sessionMaker.SessionType {
switch strings.ToLower(ValueOf.SessionType) {
case "pyrogram", "pyro":
return sessionMaker.PyrogramSession
case "gotgproto", "native":
return sessionMaker.StringSession
default:
return sessionMaker.TelethonSession
}
}
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ go 1.18

require (
github.com/PaulSonOfLars/gotgbot/v2 v2.0.0-rc.9
github.com/anonyindian/gotgproto v1.0.0-beta08.0.20220812101930-fb0f873515a2
github.com/anonyindian/gotgproto v1.0.0-beta08.0.20220813082126-f98d0f42e1d5
github.com/anonyindian/logger v1.0.0-alpha.3
github.com/go-git/go-git/v5 v5.4.2
github.com/go-redis/redis v6.15.9+incompatible
github.com/gotd/td v0.65.0
github.com/gotd/td v0.67.0
github.com/joho/godotenv v1.4.0
)

Expand Down Expand Up @@ -44,11 +44,11 @@ require (
github.com/xanzy/ssh-agent v0.3.0 // indirect
go.opentelemetry.io/otel v1.9.0 // indirect
go.opentelemetry.io/otel/trace v1.9.0 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
go.uber.org/zap v1.21.0 // indirect
go.uber.org/zap v1.22.0 // indirect
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa // indirect
golang.org/x/net v0.0.0-20220805013720-a33c5aa5df48 // indirect
golang.org/x/net v0.0.0-20220812174116-3211cb980234 // indirect
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 // indirect
golang.org/x/sys v0.0.0-20220808155132-1c4a2a72c664 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
Expand Down
10 changes: 10 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ github.com/anonyindian/gotgproto v1.0.0-beta08.0.20220811082815-57b7254ee5d4 h1:
github.com/anonyindian/gotgproto v1.0.0-beta08.0.20220811082815-57b7254ee5d4/go.mod h1:RU2UDoqFSUGQYTOR7qD2oWvcmhsRe9o3tgzW6M7JqwA=
github.com/anonyindian/gotgproto v1.0.0-beta08.0.20220812101930-fb0f873515a2 h1:8mDrT9JYyX+oVwecQ2IT4hmFpmHEdG+fI8olU1vnTBM=
github.com/anonyindian/gotgproto v1.0.0-beta08.0.20220812101930-fb0f873515a2/go.mod h1:RU2UDoqFSUGQYTOR7qD2oWvcmhsRe9o3tgzW6M7JqwA=
github.com/anonyindian/gotgproto v1.0.0-beta08.0.20220813082126-f98d0f42e1d5 h1:fuTRG0eM5efhCWpFnyYeicZ1DZOkNS+3qOGKzOCgbXQ=
github.com/anonyindian/gotgproto v1.0.0-beta08.0.20220813082126-f98d0f42e1d5/go.mod h1:aG9WEU/7POJOUYh4a4SORPtAkwkIpt1ZUdfLSJrefdA=
github.com/anonyindian/logger v1.0.0-alpha.3 h1:fYQFvadiiMI7hxW3VZNJXFzEWgmz/wgRB9tVey3oLDo=
github.com/anonyindian/logger v1.0.0-alpha.3/go.mod h1:jb51uiKdlLOMtKakbyqsbrxTNr+Zt7qh2Va8sl5trTk=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
Expand Down Expand Up @@ -96,6 +98,8 @@ github.com/gotd/neo v0.1.5 h1:oj0iQfMbGClP8xI59x7fE/uHoTJD7NZH9oV1WNuPukQ=
github.com/gotd/neo v0.1.5/go.mod h1:9A2a4bn9zL6FADufBdt7tZt+WMhvZoc5gWXihOPoiBQ=
github.com/gotd/td v0.65.0 h1:ZKRl32BRHSQY6DDzNko+HLKOkLMs/BOT0Vp1xiFbnS8=
github.com/gotd/td v0.65.0/go.mod h1:uWa8zasSkTrNlmTu7CJCq29yH8fBnF4CsfJdFOC5rdw=
github.com/gotd/td v0.67.0 h1:36uvHiZN4oIv+KsIBeC6otviU9/8HjFMrXpdn8h1nIo=
github.com/gotd/td v0.67.0/go.mod h1:menA3xajEfB1nPZGWMPLt5V8WoxFCyndlBkj4JJOL7w=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/imdario/mergo v0.3.12 h1:b6R2BslTbIEToALKP7LxUvijTsNI9TAe80pLWN2g/HU=
github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
Expand Down Expand Up @@ -184,13 +188,17 @@ go.opentelemetry.io/otel/trace v1.9.0/go.mod h1:2737Q0MuG8q1uILYm2YYVkAyLtOofiTN
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE=
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/atomic v1.10.0 h1:9qC72Qh0+3MqyJbAn8YU5xVq1frD8bn3JtD2oXtafVQ=
go.uber.org/atomic v1.10.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI=
go.uber.org/goleak v1.1.11/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ=
go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU=
go.uber.org/multierr v1.8.0 h1:dg6GjLku4EH+249NNmoIciG9N/jURbDG+pFlTkhzIC8=
go.uber.org/multierr v1.8.0/go.mod h1:7EAYxJLBy9rStEaz58O2t4Uvip6FSURkq8/ppBp95ak=
go.uber.org/zap v1.21.0 h1:WefMeulhovoZ2sYXz7st6K0sLj7bBhpiFaud4r4zST8=
go.uber.org/zap v1.21.0/go.mod h1:wjWOCqI0f2ZZrJF/UufIOkiC8ii6tm1iqIsLo76RfJw=
go.uber.org/zap v1.22.0 h1:Zcye5DUgBloQ9BaT4qc9BnjOFog5TvBSAGkJ3Nf70c0=
go.uber.org/zap v1.22.0/go.mod h1:H4siCOZOrAolnUPJEkfaSjDqyP+BDS0DdDWzwcgt3+U=
golang.org/x/crypto v0.0.0-20190219172222-a4c6cb3142f2/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
Expand All @@ -213,6 +221,8 @@ golang.org/x/net v0.0.0-20210326060303-6b1517762897/go.mod h1:uSPa2vr4CLtc/ILN5o
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
golang.org/x/net v0.0.0-20220805013720-a33c5aa5df48 h1:N9Vc/rorQUDes6B9CNdIxAn5jODGj2wzfrei2x4wNj4=
golang.org/x/net v0.0.0-20220805013720-a33c5aa5df48/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
golang.org/x/net v0.0.0-20220812174116-3211cb980234 h1:RDqmgfe7SvlMWoqC3xwQ2blLO3fcWcxMa3eBLRdRW7E=
golang.org/x/net v0.0.0-20220812174116-3211cb980234/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func runClient(l *logger.Logger) {
// Session of your client
// sessionName: name of the session / session string in case of TelethonSession or StringSession
// sessionType: can be any out of Session, TelethonSession, StringSession.
Session: sessionMaker.NewSession(config.GetSessionString(), sessionMaker.TelethonSession),
Session: sessionMaker.NewSession(config.GetSessionString(), config.GetSessionType()),
// Make sure to specify custom dispatcher here in order to enjoy gotgproto's update handling
Dispatcher: dp,
// Add the handlers, post functions in TaskFunc
Expand Down
27 changes: 21 additions & 6 deletions session_maker.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# GIGA Userbot Session String Generator

import sys
from pyrogram.client import Client
from telethon.sync import TelegramClient
from telethon.sessions import StringSession

Expand All @@ -11,17 +12,31 @@
SESSION_MSG = """
**GIGA Userbot Session Generator**
Hello! You have successfully generated the session string for GIGA Userbot as follows:
Hello! You have successfully generated the {type} session string for GIGA Userbot as follows:
`{session}`
**Note**: **DO NOT SHARE** this session string with anyone as it may cause hijacking of your account.
"""

client = TelegramClient(StringSession(), APP_ID, API_HASH)
# client.session.set_dc(2, '149.154.167.40', 80)
client.start()
client.send_message("me", SESSION_MSG.format(session=client.session.save()))
SESSION_TYPE = input(
"""Please specificy session type,
Enter 0 for telethon
Enter 1 for pyrogram
Your answer: """)

if SESSION_TYPE == "0":
client = TelegramClient(StringSession(), APP_ID, API_HASH)
# client.session.set_dc(2, '149.154.167.40', 80)
client.start()
client.send_message("me", SESSION_MSG.format(type="telethon",session=client.session.save()))
elif SESSION_TYPE == "1":
client = Client("", APP_ID, API_HASH, in_memory=True)
client.start()
client.send_message("me", SESSION_MSG.format(type="pyrogram", session=client.export_session_string()))
else:
print("Your input was invalid, expected 0 or 1.")
sys.exit(1)

print("\nYou successfully generated the session string for GIGA Userbot,")
print("Please check your saved messages on telegram to get it noted.")
1 change: 1 addition & 0 deletions session_maker.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pip3 install telethon
pip3 install pyrogram
python3 session_maker.py

0 comments on commit 8d36231

Please sign in to comment.