This repository has been archived by the owner on Sep 13, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
options.go
156 lines (137 loc) · 4.53 KB
/
options.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
package tdjson
// The Telegram test environment will be used instead of the production environment
func WithTestDC() Option {
return func(options *options) {
options.useTestDC = true
}
}
// The path to the directory for the persistent database; if empty, the current working directory will be used
func WithDatabaseDir(path string) Option {
return func(options *options) {
options.databaseDirectory = path
}
}
// The path to the directory for storing files; if empty, database_directory will be used
func WithFilesDir(path string) Option {
return func(options *options) {
options.filesDirectory = path
}
}
// If set to true, information about downloaded and uploaded files will be saved between application restarts
func WithFileDatabase() Option {
return func(options *options) {
options.useFileDatabase = true
}
}
// If set to true, the library will maintain a cache of users, basic groups, supergroups, channels and secret chats. Implies use WithFileDatabase()
func WithChatInfoDatabase() Option {
return func(options *options) {
options.useChatInfoDatabase = true
}
}
// If set to true, the library will maintain a cache of chats and messages. Implies use WithChatInfoDatabase()
func WithMessageDatabase() Option {
return func(options *options) {
options.useMessageDatabase = true
}
}
// If set to true, support for secret chats will be enabled
func WithSecretChats() Option {
return func(options *options) {
options.useSecretChats = true
}
}
// Application identifier for Telegram API access, which can be obtained at https://my.telegram.org
func WithID(id string) Option {
return func(options *options) {
options.apiID = id
}
}
// Application identifier hash for Telegram API access, which can be obtained at https://my.telegram.org
func WithHash(hash string) Option {
return func(options *options) {
options.apiHash = hash
}
}
// IETF language tag of the user's operating system language
func WithSystemLanguage(lang string) Option {
return func(options *options) {
options.systemLanguageCode = lang
}
}
// Model of the device the application is being run on
func WithDeviceModel(model string) Option {
return func(options *options) {
options.deviceModel = model
}
}
// Version of the operating system the application is being run on
func WithSystemVersion(system string) Option {
return func(options *options) {
options.systemVersion = system
}
}
// Application version
func WithApplicationVersion(version string) Option {
return func(options *options) {
options.applicationVersion = version
}
}
// If set to true, old files will automatically be deleted
func WithStorageOptimizer() Option {
return func(options *options) {
options.enableStorageOptimizer = true
}
}
// If set to true, original file names will be ignored. Otherwise, downloaded files will be saved under names as close as possible to the original name
func WithIgnoreFileNames() Option {
return func(options *options) {
options.ignoreFileNames = true
}
}
// Sets phone number for authorization
func WithPhone(phone string) Option {
return func(options *options) {
options.phone = phone
}
}
// Changes parameters which will be used during execution Auth method with state authorizationStateWaitTdlibParameters.
type Option func(*options)
type options struct {
useTestDC bool
databaseDirectory string
filesDirectory string
useFileDatabase bool
useChatInfoDatabase bool
useMessageDatabase bool
useSecretChats bool
apiID string
apiHash string
systemLanguageCode string
deviceModel string
systemVersion string
applicationVersion string
enableStorageOptimizer bool
ignoreFileNames bool
phone string
}
func (o options) toTdlibParameters() Update {
return Update{
"@type": "tdlibParameters",
"use_test_dc": o.useTestDC,
"database_directory": o.databaseDirectory,
"files_directory": o.filesDirectory,
"use_file_database": o.useFileDatabase,
"use_chat_info_database": o.useChatInfoDatabase,
"use_message_database": o.useMessageDatabase,
"use_secret_chats": o.useSecretChats,
"api_id": o.apiID,
"api_hash": o.apiHash,
"system_language_code": o.systemLanguageCode,
"device_model": o.deviceModel,
"system_version": o.systemVersion,
"application_version": o.applicationVersion,
"enable_storage_optimizer": o.enableStorageOptimizer,
"ignore_file_names": o.ignoreFileNames,
}
}