diff --git a/README.md b/README.md index 886f12e..e6ac454 100644 --- a/README.md +++ b/README.md @@ -1,142 +1 @@ -# go-tdlib - -Go wrapper for [TDLib (Telegram Database Library)](https://github.com/tdlib/td) with full support of TDLib v1.8.0 - -## TDLib installation - -Use [TDLib build instructions](https://tdlib.github.io/td/build.html) with checkmarked `Install built TDLib to /usr/local instead of placing the files to td/tdlib`. - -### Windows - -Build with environment variables: - -``` -CGO_CFLAGS=-IC:/path/to/tdlib/build/tdlib/include -CGO_LDFLAGS=-LC:/path/to/tdlib/build/tdlib/bin -ltdjson -``` - -Example for PowerShell: - -```powershell -$env:CGO_CFLAGS="-IC:/td/tdlib/include"; $env:CGO_LDFLAGS="-LC:/td/tdlib/bin -ltdjson"; go build -trimpath -ldflags="-s -w" -o demo.exe .\cmd\demo.go -``` - -## Usage - -### Client - -[Register an application](https://my.telegram.org/apps) to obtain an api_id and api_hash - -```go -package main - -import ( - "log" - "path/filepath" - - "github.com/zelenin/go-tdlib/client" -) - -func main() { - // client authorizer - authorizer := client.ClientAuthorizer() - go client.CliInteractor(authorizer) - - // or bot authorizer - // botToken := "000000000:gsVCGG5YbikxYHC7bP5vRvmBqJ7Xz6vG6td" - // authorizer := client.BotAuthorizer(botToken) - - const ( - apiId = 00000 - apiHash = "8pu9yg32qkuukj83ozaqo5zzjwhkxhnk" - ) - - authorizer.TdlibParameters <- &client.TdlibParameters{ - UseTestDc: false, - DatabaseDirectory: filepath.Join(".tdlib", "database"), - FilesDirectory: filepath.Join(".tdlib", "files"), - UseFileDatabase: true, - UseChatInfoDatabase: true, - UseMessageDatabase: true, - UseSecretChats: false, - ApiId: apiId, - ApiHash: apiHash, - SystemLanguageCode: "en", - DeviceModel: "Server", - SystemVersion: "1.0.0", - ApplicationVersion: "1.0.0", - EnableStorageOptimizer: true, - IgnoreFileNames: false, - } - - logVerbosity := client.WithLogVerbosity(&client.SetLogVerbosityLevelRequest{ - NewVerbosityLevel: 0, - }) - - tdlibClient, err := client.NewClient(authorizer, logVerbosity) - if err != nil { - log.Fatalf("NewClient error: %s", err) - } - - optionValue, err := tdlibClient.GetOption(&client.GetOptionRequest{ - Name: "version", - }) - if err != nil { - log.Fatalf("GetOption error: %s", err) - } - - log.Printf("TDLib version: %s", optionValue.(*client.OptionValueString).Value) - - me, err := tdlibClient.GetMe() - if err != nil { - log.Fatalf("GetMe error: %s", err) - } - - log.Printf("Me: %s %s [%s]", me.FirstName, me.LastName, me.Username) -} - -``` - -### Receive updates - -```go -tdlibClient, err := client.NewClient(authorizer) -if err != nil { - log.Fatalf("NewClient error: %s", err) -} - -listener := tdlibClient.GetListener() -defer listener.Close() - -for update := range listener.Updates { - if update.GetClass() == client.ClassUpdate { - log.Printf("%#v", update) - } -} -``` - -### Proxy support - -```go -proxy := client.WithProxy(&client.AddProxyRequest{ - Server: "1.1.1.1", - Port: 1080, - Enable: true, - Type: &client.ProxyTypeSocks5{ - Username: "username", - Password: "password", - }, -}) - -tdlibClient, err := client.NewClient(authorizer, proxy) - -``` - -## Notes - -* WIP. Library API can be changed in the future -* The package includes a .tl-parser and generated [json-schema](https://github.com/zelenin/go-tdlib/tree/master/data) for creating libraries in other languages - -## Author - -[Aleksandr Zelenin](https://github.com/zelenin/), e-mail: [aleksandr@zelenin.me](mailto:aleksandr@zelenin.me) +## Fork for [modded TDLib](https://github.com/c0re100/td) diff --git a/client/puller/chat.go b/client/puller/chat.go index 415adbd..82e15a0 100644 --- a/client/puller/chat.go +++ b/client/puller/chat.go @@ -1,7 +1,7 @@ package puller import ( - "github.com/zelenin/go-tdlib/client" + "github.com/c0re100/gotdlib/client" ) func ChatHistory(tdlibClient *client.Client, chatId int64) (chan *client.Message, chan error) { diff --git a/client/puller/chats.go b/client/puller/chats.go index 27f41c7..afb4f45 100644 --- a/client/puller/chats.go +++ b/client/puller/chats.go @@ -3,7 +3,7 @@ package puller import ( "math" - "github.com/zelenin/go-tdlib/client" + "github.com/c0re100/gotdlib/client" ) func Chats(tdlibClient *client.Client) (chan *client.Chat, chan error) { diff --git a/client/puller/supergroup.go b/client/puller/supergroup.go index 2456dfa..5c42654 100644 --- a/client/puller/supergroup.go +++ b/client/puller/supergroup.go @@ -1,7 +1,7 @@ package puller import ( - "github.com/zelenin/go-tdlib/client" + "github.com/c0re100/gotdlib/client" ) func SupergroupMembers(tdlibClient *client.Client, supergroupId int64) (chan *client.ChatMember, chan error) { diff --git a/cmd/generate-code.go b/cmd/generate-code.go index baa9223..feded19 100644 --- a/cmd/generate-code.go +++ b/cmd/generate-code.go @@ -8,8 +8,8 @@ import ( "os" "path/filepath" - "github.com/zelenin/go-tdlib/codegen" - "github.com/zelenin/go-tdlib/tlparser" + "github.com/c0re100/gotdlib/codegen" + "github.com/c0re100/gotdlib/tlparser" ) type config struct { diff --git a/cmd/generate-json.go b/cmd/generate-json.go index 6c2f771..8590b71 100644 --- a/cmd/generate-json.go +++ b/cmd/generate-json.go @@ -4,7 +4,7 @@ import ( "bufio" "encoding/json" "flag" - "github.com/zelenin/go-tdlib/tlparser" + "github.com/c0re100/gotdlib/tlparser" "log" "net/http" "os" diff --git a/codegen/function.go b/codegen/function.go index 536bde9..0186d81 100644 --- a/codegen/function.go +++ b/codegen/function.go @@ -4,7 +4,7 @@ import ( "bytes" "fmt" - "github.com/zelenin/go-tdlib/tlparser" + "github.com/c0re100/gotdlib/tlparser" ) func GenerateFunctions(schema *tlparser.Schema, packageName string) []byte { diff --git a/codegen/tdlib.go b/codegen/tdlib.go index f468ceb..5149c56 100644 --- a/codegen/tdlib.go +++ b/codegen/tdlib.go @@ -1,7 +1,7 @@ package codegen import ( - "github.com/zelenin/go-tdlib/tlparser" + "github.com/c0re100/gotdlib/tlparser" "log" "strings" ) diff --git a/codegen/type.go b/codegen/type.go index 9f8d0df..f699bce 100644 --- a/codegen/type.go +++ b/codegen/type.go @@ -3,7 +3,7 @@ package codegen import ( "bytes" "fmt" - "github.com/zelenin/go-tdlib/tlparser" + "github.com/c0re100/gotdlib/tlparser" ) func GenerateTypes(schema *tlparser.Schema, packageName string) []byte { diff --git a/codegen/unmarshaler.go b/codegen/unmarshaler.go index 6da4db0..217e9da 100644 --- a/codegen/unmarshaler.go +++ b/codegen/unmarshaler.go @@ -3,7 +3,7 @@ package codegen import ( "bytes" "fmt" - "github.com/zelenin/go-tdlib/tlparser" + "github.com/c0re100/gotdlib/tlparser" ) func GenerateUnmarshalers(schema *tlparser.Schema, packageName string) []byte { diff --git a/go.mod b/go.mod index fb834e7..84926ec 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ -module github.com/zelenin/go-tdlib +module github.com/c0re100/gotdlib -go 1.12 +go 1.16