Skip to content

Commit

Permalink
feat(tdlib): switch v2 version
Browse files Browse the repository at this point in the history
switch v2 version

ref Arman92/go-tdlib#91

Signed-off-by: mritd <[email protected]>
  • Loading branch information
mritd committed Sep 20, 2021
1 parent 5363650 commit f8ab814
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 283 deletions.
18 changes: 18 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module github.com/mritd/poetbot

go 1.17

require (
github.com/Arman92/go-tdlib v1.0.1-0.20210806020223-e1bab7be7026
github.com/robfig/cron/v3 v3.0.1
github.com/sirupsen/logrus v1.8.1
github.com/urfave/cli/v2 v2.3.0
)

require (
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d // indirect
github.com/russross/blackfriday/v2 v2.0.1 // indirect
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
github.com/stretchr/testify v1.4.0 // indirect
golang.org/x/sys v0.0.0-20210917161153-d61c044b1678 // indirect
)
31 changes: 31 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
github.com/Arman92/go-tdlib v1.0.1-0.20210806020223-e1bab7be7026 h1:cx91l7O2eifOKZD7QlFcZ5qxgPaUN1gM/SdHj9tYP9I=
github.com/Arman92/go-tdlib v1.0.1-0.20210806020223-e1bab7be7026/go.mod h1:gz/NLfLyXSF3LufhmK4a+xcrlIvAUR67zxOWv0JxvsU=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/urfave/cli/v2 v2.3.0 h1:qph92Y649prgesehzOrQjdWyxFOp/QVM+6imKHad91M=
github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210917161153-d61c044b1678 h1:J27LZFQBFoihqXoegpscI10HpjZ7B5WQLLKL2FZXQKw=
golang.org/x/sys v0.0.0-20210917161153-d61c044b1678/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.3 h1:fvjTMHxHEw/mxHbtzPi3JCcKXQRAnQTBRo6YCJSVHKI=
gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
43 changes: 24 additions & 19 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package main
import (
"bufio"
"fmt"
"github.com/Arman92/go-tdlib/client"
"github.com/Arman92/go-tdlib/tdlib"
"github.com/sirupsen/logrus"
"math/rand"
"os"
"os/signal"
Expand All @@ -12,8 +15,6 @@ import (

"github.com/robfig/cron/v3"

"github.com/Arman92/go-tdlib"
"github.com/mritd/logger"
"github.com/urfave/cli/v2"
)

Expand Down Expand Up @@ -77,15 +78,19 @@ func main() {
},
Before: func(c *cli.Context) error {
if c.Bool("debug") {
logger.SetDevelopment()
logrus.SetLevel(logrus.DebugLevel)
}
logrus.SetFormatter(&logrus.TextFormatter{
FullTimestamp: true,
TimestampFormat: "2006-01-02 15:04:05",
})
return nil
},
Action: update,
}
err := app.Run(os.Args)
if err != nil {
logger.Error(err)
logrus.Error(err)
}
}

Expand All @@ -107,10 +112,10 @@ func update(c *cli.Context) error {
data = append(data, line)
}

tdlib.SetLogVerbosityLevel(1)
tdlib.SetFilePath(os.Stdout.Name())
client.SetLogVerbosityLevel(1)
client.SetFilePath(os.Stdout.Name())
// Create new instance of client
client := tdlib.NewClient(tdlib.Config{
tdCli := client.NewClient(client.Config{
APIID: c.String("appid"),
APIHash: c.String("apphash"),
SystemLanguageCode: "en",
Expand All @@ -125,34 +130,34 @@ func update(c *cli.Context) error {
})

for {
currentState, _ := client.Authorize()
currentState, _ := tdCli.Authorize()
switch currentState.GetAuthorizationStateEnum() {
case tdlib.AuthorizationStateWaitPhoneNumberType:
fmt.Print("Enter phone: ")
var number string
_, _ = fmt.Scanln(&number)
_, err := client.SendPhoneNumber(number)
_, err := tdCli.SendPhoneNumber(number)
if err != nil {
logger.Errorf("Error sending phone number: %v", err)
logrus.Errorf("Error sending phone number: %v", err)
}
case tdlib.AuthorizationStateWaitCodeType:
fmt.Print("Enter code: ")
var code string
_, _ = fmt.Scanln(&code)
_, err := client.SendAuthCode(code)
_, err := tdCli.SendAuthCode(code)
if err != nil {
logger.Errorf("Error sending auth code : %v", err)
logrus.Errorf("Error sending auth code : %v", err)
}
case tdlib.AuthorizationStateWaitPasswordType:
fmt.Print("Enter Password: ")
var password string
_, _ = fmt.Scanln(&password)
_, err := client.SendAuthPassword(password)
_, err := tdCli.SendAuthPassword(password)
if err != nil {
logger.Errorf("Error sending auth password: %v", err)
logrus.Errorf("Error sending auth password: %v", err)
}
case tdlib.AuthorizationStateReadyType:
logger.Info("Authorization Ready! Let's rock")
logrus.Info("Authorization Ready! Let's rock")
goto AuthSuccess
}
}
Expand All @@ -163,18 +168,18 @@ AuthSuccess:
_, err = cn.AddFunc(c.String("cron"), func() {
rand.Seed(time.Now().Unix())
name := data[rand.Intn(len(data)-1)]
logger.Infof("update name to [%s]...", name)
_, err := client.SetName(name, "")
logrus.Infof("update name to [%s]...", name)
_, err := tdCli.SetName(name, "")
if err != nil {
logger.Error(err)
logrus.Error(err)
}
})
if err != nil {
return err
}

cn.Start()
logger.Info("Poet Bot running...")
logrus.Info("Poet Bot running...")

sigs := make(chan os.Signal)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
Expand Down
Loading

0 comments on commit f8ab814

Please sign in to comment.