1
0
mirror of https://github.com/ManyakRus/telegram_loki.git synced 2024-12-03 08:55:23 +02:00

сделал make mod

This commit is contained in:
Nikitin Aleksandr 2024-10-28 09:48:56 +03:00
parent 91111d9f36
commit 574fc382c9
148 changed files with 7393 additions and 1738 deletions

View File

@ -10,7 +10,7 @@ TELEGRAM_MESSAGES_COUNT=1
LOKI_URL=
#LOKI_SEARCH_TEXT - is regular expression. Need escape characters, "[" = "\\\\["
LOKI_SEARCH_TEXT="\\\\[ERROR\\\\]|\\\\[PANIC\\\\]|level=error|level=panic|error:|panic:"
LOKI_SEARCH_TEXT="\\\\[ERROR\\\\]|\\\\[PANIC\\\\]|level=error|level=panic|error:|(\n\t, )panic:"
GRAFANA_LOGIN=
GRAFANA_PASSWORD=

View File

@ -15,7 +15,7 @@ run:
mod:
clear
go get -u ./...
go mod tidy -compat=1.18
go mod tidy -compat=1.22
go mod vendor
go fmt ./...
build:

View File

@ -1 +1 @@
2024-09-27 08:00:31.480
2024-10-28 06:48:12.317

View File

@ -1 +1 @@
00154
00155

32
go.mod
View File

@ -5,8 +5,8 @@ go 1.22.0
toolchain go1.22.1
require (
github.com/ManyakRus/starter v1.0.57
github.com/golang-module/carbon/v2 v2.3.12
github.com/ManyakRus/starter v1.0.65
github.com/golang-module/carbon/v2 v2.4.1
)
require (
@ -21,7 +21,7 @@ require (
github.com/cockroachdb/pebble v1.1.2 // indirect
github.com/cockroachdb/redact v1.1.5 // indirect
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect
github.com/getsentry/sentry-go v0.29.0 // indirect
github.com/getsentry/sentry-go v0.29.1 // indirect
github.com/go-faster/errors v0.7.1 // indirect
github.com/go-faster/jx v1.1.0 // indirect
github.com/go-faster/xor v1.0.0 // indirect
@ -31,33 +31,33 @@ require (
github.com/gotd/contrib v0.20.0 // indirect
github.com/gotd/ige v0.2.2 // indirect
github.com/gotd/neo v0.1.5 // indirect
github.com/gotd/td v0.110.1 // indirect
github.com/gotd/td v0.111.2 // indirect
github.com/joho/godotenv v1.5.1 // indirect
github.com/klauspost/compress v1.17.10 // indirect
github.com/klauspost/compress v1.17.11 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_golang v1.20.4 // indirect
github.com/prometheus/client_golang v1.20.5 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.59.1 // indirect
github.com/prometheus/common v0.60.1 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/rogpeppe/go-internal v1.13.1 // indirect
github.com/segmentio/asm v1.2.0 // indirect
go.etcd.io/bbolt v1.3.11 // indirect
go.opentelemetry.io/otel v1.30.0 // indirect
go.opentelemetry.io/otel/trace v1.30.0 // indirect
go.opentelemetry.io/otel v1.31.0 // indirect
go.opentelemetry.io/otel/trace v1.31.0 // indirect
go.uber.org/atomic v1.11.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/crypto v0.27.0 // indirect
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 // indirect
golang.org/x/net v0.29.0 // indirect
golang.org/x/crypto v0.28.0 // indirect
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c // indirect
golang.org/x/net v0.30.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.25.0 // indirect
golang.org/x/term v0.24.0 // indirect
golang.org/x/text v0.18.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
golang.org/x/sys v0.26.0 // indirect
golang.org/x/term v0.25.0 // indirect
golang.org/x/text v0.19.0 // indirect
google.golang.org/protobuf v1.35.1 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
nhooyr.io/websocket v1.8.17 // indirect
rsc.io/qr v0.2.0 // indirect

70
go.sum
View File

@ -2,8 +2,8 @@ github.com/DataDog/zstd v1.5.6 h1:LbEglqepa/ipmmQJUDnSsfvA8e8IStVcGaFWDuxvGOY=
github.com/DataDog/zstd v1.5.6/go.mod h1:g4AWEaM3yOg3HYfnJ3YIawPnVdXJh9QME85blwSAmyw=
github.com/ManyakRus/logrus v0.0.0-20231019115155-9e6fede0d792 h1:bxwxD0H3kSUAH3uNk/b74gkImcUiP7dyibmMoVwk338=
github.com/ManyakRus/logrus v0.0.0-20231019115155-9e6fede0d792/go.mod h1:OUyxCVbPW/2lC1e6cM7Am941SJiC88BhNnb24x2R3a8=
github.com/ManyakRus/starter v1.0.57 h1:vaqnGuJm5t2SsVoHY8/9KegXHtMnWg1n+bc8HMBcRHA=
github.com/ManyakRus/starter v1.0.57/go.mod h1:fJC9PeOHag2XTP1833OZkp8gz6s46oMz0i+tzFt8iFg=
github.com/ManyakRus/starter v1.0.65 h1:3TvYfrO2N55qUziPFxuLCVZI3nGKmKupTb4v7zMbNqo=
github.com/ManyakRus/starter v1.0.65/go.mod h1:U9WyHWnavyxu4+J5D6VpF3G2yZ4KagfSNM2Soo9O+7c=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
@ -28,8 +28,8 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3
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/getsentry/sentry-go v0.29.0 h1:YtWluuCFg9OfcqnaujpY918N/AhCCwarIDWOYSBAjCA=
github.com/getsentry/sentry-go v0.29.0/go.mod h1:jhPesDAL0Q0W2+2YEuVOvdWmVtdsr1+jtBrlDEVWwLY=
github.com/getsentry/sentry-go v0.29.1 h1:DyZuChN8Hz3ARxGVV8ePaNXh1dQ7d76AiB117xcREwA=
github.com/getsentry/sentry-go v0.29.1/go.mod h1:x3AtIzN01d6SiWkderzaH28Tm0lgkafpJ5Bm3li39O0=
github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA=
github.com/go-errors/errors v1.4.2/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og=
github.com/go-faster/errors v0.7.1 h1:MkJTnDoEdi9pDabt1dpWf7AA8/BaSYZqibYyhZ20AYg=
@ -41,8 +41,8 @@ github.com/go-faster/xor v1.0.0 h1:2o8vTOgErSGHP3/7XwA5ib1FTtUsNtwCoLLBjl31X38=
github.com/go-faster/xor v1.0.0/go.mod h1:x5CaDY9UKErKzqfRfFZdfu+OSTfoZny3w5Ak7UxcipQ=
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
github.com/golang-module/carbon/v2 v2.3.12 h1:VC1DwN1kBwJkh5MjXmTFryjs5g4CWyoM8HAHffZPX/k=
github.com/golang-module/carbon/v2 v2.3.12/go.mod h1:HNsedGzXGuNciZImYP2OMnpiwq/vhIstR/vn45ib5cI=
github.com/golang-module/carbon/v2 v2.4.1 h1:cYUD8T+rHeX+qIybGYpnJ8I90F10dvyEF67VNOO+zZM=
github.com/golang-module/carbon/v2 v2.4.1/go.mod h1:1jP9AZ4k2+lmfgY/wZgmtsN52VcHC5YuPM6varKDTkM=
github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM=
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
@ -55,16 +55,16 @@ github.com/gotd/ige v0.2.2 h1:XQ9dJZwBfDnOGSTxKXBGP4gMud3Qku2ekScRjDWWfEk=
github.com/gotd/ige v0.2.2/go.mod h1:tuCRb+Y5Y3eNTo3ypIfNpQ4MFjrnONiL2jN2AKZXmb0=
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.110.1 h1:worMp6CqduQye2NfkuBFhYe6kyt/f1EhmXaOEKKX+fY=
github.com/gotd/td v0.110.1/go.mod h1:mwQQQrrAn3wizT37UjBAUB4lTy1j2RHnkRJ4z9ivqGs=
github.com/gotd/td v0.111.2 h1:f1u3FueE1QXr6n0WzE5k4tOJOjn5oFaSeF71ai9OE/8=
github.com/gotd/td v0.111.2/go.mod h1:zzgUtTDJD4TVaCpKfCD0rxazQxPhSlPzx/CVBpqsx1g=
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/klauspost/compress v1.17.10 h1:oXAz+Vh0PMUvJczoi+flxpnBEPxoER1IaAnU/NMPtT0=
github.com/klauspost/compress v1.17.10/go.mod h1:pMDklpSncoRMuLFrf1W9Ss9KT+0rH90U12bZKk7uwG0=
github.com/klauspost/compress v1.17.11 h1:In6xLpyWOi1+C7tXUUWv2ot1QvBjxevKAaI6IXrJmUc=
github.com/klauspost/compress v1.17.11/go.mod h1:pMDklpSncoRMuLFrf1W9Ss9KT+0rH90U12bZKk7uwG0=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
@ -78,12 +78,12 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
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/prometheus/client_golang v1.20.4 h1:Tgh3Yr67PaOv/uTqloMsCEdeuFTatm5zIq5+qNN23vI=
github.com/prometheus/client_golang v1.20.4/go.mod h1:PIEt8X02hGcP8JWbeHyeZ53Y/jReSnHgO035n//V5WE=
github.com/prometheus/client_golang v1.20.5 h1:cxppBPuYhUnsO6yo/aoRol4L7q7UFfdm+bR9r+8l63Y=
github.com/prometheus/client_golang v1.20.5/go.mod h1:PIEt8X02hGcP8JWbeHyeZ53Y/jReSnHgO035n//V5WE=
github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E=
github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY=
github.com/prometheus/common v0.59.1 h1:LXb1quJHWm1P6wq/U824uxYi4Sg0oGvNeUm1z5dJoX0=
github.com/prometheus/common v0.59.1/go.mod h1:GpWM7dewqmVYcd7SmRaiWVe9SSqjf0UrwnYnpEZNuT0=
github.com/prometheus/common v0.60.1 h1:FUas6GcOw66yB/73KC+BOZoFJmbo/1pojoILArPAaSc=
github.com/prometheus/common v0.60.1/go.mod h1:h0LYf1R1deLSKtD4Vdg8gy4RuOvENW2J/h19V5NADQw=
github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc=
github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
@ -92,23 +92,17 @@ github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWN
github.com/segmentio/asm v1.2.0 h1:9BQrFxC+YOHJlTlHGkTrFWf59nbL3XnCoFLTwDCI7ys=
github.com/segmentio/asm v1.2.0/go.mod h1:BqMnlJP91P8d+4ibuonYZw9mfnzI9HfxselHZr5aAcs=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
go.etcd.io/bbolt v1.3.11 h1:yGEzV1wPz2yVCLsD8ZAiGHhHVlczyC9d1rP43/VCRJ0=
go.etcd.io/bbolt v1.3.11/go.mod h1:dksAq7YMXoljX0xu6VF5DMZGbhYYoLUalEiSySYAS4I=
go.opentelemetry.io/otel v1.30.0 h1:F2t8sK4qf1fAmY9ua4ohFS/K+FUuOPemHUIXHtktrts=
go.opentelemetry.io/otel v1.30.0/go.mod h1:tFw4Br9b7fOS+uEao81PJjVMjW/5fvNCbpsDIXqP0pc=
go.opentelemetry.io/otel/trace v1.30.0 h1:7UBkkYzeg3C7kQX8VAidWh2biiQbtAKjyIML8dQ9wmc=
go.opentelemetry.io/otel/trace v1.30.0/go.mod h1:5EyKqTzzmyqB9bwtCCq6pDLktPK6fmGf/Dph+8VI02o=
go.opentelemetry.io/otel v1.31.0 h1:NsJcKPIW0D0H3NgzPDHmo0WW6SptzPdqg/L1zsIm2hY=
go.opentelemetry.io/otel v1.31.0/go.mod h1:O0C14Yl9FgkjqcCZAsE053C13OaddMYr/hz6clDkEJE=
go.opentelemetry.io/otel/trace v1.31.0 h1:ffjsj1aRouKewfr85U2aGagJ46+MvodynlQ1HYdmJys=
go.opentelemetry.io/otel/trace v1.31.0/go.mod h1:TXZkRk7SM2ZQLtR6eoAWQFIHPvzQ06FJAsO1tJg480A=
go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE=
go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
@ -120,18 +114,18 @@ go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
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=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.27.0 h1:GXm2NjJrPaiv/h1tb2UH8QfgC/hOf/+z0p6PT8o1w7A=
golang.org/x/crypto v0.27.0/go.mod h1:1Xngt8kV6Dvbssa53Ziq6Eqn0HqbZi5Z6R0ZpwQzt70=
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 h1:e66Fs6Z+fZTbFBAxKfP3PALWBtpfqks2bwGcexMxgtk=
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0/go.mod h1:2TbTHSBQa924w8M6Xs1QcRcFwyucIwBGpK1p2f1YFFY=
golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw=
golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U=
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c h1:7dEasQXItcW1xKJ2+gg5VOiBnqWrJc+rq0DPKyvvdbY=
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c/go.mod h1:NQtJDoLvd6faHhE7m4T/1IY708gDefGGjR/iUW8yQQ8=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.29.0 h1:5ORfpBpCs4HzDYoodCDBbwHzdR5UrLBZ3sOnUJmFoHo=
golang.org/x/net v0.29.0/go.mod h1:gLkgy8jTGERgjzMic6DS9+SP0ajcu6Xu3Orq/SpETg0=
golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4=
golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@ -142,14 +136,14 @@ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5h
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.24.0 h1:Mh5cbb+Zk2hqqXNO7S1iTjEphVL+jb8ZWaqh/g+JWkM=
golang.org/x/term v0.24.0/go.mod h1:lOBK/LVxemqiMij05LGJ0tzNr8xlmwBRJ81PX6wVLH8=
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.25.0 h1:WtHI/ltw4NvSUig5KARz9h521QvRC8RmF/cuYqifU24=
golang.org/x/term v0.25.0/go.mod h1:RPyXicDX+6vLxogjjRxjgD2TKtmAO6NZBsBRfrOLu7M=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224=
golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM=
golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
@ -158,8 +152,8 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8T
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA=
google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST95x9zc=
gopkg.in/natefinch/lumberjack.v2 v2.2.1/go.mod h1:YD8tP3GAjkrDg1eZH7EGmyESg/lsYskCTPBJVb9jqSc=

View File

@ -37,7 +37,8 @@ func FillSettings() {
if err != nil || Settings.TELEGRAM_MESSAGES_COUNT == 0 {
Settings.TELEGRAM_MESSAGES_COUNT = 1
}
Settings.LOKI_SEARCH_TEXT = os.Getenv("LOKI_SEARCH_TEXT")
s := os.Getenv("LOKI_SEARCH_TEXT")
Settings.LOKI_SEARCH_TEXT = s
if Settings.LOKI_SEARCH_TEXT == "" {
Settings.LOKI_SEARCH_TEXT = "error:|panic:|ERROR:|PANIC:"
//Settings.LOKI_SEARCH_TEXT = "error:%7Cpanic:%7CERROR:%7CPANIC:"

7
make_version.sh Executable file
View File

@ -0,0 +1,7 @@
# версия приложения из git заполняется в файл: version.txt
# образец:
# v1.0.4-23-gf3bbaf4 2024-10-14 14:43:55 +0300
# v1.0.61 2024-10-14 14:25:20 +0300
# git commit TAG + git commit HASH + git commit date and time
echo $(git describe --always --tags $(git rev-parse HEAD)) $(git show --no-patch --format=%ci) >./pkg/version/version.txt

11
pkg/version/version.go Normal file
View File

@ -0,0 +1,11 @@
package version
import _ "embed"
// Version - версия приложения из git, заполняется при компиляции программы
// из файла version.txt
// для обновления версии запустите
// make_version.sh
//
//go:embed version.txt
var Version string

1
pkg/version/version.txt Normal file
View File

@ -0,0 +1 @@
v1.0.4-24-g855fd5d 2024-10-15 11:26:22 +0300

View File

@ -0,0 +1,12 @@
package version
import (
"github.com/ManyakRus/starter/micro"
"testing"
)
func TestShow_Version(t *testing.T) {
micro.Show_Version(Version)
}

View File

@ -10,6 +10,7 @@ import (
"fmt"
"github.com/google/uuid"
"hash/fnv"
"os/exec"
"reflect"
"runtime"
"sort"
@ -1004,3 +1005,150 @@ func Int32FromString(s string) (int32, error) {
return Otvet, err
}
// ExecuteShellCommand - выполняет команду в shell, и возвращает строку результата
func ExecuteShellCommand(TextCommand string, args ...string) (string, error) {
Otvet := ""
var err error
MassByte, err := exec.Command(TextCommand, args...).CombinedOutput()
Otvet = string(MassByte)
if err != nil {
return Otvet, err
}
return Otvet, err
}
// DeleteEndEndline - убирает в конце "\n"
func DeleteEndEndline(Text string) string {
Otvet := Text
if Otvet == "" {
return Otvet
}
LastSymbol := Otvet[len(Otvet)-1:]
if LastSymbol == "\n" {
Otvet = Otvet[0 : len(Otvet)-1]
}
return Otvet
}
// Find_Directory_ModifiedTime - возвращает дату последнего изменения в папке internal
func Find_Directory_ModifiedTime(FolderName string) (time.Time, error) {
var Otvet time.Time
var err error
dir := ProgramDir()
dir = dir + FolderName
ok, err := FileExists(dir)
if err != nil {
err = fmt.Errorf("Find_Directory_ModifiedTime() FileExists() error: %w", err)
return Otvet, err
}
if ok == false {
err = fmt.Errorf("Find_Directory_ModifiedTime() FileExists() error: file not exists: %s", dir)
return Otvet, err
}
//найдём дату папки
f, err := os.Open(dir)
if err != nil {
err = fmt.Errorf("Find_Directory_ModifiedTime() os.Open() error: %w", err)
return Otvet, err
}
defer f.Close()
stat, err := f.Stat()
if err != nil {
err = fmt.Errorf("Find_Directory_ModifiedTime() f.Stat() error: %w", err)
return Otvet, err
}
Otvet = stat.ModTime()
return Otvet, err
}
// Show_Repository_Code_ModifiedTime - выводит дату последнего изменения в папках cmd, internal, pkg, vendor
func Show_Repository_Code_ModifiedTime() {
Date, err := Find_Repository_Code_ModifiedTime()
if err != nil {
println("Find_Repository_Code_ModifiedTime() error: ", err.Error())
return
}
if Date.IsZero() {
println("Last repository code modified time: not found")
return
}
println("Last repository code modified time: ", Date.String())
}
// Find_Repository_Code_ModifiedTime - возвращает дату последнего изменения в папках cmd, internal, pkg, vendor
func Find_Repository_Code_ModifiedTime() (time.Time, error) {
var Otvet time.Time
var err error
//cmd
Time_cmd, err := Find_Directory_ModifiedTime("cmd")
if err != nil {
//return Otvet, err
}
//internal
Time_internal, err := Find_Directory_ModifiedTime("internal")
if err != nil {
//return Otvet, err
}
//pkg
Time_pkg, err := Find_Directory_ModifiedTime("pkg")
if err != nil {
//return Otvet, err
}
//vendor
Time_vendor, err := Find_Directory_ModifiedTime("vendor")
if err != nil {
//return Otvet, err
}
//выбираем максимальную дату
Otvet = TimeMax(Time_cmd, Time_internal, Time_pkg, Time_vendor)
return Otvet, err
}
// TimeMax - возвращает максимальную дату
func TimeMax(x time.Time, y ...time.Time) time.Time {
maxTime := x
for _, val := range y {
if val.After(maxTime) {
maxTime = val
}
}
return maxTime
}
// TimeMin - возвращает минимальную дату
func TimeMin(x time.Time, y ...time.Time) time.Time {
minTime := x
for _, val := range y {
if val.Before(minTime) {
minTime = val
}
}
return minTime
}
// Show_Version - выводит версию сервиса на экран
func Show_Version(Version string) {
println("Service version: ", Version)
}

View File

@ -94,7 +94,8 @@ func StopAppAndWait() {
if contextmain.CancelContext != nil {
contextmain.CancelContext()
} else {
os.Exit(0)
//os.Exit(0)
log.Warn("Context = nil")
}
GetWaitGroup_Main().Wait()
@ -106,7 +107,9 @@ func WaitStop() {
select {
case <-SignalInterrupt:
log.Warn("Interrupt clean shutdown.")
contextmain.CancelContext()
if contextmain.CancelContext != nil {
contextmain.CancelContext()
}
case <-contextmain.GetContext().Done():
log.Warn("Context app is canceled.")
}

View File

@ -599,12 +599,18 @@ func TimeLimit() {
// Connect подключение к серверу Телеграм, паника при ошибке
func Connect(func_OnNewMessage func(ctx context.Context, entities tg.Entities, u *tg.UpdateNewMessage, Peer1 storage.Peer) error) {
err := Connect_err(func_OnNewMessage)
LogInfo_Connected(err)
}
// LogInfo_Connected - выводит сообщение в Лог, или паника при ошибке
func LogInfo_Connected(err error) {
if err != nil {
TextError := fmt.Sprint("Telegram connection: ", Settings.TELEGRAM_PHONE_FROM, ", error: ", err)
log.Panic(TextError)
} else {
log.Info("Telegram connected: ", Settings.TELEGRAM_PHONE_FROM)
}
}
// Connect_err подключение к серверу Телеграм
@ -810,16 +816,45 @@ func AsFloodWait(err error) (d int, ok bool) {
// StartTelegram - подключается к телеграмму, запускает остановку приложения.
// func_OnNewMessage - функция для приёма новых сообщений
func StartTelegram(func_OnNewMessage func(ctx context.Context, entities tg.Entities, u *tg.UpdateNewMessage, Peer1 storage.Peer) error) {
var err error
ctx := contextmain.GetContext()
WaitGroup := stopapp.GetWaitGroup_Main()
err = Start_ctx(&ctx, WaitGroup, func_OnNewMessage)
LogInfo_Connected(err)
}
// Start_ctx - необходимые процедуры для подключения к серверу Telegram
// Свой контекст и WaitGroup нужны для остановки работы сервиса Graceful shutdown
// Для тех кто пользуется этим репозиторием для старта и останова сервиса можно просто StartTelegram()
func Start_ctx(ctx *context.Context, WaitGroup *sync.WaitGroup, func_OnNewMessage func(ctx context.Context, entities tg.Entities, u *tg.UpdateNewMessage, Peer1 storage.Peer) error) error {
var err error
//запомним к себе контекст
contextmain.Ctx = ctx
if ctx == nil {
contextmain.GetContext()
}
//запомним к себе WaitGroup
stopapp.SetWaitGroup_Main(WaitGroup)
if WaitGroup == nil {
stopapp.StartWaitStop()
}
//
CreateTelegramClient(func_OnNewMessage)
err := Connect_err(func_OnNewMessage)
err = Connect_err(func_OnNewMessage)
if err != nil {
log.Panic("Can not login to telegram ! Error: ", err)
return err
}
stopapp.GetWaitGroup_Main().Add(1)
go WaitStop()
return err
}
// FillSettings загружает переменные окружения в структуру из переменных окружения

View File

@ -1,5 +1,14 @@
# Changelog
## 0.29.1
The Sentry SDK team is happy to announce the immediate availability of Sentry Go SDK v0.29.1.
### Bug Fixes
- Correlate errors to the current trace ([#886](https://github.com/getsentry/sentry-go/pull/886))
- Set the trace context when the transaction finishes ([#888](https://github.com/getsentry/sentry-go/pull/888))
## 0.29.0
The Sentry SDK team is happy to announce the immediate availability of Sentry Go SDK v0.29.0.

View File

@ -383,6 +383,15 @@ func (scope *Scope) ApplyToEvent(event *Event, hint *EventHint, client *Client)
}
for key, value := range scope.contexts {
if key == "trace" && event.Type == transactionType {
// Do not override trace context of
// transactions, otherwise it breaks the
// transaction event representation.
// For error events, the trace context is used
// to link errors and traces/spans in Sentry.
continue
}
// Ensure we are not overwriting event fields
if _, ok := event.Contexts[key]; !ok {
event.Contexts[key] = cloneContext(value)
@ -395,7 +404,9 @@ func (scope *Scope) ApplyToEvent(event *Event, hint *EventHint, client *Client)
}
if scope.span != nil {
event.Contexts["trace"] = scope.span.traceContext().Map()
if _, ok := event.Contexts["trace"]; !ok {
event.Contexts["trace"] = scope.span.traceContext().Map()
}
transaction := scope.span.GetTransaction()
if transaction != nil {

View File

@ -6,7 +6,7 @@ import (
)
// The version of the SDK.
const SDKVersion = "0.29.0"
const SDKVersion = "0.29.1"
// apiVersion is the minimum version of the Sentry API compatible with the
// sentry-go SDK.

View File

@ -195,6 +195,10 @@ func StartSpan(ctx context.Context, operation string, options ...SpanOption) *Sp
clientOptions := span.clientOptions()
if clientOptions.EnableTracing {
hub := hubFromContext(ctx)
if !span.IsTransaction() {
// Push a new scope to stack for non transaction span
hub.PushScope()
}
hub.Scope().SetSpan(&span)
}
@ -355,6 +359,12 @@ func (s *Span) doFinish() {
s.EndTime = monotonicTimeSince(s.StartTime)
}
hub := hubFromContext(s.ctx)
if !s.IsTransaction() {
// Referenced to StartSpan function that pushes current non-transaction span to scope stack
defer hub.PopScope()
}
if !s.Sampled.Bool() {
return
}
@ -370,7 +380,6 @@ func (s *Span) doFinish() {
// TODO(tracing): add breadcrumbs
// (see https://github.com/getsentry/sentry-python/blob/f6f3525f8812f609/sentry_sdk/tracing.py#L372)
hub := hubFromContext(s.ctx)
hub.CaptureEvent(event)
}
@ -554,10 +563,11 @@ func (s *Span) toEvent() *Event {
s.dynamicSamplingContext = DynamicSamplingContextFromTransaction(s)
}
contexts := make(map[string]Context, len(s.contexts))
contexts := make(map[string]Context, len(s.contexts)+1)
for k, v := range s.contexts {
contexts[k] = cloneContext(v)
}
contexts["trace"] = s.traceContext().Map()
// Make sure that the transaction source is valid
transactionSource := s.Source

View File

@ -18,7 +18,7 @@
#### 安装使用
##### Golang 版本大于等于 1.16 (推荐)
##### Golang 版本大于等于 1.17 (推荐)
```go
// 使用 github 库
@ -32,7 +32,7 @@ go get -u gitee.com/golang-module/carbon/v2
import "gitee.com/golang-module/carbon/v2"
```
##### Golang 版本小于 1.16 (必须)
##### Golang 版本小于 1.17 (必须)
```go
// 使用 github 库
@ -59,7 +59,7 @@ carbon.SetDefault(carbon.Default{
Layout: carbon.DateTimeLayout,
Timezone: carbon.PRC,
WeekStartsAt: carbon.Sunday,
Locale: "zh-CN",
Locale: "zh-CN", // 取值范围:lang 目录下翻译文件名,不包含文件后缀
})
```
> 建议在入口文件如 `main.go` 中设置
@ -1209,85 +1209,11 @@ carbon.Parse("2020-08-05 13:14:15").IsWinter() // false
```
##### JSON
###### 场景一: 所有时间字段有相同的格式
```go
carbon.SetDefault(carbon.Default{
Layout: carbon.DateTimeLayout,
})
type Person struct {
Name string `json:"name"`
Age int `json:"age"`
Field1 carbon.Carbon `json:"field1"`
Field2 carbon.Carbon `json:"field2"`
Field3 carbon.Carbon `json:"field3"`
Field4 carbon.Carbon `json:"field4"`
Field5 carbon.Carbon `json:"field5"`
Field6 carbon.Carbon `json:"field6"`
Field7 carbon.Carbon `json:"field7"`
Field8 carbon.Carbon `json:"field8"`
}
now := carbon.Parse("2020-08-05 13:14:15", carbon.PRC)
person := Person {
Name: "gouguoyin",
Age: 18,
Field1: now,
Field2: now,
Field3: now,
Field4: now,
Field5: now,
Field6: now,
Field7: now,
Field8: now,
}
data, marshalErr := json.Marshal(person)
if marshalErr != nil {
// 错误处理
log.Fatal(marshalErr)
}
fmt.Printf("%s", data)
// 输出
{
"name": "gouguoyin",
"age": 18,
"field1": "2020-08-05 13:14:15",
"field2": "2020-08-05 13:14:15",
"field3": "2020-08-05 13:14:15",
"field4": "2020-08-05 13:14:15",
"field5": "2020-08-05 13:14:15",
"field6": "2020-08-05 13:14:15",
"field7": "2020-08-05 13:14:15",
"field8": "2020-08-05 13:14:15"
}
unmarshalErr := json.Unmarshal(data, &person)
if unmarshalErr != nil {
// 错误处理
log.Fatal(unmarshalErr)
}
fmt.Printf("%s", person.Field1) // 2020-08-05 13:14:15
fmt.Printf("%s", person.Field2) // 2020-08-05 13:14:15
fmt.Printf("%s", person.Field3) // 2020-08-05 13:14:15
fmt.Printf("%s", person.Field4) // 2020-08-05 13:14:15
fmt.Printf("%s", person.Field5) // 2020-08-05 13:14:15
fmt.Printf("%s", person.Field6) // 2020-08-05 13:14:15
fmt.Printf("%s", person.Field7) // 2020-08-05 13:14:15
fmt.Printf("%s", person.Field8) // 2020-08-05 13:14:15
```
###### 场景二: 不同时间字段有不同的格式
```go
type Person struct {
Name string `json:"name"`
Age int `json:"age"`
Birthday0 carbon.Carbon `json:"birthday0"`
Birthday1 carbon.DateTime `json:"birthday1"`
Birthday2 carbon.DateTimeMilli `json:"birthday2"`
Birthday3 carbon.DateTimeMicro `json:"birthday3"`
@ -1309,6 +1235,7 @@ type Person struct {
person := Person {
Name: "gouguoyin",
Age: 18,
Birthday0: carbon.Now().SubYears(18),
Birthday1: carbon.Now().SubYears(18).ToDateTimeStruct(),
Birthday2: carbon.Now().SubYears(18).ToDateTimeMilliStruct(),
Birthday3: carbon.Now().SubYears(18).ToDateTimeMicroStruct(),
@ -1337,6 +1264,7 @@ fmt.Printf("%s", data)
{
"name": "gouguoyin",
"age": 18,
"birthday0": "2003-07-16 13:14:15",
"birthday1": "2003-07-16 13:14:15",
"birthday2": "2003-07-16 13:14:15.999",
"birthday3": "2003-07-16 13:14:15.999999",
@ -1361,6 +1289,7 @@ if err != nil {
log.Fatal(err)
}
person.Birthday0.String() // 2003-07-16 13:14:15
person.Birthday1.String() // 2003-07-16 13:14:15
person.Birthday2.String() // 2003-07-16 13:14:15.999
person.Birthday3.String() // 2003-07-16 13:14:15.999999
@ -1423,6 +1352,7 @@ person.CreatedAt4.Int64() // 1596604455999999999
* [印地语(hi)](./lang/hi.json "印地语"): 由 [chauhan17nitin](https://github.com/chauhan17nitin "chauhan17nitin") 翻译
* [波兰语(pl)](./lang/pl.json "波兰语"): 由 [gouguoyin](https://github.com/gouguoyin "gouguoyin") 翻译
* [保加利亚语(bg)](./lang/bg.json "保加利亚语"): 由 [yuksbg](https://github.com/yuksbg "yuksbg") 翻译
* [阿拉伯语(ar)](./lang/bg.json "阿拉伯语"): 由 [zumoshi](https://github.com/yuksbg "zumoshi") 翻译
目前支持的方法有

View File

@ -20,7 +20,7 @@ Carbon は [awesome-go](https://github.com/avelino/awesome-go#date-and-time "awe
#### インストール使用
##### Golangバージョンは1.16以上です (推奨)
##### Golangバージョンは1.17以上です (推奨)
```go
// github倉庫を使う
@ -35,7 +35,7 @@ go get -u gitee.com/golang-module/carbon/v2
import "gitee.com/golang-module/carbon/v2"
```
##### Golangバージョンは1.16より小さいです (必要)
##### Golangバージョンは1.17より小さいです (必要)
```go
// github倉庫を使う
@ -63,7 +63,7 @@ carbon.SetDefault(carbon.Default{
Layout: carbon.DateTimeLayout,
Timezone: carbon.PRC,
WeekStartsAt: carbon.Sunday,
Locale: "jp",
Locale: "jp", // 値の範囲:langディレクトリ下の翻訳ファイル名、ファイル接尾辞を含まない
})
```
@ -1211,84 +1211,11 @@ carbon.Parse("2020-08-05 13:14:15").IsWinter() // false
##### JSON
###### シナリオ 1: すべての時刻フィールドが同じ形式である
```go
carbon.SetDefault(carbon.Default{
Layout: carbon.DateTimeLayout,
})
type Person struct {
Name string `json:"name"`
Age int `json:"age"`
Field1 carbon.Carbon `json:"field1"`
Field2 carbon.Carbon `json:"field2"`
Field3 carbon.Carbon `json:"field3"`
Field4 carbon.Carbon `json:"field4"`
Field5 carbon.Carbon `json:"field5"`
Field6 carbon.Carbon `json:"field6"`
Field7 carbon.Carbon `json:"field7"`
Field8 carbon.Carbon `json:"field8"`
}
now := carbon.Parse("2020-08-05 13:14:15", carbon.PRC)
person := Person {
Name: "gouguoyin",
Age: 18,
Field1: now,
Field2: now,
Field3: now,
Field4: now,
Field5: now,
Field6: now,
Field7: now,
Field8: now,
}
data, marshalErr := json.Marshal(person)
if marshalErr != nil {
// エラー処理...
log.Fatal(marshalErr)
}
fmt.Printf("%s", data)
// 出力
{
"name": "gouguoyin",
"age": 18,
"field1": "2020-08-05 13:14:15",
"field2": "2020-08-05 13:14:15",
"field3": "2020-08-05 13:14:15",
"field4": "2020-08-05 13:14:15",
"field5": "2020-08-05 13:14:15",
"field6": "2020-08-05 13:14:15",
"field7": "2020-08-05 13:14:15",
"field8": "2020-08-05 13:14:15"
}
unmarshalErr := json.Unmarshal(data, &person)
if unmarshalErr != nil {
// エラー処理...
log.Fatal(unmarshalErr)
}
fmt.Printf("%s", person.Field1) // 2020-08-05 13:14:15
fmt.Printf("%s", person.Field2) // 2020-08-05 13:14:15
fmt.Printf("%s", person.Field3) // 2020-08-05 13:14:15
fmt.Printf("%s", person.Field4) // 2020-08-05 13:14:15
fmt.Printf("%s", person.Field5) // 2020-08-05 13:14:15
fmt.Printf("%s", person.Field6) // 2020-08-05 13:14:15
fmt.Printf("%s", person.Field7) // 2020-08-05 13:14:15
fmt.Printf("%s", person.Field8) // 2020-08-05 13:14:15
```
###### シナリオ 2: 異なる時刻フィールドは異なる形式を持つ
```go
type Person struct {
Name string `json:"name"`
Age int `json:"age"`
Birthday0 carbon.Carbon `json:"birthday0"`
Birthday1 carbon.DateTime `json:"birthday1"`
Birthday2 carbon.DateTimeMilli `json:"birthday2"`
Birthday3 carbon.DateTimeMicro `json:"birthday3"`
@ -1310,6 +1237,7 @@ type Person struct {
person := Person {
Name: "gouguoyin",
Age: 18,
Birthday0: carbon.Now().SubYears(18),
Birthday1: carbon.Now().SubYears(18).ToDateTimeStruct(),
Birthday2: carbon.Now().SubYears(18).ToDateTimeMilliStruct(),
Birthday3: carbon.Now().SubYears(18).ToDateTimeMicroStruct(),
@ -1338,6 +1266,7 @@ fmt.Printf("%s", data)
{
"name": "gouguoyin",
"age": 18,
"birthday0": "2003-07-16 13:14:15",
"birthday1": "2003-07-16 13:14:15",
"birthday2": "2003-07-16 13:14:15.999",
"birthday3": "2003-07-16 13:14:15.999999",
@ -1362,6 +1291,7 @@ if err != nil {
log.Fatal(err)
}
person.Birthday0.String() // 2003-07-16 13:14:15
person.Birthday1.String() // 2003-07-16 13:14:15
person.Birthday2.String() // 2003-07-16 13:14:15.999
person.Birthday3.String() // 2003-07-16 13:14:15.999999
@ -1424,6 +1354,7 @@ person.CreatedAt4.Int64() // 1596604455999999999
* [ヒンディー語(hi)](./lang/hi.json "ヒンディー語"): [chauhan17nitin](https://github.com/chauhan17nitin "chauhan17nitin") から翻訳されます
* [ポーランド語(pl)](./lang/pl.json "ポーランド語"): [gouguoyin](https://github.com/gouguoyin "gouguoyin") から翻訳されます
* [ブルガリア語(bg)](./lang/bg.json "ブルガリア語"): 由 [yuksbg](https://github.com/yuksbg "yuksbg") 翻译
* [アラビア語(ar)](./lang/ar.json "アラビア語"): 由 [zumoshi](https://github.com/yuksbg "zumoshi") 翻译
現在サポートされている方法

View File

@ -21,7 +21,7 @@ by [awesome-go](https://github.com/avelino/awesome-go#date-and-time "awesome-go"
#### Installation
##### Go version >= 1.16 (recommend)
##### Go version >= 1.17 (recommend)
```go
// By github
@ -35,7 +35,7 @@ go get -u gitee.com/golang-module/carbon/v2
import "gitee.com/golang-module/carbon/v2"
```
##### Go version < 1.16 (must)
##### Go version < 1.17 (must)
```go
// By github
@ -62,7 +62,7 @@ carbon.SetDefault(carbon.Default{
Layout: carbon.DateTimeLayout,
Timezone: carbon.Local,
WeekStartsAt: carbon.Sunday,
Locale: "en",
Locale: "en", // value range: translate file name in the lang directory, excluding file suffix
})
```
> Suggest setting in the entry file such as `main.go`
@ -1205,85 +1205,11 @@ carbon.Parse("2020-08-05 13:14:15").IsWinter() // false
##### JSON
###### Scene one: all time fields have the same format
```go
carbon.SetDefault(carbon.Default{
Layout: carbon.DateTimeLayout,
})
type Person struct {
Name string `json:"name"`
Age int `json:"age"`
Field1 carbon.Carbon `json:"field1"`
Field2 carbon.Carbon `json:"field2"`
Field3 carbon.Carbon `json:"field3"`
Field4 carbon.Carbon `json:"field4"`
Field5 carbon.Carbon `json:"field5"`
Field6 carbon.Carbon `json:"field6"`
Field7 carbon.Carbon `json:"field7"`
Field8 carbon.Carbon `json:"field8"`
}
now := carbon.Parse("2020-08-05 13:14:15", carbon.PRC)
person := Person {
Name: "gouguoyin",
Age: 18,
Field1: now,
Field2: now,
Field3: now,
Field4: now,
Field5: now,
Field6: now,
Field7: now,
Field8: now,
}
data, marshalErr := json.Marshal(person)
if marshalErr != nil {
// Error handle...
log.Fatal(marshalErr)
}
fmt.Printf("%s", data)
// Output
{
"name": "gouguoyin",
"age": 18,
"field1": "2020-08-05 13:14:15",
"field2": "2020-08-05 13:14:15",
"field3": "2020-08-05 13:14:15",
"field4": "2020-08-05 13:14:15",
"field5": "2020-08-05 13:14:15",
"field6": "2020-08-05 13:14:15",
"field7": "2020-08-05 13:14:15",
"field8": "2020-08-05 13:14:15"
}
var person Person
unmarshalErr := json.Unmarshal(data, &person)
if unmarshalErr != nil {
// Error handle...
log.Fatal(unmarshalErr)
}
fmt.Printf("%s", person.Field1) // 2020-08-05 13:14:15
fmt.Printf("%s", person.Field2) // 2020-08-05 13:14:15
fmt.Printf("%s", person.Field3) // 2020-08-05 13:14:15
fmt.Printf("%s", person.Field4) // 2020-08-05 13:14:15
fmt.Printf("%s", person.Field5) // 2020-08-05 13:14:15
fmt.Printf("%s", person.Field6) // 2020-08-05 13:14:15
fmt.Printf("%s", person.Field7) // 2020-08-05 13:14:15
fmt.Printf("%s", person.Field8) // 2020-08-05 13:14:15
```
###### Scene two: different time fields have different formats
```go
type Person struct {
Name string `json:"name"`
Age int `json:"age"`
Birthday0 carbon.Carbon `json:"birthday0"`
Birthday1 carbon.DateTime `json:"birthday1"`
Birthday2 carbon.DateTimeMilli `json:"birthday2"`
Birthday3 carbon.DateTimeMicro `json:"birthday3"`
@ -1305,6 +1231,7 @@ type Person struct {
person := Person {
Name: "gouguoyin",
Age: 18,
Birthday0: carbon.Now().SubYears(18),
Birthday1: carbon.Now().SubYears(18).ToDateTimeStruct(),
Birthday2: carbon.Now().SubYears(18).ToDateTimeMilliStruct(),
Birthday3: carbon.Now().SubYears(18).ToDateTimeMicroStruct(),
@ -1333,6 +1260,7 @@ fmt.Printf("%s", data)
{
"name": "gouguoyin",
"age": 18,
"birthday0": "2003-07-16 13:14:15",
"birthday1": "2003-07-16 13:14:15",
"birthday2": "2003-07-16 13:14:15.999",
"birthday3": "2003-07-16 13:14:15.999999",
@ -1357,6 +1285,7 @@ if err != nil {
log.Fatal(err)
}
person.Birthday0.String() // 2003-07-16 13:14:15
person.Birthday1.String() // 2003-07-16 13:14:15
person.Birthday2.String() // 2003-07-16 13:14:15.999
person.Birthday3.String() // 2003-07-16 13:14:15.999999
@ -1425,6 +1354,7 @@ The following languages are supported
* [Hindi(hi)](./lang/hi.json "India"): translated by [chauhan17nitin](https://github.com/chauhan17nitin "chauhan17nitin")
* [Polish(pl)](./lang/pl.json "Polish"): translated by [gouguoyin](https://github.com/gouguoyin "gouguoyin")
* [Bulgarian(bg)](./lang/bg.json "Bulgarian"): translated by [yuksbg](https://github.com/yuksbg "yuksbg")
* [Arabic(ar)](./lang/ar.json "Arabic"): translated by [zumoshi](https://github.com/zumoshi "zumoshi")
The following methods are supported

View File

@ -509,7 +509,7 @@ func (l Lunar) IsPigYear() bool {
}
func (g Gregorian) diffInDays(t time.Time) int {
return int(g.Time.Sub(t).Hours() / 24)
return int(g.Time.Truncate(time.Hour).Sub(t).Hours() / 24)
}
func (l Lunar) getOffsetInYear() int {

View File

@ -14,7 +14,7 @@ import (
// Version current version
// 当前版本号
const Version = "2.3.12"
const Version = "2.4.1"
// timezone constants
// 时区常量
@ -272,8 +272,8 @@ type Carbon struct {
time time.Time
testNow int64 // nanosecond timestamp of test now time
weekStartsAt time.Weekday
tag *tag
loc *time.Location
layout string
lang *Language
Error error
}
@ -286,5 +286,6 @@ func NewCarbon() Carbon {
if weekday, ok := weekdays[defaultWeekStartsAt]; ok {
c.weekStartsAt = weekday
}
c.layout = defaultLayout
return c
}

View File

@ -33,3 +33,99 @@ func (c Carbon) Value() (driver.Value, error) {
func (c Carbon) GormDataType() string {
return "time"
}
// GormDataType implements the interface GormDataTypeInterface for DateTime struct.
// 实现 GormDataTypeInterface 接口
func (t DateTime) GormDataType() string {
return "time"
}
// GormDataType implements the interface GormDataTypeInterface for DateTimeMilli struct.
// 实现 GormDataTypeInterface 接口
func (t DateTimeMilli) GormDataType() string {
return "time"
}
// GormDataType implements the interface GormDataTypeInterface for DateTimeMicro struct.
// 实现 GormDataTypeInterface 接口
func (t DateTimeMicro) GormDataType() string {
return "time"
}
// GormDataType implements the interface GormDataTypeInterface for DateTimeNano struct.
// 实现 GormDataTypeInterface 接口
func (t DateTimeNano) GormDataType() string {
return "time"
}
// GormDataType implements the interface GormDataTypeInterface for Date struct.
// 实现 GormDataTypeInterface 接口
func (t Date) GormDataType() string {
return "time"
}
// GormDataType implements the interface GormDataTypeInterface for DateMilli struct.
// 实现 GormDataTypeInterface 接口
func (t DateMilli) GormDataType() string {
return "time"
}
// GormDataType implements the interface GormDataTypeInterface for DateMicro struct.
// 实现 GormDataTypeInterface 接口
func (t DateMicro) GormDataType() string {
return "time"
}
// GormDataType implements the interface GormDataTypeInterface for DateNano struct.
// 实现 GormDataTypeInterface 接口
func (t DateNano) GormDataType() string {
return "time"
}
// GormDataType implements the interface GormDataTypeInterface for Time struct.
// 实现 GormDataTypeInterface 接口
func (t Time) GormDataType() string {
return "time"
}
// GormDataType implements the interface GormDataTypeInterface for TimeMilli struct.
// 实现 GormDataTypeInterface 接口
func (t TimeMilli) GormDataType() string {
return "time"
}
// GormDataType implements the interface GormDataTypeInterface for TimeMicro struct.
// 实现 GormDataTypeInterface 接口
func (t TimeMicro) GormDataType() string {
return "time"
}
// GormDataType implements the interface GormDataTypeInterface for TimeNano struct.
// 实现 GormDataTypeInterface 接口
func (t TimeNano) GormDataType() string {
return "time"
}
// GormDataType implements the interface GormDataTypeInterface for Timestamp struct.
// 实现 GormDataTypeInterface 接口
func (t Timestamp) GormDataType() string {
return "int"
}
// GormDataType implements the interface GormDataTypeInterface for TimestampMilli struct.
// 实现 GormDataTypeInterface 接口
func (t TimestampMilli) GormDataType() string {
return "int"
}
// GormDataType implements the interface GormDataTypeInterface for TimestampMicro struct.
// 实现 GormDataTypeInterface 接口
func (t TimestampMicro) GormDataType() string {
return "int"
}
// GormDataType implements the interface GormDataTypeInterface for TimestampNano struct.
// 实现 GormDataTypeInterface 接口
func (t TimestampNano) GormDataType() string {
return "int"
}

View File

@ -102,6 +102,23 @@ type TimestampNano struct {
Carbon
}
// MarshalJSON implements the interface json.Marshal for Carbon struct.
// 实现 json.Marshaler 接口
func (c Carbon) MarshalJSON() ([]byte, error) {
return []byte(fmt.Sprintf(`"%s"`, c.Layout(c.layout, c.Location()))), nil
}
// UnmarshalJSON implements the interface json.Unmarshal for Carbon struct.
// 实现 json.Unmarshaler 接口
func (c *Carbon) UnmarshalJSON(b []byte) error {
value := fmt.Sprintf("%s", bytes.Trim(b, `"`))
if value == "" || value == "null" {
return nil
}
*c = ParseByLayout(value, c.layout, c.Location())
return c.Error
}
// MarshalJSON implements the interface json.Marshal for DateTime struct.
// 实现 MarshalJSON 接口
func (t DateTime) MarshalJSON() ([]byte, error) {
@ -111,7 +128,11 @@ func (t DateTime) MarshalJSON() ([]byte, error) {
// UnmarshalJSON implements the interface json.Unmarshal for DateTime struct.
// 实现 UnmarshalJSON 接口
func (t *DateTime) UnmarshalJSON(b []byte) error {
c := ParseByLayout(string(bytes.Trim(b, `"`)), DateTimeLayout, t.Location())
value := fmt.Sprintf("%s", bytes.Trim(b, `"`))
if value == "" || value == "null" {
return nil
}
c := ParseByLayout(value, DateTimeLayout, t.Location())
if c.Error == nil {
*t = DateTime{Carbon: c}
}
@ -127,7 +148,11 @@ func (t DateTimeMilli) MarshalJSON() ([]byte, error) {
// UnmarshalJSON implements the interface json.Unmarshal for DateTimeMilli struct.
// 实现 UnmarshalJSON 接口
func (t *DateTimeMilli) UnmarshalJSON(b []byte) error {
c := ParseByLayout(string(bytes.Trim(b, `"`)), DateTimeMilliLayout, t.Location())
value := fmt.Sprintf("%s", bytes.Trim(b, `"`))
if value == "" || value == "null" {
return nil
}
c := ParseByLayout(value, DateTimeMilliLayout, t.Location())
if c.Error == nil {
*t = DateTimeMilli{Carbon: c}
}
@ -143,7 +168,11 @@ func (t DateTimeMicro) MarshalJSON() ([]byte, error) {
// UnmarshalJSON implements the interface json.Unmarshal for DateTimeMicro struct.
// 实现 UnmarshalJSON 接口
func (t *DateTimeMicro) UnmarshalJSON(b []byte) error {
c := ParseByLayout(string(bytes.Trim(b, `"`)), DateTimeMicroLayout, t.Location())
value := fmt.Sprintf("%s", bytes.Trim(b, `"`))
if value == "" || value == "null" {
return nil
}
c := ParseByLayout(value, DateTimeMicroLayout, t.Location())
if c.Error == nil {
*t = DateTimeMicro{Carbon: c}
}
@ -159,7 +188,11 @@ func (t DateTimeNano) MarshalJSON() ([]byte, error) {
// UnmarshalJSON implements the interface json.Unmarshal for DateTimeNano struct.
// 实现 UnmarshalJSON 接口
func (t *DateTimeNano) UnmarshalJSON(b []byte) error {
c := ParseByLayout(string(bytes.Trim(b, `"`)), DateTimeNanoLayout, t.Location())
value := fmt.Sprintf("%s", bytes.Trim(b, `"`))
if value == "" || value == "null" {
return nil
}
c := ParseByLayout(value, DateTimeNanoLayout, t.Location())
if c.Error == nil {
*t = DateTimeNano{Carbon: c}
}
@ -175,7 +208,11 @@ func (t Date) MarshalJSON() ([]byte, error) {
// UnmarshalJSON implements the interface json.Unmarshal for Date struct.
// 实现 UnmarshalJSON 接口
func (t *Date) UnmarshalJSON(b []byte) error {
c := ParseByLayout(string(bytes.Trim(b, `"`)), DateLayout, t.Location())
value := fmt.Sprintf("%s", bytes.Trim(b, `"`))
if value == "" || value == "null" {
return nil
}
c := ParseByLayout(value, DateLayout, t.Location())
if c.Error == nil {
*t = Date{Carbon: c}
}
@ -191,7 +228,11 @@ func (t DateMilli) MarshalJSON() ([]byte, error) {
// UnmarshalJSON implements the interface json.Unmarshal for DateMilli struct.
// 实现 UnmarshalJSON 接口
func (t *DateMilli) UnmarshalJSON(b []byte) error {
c := ParseByLayout(string(bytes.Trim(b, `"`)), DateMilliLayout, t.Location())
value := fmt.Sprintf("%s", bytes.Trim(b, `"`))
if value == "" || value == "null" {
return nil
}
c := ParseByLayout(value, DateMilliLayout, t.Location())
if c.Error == nil {
*t = DateMilli{Carbon: c}
}
@ -207,7 +248,11 @@ func (t DateMicro) MarshalJSON() ([]byte, error) {
// UnmarshalJSON implements the interface json.Unmarshal for DateMicro struct.
// 实现 UnmarshalJSON 接口
func (t *DateMicro) UnmarshalJSON(b []byte) error {
c := ParseByLayout(string(bytes.Trim(b, `"`)), DateMicroLayout, t.Location())
value := fmt.Sprintf("%s", bytes.Trim(b, `"`))
if value == "" || value == "null" {
return nil
}
c := ParseByLayout(value, DateMicroLayout, t.Location())
if c.Error == nil {
*t = DateMicro{Carbon: c}
}
@ -223,7 +268,11 @@ func (t DateNano) MarshalJSON() ([]byte, error) {
// UnmarshalJSON implements the interface json.Unmarshal for DateNano struct.
// 实现 UnmarshalJSON 接口
func (t *DateNano) UnmarshalJSON(b []byte) error {
c := ParseByLayout(string(bytes.Trim(b, `"`)), DateNanoLayout, t.Location())
value := fmt.Sprintf("%s", bytes.Trim(b, `"`))
if value == "" || value == "null" {
return nil
}
c := ParseByLayout(value, DateNanoLayout, t.Location())
if c.Error == nil {
*t = DateNano{Carbon: c}
}
@ -239,7 +288,11 @@ func (t Time) MarshalJSON() ([]byte, error) {
// UnmarshalJSON implements the interface json.Unmarshal for Time struct.
// 实现 UnmarshalJSON 接口
func (t *Time) UnmarshalJSON(b []byte) error {
c := ParseByLayout(string(bytes.Trim(b, `"`)), TimeLayout, t.Location())
value := fmt.Sprintf("%s", bytes.Trim(b, `"`))
if value == "" || value == "null" {
return nil
}
c := ParseByLayout(value, TimeLayout, t.Location())
if c.Error == nil {
*t = Time{Carbon: c}
}
@ -255,7 +308,11 @@ func (t TimeMilli) MarshalJSON() ([]byte, error) {
// UnmarshalJSON implements the interface json.Unmarshal for TimeMilli struct.
// 实现 UnmarshalJSON 接口
func (t *TimeMilli) UnmarshalJSON(b []byte) error {
c := ParseByLayout(string(bytes.Trim(b, `"`)), TimeMilliLayout, t.Location())
value := fmt.Sprintf("%s", bytes.Trim(b, `"`))
if value == "" || value == "null" {
return nil
}
c := ParseByLayout(value, TimeMilliLayout, t.Location())
if c.Error == nil {
*t = TimeMilli{Carbon: c}
}
@ -271,7 +328,11 @@ func (t TimeMicro) MarshalJSON() ([]byte, error) {
// UnmarshalJSON implements the interface json.Unmarshal for TimeMicro struct.
// 实现 UnmarshalJSON 接口
func (t *TimeMicro) UnmarshalJSON(b []byte) error {
c := ParseByLayout(string(bytes.Trim(b, `"`)), TimeMicroLayout, t.Location())
value := fmt.Sprintf("%s", bytes.Trim(b, `"`))
if value == "" || value == "null" {
return nil
}
c := ParseByLayout(value, TimeMicroLayout, t.Location())
if c.Error == nil {
*t = TimeMicro{Carbon: c}
}
@ -287,7 +348,11 @@ func (t TimeNano) MarshalJSON() ([]byte, error) {
// UnmarshalJSON implements the interface json.Unmarshal for TimeNano struct.
// 实现 UnmarshalJSON 接口
func (t *TimeNano) UnmarshalJSON(b []byte) error {
c := ParseByLayout(string(bytes.Trim(b, `"`)), TimeNanoLayout, t.Location())
value := fmt.Sprintf("%s", bytes.Trim(b, `"`))
if value == "" || value == "null" {
return nil
}
c := ParseByLayout(value, TimeNanoLayout, t.Location())
if c.Error == nil {
*t = TimeNano{Carbon: c}
}
@ -303,7 +368,11 @@ func (t Timestamp) MarshalJSON() ([]byte, error) {
// UnmarshalJSON implements the interface json.Unmarshal for Timestamp struct.
// 实现 UnmarshalJSON 接口
func (t *Timestamp) UnmarshalJSON(b []byte) error {
ts, _ := strconv.ParseInt(string(b), 10, 64)
value := fmt.Sprintf("%s", bytes.Trim(b, `"`))
if value == "" || value == "null" {
return nil
}
ts, _ := strconv.ParseInt(value, 10, 64)
c := CreateFromTimestamp(ts)
if c.Error == nil {
*t = Timestamp{Carbon: c}
@ -320,7 +389,11 @@ func (t TimestampMilli) MarshalJSON() ([]byte, error) {
// UnmarshalJSON implements the interface json.Unmarshal for TimestampMilli struct.
// 实现 UnmarshalJSON 接口
func (t *TimestampMilli) UnmarshalJSON(b []byte) error {
ts, _ := strconv.ParseInt(string(b), 10, 64)
value := fmt.Sprintf("%s", bytes.Trim(b, `"`))
if value == "" || value == "null" {
return nil
}
ts, _ := strconv.ParseInt(value, 10, 64)
c := CreateFromTimestampMilli(ts)
if c.Error == nil {
*t = TimestampMilli{Carbon: c}
@ -337,7 +410,11 @@ func (t TimestampMicro) MarshalJSON() ([]byte, error) {
// UnmarshalJSON implements the interface json.Unmarshal for TimestampMicro struct.
// 实现 UnmarshalJSON 接口
func (t *TimestampMicro) UnmarshalJSON(b []byte) error {
ts, _ := strconv.ParseInt(string(b), 10, 64)
value := fmt.Sprintf("%s", bytes.Trim(b, `"`))
if value == "" || value == "null" {
return nil
}
ts, _ := strconv.ParseInt(value, 10, 64)
c := CreateFromTimestampMicro(ts)
if c.Error == nil {
*t = TimestampMicro{Carbon: c}
@ -354,7 +431,11 @@ func (t TimestampNano) MarshalJSON() ([]byte, error) {
// UnmarshalJSON implements the interface json.Unmarshal for TimestampNano struct.
// 实现 UnmarshalJSON 接口
func (t *TimestampNano) UnmarshalJSON(b []byte) error {
ts, _ := strconv.ParseInt(string(b), 10, 64)
value := fmt.Sprintf("%s", bytes.Trim(b, `"`))
if value == "" || value == "null" {
return nil
}
ts, _ := strconv.ParseInt(value, 10, 64)
c := CreateFromTimestampNano(ts)
if c.Error == nil {
*t = TimestampNano{Carbon: c}
@ -362,52 +443,6 @@ func (t *TimestampNano) UnmarshalJSON(b []byte) error {
return c.Error
}
// MarshalJSON implements the json.Marshaler interface.
// 实现 json.Marshaler 接口
func (c Carbon) MarshalJSON() ([]byte, error) {
if c.Error != nil {
return nil, c.Error
}
key, value, tz := c.parseTag()
data := ""
if key == "layout" {
data = fmt.Sprintf(`"%s"`, c.Layout(value, tz))
}
if key == "format" {
// timestamp without double quotes in json
if value == "U" || value == "V" || value == "X" || value == "Z" {
data = fmt.Sprintf(`%s`, c.Format(value, tz))
} else {
data = fmt.Sprintf(`"%s"`, c.Format(value, tz))
}
}
return []byte(data), nil
}
// UnmarshalJSON implements the json.Unmarshaler interface.
// 实现 json.Unmarshaler 接口
func (c *Carbon) UnmarshalJSON(b []byte) error {
if c.Error != nil {
return c.Error
}
if len(b) == 0 || string(b) == "null" {
return nil
}
key, value, tz := c.parseTag()
data := fmt.Sprintf("%s", bytes.Trim(b, `"`))
if key == "layout" {
*c = ParseByLayout(data, value, tz)
}
if key == "format" {
*c = ParseByFormat(data, value, tz)
}
c.tag = &tag{
carbon: fmt.Sprintf("%s:%s", key, value),
tz: tz,
}
return c.Error
}
// Int64 outputs timestamp with second.
// 输出秒级时间戳
func (t Timestamp) Int64() int64 {
@ -528,102 +563,6 @@ func (t TimestampNano) String() string {
return strconv.FormatInt(t.TimestampNano(), 10)
}
// GormDataType implements the interface GormDataTypeInterface for DateTime struct.
// 实现 GormDataTypeInterface 接口
func (t DateTime) GormDataType() string {
return "time"
}
// GormDataType implements the interface GormDataTypeInterface for DateTimeMilli struct.
// 实现 GormDataTypeInterface 接口
func (t DateTimeMilli) GormDataType() string {
return "time"
}
// GormDataType implements the interface GormDataTypeInterface for DateTimeMicro struct.
// 实现 GormDataTypeInterface 接口
func (t DateTimeMicro) GormDataType() string {
return "time"
}
// GormDataType implements the interface GormDataTypeInterface for DateTimeNano struct.
// 实现 GormDataTypeInterface 接口
func (t DateTimeNano) GormDataType() string {
return "time"
}
// GormDataType implements the interface GormDataTypeInterface for Date struct.
// 实现 GormDataTypeInterface 接口
func (t Date) GormDataType() string {
return "time"
}
// GormDataType implements the interface GormDataTypeInterface for DateMilli struct.
// 实现 GormDataTypeInterface 接口
func (t DateMilli) GormDataType() string {
return "time"
}
// GormDataType implements the interface GormDataTypeInterface for DateMicro struct.
// 实现 GormDataTypeInterface 接口
func (t DateMicro) GormDataType() string {
return "time"
}
// GormDataType implements the interface GormDataTypeInterface for DateNano struct.
// 实现 GormDataTypeInterface 接口
func (t DateNano) GormDataType() string {
return "time"
}
// GormDataType implements the interface GormDataTypeInterface for Time struct.
// 实现 GormDataTypeInterface 接口
func (t Time) GormDataType() string {
return "time"
}
// GormDataType implements the interface GormDataTypeInterface for TimeMilli struct.
// 实现 GormDataTypeInterface 接口
func (t TimeMilli) GormDataType() string {
return "time"
}
// GormDataType implements the interface GormDataTypeInterface for TimeMicro struct.
// 实现 GormDataTypeInterface 接口
func (t TimeMicro) GormDataType() string {
return "time"
}
// GormDataType implements the interface GormDataTypeInterface for TimeNano struct.
// 实现 GormDataTypeInterface 接口
func (t TimeNano) GormDataType() string {
return "time"
}
// GormDataType implements the interface GormDataTypeInterface for Timestamp struct.
// 实现 GormDataTypeInterface 接口
func (t Timestamp) GormDataType() string {
return "int"
}
// GormDataType implements the interface GormDataTypeInterface for TimestampMilli struct.
// 实现 GormDataTypeInterface 接口
func (t TimestampMilli) GormDataType() string {
return "int"
}
// GormDataType implements the interface GormDataTypeInterface for TimestampMicro struct.
// 实现 GormDataTypeInterface 接口
func (t TimestampMicro) GormDataType() string {
return "int"
}
// GormDataType implements the interface GormDataTypeInterface for TimestampNano struct.
// 实现 GormDataTypeInterface 接口
func (t TimestampNano) GormDataType() string {
return "int"
}
// ToDateTimeStruct converts Carbon to DateTime.
// 将 Carbon 结构体转换成 DateTime 结构体
func (c Carbon) ToDateTimeStruct() DateTime {

View File

@ -18,10 +18,10 @@ func (c Carbon) Closest(c1 Carbon, c2 Carbon) Carbon {
// Farthest returns the farthest Carbon instance from the given Carbon instance.
// 返回离给定 carbon 实例最远的 Carbon 实例
func (c Carbon) Farthest(c1 Carbon, c2 Carbon) Carbon {
if c1.Error != nil {
if c1.IsZero() || c1.IsInvalid() {
return c2
}
if c2.Error != nil {
if c2.IsZero() || c2.IsInvalid() {
return c1
}
if c.DiffAbsInSeconds(c1) > c.DiffAbsInSeconds(c2) {

View File

@ -7,6 +7,9 @@ import (
// StdTime gets standard time.Time.
// 获取标准 time.Time
func (c Carbon) StdTime() time.Time {
if c.time.IsZero() {
return c.time
}
return c.time.In(c.loc)
}
@ -28,7 +31,7 @@ func (c Carbon) DaysInMonth() int {
if c.Error != nil {
return 0
}
return c.EndOfMonth().time.In(c.loc).Day()
return c.EndOfMonth().StdTime().Day()
}
// MonthOfYear gets month of year like 12.

View File

@ -103,6 +103,9 @@ func format2layout(format string) string {
// gets a Location instance by a timezone string.
// 通过时区获取 Location 实例
func getLocationByTimezone(timezone string) (*time.Location, error) {
if timezone == "" {
timezone = defaultTimezone
}
loc, err := time.LoadLocation(timezone)
if err != nil {
err = invalidTimezoneError(timezone)

21
vendor/github.com/golang-module/carbon/v2/lang/ar.json generated vendored Normal file
View File

@ -0,0 +1,21 @@
{
"name": "Arabic",
"months": "يناير|فبراير|مارس|أبريل|مايو|يونيو|يوليو|أغسطس|سبتمبر|أكتوبر|نوفمبر|ديسمبر",
"short_months": "يناير|فبراير|مارس|أبريل|مايو|يونيو|يوليو|أغسطس|سبتمبر|أكتوبر|نوفمبر|ديسمبر",
"weeks": "الأحد|الإثنين|الثلاثاء|الأربعاء|الخميس|الجمعة|السبت",
"short_weeks": "أحد|إثنين|ثلاثاء|أربعاء|خميس|جمعة|سبت",
"seasons": "الربيع|الصيف|الخريف|الشتاء",
"constellations": "الحمل|الثور|الجوزاء|السرطان|الأسد|العذراء|الميزان|العقرب|القوس|الجدي|الدلو|الحوت",
"year": "1 سنة|%d سنوات",
"month": "1 شهر|%d أشهر",
"week": "1 أسبوع|%d أسابيع",
"day": "1 يوم|%d أيام",
"hour": "1 ساعة|%d ساعات",
"minute": "1 دقيقة|%d دقائق",
"second": "1 ثانية|%d ثواني",
"now": "الآن",
"ago": "%s مضت",
"from_now": "من %s",
"before": "%s قبل",
"after": "%s بعد"
}

21
vendor/github.com/golang-module/carbon/v2/lang/dk.json generated vendored Normal file
View File

@ -0,0 +1,21 @@
{
"name": "Dansk",
"months": "januar|februar|marts|april|maj|juni|juli|august|september|oktober|november|december",
"short_months": "jan|feb|mar|apr|maj|jun|jul|aug|sep|okt|nov|dec",
"weeks": "søndag|mandag|tirsdag|onsdag|torsdag|fredag|lørdag",
"short_weeks": "søn|man|tir|ons|tor|fre|lør",
"seasons": "forår|sommer|efterår|vinter",
"constellations": "vædder|tyr|tvilling|krebs|løve|jomfru|vægt|skorpion|skytte|stenbuk|vandmand|fisk",
"year": "1 år|%d år",
"month": "1 måned|%d måneder",
"week": "1 uge|%d uger",
"day": "1 dag|%d dage",
"hour": "1 time|%d timer",
"minute": "1 minut|%d minutter",
"second": "1 sekund|%d sekunder",
"now": "lige nu",
"ago": "%s siden",
"from_now": "om %s",
"before": "%s før",
"after": "%s efter"
}

View File

@ -1,21 +1,21 @@
{
"name": "Farsi",
"months": "دسامبر|نوامبر|اکتبر|سپتامبر|اوت|ژوئیه|ژوئن|مه|آوریل|مارس|فوریه|ژانویه",
"short_months": "دسامبر|نوامبر|اکتبر|سپتامبر|اوت|ژوئیه|ژوئن|مه|آوریل|مارس|فوریه|ژانویه",
"weeks": "شنبه|جمعه|پنجشنبه|چهارشنبه|سه شنبه|دوشنبه|یکشنبه",
"short_weeks": "شنبه|جمعه|پنجشنبه|چهارشنبه|سه شنبه|دوشنبه|یکشنبه",
"seasons": "زمستان|پاییز|تابستان|بهار",
"constellations": "ماهی|آبریز|بز|کمان|عقرب|ترازو|خوشه|شیر|خرچنگ|دوپیکر|گاو نر|قوچ",
"year": "سال|۱ سال %d",
"month": "ماه|۱ ماه %d",
"week": "هفته|۱ هفته %d",
"day": "روز|۱ روز %d",
"hour": "ساعت|۱ ساعت %d",
"minute": "دقیقه|۱ دقیقه %d",
"second": "ثانیه|۱ ثانیه %d",
"now": "الان",
"ago": "قبل %s",
"from_now": "از الان %s",
"before": "قبل %s",
"after": "بعد %s"
}
"months": "ژانویه|فوریه|مارس|آوریل|مه|ژوئن|ژوئیه|اوت|سپتامبر|اکتبر|نوامبر|دسامبر",
"short_months": "ژانویه|فوریه|مارس|آوریل|مه|ژوئن|ژوئیه|اوت|سپتامبر|اکتبر|نوامبر|دسامبر",
"weeks": "یکشنبه|دوشنبه|سه‌شنبه|چهارشنبه|پنجشنبه|جمعه|شنبه",
"short_weeks": "یکشنبه|دوشنبه|سه‌شنبه|چهارشنبه|پنجشنبه|جمعه|شنبه",
"seasons": "بهار|تابستان|پاییز|زمستان",
"constellations": "قوچ|گاو نر|دو پیکر|خرچنگ|شیر|خوشه|ترازو|عقرب|کماندار|بز|آبریز|ماهی",
"year": "1 سال|%d سال",
"month": "1 ماه|%d ماه",
"week": "1 هفته|%d هفته",
"day": "1 روز|%d روز",
"hour": "1 ساعت|%d ساعت",
"minute": "1 دقیقه|%d دقیقه",
"second": "1 ثانیه|%d ثانیه",
"now": "همین الان",
"ago": "%s پیش",
"from_now": "در %s",
"before": "%s قبل",
"after": "%s بعد"
}

View File

@ -11,14 +11,7 @@ import (
// String implements the interface Stringer for Carbon struct.
// 实现 Stringer 接口
func (c Carbon) String() string {
key, value, tz := c.parseTag()
if key == "layout" {
return c.Layout(value, tz)
}
if key == "format" {
return c.Format(value, tz)
}
return c.ToDateTimeString(c.Location())
return c.Layout(c.layout, c.Location())
}
// GoString implements fmt.GoStringer and formats c to be printed in Go source code.

View File

@ -8,7 +8,7 @@ import (
// Parse parses a standard time string as a Carbon instance.
// 将标准格式时间字符串解析成 Carbon 实例
func (c Carbon) Parse(value string, timezone ...string) Carbon {
if value == "" {
if len(value) == 0 {
c.Error = invalidValueError(value)
return c
}
@ -65,9 +65,12 @@ func (c Carbon) ParseByLayout(value, layout string, timezone ...string) Carbon {
if c.Error != nil {
return c
}
if value == "" {
if len(value) == 0 {
return c
}
if len(layout) == 0 {
layout = defaultLayout
}
if layout == "timestamp" {
timestamp, _ := strconv.ParseInt(value, 10, 64)
return c.CreateFromTimestamp(timestamp)

View File

@ -1,160 +0,0 @@
package carbon
import (
"fmt"
"reflect"
"strings"
)
var (
// supported types
// 支持的类型
tagTypes = map[string]string{
"dateTime": "layout:" + DateTimeLayout,
"dateTimeMilli": "layout:" + DateTimeMilliLayout,
"dateTimeMicro": "layout:" + DateTimeMicroLayout,
"dateTimeNano": "layout:" + DateTimeNanoLayout,
"shortDateTime": "layout:" + ShortDateTimeLayout,
"shortDateTimeMilli": "layout:" + ShortDateTimeMilliLayout,
"shortDateTimeMicro": "layout:" + ShortDateTimeMicroLayout,
"shortDateTimeNano": "layout:" + ShortDateTimeNanoLayout,
"dayDateTime": "layout:" + DayDateTimeLayout,
"date": "layout:" + DateLayout,
"dateMilli": "layout:" + DateMilliLayout,
"dateMicro": "layout:" + DateMicroLayout,
"dateNano": "layout:" + DateNanoLayout,
"shortDate": "layout:" + ShortDateLayout,
"shortDateMilli": "layout:" + ShortDateMilliLayout,
"shortDateMicro": "layout:" + ShortDateMicroLayout,
"shortDateNano": "layout:" + ShortDateNanoLayout,
"time": "layout:" + TimeLayout,
"timeMilli": "layout:" + TimeMilliLayout,
"timeMicro": "layout:" + TimeMicroLayout,
"timeNano": "layout:" + TimeNanoLayout,
"shortTime": "layout:" + ShortTimeLayout,
"shortTimeMilli": "layout:" + ShortTimeMilliLayout,
"shortTimeMicro": "layout:" + ShortTimeMicroLayout,
"shortTimeNano": "layout:" + ShortTimeNanoLayout,
"atom": "layout:" + AtomLayout,
"ansic": "layout:" + ANSICLayout,
"cookie": "layout:" + CookieLayout,
"kitchen": "layout:" + KitchenLayout,
"rss": "layout:" + RssLayout,
"rubyDate": "layout:" + RubyDateLayout,
"unixDate": "layout:" + UnixDateLayout,
"rfc1036": "layout:" + RFC1036Layout,
"rfc1123": "layout:" + RFC1123Layout,
"rfc1123Z": "layout:" + RFC1123ZLayout,
"rfc2822": "layout:" + RFC2822Layout,
"rfc3339": "layout:" + RFC3339Layout,
"rfc3339Milli": "layout:" + RFC3339MilliLayout,
"rfc3339Micro": "layout:" + RFC3339MicroLayout,
"rfc3339Nano": "layout:" + RFC3339NanoLayout,
"rfc7231": "layout:" + RFC7231Layout,
"rfc822": "layout:" + RFC822Layout,
"rfc822Z": "layout:" + RFC822ZLayout,
"rfc850": "layout:" + RFC850Layout,
"iso8601": "layout:" + ISO8601Layout,
"iso8601Milli": "layout:" + ISO8601MilliLayout,
"iso8601Micro": "layout:" + ISO8601MicroLayout,
"iso8601Nano": "layout:" + ISO8601NanoLayout,
"timestamp": "format:U",
"timestampMilli": "format:V",
"timestampMicro": "format:X",
"timestampNano": "format:Z",
}
// invalid pointer error
// 无效的指针错误
invalidPtrError = func() error {
return fmt.Errorf("invalid struct pointer, please make sure the struct is a pointer")
}
// invalid tag error
// 无效的标签错误
invalidTagError = func(field string) error {
return fmt.Errorf("invalid carbon tag in %s field, please make sure the tag is valid", field)
}
)
// tag defines a tag struct.
// 定义 tag 结构体
type tag struct {
carbon string
tz string
}
// SetTag sets tag.
// 设置标签
func (c Carbon) SetTag(tag *tag) Carbon {
if c.Error != nil {
return c
}
c.tag = tag
return c
}
// parseTag parses tag.
// 解析标签
func (c Carbon) parseTag() (key, value, tz string) {
if c.tag == nil {
return "layout", defaultLayout, defaultTimezone
}
tz = strings.TrimSpace(c.tag.tz)
if tz == "" {
tz = defaultTimezone
}
carbon := strings.TrimSpace(c.tag.carbon)
if carbon == "" {
return "layout", defaultLayout, tz
}
if !strings.HasPrefix(carbon, "layout:") && !strings.HasPrefix(carbon, "format:") {
return "", "", tz
}
key = strings.TrimSpace(carbon[:6])
value = strings.TrimSpace(carbon[7:])
return
}
// LoadTag loads tag.
// 加载标签
func LoadTag(v interface{}) error {
typeObj, valueObj := reflect.TypeOf(v), reflect.ValueOf(v)
if typeObj.Kind() != reflect.Ptr {
return invalidPtrError()
}
typeElem, valueElem := typeObj.Elem(), valueObj.Elem()
params := make([]reflect.Value, 1)
for i := 0; i < valueElem.NumField(); i++ {
fieldType, fieldValue := typeElem.Field(i), valueElem.Field(i)
if reflect.TypeOf(Carbon{}) != fieldValue.Type() {
continue
}
carbon := fieldType.Tag.Get("carbon")
if carbon == "" {
carbon = "layout:" + defaultLayout
}
if strings.HasPrefix(carbon, "type:") {
carbon = tagTypes[carbon[5:]]
}
if !strings.HasPrefix(carbon, "layout:") && !strings.HasPrefix(carbon, "format:") {
return invalidTagError(fieldType.Name)
}
tz := fieldType.Tag.Get("tz")
if tz == "" {
tz = defaultTimezone
}
params[0] = reflect.ValueOf(&tag{
carbon: carbon,
tz: tz,
})
fieldValue.Set(fieldValue.MethodByName("SetTag").Call(params)[0])
}
return nil
}

View File

@ -22,58 +22,23 @@ func (b *ReportBuilder) Message(msg string) *ReportBuilder {
return b
}
func (b *ReportBuilder) send(ctx context.Context, reason tg.ReportReasonClass) (bool, error) {
func (b *ReportBuilder) send(ctx context.Context, option []byte) (tg.ReportResultClass, error) {
p, err := b.peer(ctx)
if err != nil {
return false, errors.Wrap(err, "peer")
return nil, errors.Wrap(err, "peer")
}
return b.sender.report(ctx, &tg.MessagesReportRequest{
Peer: p,
ID: b.ids,
Reason: reason,
Option: option,
Message: b.message,
})
}
// Spam sends report for spam.
func (b *ReportBuilder) Spam(ctx context.Context) (bool, error) {
return b.send(ctx, &tg.InputReportReasonSpam{})
}
// Violence sends report for violence.
func (b *ReportBuilder) Violence(ctx context.Context) (bool, error) {
return b.send(ctx, &tg.InputReportReasonViolence{})
}
// Pornography sends report for pornography.
func (b *ReportBuilder) Pornography(ctx context.Context) (bool, error) {
return b.send(ctx, &tg.InputReportReasonPornography{})
}
// ChildAbuse sends report for child abuse.
func (b *ReportBuilder) ChildAbuse(ctx context.Context) (bool, error) {
return b.send(ctx, &tg.InputReportReasonChildAbuse{})
}
// Other sends report for other.
func (b *ReportBuilder) Other(ctx context.Context) (bool, error) {
return b.send(ctx, &tg.InputReportReasonOther{})
}
// Copyright sends report for copyrighted content.
func (b *ReportBuilder) Copyright(ctx context.Context) (bool, error) {
return b.send(ctx, &tg.InputReportReasonCopyright{})
}
// GeoIrrelevant sends report for irrelevant geogroup.
func (b *ReportBuilder) GeoIrrelevant(ctx context.Context) (bool, error) {
return b.send(ctx, &tg.InputReportReasonGeoIrrelevant{})
}
// Fake sends report for fake.
func (b *ReportBuilder) Fake(ctx context.Context) (bool, error) {
return b.send(ctx, &tg.InputReportReasonFake{})
// Option sends report with provided option field.
func (b *ReportBuilder) Option(ctx context.Context, option []byte) (tg.ReportResultClass, error) {
return b.send(ctx, option)
}
// Report reports messages in a chat for violation of Telegram's Terms of Service.

View File

@ -160,7 +160,7 @@ func (s *Sender) setTyping(ctx context.Context, req *tg.MessagesSetTypingRequest
}
// report reports a message in a chat for violation of Telegram's Terms of Service.
func (s *Sender) report(ctx context.Context, req *tg.MessagesReportRequest) (bool, error) {
func (s *Sender) report(ctx context.Context, req *tg.MessagesReportRequest) (tg.ReportResultClass, error) {
return s.raw.MessagesReport(ctx, req)
}

View File

@ -31,11 +31,17 @@ var (
_ = tdjson.Encoder{}
)
// ChannelsClickSponsoredMessageRequest represents TL type `channels.clickSponsoredMessage#18afbc93`.
// ChannelsClickSponsoredMessageRequest represents TL type `channels.clickSponsoredMessage#1445d75`.
// Informs the server that the user has either:
//
// See https://core.telegram.org/method/channels.clickSponsoredMessage for reference.
type ChannelsClickSponsoredMessageRequest struct {
// Flags field of ChannelsClickSponsoredMessageRequest.
Flags bin.Fields
// Media field of ChannelsClickSponsoredMessageRequest.
Media bool
// Fullscreen field of ChannelsClickSponsoredMessageRequest.
Fullscreen bool
// Channel where the sponsored message was posted
Channel InputChannelClass
// Message ID
@ -43,7 +49,7 @@ type ChannelsClickSponsoredMessageRequest struct {
}
// ChannelsClickSponsoredMessageRequestTypeID is TL type id of ChannelsClickSponsoredMessageRequest.
const ChannelsClickSponsoredMessageRequestTypeID = 0x18afbc93
const ChannelsClickSponsoredMessageRequestTypeID = 0x1445d75
// Ensuring interfaces in compile-time for ChannelsClickSponsoredMessageRequest.
var (
@ -57,6 +63,15 @@ func (c *ChannelsClickSponsoredMessageRequest) Zero() bool {
if c == nil {
return true
}
if !(c.Flags.Zero()) {
return false
}
if !(c.Media == false) {
return false
}
if !(c.Fullscreen == false) {
return false
}
if !(c.Channel == nil) {
return false
}
@ -78,9 +93,13 @@ func (c *ChannelsClickSponsoredMessageRequest) String() string {
// FillFrom fills ChannelsClickSponsoredMessageRequest from given interface.
func (c *ChannelsClickSponsoredMessageRequest) FillFrom(from interface {
GetMedia() (value bool)
GetFullscreen() (value bool)
GetChannel() (value InputChannelClass)
GetRandomID() (value []byte)
}) {
c.Media = from.GetMedia()
c.Fullscreen = from.GetFullscreen()
c.Channel = from.GetChannel()
c.RandomID = from.GetRandomID()
}
@ -108,6 +127,16 @@ func (c *ChannelsClickSponsoredMessageRequest) TypeInfo() tdp.Type {
return typ
}
typ.Fields = []tdp.Field{
{
Name: "Media",
SchemaName: "media",
Null: !c.Flags.Has(0),
},
{
Name: "Fullscreen",
SchemaName: "fullscreen",
Null: !c.Flags.Has(1),
},
{
Name: "Channel",
SchemaName: "channel",
@ -120,10 +149,20 @@ func (c *ChannelsClickSponsoredMessageRequest) TypeInfo() tdp.Type {
return typ
}
// SetFlags sets flags for non-zero fields.
func (c *ChannelsClickSponsoredMessageRequest) SetFlags() {
if !(c.Media == false) {
c.Flags.Set(0)
}
if !(c.Fullscreen == false) {
c.Flags.Set(1)
}
}
// Encode implements bin.Encoder.
func (c *ChannelsClickSponsoredMessageRequest) Encode(b *bin.Buffer) error {
if c == nil {
return fmt.Errorf("can't encode channels.clickSponsoredMessage#18afbc93 as nil")
return fmt.Errorf("can't encode channels.clickSponsoredMessage#1445d75 as nil")
}
b.PutID(ChannelsClickSponsoredMessageRequestTypeID)
return c.EncodeBare(b)
@ -132,13 +171,17 @@ func (c *ChannelsClickSponsoredMessageRequest) Encode(b *bin.Buffer) error {
// EncodeBare implements bin.BareEncoder.
func (c *ChannelsClickSponsoredMessageRequest) EncodeBare(b *bin.Buffer) error {
if c == nil {
return fmt.Errorf("can't encode channels.clickSponsoredMessage#18afbc93 as nil")
return fmt.Errorf("can't encode channels.clickSponsoredMessage#1445d75 as nil")
}
c.SetFlags()
if err := c.Flags.Encode(b); err != nil {
return fmt.Errorf("unable to encode channels.clickSponsoredMessage#1445d75: field flags: %w", err)
}
if c.Channel == nil {
return fmt.Errorf("unable to encode channels.clickSponsoredMessage#18afbc93: field channel is nil")
return fmt.Errorf("unable to encode channels.clickSponsoredMessage#1445d75: field channel is nil")
}
if err := c.Channel.Encode(b); err != nil {
return fmt.Errorf("unable to encode channels.clickSponsoredMessage#18afbc93: field channel: %w", err)
return fmt.Errorf("unable to encode channels.clickSponsoredMessage#1445d75: field channel: %w", err)
}
b.PutBytes(c.RandomID)
return nil
@ -147,10 +190,10 @@ func (c *ChannelsClickSponsoredMessageRequest) EncodeBare(b *bin.Buffer) error {
// Decode implements bin.Decoder.
func (c *ChannelsClickSponsoredMessageRequest) Decode(b *bin.Buffer) error {
if c == nil {
return fmt.Errorf("can't decode channels.clickSponsoredMessage#18afbc93 to nil")
return fmt.Errorf("can't decode channels.clickSponsoredMessage#1445d75 to nil")
}
if err := b.ConsumeID(ChannelsClickSponsoredMessageRequestTypeID); err != nil {
return fmt.Errorf("unable to decode channels.clickSponsoredMessage#18afbc93: %w", err)
return fmt.Errorf("unable to decode channels.clickSponsoredMessage#1445d75: %w", err)
}
return c.DecodeBare(b)
}
@ -158,25 +201,70 @@ func (c *ChannelsClickSponsoredMessageRequest) Decode(b *bin.Buffer) error {
// DecodeBare implements bin.BareDecoder.
func (c *ChannelsClickSponsoredMessageRequest) DecodeBare(b *bin.Buffer) error {
if c == nil {
return fmt.Errorf("can't decode channels.clickSponsoredMessage#18afbc93 to nil")
return fmt.Errorf("can't decode channels.clickSponsoredMessage#1445d75 to nil")
}
{
if err := c.Flags.Decode(b); err != nil {
return fmt.Errorf("unable to decode channels.clickSponsoredMessage#1445d75: field flags: %w", err)
}
}
c.Media = c.Flags.Has(0)
c.Fullscreen = c.Flags.Has(1)
{
value, err := DecodeInputChannel(b)
if err != nil {
return fmt.Errorf("unable to decode channels.clickSponsoredMessage#18afbc93: field channel: %w", err)
return fmt.Errorf("unable to decode channels.clickSponsoredMessage#1445d75: field channel: %w", err)
}
c.Channel = value
}
{
value, err := b.Bytes()
if err != nil {
return fmt.Errorf("unable to decode channels.clickSponsoredMessage#18afbc93: field random_id: %w", err)
return fmt.Errorf("unable to decode channels.clickSponsoredMessage#1445d75: field random_id: %w", err)
}
c.RandomID = value
}
return nil
}
// SetMedia sets value of Media conditional field.
func (c *ChannelsClickSponsoredMessageRequest) SetMedia(value bool) {
if value {
c.Flags.Set(0)
c.Media = true
} else {
c.Flags.Unset(0)
c.Media = false
}
}
// GetMedia returns value of Media conditional field.
func (c *ChannelsClickSponsoredMessageRequest) GetMedia() (value bool) {
if c == nil {
return
}
return c.Flags.Has(0)
}
// SetFullscreen sets value of Fullscreen conditional field.
func (c *ChannelsClickSponsoredMessageRequest) SetFullscreen(value bool) {
if value {
c.Flags.Set(1)
c.Fullscreen = true
} else {
c.Flags.Unset(1)
c.Fullscreen = false
}
}
// GetFullscreen returns value of Fullscreen conditional field.
func (c *ChannelsClickSponsoredMessageRequest) GetFullscreen() (value bool) {
if c == nil {
return
}
return c.Flags.Has(1)
}
// GetChannel returns value of Channel field.
func (c *ChannelsClickSponsoredMessageRequest) GetChannel() (value InputChannelClass) {
if c == nil {
@ -198,7 +286,7 @@ func (c *ChannelsClickSponsoredMessageRequest) GetChannelAsNotEmpty() (NotEmptyI
return c.Channel.AsNotEmpty()
}
// ChannelsClickSponsoredMessage invokes method channels.clickSponsoredMessage#18afbc93 returning error if any.
// ChannelsClickSponsoredMessage invokes method channels.clickSponsoredMessage#1445d75 returning error if any.
// Informs the server that the user has either:
//
// Possible errors:

View File

@ -566,7 +566,7 @@ func (d *DocumentAttributeSticker) GetMaskCoords() (value MaskCoords, ok bool) {
return d.MaskCoords, true
}
// DocumentAttributeVideo represents TL type `documentAttributeVideo#17399fad`.
// DocumentAttributeVideo represents TL type `documentAttributeVideo#43c57c48`.
// Defines a video
//
// See https://core.telegram.org/constructor/documentAttributeVideo for reference.
@ -601,10 +601,14 @@ type DocumentAttributeVideo struct {
//
// Use SetVideoStartTs and GetVideoStartTs helpers.
VideoStartTs float64
// VideoCodec field of DocumentAttributeVideo.
//
// Use SetVideoCodec and GetVideoCodec helpers.
VideoCodec string
}
// DocumentAttributeVideoTypeID is TL type id of DocumentAttributeVideo.
const DocumentAttributeVideoTypeID = 0x17399fad
const DocumentAttributeVideoTypeID = 0x43c57c48
// construct implements constructor of DocumentAttributeClass.
func (d DocumentAttributeVideo) construct() DocumentAttributeClass { return &d }
@ -650,6 +654,9 @@ func (d *DocumentAttributeVideo) Zero() bool {
if !(d.VideoStartTs == 0) {
return false
}
if !(d.VideoCodec == "") {
return false
}
return true
}
@ -673,6 +680,7 @@ func (d *DocumentAttributeVideo) FillFrom(from interface {
GetH() (value int)
GetPreloadPrefixSize() (value int, ok bool)
GetVideoStartTs() (value float64, ok bool)
GetVideoCodec() (value string, ok bool)
}) {
d.RoundMessage = from.GetRoundMessage()
d.SupportsStreaming = from.GetSupportsStreaming()
@ -688,6 +696,10 @@ func (d *DocumentAttributeVideo) FillFrom(from interface {
d.VideoStartTs = val
}
if val, ok := from.GetVideoCodec(); ok {
d.VideoCodec = val
}
}
// TypeID returns type id in TL schema.
@ -750,6 +762,11 @@ func (d *DocumentAttributeVideo) TypeInfo() tdp.Type {
SchemaName: "video_start_ts",
Null: !d.Flags.Has(4),
},
{
Name: "VideoCodec",
SchemaName: "video_codec",
Null: !d.Flags.Has(5),
},
}
return typ
}
@ -771,12 +788,15 @@ func (d *DocumentAttributeVideo) SetFlags() {
if !(d.VideoStartTs == 0) {
d.Flags.Set(4)
}
if !(d.VideoCodec == "") {
d.Flags.Set(5)
}
}
// Encode implements bin.Encoder.
func (d *DocumentAttributeVideo) Encode(b *bin.Buffer) error {
if d == nil {
return fmt.Errorf("can't encode documentAttributeVideo#17399fad as nil")
return fmt.Errorf("can't encode documentAttributeVideo#43c57c48 as nil")
}
b.PutID(DocumentAttributeVideoTypeID)
return d.EncodeBare(b)
@ -785,11 +805,11 @@ func (d *DocumentAttributeVideo) Encode(b *bin.Buffer) error {
// EncodeBare implements bin.BareEncoder.
func (d *DocumentAttributeVideo) EncodeBare(b *bin.Buffer) error {
if d == nil {
return fmt.Errorf("can't encode documentAttributeVideo#17399fad as nil")
return fmt.Errorf("can't encode documentAttributeVideo#43c57c48 as nil")
}
d.SetFlags()
if err := d.Flags.Encode(b); err != nil {
return fmt.Errorf("unable to encode documentAttributeVideo#17399fad: field flags: %w", err)
return fmt.Errorf("unable to encode documentAttributeVideo#43c57c48: field flags: %w", err)
}
b.PutDouble(d.Duration)
b.PutInt(d.W)
@ -800,16 +820,19 @@ func (d *DocumentAttributeVideo) EncodeBare(b *bin.Buffer) error {
if d.Flags.Has(4) {
b.PutDouble(d.VideoStartTs)
}
if d.Flags.Has(5) {
b.PutString(d.VideoCodec)
}
return nil
}
// Decode implements bin.Decoder.
func (d *DocumentAttributeVideo) Decode(b *bin.Buffer) error {
if d == nil {
return fmt.Errorf("can't decode documentAttributeVideo#17399fad to nil")
return fmt.Errorf("can't decode documentAttributeVideo#43c57c48 to nil")
}
if err := b.ConsumeID(DocumentAttributeVideoTypeID); err != nil {
return fmt.Errorf("unable to decode documentAttributeVideo#17399fad: %w", err)
return fmt.Errorf("unable to decode documentAttributeVideo#43c57c48: %w", err)
}
return d.DecodeBare(b)
}
@ -817,11 +840,11 @@ func (d *DocumentAttributeVideo) Decode(b *bin.Buffer) error {
// DecodeBare implements bin.BareDecoder.
func (d *DocumentAttributeVideo) DecodeBare(b *bin.Buffer) error {
if d == nil {
return fmt.Errorf("can't decode documentAttributeVideo#17399fad to nil")
return fmt.Errorf("can't decode documentAttributeVideo#43c57c48 to nil")
}
{
if err := d.Flags.Decode(b); err != nil {
return fmt.Errorf("unable to decode documentAttributeVideo#17399fad: field flags: %w", err)
return fmt.Errorf("unable to decode documentAttributeVideo#43c57c48: field flags: %w", err)
}
}
d.RoundMessage = d.Flags.Has(0)
@ -830,38 +853,45 @@ func (d *DocumentAttributeVideo) DecodeBare(b *bin.Buffer) error {
{
value, err := b.Double()
if err != nil {
return fmt.Errorf("unable to decode documentAttributeVideo#17399fad: field duration: %w", err)
return fmt.Errorf("unable to decode documentAttributeVideo#43c57c48: field duration: %w", err)
}
d.Duration = value
}
{
value, err := b.Int()
if err != nil {
return fmt.Errorf("unable to decode documentAttributeVideo#17399fad: field w: %w", err)
return fmt.Errorf("unable to decode documentAttributeVideo#43c57c48: field w: %w", err)
}
d.W = value
}
{
value, err := b.Int()
if err != nil {
return fmt.Errorf("unable to decode documentAttributeVideo#17399fad: field h: %w", err)
return fmt.Errorf("unable to decode documentAttributeVideo#43c57c48: field h: %w", err)
}
d.H = value
}
if d.Flags.Has(2) {
value, err := b.Int()
if err != nil {
return fmt.Errorf("unable to decode documentAttributeVideo#17399fad: field preload_prefix_size: %w", err)
return fmt.Errorf("unable to decode documentAttributeVideo#43c57c48: field preload_prefix_size: %w", err)
}
d.PreloadPrefixSize = value
}
if d.Flags.Has(4) {
value, err := b.Double()
if err != nil {
return fmt.Errorf("unable to decode documentAttributeVideo#17399fad: field video_start_ts: %w", err)
return fmt.Errorf("unable to decode documentAttributeVideo#43c57c48: field video_start_ts: %w", err)
}
d.VideoStartTs = value
}
if d.Flags.Has(5) {
value, err := b.String()
if err != nil {
return fmt.Errorf("unable to decode documentAttributeVideo#43c57c48: field video_codec: %w", err)
}
d.VideoCodec = value
}
return nil
}
@ -982,6 +1012,24 @@ func (d *DocumentAttributeVideo) GetVideoStartTs() (value float64, ok bool) {
return d.VideoStartTs, true
}
// SetVideoCodec sets value of VideoCodec conditional field.
func (d *DocumentAttributeVideo) SetVideoCodec(value string) {
d.Flags.Set(5)
d.VideoCodec = value
}
// GetVideoCodec returns value of VideoCodec conditional field and
// boolean which is true if field was set.
func (d *DocumentAttributeVideo) GetVideoCodec() (value string, ok bool) {
if d == nil {
return
}
if !d.Flags.Has(5) {
return value, false
}
return d.VideoCodec, true
}
// DocumentAttributeAudio represents TL type `documentAttributeAudio#9852f9c6`.
// Represents an audio file
//
@ -1835,7 +1883,7 @@ const DocumentAttributeClassName = "DocumentAttribute"
// case *tg.DocumentAttributeImageSize: // documentAttributeImageSize#6c37c15c
// case *tg.DocumentAttributeAnimated: // documentAttributeAnimated#11b58939
// case *tg.DocumentAttributeSticker: // documentAttributeSticker#6319d612
// case *tg.DocumentAttributeVideo: // documentAttributeVideo#17399fad
// case *tg.DocumentAttributeVideo: // documentAttributeVideo#43c57c48
// case *tg.DocumentAttributeAudio: // documentAttributeAudio#9852f9c6
// case *tg.DocumentAttributeFilename: // documentAttributeFilename#15590068
// case *tg.DocumentAttributeHasStickers: // documentAttributeHasStickers#9801d2f7
@ -1890,7 +1938,7 @@ func DecodeDocumentAttribute(buf *bin.Buffer) (DocumentAttributeClass, error) {
}
return &v, nil
case DocumentAttributeVideoTypeID:
// Decoding documentAttributeVideo#17399fad.
// Decoding documentAttributeVideo#43c57c48.
v := DocumentAttributeVideo{}
if err := v.Decode(buf); err != nil {
return nil, fmt.Errorf("unable to decode DocumentAttributeClass: %w", err)

View File

@ -809,6 +809,273 @@ func (i *InputInvoiceChatInviteSubscription) GetHash() (value string) {
return i.Hash
}
// InputInvoiceStarGift represents TL type `inputInvoiceStarGift#25d8c1d8`.
//
// See https://core.telegram.org/constructor/inputInvoiceStarGift for reference.
type InputInvoiceStarGift struct {
// Flags field of InputInvoiceStarGift.
Flags bin.Fields
// HideName field of InputInvoiceStarGift.
HideName bool
// UserID field of InputInvoiceStarGift.
UserID InputUserClass
// GiftID field of InputInvoiceStarGift.
GiftID int64
// Message field of InputInvoiceStarGift.
//
// Use SetMessage and GetMessage helpers.
Message TextWithEntities
}
// InputInvoiceStarGiftTypeID is TL type id of InputInvoiceStarGift.
const InputInvoiceStarGiftTypeID = 0x25d8c1d8
// construct implements constructor of InputInvoiceClass.
func (i InputInvoiceStarGift) construct() InputInvoiceClass { return &i }
// Ensuring interfaces in compile-time for InputInvoiceStarGift.
var (
_ bin.Encoder = &InputInvoiceStarGift{}
_ bin.Decoder = &InputInvoiceStarGift{}
_ bin.BareEncoder = &InputInvoiceStarGift{}
_ bin.BareDecoder = &InputInvoiceStarGift{}
_ InputInvoiceClass = &InputInvoiceStarGift{}
)
func (i *InputInvoiceStarGift) Zero() bool {
if i == nil {
return true
}
if !(i.Flags.Zero()) {
return false
}
if !(i.HideName == false) {
return false
}
if !(i.UserID == nil) {
return false
}
if !(i.GiftID == 0) {
return false
}
if !(i.Message.Zero()) {
return false
}
return true
}
// String implements fmt.Stringer.
func (i *InputInvoiceStarGift) String() string {
if i == nil {
return "InputInvoiceStarGift(nil)"
}
type Alias InputInvoiceStarGift
return fmt.Sprintf("InputInvoiceStarGift%+v", Alias(*i))
}
// FillFrom fills InputInvoiceStarGift from given interface.
func (i *InputInvoiceStarGift) FillFrom(from interface {
GetHideName() (value bool)
GetUserID() (value InputUserClass)
GetGiftID() (value int64)
GetMessage() (value TextWithEntities, ok bool)
}) {
i.HideName = from.GetHideName()
i.UserID = from.GetUserID()
i.GiftID = from.GetGiftID()
if val, ok := from.GetMessage(); ok {
i.Message = val
}
}
// TypeID returns type id in TL schema.
//
// See https://core.telegram.org/mtproto/TL-tl#remarks.
func (*InputInvoiceStarGift) TypeID() uint32 {
return InputInvoiceStarGiftTypeID
}
// TypeName returns name of type in TL schema.
func (*InputInvoiceStarGift) TypeName() string {
return "inputInvoiceStarGift"
}
// TypeInfo returns info about TL type.
func (i *InputInvoiceStarGift) TypeInfo() tdp.Type {
typ := tdp.Type{
Name: "inputInvoiceStarGift",
ID: InputInvoiceStarGiftTypeID,
}
if i == nil {
typ.Null = true
return typ
}
typ.Fields = []tdp.Field{
{
Name: "HideName",
SchemaName: "hide_name",
Null: !i.Flags.Has(0),
},
{
Name: "UserID",
SchemaName: "user_id",
},
{
Name: "GiftID",
SchemaName: "gift_id",
},
{
Name: "Message",
SchemaName: "message",
Null: !i.Flags.Has(1),
},
}
return typ
}
// SetFlags sets flags for non-zero fields.
func (i *InputInvoiceStarGift) SetFlags() {
if !(i.HideName == false) {
i.Flags.Set(0)
}
if !(i.Message.Zero()) {
i.Flags.Set(1)
}
}
// Encode implements bin.Encoder.
func (i *InputInvoiceStarGift) Encode(b *bin.Buffer) error {
if i == nil {
return fmt.Errorf("can't encode inputInvoiceStarGift#25d8c1d8 as nil")
}
b.PutID(InputInvoiceStarGiftTypeID)
return i.EncodeBare(b)
}
// EncodeBare implements bin.BareEncoder.
func (i *InputInvoiceStarGift) EncodeBare(b *bin.Buffer) error {
if i == nil {
return fmt.Errorf("can't encode inputInvoiceStarGift#25d8c1d8 as nil")
}
i.SetFlags()
if err := i.Flags.Encode(b); err != nil {
return fmt.Errorf("unable to encode inputInvoiceStarGift#25d8c1d8: field flags: %w", err)
}
if i.UserID == nil {
return fmt.Errorf("unable to encode inputInvoiceStarGift#25d8c1d8: field user_id is nil")
}
if err := i.UserID.Encode(b); err != nil {
return fmt.Errorf("unable to encode inputInvoiceStarGift#25d8c1d8: field user_id: %w", err)
}
b.PutLong(i.GiftID)
if i.Flags.Has(1) {
if err := i.Message.Encode(b); err != nil {
return fmt.Errorf("unable to encode inputInvoiceStarGift#25d8c1d8: field message: %w", err)
}
}
return nil
}
// Decode implements bin.Decoder.
func (i *InputInvoiceStarGift) Decode(b *bin.Buffer) error {
if i == nil {
return fmt.Errorf("can't decode inputInvoiceStarGift#25d8c1d8 to nil")
}
if err := b.ConsumeID(InputInvoiceStarGiftTypeID); err != nil {
return fmt.Errorf("unable to decode inputInvoiceStarGift#25d8c1d8: %w", err)
}
return i.DecodeBare(b)
}
// DecodeBare implements bin.BareDecoder.
func (i *InputInvoiceStarGift) DecodeBare(b *bin.Buffer) error {
if i == nil {
return fmt.Errorf("can't decode inputInvoiceStarGift#25d8c1d8 to nil")
}
{
if err := i.Flags.Decode(b); err != nil {
return fmt.Errorf("unable to decode inputInvoiceStarGift#25d8c1d8: field flags: %w", err)
}
}
i.HideName = i.Flags.Has(0)
{
value, err := DecodeInputUser(b)
if err != nil {
return fmt.Errorf("unable to decode inputInvoiceStarGift#25d8c1d8: field user_id: %w", err)
}
i.UserID = value
}
{
value, err := b.Long()
if err != nil {
return fmt.Errorf("unable to decode inputInvoiceStarGift#25d8c1d8: field gift_id: %w", err)
}
i.GiftID = value
}
if i.Flags.Has(1) {
if err := i.Message.Decode(b); err != nil {
return fmt.Errorf("unable to decode inputInvoiceStarGift#25d8c1d8: field message: %w", err)
}
}
return nil
}
// SetHideName sets value of HideName conditional field.
func (i *InputInvoiceStarGift) SetHideName(value bool) {
if value {
i.Flags.Set(0)
i.HideName = true
} else {
i.Flags.Unset(0)
i.HideName = false
}
}
// GetHideName returns value of HideName conditional field.
func (i *InputInvoiceStarGift) GetHideName() (value bool) {
if i == nil {
return
}
return i.Flags.Has(0)
}
// GetUserID returns value of UserID field.
func (i *InputInvoiceStarGift) GetUserID() (value InputUserClass) {
if i == nil {
return
}
return i.UserID
}
// GetGiftID returns value of GiftID field.
func (i *InputInvoiceStarGift) GetGiftID() (value int64) {
if i == nil {
return
}
return i.GiftID
}
// SetMessage sets value of Message conditional field.
func (i *InputInvoiceStarGift) SetMessage(value TextWithEntities) {
i.Flags.Set(1)
i.Message = value
}
// GetMessage returns value of Message conditional field and
// boolean which is true if field was set.
func (i *InputInvoiceStarGift) GetMessage() (value TextWithEntities, ok bool) {
if i == nil {
return
}
if !i.Flags.Has(1) {
return value, false
}
return i.Message, true
}
// InputInvoiceClassName is schema name of InputInvoiceClass.
const InputInvoiceClassName = "InputInvoice"
@ -828,6 +1095,7 @@ const InputInvoiceClassName = "InputInvoice"
// case *tg.InputInvoicePremiumGiftCode: // inputInvoicePremiumGiftCode#98986c0d
// case *tg.InputInvoiceStars: // inputInvoiceStars#65f00ce3
// case *tg.InputInvoiceChatInviteSubscription: // inputInvoiceChatInviteSubscription#34e793f1
// case *tg.InputInvoiceStarGift: // inputInvoiceStarGift#25d8c1d8
// default: panic(v)
// }
type InputInvoiceClass interface {
@ -891,6 +1159,13 @@ func DecodeInputInvoice(buf *bin.Buffer) (InputInvoiceClass, error) {
return nil, fmt.Errorf("unable to decode InputInvoiceClass: %w", err)
}
return &v, nil
case InputInvoiceStarGiftTypeID:
// Decoding inputInvoiceStarGift#25d8c1d8.
v := InputInvoiceStarGift{}
if err := v.Decode(buf); err != nil {
return nil, fmt.Errorf("unable to decode InputInvoiceClass: %w", err)
}
return &v, nil
default:
return nil, fmt.Errorf("unable to decode InputInvoiceClass: %w", bin.NewUnexpectedID(id))
}

View File

@ -181,6 +181,19 @@ func (s InputInvoiceClassArray) AsInputInvoiceChatInviteSubscription() (to Input
return to
}
// AsInputInvoiceStarGift returns copy with only InputInvoiceStarGift constructors.
func (s InputInvoiceClassArray) AsInputInvoiceStarGift() (to InputInvoiceStarGiftArray) {
for _, elem := range s {
value, ok := elem.(*InputInvoiceStarGift)
if !ok {
continue
}
to = append(to, *value)
}
return to
}
// InputInvoiceMessageArray is adapter for slice of InputInvoiceMessage.
type InputInvoiceMessageArray []InputInvoiceMessage
@ -590,3 +603,85 @@ func (s *InputInvoiceChatInviteSubscriptionArray) Pop() (v InputInvoiceChatInvit
return v, true
}
// InputInvoiceStarGiftArray is adapter for slice of InputInvoiceStarGift.
type InputInvoiceStarGiftArray []InputInvoiceStarGift
// Sort sorts slice of InputInvoiceStarGift.
func (s InputInvoiceStarGiftArray) Sort(less func(a, b InputInvoiceStarGift) bool) InputInvoiceStarGiftArray {
sort.Slice(s, func(i, j int) bool {
return less(s[i], s[j])
})
return s
}
// SortStable sorts slice of InputInvoiceStarGift.
func (s InputInvoiceStarGiftArray) SortStable(less func(a, b InputInvoiceStarGift) bool) InputInvoiceStarGiftArray {
sort.SliceStable(s, func(i, j int) bool {
return less(s[i], s[j])
})
return s
}
// Retain filters in-place slice of InputInvoiceStarGift.
func (s InputInvoiceStarGiftArray) Retain(keep func(x InputInvoiceStarGift) bool) InputInvoiceStarGiftArray {
n := 0
for _, x := range s {
if keep(x) {
s[n] = x
n++
}
}
s = s[:n]
return s
}
// First returns first element of slice (if exists).
func (s InputInvoiceStarGiftArray) First() (v InputInvoiceStarGift, ok bool) {
if len(s) < 1 {
return
}
return s[0], true
}
// Last returns last element of slice (if exists).
func (s InputInvoiceStarGiftArray) Last() (v InputInvoiceStarGift, ok bool) {
if len(s) < 1 {
return
}
return s[len(s)-1], true
}
// PopFirst returns first element of slice (if exists) and deletes it.
func (s *InputInvoiceStarGiftArray) PopFirst() (v InputInvoiceStarGift, ok bool) {
if s == nil || len(*s) < 1 {
return
}
a := *s
v = a[0]
// Delete by index from SliceTricks.
copy(a[0:], a[1:])
var zero InputInvoiceStarGift
a[len(a)-1] = zero
a = a[:len(a)-1]
*s = a
return v, true
}
// Pop returns last element of slice (if exists) and deletes it.
func (s *InputInvoiceStarGiftArray) Pop() (v InputInvoiceStarGift, ok bool) {
if s == nil || len(*s) < 1 {
return
}
a := *s
v = a[len(a)-1]
a = a[:len(a)-1]
*s = a
return v, true
}

View File

@ -3465,6 +3465,167 @@ func (i *InputKeyboardButtonRequestPeer) GetMaxQuantity() (value int) {
return i.MaxQuantity
}
// KeyboardButtonCopy represents TL type `keyboardButtonCopy#75d2698e`.
//
// See https://core.telegram.org/constructor/keyboardButtonCopy for reference.
type KeyboardButtonCopy struct {
// Text field of KeyboardButtonCopy.
Text string
// CopyText field of KeyboardButtonCopy.
CopyText string
}
// KeyboardButtonCopyTypeID is TL type id of KeyboardButtonCopy.
const KeyboardButtonCopyTypeID = 0x75d2698e
// construct implements constructor of KeyboardButtonClass.
func (k KeyboardButtonCopy) construct() KeyboardButtonClass { return &k }
// Ensuring interfaces in compile-time for KeyboardButtonCopy.
var (
_ bin.Encoder = &KeyboardButtonCopy{}
_ bin.Decoder = &KeyboardButtonCopy{}
_ bin.BareEncoder = &KeyboardButtonCopy{}
_ bin.BareDecoder = &KeyboardButtonCopy{}
_ KeyboardButtonClass = &KeyboardButtonCopy{}
)
func (k *KeyboardButtonCopy) Zero() bool {
if k == nil {
return true
}
if !(k.Text == "") {
return false
}
if !(k.CopyText == "") {
return false
}
return true
}
// String implements fmt.Stringer.
func (k *KeyboardButtonCopy) String() string {
if k == nil {
return "KeyboardButtonCopy(nil)"
}
type Alias KeyboardButtonCopy
return fmt.Sprintf("KeyboardButtonCopy%+v", Alias(*k))
}
// FillFrom fills KeyboardButtonCopy from given interface.
func (k *KeyboardButtonCopy) FillFrom(from interface {
GetText() (value string)
GetCopyText() (value string)
}) {
k.Text = from.GetText()
k.CopyText = from.GetCopyText()
}
// TypeID returns type id in TL schema.
//
// See https://core.telegram.org/mtproto/TL-tl#remarks.
func (*KeyboardButtonCopy) TypeID() uint32 {
return KeyboardButtonCopyTypeID
}
// TypeName returns name of type in TL schema.
func (*KeyboardButtonCopy) TypeName() string {
return "keyboardButtonCopy"
}
// TypeInfo returns info about TL type.
func (k *KeyboardButtonCopy) TypeInfo() tdp.Type {
typ := tdp.Type{
Name: "keyboardButtonCopy",
ID: KeyboardButtonCopyTypeID,
}
if k == nil {
typ.Null = true
return typ
}
typ.Fields = []tdp.Field{
{
Name: "Text",
SchemaName: "text",
},
{
Name: "CopyText",
SchemaName: "copy_text",
},
}
return typ
}
// Encode implements bin.Encoder.
func (k *KeyboardButtonCopy) Encode(b *bin.Buffer) error {
if k == nil {
return fmt.Errorf("can't encode keyboardButtonCopy#75d2698e as nil")
}
b.PutID(KeyboardButtonCopyTypeID)
return k.EncodeBare(b)
}
// EncodeBare implements bin.BareEncoder.
func (k *KeyboardButtonCopy) EncodeBare(b *bin.Buffer) error {
if k == nil {
return fmt.Errorf("can't encode keyboardButtonCopy#75d2698e as nil")
}
b.PutString(k.Text)
b.PutString(k.CopyText)
return nil
}
// Decode implements bin.Decoder.
func (k *KeyboardButtonCopy) Decode(b *bin.Buffer) error {
if k == nil {
return fmt.Errorf("can't decode keyboardButtonCopy#75d2698e to nil")
}
if err := b.ConsumeID(KeyboardButtonCopyTypeID); err != nil {
return fmt.Errorf("unable to decode keyboardButtonCopy#75d2698e: %w", err)
}
return k.DecodeBare(b)
}
// DecodeBare implements bin.BareDecoder.
func (k *KeyboardButtonCopy) DecodeBare(b *bin.Buffer) error {
if k == nil {
return fmt.Errorf("can't decode keyboardButtonCopy#75d2698e to nil")
}
{
value, err := b.String()
if err != nil {
return fmt.Errorf("unable to decode keyboardButtonCopy#75d2698e: field text: %w", err)
}
k.Text = value
}
{
value, err := b.String()
if err != nil {
return fmt.Errorf("unable to decode keyboardButtonCopy#75d2698e: field copy_text: %w", err)
}
k.CopyText = value
}
return nil
}
// GetText returns value of Text field.
func (k *KeyboardButtonCopy) GetText() (value string) {
if k == nil {
return
}
return k.Text
}
// GetCopyText returns value of CopyText field.
func (k *KeyboardButtonCopy) GetCopyText() (value string) {
if k == nil {
return
}
return k.CopyText
}
// KeyboardButtonClassName is schema name of KeyboardButtonClass.
const KeyboardButtonClassName = "KeyboardButton"
@ -3496,6 +3657,7 @@ const KeyboardButtonClassName = "KeyboardButton"
// case *tg.KeyboardButtonSimpleWebView: // keyboardButtonSimpleWebView#a0c0505c
// case *tg.KeyboardButtonRequestPeer: // keyboardButtonRequestPeer#53d7bfd8
// case *tg.InputKeyboardButtonRequestPeer: // inputKeyboardButtonRequestPeer#c9662d05
// case *tg.KeyboardButtonCopy: // keyboardButtonCopy#75d2698e
// default: panic(v)
// }
type KeyboardButtonClass interface {
@ -3646,6 +3808,13 @@ func DecodeKeyboardButton(buf *bin.Buffer) (KeyboardButtonClass, error) {
return nil, fmt.Errorf("unable to decode KeyboardButtonClass: %w", err)
}
return &v, nil
case KeyboardButtonCopyTypeID:
// Decoding keyboardButtonCopy#75d2698e.
v := KeyboardButtonCopy{}
if err := v.Decode(buf); err != nil {
return nil, fmt.Errorf("unable to decode KeyboardButtonClass: %w", err)
}
return &v, nil
default:
return nil, fmt.Errorf("unable to decode KeyboardButtonClass: %w", bin.NewUnexpectedID(id))
}

View File

@ -337,6 +337,19 @@ func (s KeyboardButtonClassArray) AsInputKeyboardButtonRequestPeer() (to InputKe
return to
}
// AsKeyboardButtonCopy returns copy with only KeyboardButtonCopy constructors.
func (s KeyboardButtonClassArray) AsKeyboardButtonCopy() (to KeyboardButtonCopyArray) {
for _, elem := range s {
value, ok := elem.(*KeyboardButtonCopy)
if !ok {
continue
}
to = append(to, *value)
}
return to
}
// KeyboardButtonArray is adapter for slice of KeyboardButton.
type KeyboardButtonArray []KeyboardButton
@ -1730,3 +1743,85 @@ func (s *InputKeyboardButtonRequestPeerArray) Pop() (v InputKeyboardButtonReques
return v, true
}
// KeyboardButtonCopyArray is adapter for slice of KeyboardButtonCopy.
type KeyboardButtonCopyArray []KeyboardButtonCopy
// Sort sorts slice of KeyboardButtonCopy.
func (s KeyboardButtonCopyArray) Sort(less func(a, b KeyboardButtonCopy) bool) KeyboardButtonCopyArray {
sort.Slice(s, func(i, j int) bool {
return less(s[i], s[j])
})
return s
}
// SortStable sorts slice of KeyboardButtonCopy.
func (s KeyboardButtonCopyArray) SortStable(less func(a, b KeyboardButtonCopy) bool) KeyboardButtonCopyArray {
sort.SliceStable(s, func(i, j int) bool {
return less(s[i], s[j])
})
return s
}
// Retain filters in-place slice of KeyboardButtonCopy.
func (s KeyboardButtonCopyArray) Retain(keep func(x KeyboardButtonCopy) bool) KeyboardButtonCopyArray {
n := 0
for _, x := range s {
if keep(x) {
s[n] = x
n++
}
}
s = s[:n]
return s
}
// First returns first element of slice (if exists).
func (s KeyboardButtonCopyArray) First() (v KeyboardButtonCopy, ok bool) {
if len(s) < 1 {
return
}
return s[0], true
}
// Last returns last element of slice (if exists).
func (s KeyboardButtonCopyArray) Last() (v KeyboardButtonCopy, ok bool) {
if len(s) < 1 {
return
}
return s[len(s)-1], true
}
// PopFirst returns first element of slice (if exists) and deletes it.
func (s *KeyboardButtonCopyArray) PopFirst() (v KeyboardButtonCopy, ok bool) {
if s == nil || len(*s) < 1 {
return
}
a := *s
v = a[0]
// Delete by index from SliceTricks.
copy(a[0:], a[1:])
var zero KeyboardButtonCopy
a[len(a)-1] = zero
a = a[:len(a)-1]
*s = a
return v, true
}
// Pop returns last element of slice (if exists) and deletes it.
func (s *KeyboardButtonCopyArray) Pop() (v KeyboardButtonCopy, ok bool) {
if s == nil || len(*s) < 1 {
return
}
a := *s
v = a[len(a)-1]
a = a[:len(a)-1]
*s = a
return v, true
}

View File

@ -9090,6 +9090,338 @@ func (m *MessageActionPrizeStars) GetGiveawayMsgID() (value int) {
return m.GiveawayMsgID
}
// MessageActionStarGift represents TL type `messageActionStarGift#9bb3ef44`.
//
// See https://core.telegram.org/constructor/messageActionStarGift for reference.
type MessageActionStarGift struct {
// Flags field of MessageActionStarGift.
Flags bin.Fields
// NameHidden field of MessageActionStarGift.
NameHidden bool
// Saved field of MessageActionStarGift.
Saved bool
// Converted field of MessageActionStarGift.
Converted bool
// Gift field of MessageActionStarGift.
Gift StarGift
// Message field of MessageActionStarGift.
//
// Use SetMessage and GetMessage helpers.
Message TextWithEntities
// ConvertStars field of MessageActionStarGift.
ConvertStars int64
}
// MessageActionStarGiftTypeID is TL type id of MessageActionStarGift.
const MessageActionStarGiftTypeID = 0x9bb3ef44
// construct implements constructor of MessageActionClass.
func (m MessageActionStarGift) construct() MessageActionClass { return &m }
// Ensuring interfaces in compile-time for MessageActionStarGift.
var (
_ bin.Encoder = &MessageActionStarGift{}
_ bin.Decoder = &MessageActionStarGift{}
_ bin.BareEncoder = &MessageActionStarGift{}
_ bin.BareDecoder = &MessageActionStarGift{}
_ MessageActionClass = &MessageActionStarGift{}
)
func (m *MessageActionStarGift) Zero() bool {
if m == nil {
return true
}
if !(m.Flags.Zero()) {
return false
}
if !(m.NameHidden == false) {
return false
}
if !(m.Saved == false) {
return false
}
if !(m.Converted == false) {
return false
}
if !(m.Gift.Zero()) {
return false
}
if !(m.Message.Zero()) {
return false
}
if !(m.ConvertStars == 0) {
return false
}
return true
}
// String implements fmt.Stringer.
func (m *MessageActionStarGift) String() string {
if m == nil {
return "MessageActionStarGift(nil)"
}
type Alias MessageActionStarGift
return fmt.Sprintf("MessageActionStarGift%+v", Alias(*m))
}
// FillFrom fills MessageActionStarGift from given interface.
func (m *MessageActionStarGift) FillFrom(from interface {
GetNameHidden() (value bool)
GetSaved() (value bool)
GetConverted() (value bool)
GetGift() (value StarGift)
GetMessage() (value TextWithEntities, ok bool)
GetConvertStars() (value int64)
}) {
m.NameHidden = from.GetNameHidden()
m.Saved = from.GetSaved()
m.Converted = from.GetConverted()
m.Gift = from.GetGift()
if val, ok := from.GetMessage(); ok {
m.Message = val
}
m.ConvertStars = from.GetConvertStars()
}
// TypeID returns type id in TL schema.
//
// See https://core.telegram.org/mtproto/TL-tl#remarks.
func (*MessageActionStarGift) TypeID() uint32 {
return MessageActionStarGiftTypeID
}
// TypeName returns name of type in TL schema.
func (*MessageActionStarGift) TypeName() string {
return "messageActionStarGift"
}
// TypeInfo returns info about TL type.
func (m *MessageActionStarGift) TypeInfo() tdp.Type {
typ := tdp.Type{
Name: "messageActionStarGift",
ID: MessageActionStarGiftTypeID,
}
if m == nil {
typ.Null = true
return typ
}
typ.Fields = []tdp.Field{
{
Name: "NameHidden",
SchemaName: "name_hidden",
Null: !m.Flags.Has(0),
},
{
Name: "Saved",
SchemaName: "saved",
Null: !m.Flags.Has(2),
},
{
Name: "Converted",
SchemaName: "converted",
Null: !m.Flags.Has(3),
},
{
Name: "Gift",
SchemaName: "gift",
},
{
Name: "Message",
SchemaName: "message",
Null: !m.Flags.Has(1),
},
{
Name: "ConvertStars",
SchemaName: "convert_stars",
},
}
return typ
}
// SetFlags sets flags for non-zero fields.
func (m *MessageActionStarGift) SetFlags() {
if !(m.NameHidden == false) {
m.Flags.Set(0)
}
if !(m.Saved == false) {
m.Flags.Set(2)
}
if !(m.Converted == false) {
m.Flags.Set(3)
}
if !(m.Message.Zero()) {
m.Flags.Set(1)
}
}
// Encode implements bin.Encoder.
func (m *MessageActionStarGift) Encode(b *bin.Buffer) error {
if m == nil {
return fmt.Errorf("can't encode messageActionStarGift#9bb3ef44 as nil")
}
b.PutID(MessageActionStarGiftTypeID)
return m.EncodeBare(b)
}
// EncodeBare implements bin.BareEncoder.
func (m *MessageActionStarGift) EncodeBare(b *bin.Buffer) error {
if m == nil {
return fmt.Errorf("can't encode messageActionStarGift#9bb3ef44 as nil")
}
m.SetFlags()
if err := m.Flags.Encode(b); err != nil {
return fmt.Errorf("unable to encode messageActionStarGift#9bb3ef44: field flags: %w", err)
}
if err := m.Gift.Encode(b); err != nil {
return fmt.Errorf("unable to encode messageActionStarGift#9bb3ef44: field gift: %w", err)
}
if m.Flags.Has(1) {
if err := m.Message.Encode(b); err != nil {
return fmt.Errorf("unable to encode messageActionStarGift#9bb3ef44: field message: %w", err)
}
}
b.PutLong(m.ConvertStars)
return nil
}
// Decode implements bin.Decoder.
func (m *MessageActionStarGift) Decode(b *bin.Buffer) error {
if m == nil {
return fmt.Errorf("can't decode messageActionStarGift#9bb3ef44 to nil")
}
if err := b.ConsumeID(MessageActionStarGiftTypeID); err != nil {
return fmt.Errorf("unable to decode messageActionStarGift#9bb3ef44: %w", err)
}
return m.DecodeBare(b)
}
// DecodeBare implements bin.BareDecoder.
func (m *MessageActionStarGift) DecodeBare(b *bin.Buffer) error {
if m == nil {
return fmt.Errorf("can't decode messageActionStarGift#9bb3ef44 to nil")
}
{
if err := m.Flags.Decode(b); err != nil {
return fmt.Errorf("unable to decode messageActionStarGift#9bb3ef44: field flags: %w", err)
}
}
m.NameHidden = m.Flags.Has(0)
m.Saved = m.Flags.Has(2)
m.Converted = m.Flags.Has(3)
{
if err := m.Gift.Decode(b); err != nil {
return fmt.Errorf("unable to decode messageActionStarGift#9bb3ef44: field gift: %w", err)
}
}
if m.Flags.Has(1) {
if err := m.Message.Decode(b); err != nil {
return fmt.Errorf("unable to decode messageActionStarGift#9bb3ef44: field message: %w", err)
}
}
{
value, err := b.Long()
if err != nil {
return fmt.Errorf("unable to decode messageActionStarGift#9bb3ef44: field convert_stars: %w", err)
}
m.ConvertStars = value
}
return nil
}
// SetNameHidden sets value of NameHidden conditional field.
func (m *MessageActionStarGift) SetNameHidden(value bool) {
if value {
m.Flags.Set(0)
m.NameHidden = true
} else {
m.Flags.Unset(0)
m.NameHidden = false
}
}
// GetNameHidden returns value of NameHidden conditional field.
func (m *MessageActionStarGift) GetNameHidden() (value bool) {
if m == nil {
return
}
return m.Flags.Has(0)
}
// SetSaved sets value of Saved conditional field.
func (m *MessageActionStarGift) SetSaved(value bool) {
if value {
m.Flags.Set(2)
m.Saved = true
} else {
m.Flags.Unset(2)
m.Saved = false
}
}
// GetSaved returns value of Saved conditional field.
func (m *MessageActionStarGift) GetSaved() (value bool) {
if m == nil {
return
}
return m.Flags.Has(2)
}
// SetConverted sets value of Converted conditional field.
func (m *MessageActionStarGift) SetConverted(value bool) {
if value {
m.Flags.Set(3)
m.Converted = true
} else {
m.Flags.Unset(3)
m.Converted = false
}
}
// GetConverted returns value of Converted conditional field.
func (m *MessageActionStarGift) GetConverted() (value bool) {
if m == nil {
return
}
return m.Flags.Has(3)
}
// GetGift returns value of Gift field.
func (m *MessageActionStarGift) GetGift() (value StarGift) {
if m == nil {
return
}
return m.Gift
}
// SetMessage sets value of Message conditional field.
func (m *MessageActionStarGift) SetMessage(value TextWithEntities) {
m.Flags.Set(1)
m.Message = value
}
// GetMessage returns value of Message conditional field and
// boolean which is true if field was set.
func (m *MessageActionStarGift) GetMessage() (value TextWithEntities, ok bool) {
if m == nil {
return
}
if !m.Flags.Has(1) {
return value, false
}
return m.Message, true
}
// GetConvertStars returns value of ConvertStars field.
func (m *MessageActionStarGift) GetConvertStars() (value int64) {
if m == nil {
return
}
return m.ConvertStars
}
// MessageActionClassName is schema name of MessageActionClass.
const MessageActionClassName = "MessageAction"
@ -9150,6 +9482,7 @@ const MessageActionClassName = "MessageAction"
// case *tg.MessageActionPaymentRefunded: // messageActionPaymentRefunded#41b3e202
// case *tg.MessageActionGiftStars: // messageActionGiftStars#45d5b021
// case *tg.MessageActionPrizeStars: // messageActionPrizeStars#b00c47a2
// case *tg.MessageActionStarGift: // messageActionStarGift#9bb3ef44
// default: panic(v)
// }
type MessageActionClass interface {
@ -9500,6 +9833,13 @@ func DecodeMessageAction(buf *bin.Buffer) (MessageActionClass, error) {
return nil, fmt.Errorf("unable to decode MessageActionClass: %w", err)
}
return &v, nil
case MessageActionStarGiftTypeID:
// Decoding messageActionStarGift#9bb3ef44.
v := MessageActionStarGift{}
if err := v.Decode(buf); err != nil {
return nil, fmt.Errorf("unable to decode MessageActionClass: %w", err)
}
return &v, nil
default:
return nil, fmt.Errorf("unable to decode MessageActionClass: %w", bin.NewUnexpectedID(id))
}

View File

@ -623,6 +623,19 @@ func (s MessageActionClassArray) AsMessageActionPrizeStars() (to MessageActionPr
return to
}
// AsMessageActionStarGift returns copy with only MessageActionStarGift constructors.
func (s MessageActionClassArray) AsMessageActionStarGift() (to MessageActionStarGiftArray) {
for _, elem := range s {
value, ok := elem.(*MessageActionStarGift)
if !ok {
continue
}
to = append(to, *value)
}
return to
}
// MessageActionChatCreateArray is adapter for slice of MessageActionChatCreate.
type MessageActionChatCreateArray []MessageActionChatCreate
@ -3820,3 +3833,85 @@ func (s *MessageActionPrizeStarsArray) Pop() (v MessageActionPrizeStars, ok bool
return v, true
}
// MessageActionStarGiftArray is adapter for slice of MessageActionStarGift.
type MessageActionStarGiftArray []MessageActionStarGift
// Sort sorts slice of MessageActionStarGift.
func (s MessageActionStarGiftArray) Sort(less func(a, b MessageActionStarGift) bool) MessageActionStarGiftArray {
sort.Slice(s, func(i, j int) bool {
return less(s[i], s[j])
})
return s
}
// SortStable sorts slice of MessageActionStarGift.
func (s MessageActionStarGiftArray) SortStable(less func(a, b MessageActionStarGift) bool) MessageActionStarGiftArray {
sort.SliceStable(s, func(i, j int) bool {
return less(s[i], s[j])
})
return s
}
// Retain filters in-place slice of MessageActionStarGift.
func (s MessageActionStarGiftArray) Retain(keep func(x MessageActionStarGift) bool) MessageActionStarGiftArray {
n := 0
for _, x := range s {
if keep(x) {
s[n] = x
n++
}
}
s = s[:n]
return s
}
// First returns first element of slice (if exists).
func (s MessageActionStarGiftArray) First() (v MessageActionStarGift, ok bool) {
if len(s) < 1 {
return
}
return s[0], true
}
// Last returns last element of slice (if exists).
func (s MessageActionStarGiftArray) Last() (v MessageActionStarGift, ok bool) {
if len(s) < 1 {
return
}
return s[len(s)-1], true
}
// PopFirst returns first element of slice (if exists) and deletes it.
func (s *MessageActionStarGiftArray) PopFirst() (v MessageActionStarGift, ok bool) {
if s == nil || len(*s) < 1 {
return
}
a := *s
v = a[0]
// Delete by index from SliceTricks.
copy(a[0:], a[1:])
var zero MessageActionStarGift
a[len(a)-1] = zero
a = a[:len(a)-1]
*s = a
return v, true
}
// Pop returns last element of slice (if exists) and deletes it.
func (s *MessageActionStarGiftArray) Pop() (v MessageActionStarGift, ok bool) {
if s == nil || len(*s) < 1 {
return
}
a := *s
v = a[len(a)-1]
a = a[:len(a)-1]
*s = a
return v, true
}

View File

@ -883,7 +883,7 @@ func (m *MessageMediaUnsupported) DecodeBare(b *bin.Buffer) error {
return nil
}
// MessageMediaDocument represents TL type `messageMediaDocument#4cf4d72d`.
// MessageMediaDocument represents TL type `messageMediaDocument#dd570bd5`.
// Document (video, audio, voice, sticker, any media type except photo)
//
// See https://core.telegram.org/constructor/messageMediaDocument for reference.
@ -908,12 +908,10 @@ type MessageMediaDocument struct {
//
// Use SetDocument and GetDocument helpers.
Document DocumentClass
// Currently only used for story videos, may contain an alternative version of the story
// video, explicitly encoded using H.264 (in MPEG4 transport) at a lower resolution than
// document.
// AltDocuments field of MessageMediaDocument.
//
// Use SetAltDocument and GetAltDocument helpers.
AltDocument DocumentClass
// Use SetAltDocuments and GetAltDocuments helpers.
AltDocuments []DocumentClass
// Time to live of self-destructing document
//
// Use SetTTLSeconds and GetTTLSeconds helpers.
@ -921,7 +919,7 @@ type MessageMediaDocument struct {
}
// MessageMediaDocumentTypeID is TL type id of MessageMediaDocument.
const MessageMediaDocumentTypeID = 0x4cf4d72d
const MessageMediaDocumentTypeID = 0xdd570bd5
// construct implements constructor of MessageMediaClass.
func (m MessageMediaDocument) construct() MessageMediaClass { return &m }
@ -961,7 +959,7 @@ func (m *MessageMediaDocument) Zero() bool {
if !(m.Document == nil) {
return false
}
if !(m.AltDocument == nil) {
if !(m.AltDocuments == nil) {
return false
}
if !(m.TTLSeconds == 0) {
@ -988,7 +986,7 @@ func (m *MessageMediaDocument) FillFrom(from interface {
GetRound() (value bool)
GetVoice() (value bool)
GetDocument() (value DocumentClass, ok bool)
GetAltDocument() (value DocumentClass, ok bool)
GetAltDocuments() (value []DocumentClass, ok bool)
GetTTLSeconds() (value int, ok bool)
}) {
m.Nopremium = from.GetNopremium()
@ -1000,8 +998,8 @@ func (m *MessageMediaDocument) FillFrom(from interface {
m.Document = val
}
if val, ok := from.GetAltDocument(); ok {
m.AltDocument = val
if val, ok := from.GetAltDocuments(); ok {
m.AltDocuments = val
}
if val, ok := from.GetTTLSeconds(); ok {
@ -1064,8 +1062,8 @@ func (m *MessageMediaDocument) TypeInfo() tdp.Type {
Null: !m.Flags.Has(0),
},
{
Name: "AltDocument",
SchemaName: "alt_document",
Name: "AltDocuments",
SchemaName: "alt_documents",
Null: !m.Flags.Has(5),
},
{
@ -1097,7 +1095,7 @@ func (m *MessageMediaDocument) SetFlags() {
if !(m.Document == nil) {
m.Flags.Set(0)
}
if !(m.AltDocument == nil) {
if !(m.AltDocuments == nil) {
m.Flags.Set(5)
}
if !(m.TTLSeconds == 0) {
@ -1108,7 +1106,7 @@ func (m *MessageMediaDocument) SetFlags() {
// Encode implements bin.Encoder.
func (m *MessageMediaDocument) Encode(b *bin.Buffer) error {
if m == nil {
return fmt.Errorf("can't encode messageMediaDocument#4cf4d72d as nil")
return fmt.Errorf("can't encode messageMediaDocument#dd570bd5 as nil")
}
b.PutID(MessageMediaDocumentTypeID)
return m.EncodeBare(b)
@ -1117,26 +1115,29 @@ func (m *MessageMediaDocument) Encode(b *bin.Buffer) error {
// EncodeBare implements bin.BareEncoder.
func (m *MessageMediaDocument) EncodeBare(b *bin.Buffer) error {
if m == nil {
return fmt.Errorf("can't encode messageMediaDocument#4cf4d72d as nil")
return fmt.Errorf("can't encode messageMediaDocument#dd570bd5 as nil")
}
m.SetFlags()
if err := m.Flags.Encode(b); err != nil {
return fmt.Errorf("unable to encode messageMediaDocument#4cf4d72d: field flags: %w", err)
return fmt.Errorf("unable to encode messageMediaDocument#dd570bd5: field flags: %w", err)
}
if m.Flags.Has(0) {
if m.Document == nil {
return fmt.Errorf("unable to encode messageMediaDocument#4cf4d72d: field document is nil")
return fmt.Errorf("unable to encode messageMediaDocument#dd570bd5: field document is nil")
}
if err := m.Document.Encode(b); err != nil {
return fmt.Errorf("unable to encode messageMediaDocument#4cf4d72d: field document: %w", err)
return fmt.Errorf("unable to encode messageMediaDocument#dd570bd5: field document: %w", err)
}
}
if m.Flags.Has(5) {
if m.AltDocument == nil {
return fmt.Errorf("unable to encode messageMediaDocument#4cf4d72d: field alt_document is nil")
}
if err := m.AltDocument.Encode(b); err != nil {
return fmt.Errorf("unable to encode messageMediaDocument#4cf4d72d: field alt_document: %w", err)
b.PutVectorHeader(len(m.AltDocuments))
for idx, v := range m.AltDocuments {
if v == nil {
return fmt.Errorf("unable to encode messageMediaDocument#dd570bd5: field alt_documents element with index %d is nil", idx)
}
if err := v.Encode(b); err != nil {
return fmt.Errorf("unable to encode messageMediaDocument#dd570bd5: field alt_documents element with index %d: %w", idx, err)
}
}
}
if m.Flags.Has(2) {
@ -1148,10 +1149,10 @@ func (m *MessageMediaDocument) EncodeBare(b *bin.Buffer) error {
// Decode implements bin.Decoder.
func (m *MessageMediaDocument) Decode(b *bin.Buffer) error {
if m == nil {
return fmt.Errorf("can't decode messageMediaDocument#4cf4d72d to nil")
return fmt.Errorf("can't decode messageMediaDocument#dd570bd5 to nil")
}
if err := b.ConsumeID(MessageMediaDocumentTypeID); err != nil {
return fmt.Errorf("unable to decode messageMediaDocument#4cf4d72d: %w", err)
return fmt.Errorf("unable to decode messageMediaDocument#dd570bd5: %w", err)
}
return m.DecodeBare(b)
}
@ -1159,11 +1160,11 @@ func (m *MessageMediaDocument) Decode(b *bin.Buffer) error {
// DecodeBare implements bin.BareDecoder.
func (m *MessageMediaDocument) DecodeBare(b *bin.Buffer) error {
if m == nil {
return fmt.Errorf("can't decode messageMediaDocument#4cf4d72d to nil")
return fmt.Errorf("can't decode messageMediaDocument#dd570bd5 to nil")
}
{
if err := m.Flags.Decode(b); err != nil {
return fmt.Errorf("unable to decode messageMediaDocument#4cf4d72d: field flags: %w", err)
return fmt.Errorf("unable to decode messageMediaDocument#dd570bd5: field flags: %w", err)
}
}
m.Nopremium = m.Flags.Has(3)
@ -1174,21 +1175,31 @@ func (m *MessageMediaDocument) DecodeBare(b *bin.Buffer) error {
if m.Flags.Has(0) {
value, err := DecodeDocument(b)
if err != nil {
return fmt.Errorf("unable to decode messageMediaDocument#4cf4d72d: field document: %w", err)
return fmt.Errorf("unable to decode messageMediaDocument#dd570bd5: field document: %w", err)
}
m.Document = value
}
if m.Flags.Has(5) {
value, err := DecodeDocument(b)
headerLen, err := b.VectorHeader()
if err != nil {
return fmt.Errorf("unable to decode messageMediaDocument#4cf4d72d: field alt_document: %w", err)
return fmt.Errorf("unable to decode messageMediaDocument#dd570bd5: field alt_documents: %w", err)
}
if headerLen > 0 {
m.AltDocuments = make([]DocumentClass, 0, headerLen%bin.PreallocateLimit)
}
for idx := 0; idx < headerLen; idx++ {
value, err := DecodeDocument(b)
if err != nil {
return fmt.Errorf("unable to decode messageMediaDocument#dd570bd5: field alt_documents: %w", err)
}
m.AltDocuments = append(m.AltDocuments, value)
}
m.AltDocument = value
}
if m.Flags.Has(2) {
value, err := b.Int()
if err != nil {
return fmt.Errorf("unable to decode messageMediaDocument#4cf4d72d: field ttl_seconds: %w", err)
return fmt.Errorf("unable to decode messageMediaDocument#dd570bd5: field ttl_seconds: %w", err)
}
m.TTLSeconds = value
}
@ -1308,22 +1319,22 @@ func (m *MessageMediaDocument) GetDocument() (value DocumentClass, ok bool) {
return m.Document, true
}
// SetAltDocument sets value of AltDocument conditional field.
func (m *MessageMediaDocument) SetAltDocument(value DocumentClass) {
// SetAltDocuments sets value of AltDocuments conditional field.
func (m *MessageMediaDocument) SetAltDocuments(value []DocumentClass) {
m.Flags.Set(5)
m.AltDocument = value
m.AltDocuments = value
}
// GetAltDocument returns value of AltDocument conditional field and
// GetAltDocuments returns value of AltDocuments conditional field and
// boolean which is true if field was set.
func (m *MessageMediaDocument) GetAltDocument() (value DocumentClass, ok bool) {
func (m *MessageMediaDocument) GetAltDocuments() (value []DocumentClass, ok bool) {
if m == nil {
return
}
if !m.Flags.Has(5) {
return value, false
}
return m.AltDocument, true
return m.AltDocuments, true
}
// SetTTLSeconds sets value of TTLSeconds conditional field.
@ -1344,6 +1355,14 @@ func (m *MessageMediaDocument) GetTTLSeconds() (value int, ok bool) {
return m.TTLSeconds, true
}
// MapAltDocuments returns field AltDocuments wrapped in DocumentClassArray helper.
func (m *MessageMediaDocument) MapAltDocuments() (value DocumentClassArray, ok bool) {
if !m.Flags.Has(5) {
return value, false
}
return DocumentClassArray(m.AltDocuments), true
}
// MessageMediaWebPage represents TL type `messageMediaWebPage#ddf10c3b`.
// Preview of webpage
//
@ -4784,7 +4803,7 @@ const MessageMediaClassName = "MessageMedia"
// case *tg.MessageMediaGeo: // messageMediaGeo#56e0d474
// case *tg.MessageMediaContact: // messageMediaContact#70322949
// case *tg.MessageMediaUnsupported: // messageMediaUnsupported#9f84f49e
// case *tg.MessageMediaDocument: // messageMediaDocument#4cf4d72d
// case *tg.MessageMediaDocument: // messageMediaDocument#dd570bd5
// case *tg.MessageMediaWebPage: // messageMediaWebPage#ddf10c3b
// case *tg.MessageMediaVenue: // messageMediaVenue#2ec0533f
// case *tg.MessageMediaGame: // messageMediaGame#fdb19008
@ -4860,7 +4879,7 @@ func DecodeMessageMedia(buf *bin.Buffer) (MessageMediaClass, error) {
}
return &v, nil
case MessageMediaDocumentTypeID:
// Decoding messageMediaDocument#4cf4d72d.
// Decoding messageMediaDocument#dd570bd5.
v := MessageMediaDocument{}
if err := v.Decode(buf); err != nil {
return nil, fmt.Errorf("unable to decode MessageMediaClass: %w", err)

View File

@ -0,0 +1,188 @@
// Code generated by gotdgen, DO NOT EDIT.
package tg
import (
"context"
"errors"
"fmt"
"sort"
"strings"
"go.uber.org/multierr"
"github.com/gotd/td/bin"
"github.com/gotd/td/tdjson"
"github.com/gotd/td/tdp"
"github.com/gotd/td/tgerr"
)
// No-op definition for keeping imports.
var (
_ = bin.Buffer{}
_ = context.Background()
_ = fmt.Stringer(nil)
_ = strings.Builder{}
_ = errors.Is
_ = multierr.AppendInto
_ = sort.Ints
_ = tdp.Format
_ = tgerr.Error{}
_ = tdjson.Encoder{}
)
// MessageReportOption represents TL type `messageReportOption#7903e3d9`.
//
// See https://core.telegram.org/constructor/messageReportOption for reference.
type MessageReportOption struct {
// Text field of MessageReportOption.
Text string
// Option field of MessageReportOption.
Option []byte
}
// MessageReportOptionTypeID is TL type id of MessageReportOption.
const MessageReportOptionTypeID = 0x7903e3d9
// Ensuring interfaces in compile-time for MessageReportOption.
var (
_ bin.Encoder = &MessageReportOption{}
_ bin.Decoder = &MessageReportOption{}
_ bin.BareEncoder = &MessageReportOption{}
_ bin.BareDecoder = &MessageReportOption{}
)
func (m *MessageReportOption) Zero() bool {
if m == nil {
return true
}
if !(m.Text == "") {
return false
}
if !(m.Option == nil) {
return false
}
return true
}
// String implements fmt.Stringer.
func (m *MessageReportOption) String() string {
if m == nil {
return "MessageReportOption(nil)"
}
type Alias MessageReportOption
return fmt.Sprintf("MessageReportOption%+v", Alias(*m))
}
// FillFrom fills MessageReportOption from given interface.
func (m *MessageReportOption) FillFrom(from interface {
GetText() (value string)
GetOption() (value []byte)
}) {
m.Text = from.GetText()
m.Option = from.GetOption()
}
// TypeID returns type id in TL schema.
//
// See https://core.telegram.org/mtproto/TL-tl#remarks.
func (*MessageReportOption) TypeID() uint32 {
return MessageReportOptionTypeID
}
// TypeName returns name of type in TL schema.
func (*MessageReportOption) TypeName() string {
return "messageReportOption"
}
// TypeInfo returns info about TL type.
func (m *MessageReportOption) TypeInfo() tdp.Type {
typ := tdp.Type{
Name: "messageReportOption",
ID: MessageReportOptionTypeID,
}
if m == nil {
typ.Null = true
return typ
}
typ.Fields = []tdp.Field{
{
Name: "Text",
SchemaName: "text",
},
{
Name: "Option",
SchemaName: "option",
},
}
return typ
}
// Encode implements bin.Encoder.
func (m *MessageReportOption) Encode(b *bin.Buffer) error {
if m == nil {
return fmt.Errorf("can't encode messageReportOption#7903e3d9 as nil")
}
b.PutID(MessageReportOptionTypeID)
return m.EncodeBare(b)
}
// EncodeBare implements bin.BareEncoder.
func (m *MessageReportOption) EncodeBare(b *bin.Buffer) error {
if m == nil {
return fmt.Errorf("can't encode messageReportOption#7903e3d9 as nil")
}
b.PutString(m.Text)
b.PutBytes(m.Option)
return nil
}
// Decode implements bin.Decoder.
func (m *MessageReportOption) Decode(b *bin.Buffer) error {
if m == nil {
return fmt.Errorf("can't decode messageReportOption#7903e3d9 to nil")
}
if err := b.ConsumeID(MessageReportOptionTypeID); err != nil {
return fmt.Errorf("unable to decode messageReportOption#7903e3d9: %w", err)
}
return m.DecodeBare(b)
}
// DecodeBare implements bin.BareDecoder.
func (m *MessageReportOption) DecodeBare(b *bin.Buffer) error {
if m == nil {
return fmt.Errorf("can't decode messageReportOption#7903e3d9 to nil")
}
{
value, err := b.String()
if err != nil {
return fmt.Errorf("unable to decode messageReportOption#7903e3d9: field text: %w", err)
}
m.Text = value
}
{
value, err := b.Bytes()
if err != nil {
return fmt.Errorf("unable to decode messageReportOption#7903e3d9: field option: %w", err)
}
m.Option = value
}
return nil
}
// GetText returns value of Text field.
func (m *MessageReportOption) GetText() (value string) {
if m == nil {
return
}
return m.Text
}
// GetOption returns value of Option field.
func (m *MessageReportOption) GetOption() (value []byte) {
if m == nil {
return
}
return m.Option
}

View File

@ -0,0 +1,35 @@
//go:build !no_gotd_slices
// +build !no_gotd_slices
// Code generated by gotdgen, DO NOT EDIT.
package tg
import (
"context"
"errors"
"fmt"
"sort"
"strings"
"go.uber.org/multierr"
"github.com/gotd/td/bin"
"github.com/gotd/td/tdjson"
"github.com/gotd/td/tdp"
"github.com/gotd/td/tgerr"
)
// No-op definition for keeping imports.
var (
_ = bin.Buffer{}
_ = context.Background()
_ = fmt.Stringer(nil)
_ = strings.Builder{}
_ = errors.Is
_ = multierr.AppendInto
_ = sort.Ints
_ = tdp.Format
_ = tgerr.Error{}
_ = tdjson.Encoder{}
)

View File

@ -31,7 +31,7 @@ var (
_ = tdjson.Encoder{}
)
// MessagesReportRequest represents TL type `messages.report#8953ab4e`.
// MessagesReportRequest represents TL type `messages.report#fc78af9b`.
// Report a message in a chat for violation of telegram's Terms of Service
//
// See https://core.telegram.org/method/messages.report for reference.
@ -40,14 +40,14 @@ type MessagesReportRequest struct {
Peer InputPeerClass
// IDs of messages to report
ID []int
// Why are these messages being reported
Reason ReportReasonClass
// Option field of MessagesReportRequest.
Option []byte
// Comment for report moderation
Message string
}
// MessagesReportRequestTypeID is TL type id of MessagesReportRequest.
const MessagesReportRequestTypeID = 0x8953ab4e
const MessagesReportRequestTypeID = 0xfc78af9b
// Ensuring interfaces in compile-time for MessagesReportRequest.
var (
@ -67,7 +67,7 @@ func (r *MessagesReportRequest) Zero() bool {
if !(r.ID == nil) {
return false
}
if !(r.Reason == nil) {
if !(r.Option == nil) {
return false
}
if !(r.Message == "") {
@ -90,12 +90,12 @@ func (r *MessagesReportRequest) String() string {
func (r *MessagesReportRequest) FillFrom(from interface {
GetPeer() (value InputPeerClass)
GetID() (value []int)
GetReason() (value ReportReasonClass)
GetOption() (value []byte)
GetMessage() (value string)
}) {
r.Peer = from.GetPeer()
r.ID = from.GetID()
r.Reason = from.GetReason()
r.Option = from.GetOption()
r.Message = from.GetMessage()
}
@ -131,8 +131,8 @@ func (r *MessagesReportRequest) TypeInfo() tdp.Type {
SchemaName: "id",
},
{
Name: "Reason",
SchemaName: "reason",
Name: "Option",
SchemaName: "option",
},
{
Name: "Message",
@ -145,7 +145,7 @@ func (r *MessagesReportRequest) TypeInfo() tdp.Type {
// Encode implements bin.Encoder.
func (r *MessagesReportRequest) Encode(b *bin.Buffer) error {
if r == nil {
return fmt.Errorf("can't encode messages.report#8953ab4e as nil")
return fmt.Errorf("can't encode messages.report#fc78af9b as nil")
}
b.PutID(MessagesReportRequestTypeID)
return r.EncodeBare(b)
@ -154,24 +154,19 @@ func (r *MessagesReportRequest) Encode(b *bin.Buffer) error {
// EncodeBare implements bin.BareEncoder.
func (r *MessagesReportRequest) EncodeBare(b *bin.Buffer) error {
if r == nil {
return fmt.Errorf("can't encode messages.report#8953ab4e as nil")
return fmt.Errorf("can't encode messages.report#fc78af9b as nil")
}
if r.Peer == nil {
return fmt.Errorf("unable to encode messages.report#8953ab4e: field peer is nil")
return fmt.Errorf("unable to encode messages.report#fc78af9b: field peer is nil")
}
if err := r.Peer.Encode(b); err != nil {
return fmt.Errorf("unable to encode messages.report#8953ab4e: field peer: %w", err)
return fmt.Errorf("unable to encode messages.report#fc78af9b: field peer: %w", err)
}
b.PutVectorHeader(len(r.ID))
for _, v := range r.ID {
b.PutInt(v)
}
if r.Reason == nil {
return fmt.Errorf("unable to encode messages.report#8953ab4e: field reason is nil")
}
if err := r.Reason.Encode(b); err != nil {
return fmt.Errorf("unable to encode messages.report#8953ab4e: field reason: %w", err)
}
b.PutBytes(r.Option)
b.PutString(r.Message)
return nil
}
@ -179,10 +174,10 @@ func (r *MessagesReportRequest) EncodeBare(b *bin.Buffer) error {
// Decode implements bin.Decoder.
func (r *MessagesReportRequest) Decode(b *bin.Buffer) error {
if r == nil {
return fmt.Errorf("can't decode messages.report#8953ab4e to nil")
return fmt.Errorf("can't decode messages.report#fc78af9b to nil")
}
if err := b.ConsumeID(MessagesReportRequestTypeID); err != nil {
return fmt.Errorf("unable to decode messages.report#8953ab4e: %w", err)
return fmt.Errorf("unable to decode messages.report#fc78af9b: %w", err)
}
return r.DecodeBare(b)
}
@ -190,19 +185,19 @@ func (r *MessagesReportRequest) Decode(b *bin.Buffer) error {
// DecodeBare implements bin.BareDecoder.
func (r *MessagesReportRequest) DecodeBare(b *bin.Buffer) error {
if r == nil {
return fmt.Errorf("can't decode messages.report#8953ab4e to nil")
return fmt.Errorf("can't decode messages.report#fc78af9b to nil")
}
{
value, err := DecodeInputPeer(b)
if err != nil {
return fmt.Errorf("unable to decode messages.report#8953ab4e: field peer: %w", err)
return fmt.Errorf("unable to decode messages.report#fc78af9b: field peer: %w", err)
}
r.Peer = value
}
{
headerLen, err := b.VectorHeader()
if err != nil {
return fmt.Errorf("unable to decode messages.report#8953ab4e: field id: %w", err)
return fmt.Errorf("unable to decode messages.report#fc78af9b: field id: %w", err)
}
if headerLen > 0 {
@ -211,22 +206,22 @@ func (r *MessagesReportRequest) DecodeBare(b *bin.Buffer) error {
for idx := 0; idx < headerLen; idx++ {
value, err := b.Int()
if err != nil {
return fmt.Errorf("unable to decode messages.report#8953ab4e: field id: %w", err)
return fmt.Errorf("unable to decode messages.report#fc78af9b: field id: %w", err)
}
r.ID = append(r.ID, value)
}
}
{
value, err := DecodeReportReason(b)
value, err := b.Bytes()
if err != nil {
return fmt.Errorf("unable to decode messages.report#8953ab4e: field reason: %w", err)
return fmt.Errorf("unable to decode messages.report#fc78af9b: field option: %w", err)
}
r.Reason = value
r.Option = value
}
{
value, err := b.String()
if err != nil {
return fmt.Errorf("unable to decode messages.report#8953ab4e: field message: %w", err)
return fmt.Errorf("unable to decode messages.report#fc78af9b: field message: %w", err)
}
r.Message = value
}
@ -249,12 +244,12 @@ func (r *MessagesReportRequest) GetID() (value []int) {
return r.ID
}
// GetReason returns value of Reason field.
func (r *MessagesReportRequest) GetReason() (value ReportReasonClass) {
// GetOption returns value of Option field.
func (r *MessagesReportRequest) GetOption() (value []byte) {
if r == nil {
return
}
return r.Reason
return r.Option
}
// GetMessage returns value of Message field.
@ -265,7 +260,7 @@ func (r *MessagesReportRequest) GetMessage() (value string) {
return r.Message
}
// MessagesReport invokes method messages.report#8953ab4e returning error if any.
// MessagesReport invokes method messages.report#fc78af9b returning error if any.
// Report a message in a chat for violation of telegram's Terms of Service
//
// Possible errors:
@ -275,12 +270,11 @@ func (r *MessagesReportRequest) GetMessage() (value string) {
// 400 PEER_ID_INVALID: The provided peer id is invalid.
//
// See https://core.telegram.org/method/messages.report for reference.
func (c *Client) MessagesReport(ctx context.Context, request *MessagesReportRequest) (bool, error) {
var result BoolBox
func (c *Client) MessagesReport(ctx context.Context, request *MessagesReportRequest) (ReportResultClass, error) {
var result ReportResultBox
if err := c.rpc.Invoke(ctx, request, &result); err != nil {
return false, err
return nil, err
}
_, ok := result.Bool.(*BoolTrue)
return ok, nil
return result.ReportResult, nil
}

View File

@ -0,0 +1,206 @@
// Code generated by gotdgen, DO NOT EDIT.
package tg
import (
"context"
"errors"
"fmt"
"sort"
"strings"
"go.uber.org/multierr"
"github.com/gotd/td/bin"
"github.com/gotd/td/tdjson"
"github.com/gotd/td/tdp"
"github.com/gotd/td/tgerr"
)
// No-op definition for keeping imports.
var (
_ = bin.Buffer{}
_ = context.Background()
_ = fmt.Stringer(nil)
_ = strings.Builder{}
_ = errors.Is
_ = multierr.AppendInto
_ = sort.Ints
_ = tdp.Format
_ = tgerr.Error{}
_ = tdjson.Encoder{}
)
// PaymentsConvertStarGiftRequest represents TL type `payments.convertStarGift#421e027`.
//
// See https://core.telegram.org/method/payments.convertStarGift for reference.
type PaymentsConvertStarGiftRequest struct {
// UserID field of PaymentsConvertStarGiftRequest.
UserID InputUserClass
// MsgID field of PaymentsConvertStarGiftRequest.
MsgID int
}
// PaymentsConvertStarGiftRequestTypeID is TL type id of PaymentsConvertStarGiftRequest.
const PaymentsConvertStarGiftRequestTypeID = 0x421e027
// Ensuring interfaces in compile-time for PaymentsConvertStarGiftRequest.
var (
_ bin.Encoder = &PaymentsConvertStarGiftRequest{}
_ bin.Decoder = &PaymentsConvertStarGiftRequest{}
_ bin.BareEncoder = &PaymentsConvertStarGiftRequest{}
_ bin.BareDecoder = &PaymentsConvertStarGiftRequest{}
)
func (c *PaymentsConvertStarGiftRequest) Zero() bool {
if c == nil {
return true
}
if !(c.UserID == nil) {
return false
}
if !(c.MsgID == 0) {
return false
}
return true
}
// String implements fmt.Stringer.
func (c *PaymentsConvertStarGiftRequest) String() string {
if c == nil {
return "PaymentsConvertStarGiftRequest(nil)"
}
type Alias PaymentsConvertStarGiftRequest
return fmt.Sprintf("PaymentsConvertStarGiftRequest%+v", Alias(*c))
}
// FillFrom fills PaymentsConvertStarGiftRequest from given interface.
func (c *PaymentsConvertStarGiftRequest) FillFrom(from interface {
GetUserID() (value InputUserClass)
GetMsgID() (value int)
}) {
c.UserID = from.GetUserID()
c.MsgID = from.GetMsgID()
}
// TypeID returns type id in TL schema.
//
// See https://core.telegram.org/mtproto/TL-tl#remarks.
func (*PaymentsConvertStarGiftRequest) TypeID() uint32 {
return PaymentsConvertStarGiftRequestTypeID
}
// TypeName returns name of type in TL schema.
func (*PaymentsConvertStarGiftRequest) TypeName() string {
return "payments.convertStarGift"
}
// TypeInfo returns info about TL type.
func (c *PaymentsConvertStarGiftRequest) TypeInfo() tdp.Type {
typ := tdp.Type{
Name: "payments.convertStarGift",
ID: PaymentsConvertStarGiftRequestTypeID,
}
if c == nil {
typ.Null = true
return typ
}
typ.Fields = []tdp.Field{
{
Name: "UserID",
SchemaName: "user_id",
},
{
Name: "MsgID",
SchemaName: "msg_id",
},
}
return typ
}
// Encode implements bin.Encoder.
func (c *PaymentsConvertStarGiftRequest) Encode(b *bin.Buffer) error {
if c == nil {
return fmt.Errorf("can't encode payments.convertStarGift#421e027 as nil")
}
b.PutID(PaymentsConvertStarGiftRequestTypeID)
return c.EncodeBare(b)
}
// EncodeBare implements bin.BareEncoder.
func (c *PaymentsConvertStarGiftRequest) EncodeBare(b *bin.Buffer) error {
if c == nil {
return fmt.Errorf("can't encode payments.convertStarGift#421e027 as nil")
}
if c.UserID == nil {
return fmt.Errorf("unable to encode payments.convertStarGift#421e027: field user_id is nil")
}
if err := c.UserID.Encode(b); err != nil {
return fmt.Errorf("unable to encode payments.convertStarGift#421e027: field user_id: %w", err)
}
b.PutInt(c.MsgID)
return nil
}
// Decode implements bin.Decoder.
func (c *PaymentsConvertStarGiftRequest) Decode(b *bin.Buffer) error {
if c == nil {
return fmt.Errorf("can't decode payments.convertStarGift#421e027 to nil")
}
if err := b.ConsumeID(PaymentsConvertStarGiftRequestTypeID); err != nil {
return fmt.Errorf("unable to decode payments.convertStarGift#421e027: %w", err)
}
return c.DecodeBare(b)
}
// DecodeBare implements bin.BareDecoder.
func (c *PaymentsConvertStarGiftRequest) DecodeBare(b *bin.Buffer) error {
if c == nil {
return fmt.Errorf("can't decode payments.convertStarGift#421e027 to nil")
}
{
value, err := DecodeInputUser(b)
if err != nil {
return fmt.Errorf("unable to decode payments.convertStarGift#421e027: field user_id: %w", err)
}
c.UserID = value
}
{
value, err := b.Int()
if err != nil {
return fmt.Errorf("unable to decode payments.convertStarGift#421e027: field msg_id: %w", err)
}
c.MsgID = value
}
return nil
}
// GetUserID returns value of UserID field.
func (c *PaymentsConvertStarGiftRequest) GetUserID() (value InputUserClass) {
if c == nil {
return
}
return c.UserID
}
// GetMsgID returns value of MsgID field.
func (c *PaymentsConvertStarGiftRequest) GetMsgID() (value int) {
if c == nil {
return
}
return c.MsgID
}
// PaymentsConvertStarGift invokes method payments.convertStarGift#421e027 returning error if any.
//
// See https://core.telegram.org/method/payments.convertStarGift for reference.
func (c *Client) PaymentsConvertStarGift(ctx context.Context, request *PaymentsConvertStarGiftRequest) (bool, error) {
var result BoolBox
if err := c.rpc.Invoke(ctx, request, &result); err != nil {
return false, err
}
_, ok := result.Bool.(*BoolTrue)
return ok, nil
}

View File

@ -0,0 +1,35 @@
//go:build !no_gotd_slices
// +build !no_gotd_slices
// Code generated by gotdgen, DO NOT EDIT.
package tg
import (
"context"
"errors"
"fmt"
"sort"
"strings"
"go.uber.org/multierr"
"github.com/gotd/td/bin"
"github.com/gotd/td/tdjson"
"github.com/gotd/td/tdp"
"github.com/gotd/td/tgerr"
)
// No-op definition for keeping imports.
var (
_ = bin.Buffer{}
_ = context.Background()
_ = fmt.Stringer(nil)
_ = strings.Builder{}
_ = errors.Is
_ = multierr.AppendInto
_ = sort.Ints
_ = tdp.Format
_ = tgerr.Error{}
_ = tdjson.Encoder{}
)

View File

@ -0,0 +1,176 @@
// Code generated by gotdgen, DO NOT EDIT.
package tg
import (
"context"
"errors"
"fmt"
"sort"
"strings"
"go.uber.org/multierr"
"github.com/gotd/td/bin"
"github.com/gotd/td/tdjson"
"github.com/gotd/td/tdp"
"github.com/gotd/td/tgerr"
)
// No-op definition for keeping imports.
var (
_ = bin.Buffer{}
_ = context.Background()
_ = fmt.Stringer(nil)
_ = strings.Builder{}
_ = errors.Is
_ = multierr.AppendInto
_ = sort.Ints
_ = tdp.Format
_ = tgerr.Error{}
_ = tdjson.Encoder{}
)
// PaymentsGetStarGiftsRequest represents TL type `payments.getStarGifts#c4563590`.
//
// See https://core.telegram.org/method/payments.getStarGifts for reference.
type PaymentsGetStarGiftsRequest struct {
// Hash field of PaymentsGetStarGiftsRequest.
Hash int
}
// PaymentsGetStarGiftsRequestTypeID is TL type id of PaymentsGetStarGiftsRequest.
const PaymentsGetStarGiftsRequestTypeID = 0xc4563590
// Ensuring interfaces in compile-time for PaymentsGetStarGiftsRequest.
var (
_ bin.Encoder = &PaymentsGetStarGiftsRequest{}
_ bin.Decoder = &PaymentsGetStarGiftsRequest{}
_ bin.BareEncoder = &PaymentsGetStarGiftsRequest{}
_ bin.BareDecoder = &PaymentsGetStarGiftsRequest{}
)
func (g *PaymentsGetStarGiftsRequest) Zero() bool {
if g == nil {
return true
}
if !(g.Hash == 0) {
return false
}
return true
}
// String implements fmt.Stringer.
func (g *PaymentsGetStarGiftsRequest) String() string {
if g == nil {
return "PaymentsGetStarGiftsRequest(nil)"
}
type Alias PaymentsGetStarGiftsRequest
return fmt.Sprintf("PaymentsGetStarGiftsRequest%+v", Alias(*g))
}
// FillFrom fills PaymentsGetStarGiftsRequest from given interface.
func (g *PaymentsGetStarGiftsRequest) FillFrom(from interface {
GetHash() (value int)
}) {
g.Hash = from.GetHash()
}
// TypeID returns type id in TL schema.
//
// See https://core.telegram.org/mtproto/TL-tl#remarks.
func (*PaymentsGetStarGiftsRequest) TypeID() uint32 {
return PaymentsGetStarGiftsRequestTypeID
}
// TypeName returns name of type in TL schema.
func (*PaymentsGetStarGiftsRequest) TypeName() string {
return "payments.getStarGifts"
}
// TypeInfo returns info about TL type.
func (g *PaymentsGetStarGiftsRequest) TypeInfo() tdp.Type {
typ := tdp.Type{
Name: "payments.getStarGifts",
ID: PaymentsGetStarGiftsRequestTypeID,
}
if g == nil {
typ.Null = true
return typ
}
typ.Fields = []tdp.Field{
{
Name: "Hash",
SchemaName: "hash",
},
}
return typ
}
// Encode implements bin.Encoder.
func (g *PaymentsGetStarGiftsRequest) Encode(b *bin.Buffer) error {
if g == nil {
return fmt.Errorf("can't encode payments.getStarGifts#c4563590 as nil")
}
b.PutID(PaymentsGetStarGiftsRequestTypeID)
return g.EncodeBare(b)
}
// EncodeBare implements bin.BareEncoder.
func (g *PaymentsGetStarGiftsRequest) EncodeBare(b *bin.Buffer) error {
if g == nil {
return fmt.Errorf("can't encode payments.getStarGifts#c4563590 as nil")
}
b.PutInt(g.Hash)
return nil
}
// Decode implements bin.Decoder.
func (g *PaymentsGetStarGiftsRequest) Decode(b *bin.Buffer) error {
if g == nil {
return fmt.Errorf("can't decode payments.getStarGifts#c4563590 to nil")
}
if err := b.ConsumeID(PaymentsGetStarGiftsRequestTypeID); err != nil {
return fmt.Errorf("unable to decode payments.getStarGifts#c4563590: %w", err)
}
return g.DecodeBare(b)
}
// DecodeBare implements bin.BareDecoder.
func (g *PaymentsGetStarGiftsRequest) DecodeBare(b *bin.Buffer) error {
if g == nil {
return fmt.Errorf("can't decode payments.getStarGifts#c4563590 to nil")
}
{
value, err := b.Int()
if err != nil {
return fmt.Errorf("unable to decode payments.getStarGifts#c4563590: field hash: %w", err)
}
g.Hash = value
}
return nil
}
// GetHash returns value of Hash field.
func (g *PaymentsGetStarGiftsRequest) GetHash() (value int) {
if g == nil {
return
}
return g.Hash
}
// PaymentsGetStarGifts invokes method payments.getStarGifts#c4563590 returning error if any.
//
// See https://core.telegram.org/method/payments.getStarGifts for reference.
func (c *Client) PaymentsGetStarGifts(ctx context.Context, hash int) (PaymentsStarGiftsClass, error) {
var result PaymentsStarGiftsBox
request := &PaymentsGetStarGiftsRequest{
Hash: hash,
}
if err := c.rpc.Invoke(ctx, request, &result); err != nil {
return nil, err
}
return result.StarGifts, nil
}

View File

@ -0,0 +1,35 @@
//go:build !no_gotd_slices
// +build !no_gotd_slices
// Code generated by gotdgen, DO NOT EDIT.
package tg
import (
"context"
"errors"
"fmt"
"sort"
"strings"
"go.uber.org/multierr"
"github.com/gotd/td/bin"
"github.com/gotd/td/tdjson"
"github.com/gotd/td/tdp"
"github.com/gotd/td/tgerr"
)
// No-op definition for keeping imports.
var (
_ = bin.Buffer{}
_ = context.Background()
_ = fmt.Stringer(nil)
_ = strings.Builder{}
_ = errors.Is
_ = multierr.AppendInto
_ = sort.Ints
_ = tdp.Format
_ = tgerr.Error{}
_ = tdjson.Encoder{}
)

View File

@ -0,0 +1,232 @@
// Code generated by gotdgen, DO NOT EDIT.
package tg
import (
"context"
"errors"
"fmt"
"sort"
"strings"
"go.uber.org/multierr"
"github.com/gotd/td/bin"
"github.com/gotd/td/tdjson"
"github.com/gotd/td/tdp"
"github.com/gotd/td/tgerr"
)
// No-op definition for keeping imports.
var (
_ = bin.Buffer{}
_ = context.Background()
_ = fmt.Stringer(nil)
_ = strings.Builder{}
_ = errors.Is
_ = multierr.AppendInto
_ = sort.Ints
_ = tdp.Format
_ = tgerr.Error{}
_ = tdjson.Encoder{}
)
// PaymentsGetUserStarGiftsRequest represents TL type `payments.getUserStarGifts#5e72c7e1`.
//
// See https://core.telegram.org/method/payments.getUserStarGifts for reference.
type PaymentsGetUserStarGiftsRequest struct {
// UserID field of PaymentsGetUserStarGiftsRequest.
UserID InputUserClass
// Offset field of PaymentsGetUserStarGiftsRequest.
Offset string
// Limit field of PaymentsGetUserStarGiftsRequest.
Limit int
}
// PaymentsGetUserStarGiftsRequestTypeID is TL type id of PaymentsGetUserStarGiftsRequest.
const PaymentsGetUserStarGiftsRequestTypeID = 0x5e72c7e1
// Ensuring interfaces in compile-time for PaymentsGetUserStarGiftsRequest.
var (
_ bin.Encoder = &PaymentsGetUserStarGiftsRequest{}
_ bin.Decoder = &PaymentsGetUserStarGiftsRequest{}
_ bin.BareEncoder = &PaymentsGetUserStarGiftsRequest{}
_ bin.BareDecoder = &PaymentsGetUserStarGiftsRequest{}
)
func (g *PaymentsGetUserStarGiftsRequest) Zero() bool {
if g == nil {
return true
}
if !(g.UserID == nil) {
return false
}
if !(g.Offset == "") {
return false
}
if !(g.Limit == 0) {
return false
}
return true
}
// String implements fmt.Stringer.
func (g *PaymentsGetUserStarGiftsRequest) String() string {
if g == nil {
return "PaymentsGetUserStarGiftsRequest(nil)"
}
type Alias PaymentsGetUserStarGiftsRequest
return fmt.Sprintf("PaymentsGetUserStarGiftsRequest%+v", Alias(*g))
}
// FillFrom fills PaymentsGetUserStarGiftsRequest from given interface.
func (g *PaymentsGetUserStarGiftsRequest) FillFrom(from interface {
GetUserID() (value InputUserClass)
GetOffset() (value string)
GetLimit() (value int)
}) {
g.UserID = from.GetUserID()
g.Offset = from.GetOffset()
g.Limit = from.GetLimit()
}
// TypeID returns type id in TL schema.
//
// See https://core.telegram.org/mtproto/TL-tl#remarks.
func (*PaymentsGetUserStarGiftsRequest) TypeID() uint32 {
return PaymentsGetUserStarGiftsRequestTypeID
}
// TypeName returns name of type in TL schema.
func (*PaymentsGetUserStarGiftsRequest) TypeName() string {
return "payments.getUserStarGifts"
}
// TypeInfo returns info about TL type.
func (g *PaymentsGetUserStarGiftsRequest) TypeInfo() tdp.Type {
typ := tdp.Type{
Name: "payments.getUserStarGifts",
ID: PaymentsGetUserStarGiftsRequestTypeID,
}
if g == nil {
typ.Null = true
return typ
}
typ.Fields = []tdp.Field{
{
Name: "UserID",
SchemaName: "user_id",
},
{
Name: "Offset",
SchemaName: "offset",
},
{
Name: "Limit",
SchemaName: "limit",
},
}
return typ
}
// Encode implements bin.Encoder.
func (g *PaymentsGetUserStarGiftsRequest) Encode(b *bin.Buffer) error {
if g == nil {
return fmt.Errorf("can't encode payments.getUserStarGifts#5e72c7e1 as nil")
}
b.PutID(PaymentsGetUserStarGiftsRequestTypeID)
return g.EncodeBare(b)
}
// EncodeBare implements bin.BareEncoder.
func (g *PaymentsGetUserStarGiftsRequest) EncodeBare(b *bin.Buffer) error {
if g == nil {
return fmt.Errorf("can't encode payments.getUserStarGifts#5e72c7e1 as nil")
}
if g.UserID == nil {
return fmt.Errorf("unable to encode payments.getUserStarGifts#5e72c7e1: field user_id is nil")
}
if err := g.UserID.Encode(b); err != nil {
return fmt.Errorf("unable to encode payments.getUserStarGifts#5e72c7e1: field user_id: %w", err)
}
b.PutString(g.Offset)
b.PutInt(g.Limit)
return nil
}
// Decode implements bin.Decoder.
func (g *PaymentsGetUserStarGiftsRequest) Decode(b *bin.Buffer) error {
if g == nil {
return fmt.Errorf("can't decode payments.getUserStarGifts#5e72c7e1 to nil")
}
if err := b.ConsumeID(PaymentsGetUserStarGiftsRequestTypeID); err != nil {
return fmt.Errorf("unable to decode payments.getUserStarGifts#5e72c7e1: %w", err)
}
return g.DecodeBare(b)
}
// DecodeBare implements bin.BareDecoder.
func (g *PaymentsGetUserStarGiftsRequest) DecodeBare(b *bin.Buffer) error {
if g == nil {
return fmt.Errorf("can't decode payments.getUserStarGifts#5e72c7e1 to nil")
}
{
value, err := DecodeInputUser(b)
if err != nil {
return fmt.Errorf("unable to decode payments.getUserStarGifts#5e72c7e1: field user_id: %w", err)
}
g.UserID = value
}
{
value, err := b.String()
if err != nil {
return fmt.Errorf("unable to decode payments.getUserStarGifts#5e72c7e1: field offset: %w", err)
}
g.Offset = value
}
{
value, err := b.Int()
if err != nil {
return fmt.Errorf("unable to decode payments.getUserStarGifts#5e72c7e1: field limit: %w", err)
}
g.Limit = value
}
return nil
}
// GetUserID returns value of UserID field.
func (g *PaymentsGetUserStarGiftsRequest) GetUserID() (value InputUserClass) {
if g == nil {
return
}
return g.UserID
}
// GetOffset returns value of Offset field.
func (g *PaymentsGetUserStarGiftsRequest) GetOffset() (value string) {
if g == nil {
return
}
return g.Offset
}
// GetLimit returns value of Limit field.
func (g *PaymentsGetUserStarGiftsRequest) GetLimit() (value int) {
if g == nil {
return
}
return g.Limit
}
// PaymentsGetUserStarGifts invokes method payments.getUserStarGifts#5e72c7e1 returning error if any.
//
// See https://core.telegram.org/method/payments.getUserStarGifts for reference.
func (c *Client) PaymentsGetUserStarGifts(ctx context.Context, request *PaymentsGetUserStarGiftsRequest) (*PaymentsUserStarGifts, error) {
var result PaymentsUserStarGifts
if err := c.rpc.Invoke(ctx, request, &result); err != nil {
return nil, err
}
return &result, nil
}

View File

@ -0,0 +1,35 @@
//go:build !no_gotd_slices
// +build !no_gotd_slices
// Code generated by gotdgen, DO NOT EDIT.
package tg
import (
"context"
"errors"
"fmt"
"sort"
"strings"
"go.uber.org/multierr"
"github.com/gotd/td/bin"
"github.com/gotd/td/tdjson"
"github.com/gotd/td/tdp"
"github.com/gotd/td/tgerr"
)
// No-op definition for keeping imports.
var (
_ = bin.Buffer{}
_ = context.Background()
_ = fmt.Stringer(nil)
_ = strings.Builder{}
_ = errors.Is
_ = multierr.AppendInto
_ = sort.Ints
_ = tdp.Format
_ = tgerr.Error{}
_ = tdjson.Encoder{}
)

View File

@ -1173,6 +1173,167 @@ func (p *PaymentsPaymentFormStars) MapUsers() (value UserClassArray) {
return UserClassArray(p.Users)
}
// PaymentsPaymentFormStarGift represents TL type `payments.paymentFormStarGift#b425cfe1`.
//
// See https://core.telegram.org/constructor/payments.paymentFormStarGift for reference.
type PaymentsPaymentFormStarGift struct {
// FormID field of PaymentsPaymentFormStarGift.
FormID int64
// Invoice field of PaymentsPaymentFormStarGift.
Invoice Invoice
}
// PaymentsPaymentFormStarGiftTypeID is TL type id of PaymentsPaymentFormStarGift.
const PaymentsPaymentFormStarGiftTypeID = 0xb425cfe1
// construct implements constructor of PaymentsPaymentFormClass.
func (p PaymentsPaymentFormStarGift) construct() PaymentsPaymentFormClass { return &p }
// Ensuring interfaces in compile-time for PaymentsPaymentFormStarGift.
var (
_ bin.Encoder = &PaymentsPaymentFormStarGift{}
_ bin.Decoder = &PaymentsPaymentFormStarGift{}
_ bin.BareEncoder = &PaymentsPaymentFormStarGift{}
_ bin.BareDecoder = &PaymentsPaymentFormStarGift{}
_ PaymentsPaymentFormClass = &PaymentsPaymentFormStarGift{}
)
func (p *PaymentsPaymentFormStarGift) Zero() bool {
if p == nil {
return true
}
if !(p.FormID == 0) {
return false
}
if !(p.Invoice.Zero()) {
return false
}
return true
}
// String implements fmt.Stringer.
func (p *PaymentsPaymentFormStarGift) String() string {
if p == nil {
return "PaymentsPaymentFormStarGift(nil)"
}
type Alias PaymentsPaymentFormStarGift
return fmt.Sprintf("PaymentsPaymentFormStarGift%+v", Alias(*p))
}
// FillFrom fills PaymentsPaymentFormStarGift from given interface.
func (p *PaymentsPaymentFormStarGift) FillFrom(from interface {
GetFormID() (value int64)
GetInvoice() (value Invoice)
}) {
p.FormID = from.GetFormID()
p.Invoice = from.GetInvoice()
}
// TypeID returns type id in TL schema.
//
// See https://core.telegram.org/mtproto/TL-tl#remarks.
func (*PaymentsPaymentFormStarGift) TypeID() uint32 {
return PaymentsPaymentFormStarGiftTypeID
}
// TypeName returns name of type in TL schema.
func (*PaymentsPaymentFormStarGift) TypeName() string {
return "payments.paymentFormStarGift"
}
// TypeInfo returns info about TL type.
func (p *PaymentsPaymentFormStarGift) TypeInfo() tdp.Type {
typ := tdp.Type{
Name: "payments.paymentFormStarGift",
ID: PaymentsPaymentFormStarGiftTypeID,
}
if p == nil {
typ.Null = true
return typ
}
typ.Fields = []tdp.Field{
{
Name: "FormID",
SchemaName: "form_id",
},
{
Name: "Invoice",
SchemaName: "invoice",
},
}
return typ
}
// Encode implements bin.Encoder.
func (p *PaymentsPaymentFormStarGift) Encode(b *bin.Buffer) error {
if p == nil {
return fmt.Errorf("can't encode payments.paymentFormStarGift#b425cfe1 as nil")
}
b.PutID(PaymentsPaymentFormStarGiftTypeID)
return p.EncodeBare(b)
}
// EncodeBare implements bin.BareEncoder.
func (p *PaymentsPaymentFormStarGift) EncodeBare(b *bin.Buffer) error {
if p == nil {
return fmt.Errorf("can't encode payments.paymentFormStarGift#b425cfe1 as nil")
}
b.PutLong(p.FormID)
if err := p.Invoice.Encode(b); err != nil {
return fmt.Errorf("unable to encode payments.paymentFormStarGift#b425cfe1: field invoice: %w", err)
}
return nil
}
// Decode implements bin.Decoder.
func (p *PaymentsPaymentFormStarGift) Decode(b *bin.Buffer) error {
if p == nil {
return fmt.Errorf("can't decode payments.paymentFormStarGift#b425cfe1 to nil")
}
if err := b.ConsumeID(PaymentsPaymentFormStarGiftTypeID); err != nil {
return fmt.Errorf("unable to decode payments.paymentFormStarGift#b425cfe1: %w", err)
}
return p.DecodeBare(b)
}
// DecodeBare implements bin.BareDecoder.
func (p *PaymentsPaymentFormStarGift) DecodeBare(b *bin.Buffer) error {
if p == nil {
return fmt.Errorf("can't decode payments.paymentFormStarGift#b425cfe1 to nil")
}
{
value, err := b.Long()
if err != nil {
return fmt.Errorf("unable to decode payments.paymentFormStarGift#b425cfe1: field form_id: %w", err)
}
p.FormID = value
}
{
if err := p.Invoice.Decode(b); err != nil {
return fmt.Errorf("unable to decode payments.paymentFormStarGift#b425cfe1: field invoice: %w", err)
}
}
return nil
}
// GetFormID returns value of FormID field.
func (p *PaymentsPaymentFormStarGift) GetFormID() (value int64) {
if p == nil {
return
}
return p.FormID
}
// GetInvoice returns value of Invoice field.
func (p *PaymentsPaymentFormStarGift) GetInvoice() (value Invoice) {
if p == nil {
return
}
return p.Invoice
}
// PaymentsPaymentFormClassName is schema name of PaymentsPaymentFormClass.
const PaymentsPaymentFormClassName = "payments.PaymentForm"
@ -1189,6 +1350,7 @@ const PaymentsPaymentFormClassName = "payments.PaymentForm"
// switch v := g.(type) {
// case *tg.PaymentsPaymentForm: // payments.paymentForm#a0058751
// case *tg.PaymentsPaymentFormStars: // payments.paymentFormStars#7bf6b15c
// case *tg.PaymentsPaymentFormStarGift: // payments.paymentFormStarGift#b425cfe1
// default: panic(v)
// }
type PaymentsPaymentFormClass interface {
@ -1212,25 +1374,8 @@ type PaymentsPaymentFormClass interface {
// Form ID
GetFormID() (value int64)
// Bot ID
GetBotID() (value int64)
// Form title
GetTitle() (value string)
// Description
GetDescription() (value string)
// Product photo
GetPhoto() (value WebDocumentClass, ok bool)
// Invoice
GetInvoice() (value Invoice)
// Users
GetUsers() (value []UserClass)
// Users
MapUsers() (value UserClassArray)
}
// DecodePaymentsPaymentForm implements binary de-serialization for PaymentsPaymentFormClass.
@ -1254,6 +1399,13 @@ func DecodePaymentsPaymentForm(buf *bin.Buffer) (PaymentsPaymentFormClass, error
return nil, fmt.Errorf("unable to decode PaymentsPaymentFormClass: %w", err)
}
return &v, nil
case PaymentsPaymentFormStarGiftTypeID:
// Decoding payments.paymentFormStarGift#b425cfe1.
v := PaymentsPaymentFormStarGift{}
if err := v.Decode(buf); err != nil {
return nil, fmt.Errorf("unable to decode PaymentsPaymentFormClass: %w", err)
}
return &v, nil
default:
return nil, fmt.Errorf("unable to decode PaymentsPaymentFormClass: %w", bin.NewUnexpectedID(id))
}

View File

@ -142,6 +142,19 @@ func (s PaymentsPaymentFormClassArray) AsPaymentsPaymentFormStars() (to Payments
return to
}
// AsPaymentsPaymentFormStarGift returns copy with only PaymentsPaymentFormStarGift constructors.
func (s PaymentsPaymentFormClassArray) AsPaymentsPaymentFormStarGift() (to PaymentsPaymentFormStarGiftArray) {
for _, elem := range s {
value, ok := elem.(*PaymentsPaymentFormStarGift)
if !ok {
continue
}
to = append(to, *value)
}
return to
}
// PaymentsPaymentFormArray is adapter for slice of PaymentsPaymentForm.
type PaymentsPaymentFormArray []PaymentsPaymentForm
@ -305,3 +318,85 @@ func (s *PaymentsPaymentFormStarsArray) Pop() (v PaymentsPaymentFormStars, ok bo
return v, true
}
// PaymentsPaymentFormStarGiftArray is adapter for slice of PaymentsPaymentFormStarGift.
type PaymentsPaymentFormStarGiftArray []PaymentsPaymentFormStarGift
// Sort sorts slice of PaymentsPaymentFormStarGift.
func (s PaymentsPaymentFormStarGiftArray) Sort(less func(a, b PaymentsPaymentFormStarGift) bool) PaymentsPaymentFormStarGiftArray {
sort.Slice(s, func(i, j int) bool {
return less(s[i], s[j])
})
return s
}
// SortStable sorts slice of PaymentsPaymentFormStarGift.
func (s PaymentsPaymentFormStarGiftArray) SortStable(less func(a, b PaymentsPaymentFormStarGift) bool) PaymentsPaymentFormStarGiftArray {
sort.SliceStable(s, func(i, j int) bool {
return less(s[i], s[j])
})
return s
}
// Retain filters in-place slice of PaymentsPaymentFormStarGift.
func (s PaymentsPaymentFormStarGiftArray) Retain(keep func(x PaymentsPaymentFormStarGift) bool) PaymentsPaymentFormStarGiftArray {
n := 0
for _, x := range s {
if keep(x) {
s[n] = x
n++
}
}
s = s[:n]
return s
}
// First returns first element of slice (if exists).
func (s PaymentsPaymentFormStarGiftArray) First() (v PaymentsPaymentFormStarGift, ok bool) {
if len(s) < 1 {
return
}
return s[0], true
}
// Last returns last element of slice (if exists).
func (s PaymentsPaymentFormStarGiftArray) Last() (v PaymentsPaymentFormStarGift, ok bool) {
if len(s) < 1 {
return
}
return s[len(s)-1], true
}
// PopFirst returns first element of slice (if exists) and deletes it.
func (s *PaymentsPaymentFormStarGiftArray) PopFirst() (v PaymentsPaymentFormStarGift, ok bool) {
if s == nil || len(*s) < 1 {
return
}
a := *s
v = a[0]
// Delete by index from SliceTricks.
copy(a[0:], a[1:])
var zero PaymentsPaymentFormStarGift
a[len(a)-1] = zero
a = a[:len(a)-1]
*s = a
return v, true
}
// Pop returns last element of slice (if exists) and deletes it.
func (s *PaymentsPaymentFormStarGiftArray) Pop() (v PaymentsPaymentFormStarGift, ok bool) {
if s == nil || len(*s) < 1 {
return
}
a := *s
v = a[len(a)-1]
a = a[:len(a)-1]
*s = a
return v, true
}

View File

@ -0,0 +1,259 @@
// Code generated by gotdgen, DO NOT EDIT.
package tg
import (
"context"
"errors"
"fmt"
"sort"
"strings"
"go.uber.org/multierr"
"github.com/gotd/td/bin"
"github.com/gotd/td/tdjson"
"github.com/gotd/td/tdp"
"github.com/gotd/td/tgerr"
)
// No-op definition for keeping imports.
var (
_ = bin.Buffer{}
_ = context.Background()
_ = fmt.Stringer(nil)
_ = strings.Builder{}
_ = errors.Is
_ = multierr.AppendInto
_ = sort.Ints
_ = tdp.Format
_ = tgerr.Error{}
_ = tdjson.Encoder{}
)
// PaymentsSaveStarGiftRequest represents TL type `payments.saveStarGift#87acf08e`.
//
// See https://core.telegram.org/method/payments.saveStarGift for reference.
type PaymentsSaveStarGiftRequest struct {
// Flags field of PaymentsSaveStarGiftRequest.
Flags bin.Fields
// Unsave field of PaymentsSaveStarGiftRequest.
Unsave bool
// UserID field of PaymentsSaveStarGiftRequest.
UserID InputUserClass
// MsgID field of PaymentsSaveStarGiftRequest.
MsgID int
}
// PaymentsSaveStarGiftRequestTypeID is TL type id of PaymentsSaveStarGiftRequest.
const PaymentsSaveStarGiftRequestTypeID = 0x87acf08e
// Ensuring interfaces in compile-time for PaymentsSaveStarGiftRequest.
var (
_ bin.Encoder = &PaymentsSaveStarGiftRequest{}
_ bin.Decoder = &PaymentsSaveStarGiftRequest{}
_ bin.BareEncoder = &PaymentsSaveStarGiftRequest{}
_ bin.BareDecoder = &PaymentsSaveStarGiftRequest{}
)
func (s *PaymentsSaveStarGiftRequest) Zero() bool {
if s == nil {
return true
}
if !(s.Flags.Zero()) {
return false
}
if !(s.Unsave == false) {
return false
}
if !(s.UserID == nil) {
return false
}
if !(s.MsgID == 0) {
return false
}
return true
}
// String implements fmt.Stringer.
func (s *PaymentsSaveStarGiftRequest) String() string {
if s == nil {
return "PaymentsSaveStarGiftRequest(nil)"
}
type Alias PaymentsSaveStarGiftRequest
return fmt.Sprintf("PaymentsSaveStarGiftRequest%+v", Alias(*s))
}
// FillFrom fills PaymentsSaveStarGiftRequest from given interface.
func (s *PaymentsSaveStarGiftRequest) FillFrom(from interface {
GetUnsave() (value bool)
GetUserID() (value InputUserClass)
GetMsgID() (value int)
}) {
s.Unsave = from.GetUnsave()
s.UserID = from.GetUserID()
s.MsgID = from.GetMsgID()
}
// TypeID returns type id in TL schema.
//
// See https://core.telegram.org/mtproto/TL-tl#remarks.
func (*PaymentsSaveStarGiftRequest) TypeID() uint32 {
return PaymentsSaveStarGiftRequestTypeID
}
// TypeName returns name of type in TL schema.
func (*PaymentsSaveStarGiftRequest) TypeName() string {
return "payments.saveStarGift"
}
// TypeInfo returns info about TL type.
func (s *PaymentsSaveStarGiftRequest) TypeInfo() tdp.Type {
typ := tdp.Type{
Name: "payments.saveStarGift",
ID: PaymentsSaveStarGiftRequestTypeID,
}
if s == nil {
typ.Null = true
return typ
}
typ.Fields = []tdp.Field{
{
Name: "Unsave",
SchemaName: "unsave",
Null: !s.Flags.Has(0),
},
{
Name: "UserID",
SchemaName: "user_id",
},
{
Name: "MsgID",
SchemaName: "msg_id",
},
}
return typ
}
// SetFlags sets flags for non-zero fields.
func (s *PaymentsSaveStarGiftRequest) SetFlags() {
if !(s.Unsave == false) {
s.Flags.Set(0)
}
}
// Encode implements bin.Encoder.
func (s *PaymentsSaveStarGiftRequest) Encode(b *bin.Buffer) error {
if s == nil {
return fmt.Errorf("can't encode payments.saveStarGift#87acf08e as nil")
}
b.PutID(PaymentsSaveStarGiftRequestTypeID)
return s.EncodeBare(b)
}
// EncodeBare implements bin.BareEncoder.
func (s *PaymentsSaveStarGiftRequest) EncodeBare(b *bin.Buffer) error {
if s == nil {
return fmt.Errorf("can't encode payments.saveStarGift#87acf08e as nil")
}
s.SetFlags()
if err := s.Flags.Encode(b); err != nil {
return fmt.Errorf("unable to encode payments.saveStarGift#87acf08e: field flags: %w", err)
}
if s.UserID == nil {
return fmt.Errorf("unable to encode payments.saveStarGift#87acf08e: field user_id is nil")
}
if err := s.UserID.Encode(b); err != nil {
return fmt.Errorf("unable to encode payments.saveStarGift#87acf08e: field user_id: %w", err)
}
b.PutInt(s.MsgID)
return nil
}
// Decode implements bin.Decoder.
func (s *PaymentsSaveStarGiftRequest) Decode(b *bin.Buffer) error {
if s == nil {
return fmt.Errorf("can't decode payments.saveStarGift#87acf08e to nil")
}
if err := b.ConsumeID(PaymentsSaveStarGiftRequestTypeID); err != nil {
return fmt.Errorf("unable to decode payments.saveStarGift#87acf08e: %w", err)
}
return s.DecodeBare(b)
}
// DecodeBare implements bin.BareDecoder.
func (s *PaymentsSaveStarGiftRequest) DecodeBare(b *bin.Buffer) error {
if s == nil {
return fmt.Errorf("can't decode payments.saveStarGift#87acf08e to nil")
}
{
if err := s.Flags.Decode(b); err != nil {
return fmt.Errorf("unable to decode payments.saveStarGift#87acf08e: field flags: %w", err)
}
}
s.Unsave = s.Flags.Has(0)
{
value, err := DecodeInputUser(b)
if err != nil {
return fmt.Errorf("unable to decode payments.saveStarGift#87acf08e: field user_id: %w", err)
}
s.UserID = value
}
{
value, err := b.Int()
if err != nil {
return fmt.Errorf("unable to decode payments.saveStarGift#87acf08e: field msg_id: %w", err)
}
s.MsgID = value
}
return nil
}
// SetUnsave sets value of Unsave conditional field.
func (s *PaymentsSaveStarGiftRequest) SetUnsave(value bool) {
if value {
s.Flags.Set(0)
s.Unsave = true
} else {
s.Flags.Unset(0)
s.Unsave = false
}
}
// GetUnsave returns value of Unsave conditional field.
func (s *PaymentsSaveStarGiftRequest) GetUnsave() (value bool) {
if s == nil {
return
}
return s.Flags.Has(0)
}
// GetUserID returns value of UserID field.
func (s *PaymentsSaveStarGiftRequest) GetUserID() (value InputUserClass) {
if s == nil {
return
}
return s.UserID
}
// GetMsgID returns value of MsgID field.
func (s *PaymentsSaveStarGiftRequest) GetMsgID() (value int) {
if s == nil {
return
}
return s.MsgID
}
// PaymentsSaveStarGift invokes method payments.saveStarGift#87acf08e returning error if any.
//
// See https://core.telegram.org/method/payments.saveStarGift for reference.
func (c *Client) PaymentsSaveStarGift(ctx context.Context, request *PaymentsSaveStarGiftRequest) (bool, error) {
var result BoolBox
if err := c.rpc.Invoke(ctx, request, &result); err != nil {
return false, err
}
_, ok := result.Bool.(*BoolTrue)
return ok, nil
}

View File

@ -0,0 +1,35 @@
//go:build !no_gotd_slices
// +build !no_gotd_slices
// Code generated by gotdgen, DO NOT EDIT.
package tg
import (
"context"
"errors"
"fmt"
"sort"
"strings"
"go.uber.org/multierr"
"github.com/gotd/td/bin"
"github.com/gotd/td/tdjson"
"github.com/gotd/td/tdp"
"github.com/gotd/td/tgerr"
)
// No-op definition for keeping imports.
var (
_ = bin.Buffer{}
_ = context.Background()
_ = fmt.Stringer(nil)
_ = strings.Builder{}
_ = errors.Is
_ = multierr.AppendInto
_ = sort.Ints
_ = tdp.Format
_ = tgerr.Error{}
_ = tdjson.Encoder{}
)

View File

@ -31,7 +31,7 @@ var (
_ = tdjson.Encoder{}
)
// PaymentsSendStarsFormRequest represents TL type `payments.sendStarsForm#2bb731d`.
// PaymentsSendStarsFormRequest represents TL type `payments.sendStarsForm#7998c914`.
// Make a payment using Telegram Stars, see here »¹ for more info.
//
// Links:
@ -39,11 +39,6 @@ var (
//
// See https://core.telegram.org/method/payments.sendStarsForm for reference.
type PaymentsSendStarsFormRequest struct {
// Flags, see TL conditional fields¹
//
// Links:
// 1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
Flags bin.Fields
// Payment form ID
FormID int64
// Invoice
@ -51,7 +46,7 @@ type PaymentsSendStarsFormRequest struct {
}
// PaymentsSendStarsFormRequestTypeID is TL type id of PaymentsSendStarsFormRequest.
const PaymentsSendStarsFormRequestTypeID = 0x2bb731d
const PaymentsSendStarsFormRequestTypeID = 0x7998c914
// Ensuring interfaces in compile-time for PaymentsSendStarsFormRequest.
var (
@ -65,9 +60,6 @@ func (s *PaymentsSendStarsFormRequest) Zero() bool {
if s == nil {
return true
}
if !(s.Flags.Zero()) {
return false
}
if !(s.FormID == 0) {
return false
}
@ -131,14 +123,10 @@ func (s *PaymentsSendStarsFormRequest) TypeInfo() tdp.Type {
return typ
}
// SetFlags sets flags for non-zero fields.
func (s *PaymentsSendStarsFormRequest) SetFlags() {
}
// Encode implements bin.Encoder.
func (s *PaymentsSendStarsFormRequest) Encode(b *bin.Buffer) error {
if s == nil {
return fmt.Errorf("can't encode payments.sendStarsForm#2bb731d as nil")
return fmt.Errorf("can't encode payments.sendStarsForm#7998c914 as nil")
}
b.PutID(PaymentsSendStarsFormRequestTypeID)
return s.EncodeBare(b)
@ -147,18 +135,14 @@ func (s *PaymentsSendStarsFormRequest) Encode(b *bin.Buffer) error {
// EncodeBare implements bin.BareEncoder.
func (s *PaymentsSendStarsFormRequest) EncodeBare(b *bin.Buffer) error {
if s == nil {
return fmt.Errorf("can't encode payments.sendStarsForm#2bb731d as nil")
}
s.SetFlags()
if err := s.Flags.Encode(b); err != nil {
return fmt.Errorf("unable to encode payments.sendStarsForm#2bb731d: field flags: %w", err)
return fmt.Errorf("can't encode payments.sendStarsForm#7998c914 as nil")
}
b.PutLong(s.FormID)
if s.Invoice == nil {
return fmt.Errorf("unable to encode payments.sendStarsForm#2bb731d: field invoice is nil")
return fmt.Errorf("unable to encode payments.sendStarsForm#7998c914: field invoice is nil")
}
if err := s.Invoice.Encode(b); err != nil {
return fmt.Errorf("unable to encode payments.sendStarsForm#2bb731d: field invoice: %w", err)
return fmt.Errorf("unable to encode payments.sendStarsForm#7998c914: field invoice: %w", err)
}
return nil
}
@ -166,10 +150,10 @@ func (s *PaymentsSendStarsFormRequest) EncodeBare(b *bin.Buffer) error {
// Decode implements bin.Decoder.
func (s *PaymentsSendStarsFormRequest) Decode(b *bin.Buffer) error {
if s == nil {
return fmt.Errorf("can't decode payments.sendStarsForm#2bb731d to nil")
return fmt.Errorf("can't decode payments.sendStarsForm#7998c914 to nil")
}
if err := b.ConsumeID(PaymentsSendStarsFormRequestTypeID); err != nil {
return fmt.Errorf("unable to decode payments.sendStarsForm#2bb731d: %w", err)
return fmt.Errorf("unable to decode payments.sendStarsForm#7998c914: %w", err)
}
return s.DecodeBare(b)
}
@ -177,24 +161,19 @@ func (s *PaymentsSendStarsFormRequest) Decode(b *bin.Buffer) error {
// DecodeBare implements bin.BareDecoder.
func (s *PaymentsSendStarsFormRequest) DecodeBare(b *bin.Buffer) error {
if s == nil {
return fmt.Errorf("can't decode payments.sendStarsForm#2bb731d to nil")
}
{
if err := s.Flags.Decode(b); err != nil {
return fmt.Errorf("unable to decode payments.sendStarsForm#2bb731d: field flags: %w", err)
}
return fmt.Errorf("can't decode payments.sendStarsForm#7998c914 to nil")
}
{
value, err := b.Long()
if err != nil {
return fmt.Errorf("unable to decode payments.sendStarsForm#2bb731d: field form_id: %w", err)
return fmt.Errorf("unable to decode payments.sendStarsForm#7998c914: field form_id: %w", err)
}
s.FormID = value
}
{
value, err := DecodeInputInvoice(b)
if err != nil {
return fmt.Errorf("unable to decode payments.sendStarsForm#2bb731d: field invoice: %w", err)
return fmt.Errorf("unable to decode payments.sendStarsForm#7998c914: field invoice: %w", err)
}
s.Invoice = value
}
@ -217,7 +196,7 @@ func (s *PaymentsSendStarsFormRequest) GetInvoice() (value InputInvoiceClass) {
return s.Invoice
}
// PaymentsSendStarsForm invokes method payments.sendStarsForm#2bb731d returning error if any.
// PaymentsSendStarsForm invokes method payments.sendStarsForm#7998c914 returning error if any.
// Make a payment using Telegram Stars, see here »¹ for more info.
//
// Links:

View File

@ -0,0 +1,411 @@
// Code generated by gotdgen, DO NOT EDIT.
package tg
import (
"context"
"errors"
"fmt"
"sort"
"strings"
"go.uber.org/multierr"
"github.com/gotd/td/bin"
"github.com/gotd/td/tdjson"
"github.com/gotd/td/tdp"
"github.com/gotd/td/tgerr"
)
// No-op definition for keeping imports.
var (
_ = bin.Buffer{}
_ = context.Background()
_ = fmt.Stringer(nil)
_ = strings.Builder{}
_ = errors.Is
_ = multierr.AppendInto
_ = sort.Ints
_ = tdp.Format
_ = tgerr.Error{}
_ = tdjson.Encoder{}
)
// PaymentsStarGiftsNotModified represents TL type `payments.starGiftsNotModified#a388a368`.
//
// See https://core.telegram.org/constructor/payments.starGiftsNotModified for reference.
type PaymentsStarGiftsNotModified struct {
}
// PaymentsStarGiftsNotModifiedTypeID is TL type id of PaymentsStarGiftsNotModified.
const PaymentsStarGiftsNotModifiedTypeID = 0xa388a368
// construct implements constructor of PaymentsStarGiftsClass.
func (s PaymentsStarGiftsNotModified) construct() PaymentsStarGiftsClass { return &s }
// Ensuring interfaces in compile-time for PaymentsStarGiftsNotModified.
var (
_ bin.Encoder = &PaymentsStarGiftsNotModified{}
_ bin.Decoder = &PaymentsStarGiftsNotModified{}
_ bin.BareEncoder = &PaymentsStarGiftsNotModified{}
_ bin.BareDecoder = &PaymentsStarGiftsNotModified{}
_ PaymentsStarGiftsClass = &PaymentsStarGiftsNotModified{}
)
func (s *PaymentsStarGiftsNotModified) Zero() bool {
if s == nil {
return true
}
return true
}
// String implements fmt.Stringer.
func (s *PaymentsStarGiftsNotModified) String() string {
if s == nil {
return "PaymentsStarGiftsNotModified(nil)"
}
type Alias PaymentsStarGiftsNotModified
return fmt.Sprintf("PaymentsStarGiftsNotModified%+v", Alias(*s))
}
// TypeID returns type id in TL schema.
//
// See https://core.telegram.org/mtproto/TL-tl#remarks.
func (*PaymentsStarGiftsNotModified) TypeID() uint32 {
return PaymentsStarGiftsNotModifiedTypeID
}
// TypeName returns name of type in TL schema.
func (*PaymentsStarGiftsNotModified) TypeName() string {
return "payments.starGiftsNotModified"
}
// TypeInfo returns info about TL type.
func (s *PaymentsStarGiftsNotModified) TypeInfo() tdp.Type {
typ := tdp.Type{
Name: "payments.starGiftsNotModified",
ID: PaymentsStarGiftsNotModifiedTypeID,
}
if s == nil {
typ.Null = true
return typ
}
typ.Fields = []tdp.Field{}
return typ
}
// Encode implements bin.Encoder.
func (s *PaymentsStarGiftsNotModified) Encode(b *bin.Buffer) error {
if s == nil {
return fmt.Errorf("can't encode payments.starGiftsNotModified#a388a368 as nil")
}
b.PutID(PaymentsStarGiftsNotModifiedTypeID)
return s.EncodeBare(b)
}
// EncodeBare implements bin.BareEncoder.
func (s *PaymentsStarGiftsNotModified) EncodeBare(b *bin.Buffer) error {
if s == nil {
return fmt.Errorf("can't encode payments.starGiftsNotModified#a388a368 as nil")
}
return nil
}
// Decode implements bin.Decoder.
func (s *PaymentsStarGiftsNotModified) Decode(b *bin.Buffer) error {
if s == nil {
return fmt.Errorf("can't decode payments.starGiftsNotModified#a388a368 to nil")
}
if err := b.ConsumeID(PaymentsStarGiftsNotModifiedTypeID); err != nil {
return fmt.Errorf("unable to decode payments.starGiftsNotModified#a388a368: %w", err)
}
return s.DecodeBare(b)
}
// DecodeBare implements bin.BareDecoder.
func (s *PaymentsStarGiftsNotModified) DecodeBare(b *bin.Buffer) error {
if s == nil {
return fmt.Errorf("can't decode payments.starGiftsNotModified#a388a368 to nil")
}
return nil
}
// PaymentsStarGifts represents TL type `payments.starGifts#901689ea`.
//
// See https://core.telegram.org/constructor/payments.starGifts for reference.
type PaymentsStarGifts struct {
// Hash field of PaymentsStarGifts.
Hash int
// Gifts field of PaymentsStarGifts.
Gifts []StarGift
}
// PaymentsStarGiftsTypeID is TL type id of PaymentsStarGifts.
const PaymentsStarGiftsTypeID = 0x901689ea
// construct implements constructor of PaymentsStarGiftsClass.
func (s PaymentsStarGifts) construct() PaymentsStarGiftsClass { return &s }
// Ensuring interfaces in compile-time for PaymentsStarGifts.
var (
_ bin.Encoder = &PaymentsStarGifts{}
_ bin.Decoder = &PaymentsStarGifts{}
_ bin.BareEncoder = &PaymentsStarGifts{}
_ bin.BareDecoder = &PaymentsStarGifts{}
_ PaymentsStarGiftsClass = &PaymentsStarGifts{}
)
func (s *PaymentsStarGifts) Zero() bool {
if s == nil {
return true
}
if !(s.Hash == 0) {
return false
}
if !(s.Gifts == nil) {
return false
}
return true
}
// String implements fmt.Stringer.
func (s *PaymentsStarGifts) String() string {
if s == nil {
return "PaymentsStarGifts(nil)"
}
type Alias PaymentsStarGifts
return fmt.Sprintf("PaymentsStarGifts%+v", Alias(*s))
}
// FillFrom fills PaymentsStarGifts from given interface.
func (s *PaymentsStarGifts) FillFrom(from interface {
GetHash() (value int)
GetGifts() (value []StarGift)
}) {
s.Hash = from.GetHash()
s.Gifts = from.GetGifts()
}
// TypeID returns type id in TL schema.
//
// See https://core.telegram.org/mtproto/TL-tl#remarks.
func (*PaymentsStarGifts) TypeID() uint32 {
return PaymentsStarGiftsTypeID
}
// TypeName returns name of type in TL schema.
func (*PaymentsStarGifts) TypeName() string {
return "payments.starGifts"
}
// TypeInfo returns info about TL type.
func (s *PaymentsStarGifts) TypeInfo() tdp.Type {
typ := tdp.Type{
Name: "payments.starGifts",
ID: PaymentsStarGiftsTypeID,
}
if s == nil {
typ.Null = true
return typ
}
typ.Fields = []tdp.Field{
{
Name: "Hash",
SchemaName: "hash",
},
{
Name: "Gifts",
SchemaName: "gifts",
},
}
return typ
}
// Encode implements bin.Encoder.
func (s *PaymentsStarGifts) Encode(b *bin.Buffer) error {
if s == nil {
return fmt.Errorf("can't encode payments.starGifts#901689ea as nil")
}
b.PutID(PaymentsStarGiftsTypeID)
return s.EncodeBare(b)
}
// EncodeBare implements bin.BareEncoder.
func (s *PaymentsStarGifts) EncodeBare(b *bin.Buffer) error {
if s == nil {
return fmt.Errorf("can't encode payments.starGifts#901689ea as nil")
}
b.PutInt(s.Hash)
b.PutVectorHeader(len(s.Gifts))
for idx, v := range s.Gifts {
if err := v.Encode(b); err != nil {
return fmt.Errorf("unable to encode payments.starGifts#901689ea: field gifts element with index %d: %w", idx, err)
}
}
return nil
}
// Decode implements bin.Decoder.
func (s *PaymentsStarGifts) Decode(b *bin.Buffer) error {
if s == nil {
return fmt.Errorf("can't decode payments.starGifts#901689ea to nil")
}
if err := b.ConsumeID(PaymentsStarGiftsTypeID); err != nil {
return fmt.Errorf("unable to decode payments.starGifts#901689ea: %w", err)
}
return s.DecodeBare(b)
}
// DecodeBare implements bin.BareDecoder.
func (s *PaymentsStarGifts) DecodeBare(b *bin.Buffer) error {
if s == nil {
return fmt.Errorf("can't decode payments.starGifts#901689ea to nil")
}
{
value, err := b.Int()
if err != nil {
return fmt.Errorf("unable to decode payments.starGifts#901689ea: field hash: %w", err)
}
s.Hash = value
}
{
headerLen, err := b.VectorHeader()
if err != nil {
return fmt.Errorf("unable to decode payments.starGifts#901689ea: field gifts: %w", err)
}
if headerLen > 0 {
s.Gifts = make([]StarGift, 0, headerLen%bin.PreallocateLimit)
}
for idx := 0; idx < headerLen; idx++ {
var value StarGift
if err := value.Decode(b); err != nil {
return fmt.Errorf("unable to decode payments.starGifts#901689ea: field gifts: %w", err)
}
s.Gifts = append(s.Gifts, value)
}
}
return nil
}
// GetHash returns value of Hash field.
func (s *PaymentsStarGifts) GetHash() (value int) {
if s == nil {
return
}
return s.Hash
}
// GetGifts returns value of Gifts field.
func (s *PaymentsStarGifts) GetGifts() (value []StarGift) {
if s == nil {
return
}
return s.Gifts
}
// PaymentsStarGiftsClassName is schema name of PaymentsStarGiftsClass.
const PaymentsStarGiftsClassName = "payments.StarGifts"
// PaymentsStarGiftsClass represents payments.StarGifts generic type.
//
// See https://core.telegram.org/type/payments.StarGifts for reference.
//
// Example:
//
// g, err := tg.DecodePaymentsStarGifts(buf)
// if err != nil {
// panic(err)
// }
// switch v := g.(type) {
// case *tg.PaymentsStarGiftsNotModified: // payments.starGiftsNotModified#a388a368
// case *tg.PaymentsStarGifts: // payments.starGifts#901689ea
// default: panic(v)
// }
type PaymentsStarGiftsClass interface {
bin.Encoder
bin.Decoder
bin.BareEncoder
bin.BareDecoder
construct() PaymentsStarGiftsClass
// TypeID returns type id in TL schema.
//
// See https://core.telegram.org/mtproto/TL-tl#remarks.
TypeID() uint32
// TypeName returns name of type in TL schema.
TypeName() string
// String implements fmt.Stringer.
String() string
// Zero returns true if current object has a zero value.
Zero() bool
// AsModified tries to map PaymentsStarGiftsClass to PaymentsStarGifts.
AsModified() (*PaymentsStarGifts, bool)
}
// AsModified tries to map PaymentsStarGiftsNotModified to PaymentsStarGifts.
func (s *PaymentsStarGiftsNotModified) AsModified() (*PaymentsStarGifts, bool) {
return nil, false
}
// AsModified tries to map PaymentsStarGifts to PaymentsStarGifts.
func (s *PaymentsStarGifts) AsModified() (*PaymentsStarGifts, bool) {
return s, true
}
// DecodePaymentsStarGifts implements binary de-serialization for PaymentsStarGiftsClass.
func DecodePaymentsStarGifts(buf *bin.Buffer) (PaymentsStarGiftsClass, error) {
id, err := buf.PeekID()
if err != nil {
return nil, err
}
switch id {
case PaymentsStarGiftsNotModifiedTypeID:
// Decoding payments.starGiftsNotModified#a388a368.
v := PaymentsStarGiftsNotModified{}
if err := v.Decode(buf); err != nil {
return nil, fmt.Errorf("unable to decode PaymentsStarGiftsClass: %w", err)
}
return &v, nil
case PaymentsStarGiftsTypeID:
// Decoding payments.starGifts#901689ea.
v := PaymentsStarGifts{}
if err := v.Decode(buf); err != nil {
return nil, fmt.Errorf("unable to decode PaymentsStarGiftsClass: %w", err)
}
return &v, nil
default:
return nil, fmt.Errorf("unable to decode PaymentsStarGiftsClass: %w", bin.NewUnexpectedID(id))
}
}
// PaymentsStarGifts boxes the PaymentsStarGiftsClass providing a helper.
type PaymentsStarGiftsBox struct {
StarGifts PaymentsStarGiftsClass
}
// Decode implements bin.Decoder for PaymentsStarGiftsBox.
func (b *PaymentsStarGiftsBox) Decode(buf *bin.Buffer) error {
if b == nil {
return fmt.Errorf("unable to decode PaymentsStarGiftsBox to nil")
}
v, err := DecodePaymentsStarGifts(buf)
if err != nil {
return fmt.Errorf("unable to decode boxed value: %w", err)
}
b.StarGifts = v
return nil
}
// Encode implements bin.Encode for PaymentsStarGiftsBox.
func (b *PaymentsStarGiftsBox) Encode(buf *bin.Buffer) error {
if b == nil || b.StarGifts == nil {
return fmt.Errorf("unable to encode PaymentsStarGiftsClass as nil")
}
return b.StarGifts.Encode(buf)
}

View File

@ -0,0 +1,267 @@
//go:build !no_gotd_slices
// +build !no_gotd_slices
// Code generated by gotdgen, DO NOT EDIT.
package tg
import (
"context"
"errors"
"fmt"
"sort"
"strings"
"go.uber.org/multierr"
"github.com/gotd/td/bin"
"github.com/gotd/td/tdjson"
"github.com/gotd/td/tdp"
"github.com/gotd/td/tgerr"
)
// No-op definition for keeping imports.
var (
_ = bin.Buffer{}
_ = context.Background()
_ = fmt.Stringer(nil)
_ = strings.Builder{}
_ = errors.Is
_ = multierr.AppendInto
_ = sort.Ints
_ = tdp.Format
_ = tgerr.Error{}
_ = tdjson.Encoder{}
)
// PaymentsStarGiftsClassArray is adapter for slice of PaymentsStarGiftsClass.
type PaymentsStarGiftsClassArray []PaymentsStarGiftsClass
// Sort sorts slice of PaymentsStarGiftsClass.
func (s PaymentsStarGiftsClassArray) Sort(less func(a, b PaymentsStarGiftsClass) bool) PaymentsStarGiftsClassArray {
sort.Slice(s, func(i, j int) bool {
return less(s[i], s[j])
})
return s
}
// SortStable sorts slice of PaymentsStarGiftsClass.
func (s PaymentsStarGiftsClassArray) SortStable(less func(a, b PaymentsStarGiftsClass) bool) PaymentsStarGiftsClassArray {
sort.SliceStable(s, func(i, j int) bool {
return less(s[i], s[j])
})
return s
}
// Retain filters in-place slice of PaymentsStarGiftsClass.
func (s PaymentsStarGiftsClassArray) Retain(keep func(x PaymentsStarGiftsClass) bool) PaymentsStarGiftsClassArray {
n := 0
for _, x := range s {
if keep(x) {
s[n] = x
n++
}
}
s = s[:n]
return s
}
// First returns first element of slice (if exists).
func (s PaymentsStarGiftsClassArray) First() (v PaymentsStarGiftsClass, ok bool) {
if len(s) < 1 {
return
}
return s[0], true
}
// Last returns last element of slice (if exists).
func (s PaymentsStarGiftsClassArray) Last() (v PaymentsStarGiftsClass, ok bool) {
if len(s) < 1 {
return
}
return s[len(s)-1], true
}
// PopFirst returns first element of slice (if exists) and deletes it.
func (s *PaymentsStarGiftsClassArray) PopFirst() (v PaymentsStarGiftsClass, ok bool) {
if s == nil || len(*s) < 1 {
return
}
a := *s
v = a[0]
// Delete by index from SliceTricks.
copy(a[0:], a[1:])
var zero PaymentsStarGiftsClass
a[len(a)-1] = zero
a = a[:len(a)-1]
*s = a
return v, true
}
// Pop returns last element of slice (if exists) and deletes it.
func (s *PaymentsStarGiftsClassArray) Pop() (v PaymentsStarGiftsClass, ok bool) {
if s == nil || len(*s) < 1 {
return
}
a := *s
v = a[len(a)-1]
a = a[:len(a)-1]
*s = a
return v, true
}
// AsPaymentsStarGifts returns copy with only PaymentsStarGifts constructors.
func (s PaymentsStarGiftsClassArray) AsPaymentsStarGifts() (to PaymentsStarGiftsArray) {
for _, elem := range s {
value, ok := elem.(*PaymentsStarGifts)
if !ok {
continue
}
to = append(to, *value)
}
return to
}
// AppendOnlyModified appends only Modified constructors to
// given slice.
func (s PaymentsStarGiftsClassArray) AppendOnlyModified(to []*PaymentsStarGifts) []*PaymentsStarGifts {
for _, elem := range s {
value, ok := elem.AsModified()
if !ok {
continue
}
to = append(to, value)
}
return to
}
// AsModified returns copy with only Modified constructors.
func (s PaymentsStarGiftsClassArray) AsModified() (to []*PaymentsStarGifts) {
return s.AppendOnlyModified(to)
}
// FirstAsModified returns first element of slice (if exists).
func (s PaymentsStarGiftsClassArray) FirstAsModified() (v *PaymentsStarGifts, ok bool) {
value, ok := s.First()
if !ok {
return
}
return value.AsModified()
}
// LastAsModified returns last element of slice (if exists).
func (s PaymentsStarGiftsClassArray) LastAsModified() (v *PaymentsStarGifts, ok bool) {
value, ok := s.Last()
if !ok {
return
}
return value.AsModified()
}
// PopFirstAsModified returns element of slice (if exists).
func (s *PaymentsStarGiftsClassArray) PopFirstAsModified() (v *PaymentsStarGifts, ok bool) {
value, ok := s.PopFirst()
if !ok {
return
}
return value.AsModified()
}
// PopAsModified returns element of slice (if exists).
func (s *PaymentsStarGiftsClassArray) PopAsModified() (v *PaymentsStarGifts, ok bool) {
value, ok := s.Pop()
if !ok {
return
}
return value.AsModified()
}
// PaymentsStarGiftsArray is adapter for slice of PaymentsStarGifts.
type PaymentsStarGiftsArray []PaymentsStarGifts
// Sort sorts slice of PaymentsStarGifts.
func (s PaymentsStarGiftsArray) Sort(less func(a, b PaymentsStarGifts) bool) PaymentsStarGiftsArray {
sort.Slice(s, func(i, j int) bool {
return less(s[i], s[j])
})
return s
}
// SortStable sorts slice of PaymentsStarGifts.
func (s PaymentsStarGiftsArray) SortStable(less func(a, b PaymentsStarGifts) bool) PaymentsStarGiftsArray {
sort.SliceStable(s, func(i, j int) bool {
return less(s[i], s[j])
})
return s
}
// Retain filters in-place slice of PaymentsStarGifts.
func (s PaymentsStarGiftsArray) Retain(keep func(x PaymentsStarGifts) bool) PaymentsStarGiftsArray {
n := 0
for _, x := range s {
if keep(x) {
s[n] = x
n++
}
}
s = s[:n]
return s
}
// First returns first element of slice (if exists).
func (s PaymentsStarGiftsArray) First() (v PaymentsStarGifts, ok bool) {
if len(s) < 1 {
return
}
return s[0], true
}
// Last returns last element of slice (if exists).
func (s PaymentsStarGiftsArray) Last() (v PaymentsStarGifts, ok bool) {
if len(s) < 1 {
return
}
return s[len(s)-1], true
}
// PopFirst returns first element of slice (if exists) and deletes it.
func (s *PaymentsStarGiftsArray) PopFirst() (v PaymentsStarGifts, ok bool) {
if s == nil || len(*s) < 1 {
return
}
a := *s
v = a[0]
// Delete by index from SliceTricks.
copy(a[0:], a[1:])
var zero PaymentsStarGifts
a[len(a)-1] = zero
a = a[:len(a)-1]
*s = a
return v, true
}
// Pop returns last element of slice (if exists) and deletes it.
func (s *PaymentsStarGiftsArray) Pop() (v PaymentsStarGifts, ok bool) {
if s == nil || len(*s) < 1 {
return
}
a := *s
v = a[len(a)-1]
a = a[:len(a)-1]
*s = a
return v, true
}

View File

@ -0,0 +1,319 @@
// Code generated by gotdgen, DO NOT EDIT.
package tg
import (
"context"
"errors"
"fmt"
"sort"
"strings"
"go.uber.org/multierr"
"github.com/gotd/td/bin"
"github.com/gotd/td/tdjson"
"github.com/gotd/td/tdp"
"github.com/gotd/td/tgerr"
)
// No-op definition for keeping imports.
var (
_ = bin.Buffer{}
_ = context.Background()
_ = fmt.Stringer(nil)
_ = strings.Builder{}
_ = errors.Is
_ = multierr.AppendInto
_ = sort.Ints
_ = tdp.Format
_ = tgerr.Error{}
_ = tdjson.Encoder{}
)
// PaymentsUserStarGifts represents TL type `payments.userStarGifts#6b65b517`.
//
// See https://core.telegram.org/constructor/payments.userStarGifts for reference.
type PaymentsUserStarGifts struct {
// Flags field of PaymentsUserStarGifts.
Flags bin.Fields
// Count field of PaymentsUserStarGifts.
Count int
// Gifts field of PaymentsUserStarGifts.
Gifts []UserStarGift
// NextOffset field of PaymentsUserStarGifts.
//
// Use SetNextOffset and GetNextOffset helpers.
NextOffset string
// Users field of PaymentsUserStarGifts.
Users []UserClass
}
// PaymentsUserStarGiftsTypeID is TL type id of PaymentsUserStarGifts.
const PaymentsUserStarGiftsTypeID = 0x6b65b517
// Ensuring interfaces in compile-time for PaymentsUserStarGifts.
var (
_ bin.Encoder = &PaymentsUserStarGifts{}
_ bin.Decoder = &PaymentsUserStarGifts{}
_ bin.BareEncoder = &PaymentsUserStarGifts{}
_ bin.BareDecoder = &PaymentsUserStarGifts{}
)
func (u *PaymentsUserStarGifts) Zero() bool {
if u == nil {
return true
}
if !(u.Flags.Zero()) {
return false
}
if !(u.Count == 0) {
return false
}
if !(u.Gifts == nil) {
return false
}
if !(u.NextOffset == "") {
return false
}
if !(u.Users == nil) {
return false
}
return true
}
// String implements fmt.Stringer.
func (u *PaymentsUserStarGifts) String() string {
if u == nil {
return "PaymentsUserStarGifts(nil)"
}
type Alias PaymentsUserStarGifts
return fmt.Sprintf("PaymentsUserStarGifts%+v", Alias(*u))
}
// FillFrom fills PaymentsUserStarGifts from given interface.
func (u *PaymentsUserStarGifts) FillFrom(from interface {
GetCount() (value int)
GetGifts() (value []UserStarGift)
GetNextOffset() (value string, ok bool)
GetUsers() (value []UserClass)
}) {
u.Count = from.GetCount()
u.Gifts = from.GetGifts()
if val, ok := from.GetNextOffset(); ok {
u.NextOffset = val
}
u.Users = from.GetUsers()
}
// TypeID returns type id in TL schema.
//
// See https://core.telegram.org/mtproto/TL-tl#remarks.
func (*PaymentsUserStarGifts) TypeID() uint32 {
return PaymentsUserStarGiftsTypeID
}
// TypeName returns name of type in TL schema.
func (*PaymentsUserStarGifts) TypeName() string {
return "payments.userStarGifts"
}
// TypeInfo returns info about TL type.
func (u *PaymentsUserStarGifts) TypeInfo() tdp.Type {
typ := tdp.Type{
Name: "payments.userStarGifts",
ID: PaymentsUserStarGiftsTypeID,
}
if u == nil {
typ.Null = true
return typ
}
typ.Fields = []tdp.Field{
{
Name: "Count",
SchemaName: "count",
},
{
Name: "Gifts",
SchemaName: "gifts",
},
{
Name: "NextOffset",
SchemaName: "next_offset",
Null: !u.Flags.Has(0),
},
{
Name: "Users",
SchemaName: "users",
},
}
return typ
}
// SetFlags sets flags for non-zero fields.
func (u *PaymentsUserStarGifts) SetFlags() {
if !(u.NextOffset == "") {
u.Flags.Set(0)
}
}
// Encode implements bin.Encoder.
func (u *PaymentsUserStarGifts) Encode(b *bin.Buffer) error {
if u == nil {
return fmt.Errorf("can't encode payments.userStarGifts#6b65b517 as nil")
}
b.PutID(PaymentsUserStarGiftsTypeID)
return u.EncodeBare(b)
}
// EncodeBare implements bin.BareEncoder.
func (u *PaymentsUserStarGifts) EncodeBare(b *bin.Buffer) error {
if u == nil {
return fmt.Errorf("can't encode payments.userStarGifts#6b65b517 as nil")
}
u.SetFlags()
if err := u.Flags.Encode(b); err != nil {
return fmt.Errorf("unable to encode payments.userStarGifts#6b65b517: field flags: %w", err)
}
b.PutInt(u.Count)
b.PutVectorHeader(len(u.Gifts))
for idx, v := range u.Gifts {
if err := v.Encode(b); err != nil {
return fmt.Errorf("unable to encode payments.userStarGifts#6b65b517: field gifts element with index %d: %w", idx, err)
}
}
if u.Flags.Has(0) {
b.PutString(u.NextOffset)
}
b.PutVectorHeader(len(u.Users))
for idx, v := range u.Users {
if v == nil {
return fmt.Errorf("unable to encode payments.userStarGifts#6b65b517: field users element with index %d is nil", idx)
}
if err := v.Encode(b); err != nil {
return fmt.Errorf("unable to encode payments.userStarGifts#6b65b517: field users element with index %d: %w", idx, err)
}
}
return nil
}
// Decode implements bin.Decoder.
func (u *PaymentsUserStarGifts) Decode(b *bin.Buffer) error {
if u == nil {
return fmt.Errorf("can't decode payments.userStarGifts#6b65b517 to nil")
}
if err := b.ConsumeID(PaymentsUserStarGiftsTypeID); err != nil {
return fmt.Errorf("unable to decode payments.userStarGifts#6b65b517: %w", err)
}
return u.DecodeBare(b)
}
// DecodeBare implements bin.BareDecoder.
func (u *PaymentsUserStarGifts) DecodeBare(b *bin.Buffer) error {
if u == nil {
return fmt.Errorf("can't decode payments.userStarGifts#6b65b517 to nil")
}
{
if err := u.Flags.Decode(b); err != nil {
return fmt.Errorf("unable to decode payments.userStarGifts#6b65b517: field flags: %w", err)
}
}
{
value, err := b.Int()
if err != nil {
return fmt.Errorf("unable to decode payments.userStarGifts#6b65b517: field count: %w", err)
}
u.Count = value
}
{
headerLen, err := b.VectorHeader()
if err != nil {
return fmt.Errorf("unable to decode payments.userStarGifts#6b65b517: field gifts: %w", err)
}
if headerLen > 0 {
u.Gifts = make([]UserStarGift, 0, headerLen%bin.PreallocateLimit)
}
for idx := 0; idx < headerLen; idx++ {
var value UserStarGift
if err := value.Decode(b); err != nil {
return fmt.Errorf("unable to decode payments.userStarGifts#6b65b517: field gifts: %w", err)
}
u.Gifts = append(u.Gifts, value)
}
}
if u.Flags.Has(0) {
value, err := b.String()
if err != nil {
return fmt.Errorf("unable to decode payments.userStarGifts#6b65b517: field next_offset: %w", err)
}
u.NextOffset = value
}
{
headerLen, err := b.VectorHeader()
if err != nil {
return fmt.Errorf("unable to decode payments.userStarGifts#6b65b517: field users: %w", err)
}
if headerLen > 0 {
u.Users = make([]UserClass, 0, headerLen%bin.PreallocateLimit)
}
for idx := 0; idx < headerLen; idx++ {
value, err := DecodeUser(b)
if err != nil {
return fmt.Errorf("unable to decode payments.userStarGifts#6b65b517: field users: %w", err)
}
u.Users = append(u.Users, value)
}
}
return nil
}
// GetCount returns value of Count field.
func (u *PaymentsUserStarGifts) GetCount() (value int) {
if u == nil {
return
}
return u.Count
}
// GetGifts returns value of Gifts field.
func (u *PaymentsUserStarGifts) GetGifts() (value []UserStarGift) {
if u == nil {
return
}
return u.Gifts
}
// SetNextOffset sets value of NextOffset conditional field.
func (u *PaymentsUserStarGifts) SetNextOffset(value string) {
u.Flags.Set(0)
u.NextOffset = value
}
// GetNextOffset returns value of NextOffset conditional field and
// boolean which is true if field was set.
func (u *PaymentsUserStarGifts) GetNextOffset() (value string, ok bool) {
if u == nil {
return
}
if !u.Flags.Has(0) {
return value, false
}
return u.NextOffset, true
}
// GetUsers returns value of Users field.
func (u *PaymentsUserStarGifts) GetUsers() (value []UserClass) {
if u == nil {
return
}
return u.Users
}
// MapUsers returns field Users wrapped in UserClassArray helper.
func (u *PaymentsUserStarGifts) MapUsers() (value UserClassArray) {
return UserClassArray(u.Users)
}

View File

@ -0,0 +1,35 @@
//go:build !no_gotd_slices
// +build !no_gotd_slices
// Code generated by gotdgen, DO NOT EDIT.
package tg
import (
"context"
"errors"
"fmt"
"sort"
"strings"
"go.uber.org/multierr"
"github.com/gotd/td/bin"
"github.com/gotd/td/tdjson"
"github.com/gotd/td/tdp"
"github.com/gotd/td/tgerr"
)
// No-op definition for keeping imports.
var (
_ = bin.Buffer{}
_ = context.Background()
_ = fmt.Stringer(nil)
_ = strings.Builder{}
_ = errors.Is
_ = multierr.AppendInto
_ = sort.Ints
_ = tdp.Format
_ = tgerr.Error{}
_ = tdjson.Encoder{}
)

View File

@ -32,7 +32,7 @@ var (
)
// Layer version of schema.
const Layer = 187
const Layer = 189
// TypesMap returns mapping from type ids to TL type names.
func TypesMap() map[uint32]string {
@ -137,7 +137,7 @@ func TypesMap() map[uint32]string {
MessageMediaGeoTypeID: "messageMediaGeo#56e0d474",
MessageMediaContactTypeID: "messageMediaContact#70322949",
MessageMediaUnsupportedTypeID: "messageMediaUnsupported#9f84f49e",
MessageMediaDocumentTypeID: "messageMediaDocument#4cf4d72d",
MessageMediaDocumentTypeID: "messageMediaDocument#dd570bd5",
MessageMediaWebPageTypeID: "messageMediaWebPage#ddf10c3b",
MessageMediaVenueTypeID: "messageMediaVenue#2ec0533f",
MessageMediaGameTypeID: "messageMediaGame#fdb19008",
@ -195,6 +195,7 @@ func TypesMap() map[uint32]string {
MessageActionPaymentRefundedTypeID: "messageActionPaymentRefunded#41b3e202",
MessageActionGiftStarsTypeID: "messageActionGiftStars#45d5b021",
MessageActionPrizeStarsTypeID: "messageActionPrizeStars#b00c47a2",
MessageActionStarGiftTypeID: "messageActionStarGift#9bb3ef44",
DialogTypeID: "dialog#d58a08c6",
DialogFolderTypeID: "dialogFolder#71bd134c",
PhotoEmptyTypeID: "photoEmpty#2331b22d",
@ -232,7 +233,7 @@ func TypesMap() map[uint32]string {
InputReportReasonFakeTypeID: "inputReportReasonFake#f5ddd6e7",
InputReportReasonIllegalDrugsTypeID: "inputReportReasonIllegalDrugs#a8eb2be",
InputReportReasonPersonalDetailsTypeID: "inputReportReasonPersonalDetails#9ec7863d",
UserFullTypeID: "userFull#cc997720",
UserFullTypeID: "userFull#1f58e369",
ContactTypeID: "contact#145ade0b",
ImportedContactTypeID: "importedContact#c13e3c50",
ContactStatusTypeID: "contactStatus#16d9703b",
@ -527,7 +528,7 @@ func TypesMap() map[uint32]string {
DocumentAttributeImageSizeTypeID: "documentAttributeImageSize#6c37c15c",
DocumentAttributeAnimatedTypeID: "documentAttributeAnimated#11b58939",
DocumentAttributeStickerTypeID: "documentAttributeSticker#6319d612",
DocumentAttributeVideoTypeID: "documentAttributeVideo#17399fad",
DocumentAttributeVideoTypeID: "documentAttributeVideo#43c57c48",
DocumentAttributeAudioTypeID: "documentAttributeAudio#9852f9c6",
DocumentAttributeFilenameTypeID: "documentAttributeFilename#15590068",
DocumentAttributeHasStickersTypeID: "documentAttributeHasStickers#9801d2f7",
@ -587,6 +588,7 @@ func TypesMap() map[uint32]string {
KeyboardButtonSimpleWebViewTypeID: "keyboardButtonSimpleWebView#a0c0505c",
KeyboardButtonRequestPeerTypeID: "keyboardButtonRequestPeer#53d7bfd8",
InputKeyboardButtonRequestPeerTypeID: "inputKeyboardButtonRequestPeer#c9662d05",
KeyboardButtonCopyTypeID: "keyboardButtonCopy#75d2698e",
KeyboardButtonRowTypeID: "keyboardButtonRow#77608b83",
ReplyKeyboardHideTypeID: "replyKeyboardHide#a03e5b85",
ReplyKeyboardForceReplyTypeID: "replyKeyboardForceReply#86b40b08",
@ -789,6 +791,7 @@ func TypesMap() map[uint32]string {
UploadWebFileTypeID: "upload.webFile#21e753bc",
PaymentsPaymentFormTypeID: "payments.paymentForm#a0058751",
PaymentsPaymentFormStarsTypeID: "payments.paymentFormStars#7bf6b15c",
PaymentsPaymentFormStarGiftTypeID: "payments.paymentFormStarGift#b425cfe1",
PaymentsValidatedRequestedInfoTypeID: "payments.validatedRequestedInfo#d1451883",
PaymentsPaymentResultTypeID: "payments.paymentResult#4e5f810d",
PaymentsPaymentVerificationNeededTypeID: "payments.paymentVerificationNeeded#d8411139",
@ -1150,6 +1153,7 @@ func TypesMap() map[uint32]string {
InputInvoicePremiumGiftCodeTypeID: "inputInvoicePremiumGiftCode#98986c0d",
InputInvoiceStarsTypeID: "inputInvoiceStars#65f00ce3",
InputInvoiceChatInviteSubscriptionTypeID: "inputInvoiceChatInviteSubscription#34e793f1",
InputInvoiceStarGiftTypeID: "inputInvoiceStarGift#25d8c1d8",
PaymentsExportedInvoiceTypeID: "payments.exportedInvoice#aed0cbd9",
MessagesTranscribedAudioTypeID: "messages.transcribedAudio#cfb9d957",
HelpPremiumPromoTypeID: "help.premiumPromo#5334759c",
@ -1367,7 +1371,7 @@ func TypesMap() map[uint32]string {
StarsTransactionPeerTypeID: "starsTransactionPeer#d80da15d",
StarsTransactionPeerAdsTypeID: "starsTransactionPeerAds#60682812",
StarsTopupOptionTypeID: "starsTopupOption#bd915c0",
StarsTransactionTypeID: "starsTransaction#ee7522d5",
StarsTransactionTypeID: "starsTransaction#a9ee4c2",
PaymentsStarsStatusTypeID: "payments.starsStatus#bbfa316c",
FoundStoryTypeID: "foundStory#e87acbc0",
StoriesFoundStoriesTypeID: "stories.foundStories#e2de7737",
@ -1386,6 +1390,15 @@ func TypesMap() map[uint32]string {
MessageReactorTypeID: "messageReactor#4ba3a95a",
StarsGiveawayOptionTypeID: "starsGiveawayOption#94ce852a",
StarsGiveawayWinnersOptionTypeID: "starsGiveawayWinnersOption#54236209",
StarGiftTypeID: "starGift#aea174ee",
PaymentsStarGiftsNotModifiedTypeID: "payments.starGiftsNotModified#a388a368",
PaymentsStarGiftsTypeID: "payments.starGifts#901689ea",
UserStarGiftTypeID: "userStarGift#eea49a6e",
PaymentsUserStarGiftsTypeID: "payments.userStarGifts#6b65b517",
MessageReportOptionTypeID: "messageReportOption#7903e3d9",
ReportResultChooseOptionTypeID: "reportResultChooseOption#f0e4e0b6",
ReportResultAddCommentTypeID: "reportResultAddComment#6f09ac31",
ReportResultReportedTypeID: "reportResultReported#8db33c4b",
InvokeAfterMsgRequestTypeID: "invokeAfterMsg#cb9f372d",
InvokeAfterMsgsRequestTypeID: "invokeAfterMsgs#3dc4b4f0",
InitConnectionRequestTypeID: "initConnection#c1cd5ea9",
@ -1575,7 +1588,7 @@ func TypesMap() map[uint32]string {
MessagesForwardMessagesRequestTypeID: "messages.forwardMessages#d5039208",
MessagesReportSpamRequestTypeID: "messages.reportSpam#cf1592db",
MessagesGetPeerSettingsRequestTypeID: "messages.getPeerSettings#efd9a6a2",
MessagesReportRequestTypeID: "messages.report#8953ab4e",
MessagesReportRequestTypeID: "messages.report#fc78af9b",
MessagesGetChatsRequestTypeID: "messages.getChats#49e9528f",
MessagesGetFullChatRequestTypeID: "messages.getFullChat#aeb00b34",
MessagesEditChatTitleRequestTypeID: "messages.editChatTitle#73783ffd",
@ -1874,7 +1887,7 @@ func TypesMap() map[uint32]string {
ChannelsToggleAntiSpamRequestTypeID: "channels.toggleAntiSpam#68f3e4eb",
ChannelsReportAntiSpamFalsePositiveRequestTypeID: "channels.reportAntiSpamFalsePositive#a850a693",
ChannelsToggleParticipantsHiddenRequestTypeID: "channels.toggleParticipantsHidden#6a6e7854",
ChannelsClickSponsoredMessageRequestTypeID: "channels.clickSponsoredMessage#18afbc93",
ChannelsClickSponsoredMessageRequestTypeID: "channels.clickSponsoredMessage#1445d75",
ChannelsUpdateColorRequestTypeID: "channels.updateColor#d8aa3671",
ChannelsToggleViewForumAsMessagesRequestTypeID: "channels.toggleViewForumAsMessages#9738bb15",
ChannelsGetChannelRecommendationsRequestTypeID: "channels.getChannelRecommendations#25a71742",
@ -1926,7 +1939,7 @@ func TypesMap() map[uint32]string {
PaymentsGetStarsTopupOptionsRequestTypeID: "payments.getStarsTopupOptions#c00ec7d3",
PaymentsGetStarsStatusRequestTypeID: "payments.getStarsStatus#104fcfa7",
PaymentsGetStarsTransactionsRequestTypeID: "payments.getStarsTransactions#69da4557",
PaymentsSendStarsFormRequestTypeID: "payments.sendStarsForm#2bb731d",
PaymentsSendStarsFormRequestTypeID: "payments.sendStarsForm#7998c914",
PaymentsRefundStarsChargeRequestTypeID: "payments.refundStarsCharge#25ae8f4a",
PaymentsGetStarsRevenueStatsRequestTypeID: "payments.getStarsRevenueStats#d91ffad6",
PaymentsGetStarsRevenueWithdrawalURLRequestTypeID: "payments.getStarsRevenueWithdrawalUrl#13bbe8b3",
@ -1937,6 +1950,10 @@ func TypesMap() map[uint32]string {
PaymentsChangeStarsSubscriptionRequestTypeID: "payments.changeStarsSubscription#c7770878",
PaymentsFulfillStarsSubscriptionRequestTypeID: "payments.fulfillStarsSubscription#cc5bebb3",
PaymentsGetStarsGiveawayOptionsRequestTypeID: "payments.getStarsGiveawayOptions#bd1efd3e",
PaymentsGetStarGiftsRequestTypeID: "payments.getStarGifts#c4563590",
PaymentsGetUserStarGiftsRequestTypeID: "payments.getUserStarGifts#5e72c7e1",
PaymentsSaveStarGiftRequestTypeID: "payments.saveStarGift#87acf08e",
PaymentsConvertStarGiftRequestTypeID: "payments.convertStarGift#421e027",
StickersCreateStickerSetRequestTypeID: "stickers.createStickerSet#9021ab67",
StickersRemoveStickerFromSetRequestTypeID: "stickers.removeStickerFromSet#f7760f51",
StickersChangeStickerPositionRequestTypeID: "stickers.changeStickerPosition#ffb6d4ca",
@ -2021,7 +2038,7 @@ func TypesMap() map[uint32]string {
StoriesGetStoryViewsListRequestTypeID: "stories.getStoryViewsList#7ed23c57",
StoriesGetStoriesViewsRequestTypeID: "stories.getStoriesViews#28e16cc8",
StoriesExportStoryLinkRequestTypeID: "stories.exportStoryLink#7b8def20",
StoriesReportRequestTypeID: "stories.report#1923fa8c",
StoriesReportRequestTypeID: "stories.report#19d8eb45",
StoriesActivateStealthModeRequestTypeID: "stories.activateStealthMode#57bbd166",
StoriesSendReactionRequestTypeID: "stories.sendReaction#7fd736b2",
StoriesGetPeerStoriesRequestTypeID: "stories.getPeerStories#2c4ada50",
@ -2222,6 +2239,7 @@ func NamesMap() map[string]uint32 {
"messageActionPaymentRefunded": MessageActionPaymentRefundedTypeID,
"messageActionGiftStars": MessageActionGiftStarsTypeID,
"messageActionPrizeStars": MessageActionPrizeStarsTypeID,
"messageActionStarGift": MessageActionStarGiftTypeID,
"dialog": DialogTypeID,
"dialogFolder": DialogFolderTypeID,
"photoEmpty": PhotoEmptyTypeID,
@ -2614,6 +2632,7 @@ func NamesMap() map[string]uint32 {
"keyboardButtonSimpleWebView": KeyboardButtonSimpleWebViewTypeID,
"keyboardButtonRequestPeer": KeyboardButtonRequestPeerTypeID,
"inputKeyboardButtonRequestPeer": InputKeyboardButtonRequestPeerTypeID,
"keyboardButtonCopy": KeyboardButtonCopyTypeID,
"keyboardButtonRow": KeyboardButtonRowTypeID,
"replyKeyboardHide": ReplyKeyboardHideTypeID,
"replyKeyboardForceReply": ReplyKeyboardForceReplyTypeID,
@ -2816,6 +2835,7 @@ func NamesMap() map[string]uint32 {
"upload.webFile": UploadWebFileTypeID,
"payments.paymentForm": PaymentsPaymentFormTypeID,
"payments.paymentFormStars": PaymentsPaymentFormStarsTypeID,
"payments.paymentFormStarGift": PaymentsPaymentFormStarGiftTypeID,
"payments.validatedRequestedInfo": PaymentsValidatedRequestedInfoTypeID,
"payments.paymentResult": PaymentsPaymentResultTypeID,
"payments.paymentVerificationNeeded": PaymentsPaymentVerificationNeededTypeID,
@ -3177,6 +3197,7 @@ func NamesMap() map[string]uint32 {
"inputInvoicePremiumGiftCode": InputInvoicePremiumGiftCodeTypeID,
"inputInvoiceStars": InputInvoiceStarsTypeID,
"inputInvoiceChatInviteSubscription": InputInvoiceChatInviteSubscriptionTypeID,
"inputInvoiceStarGift": InputInvoiceStarGiftTypeID,
"payments.exportedInvoice": PaymentsExportedInvoiceTypeID,
"messages.transcribedAudio": MessagesTranscribedAudioTypeID,
"help.premiumPromo": HelpPremiumPromoTypeID,
@ -3413,6 +3434,15 @@ func NamesMap() map[string]uint32 {
"messageReactor": MessageReactorTypeID,
"starsGiveawayOption": StarsGiveawayOptionTypeID,
"starsGiveawayWinnersOption": StarsGiveawayWinnersOptionTypeID,
"starGift": StarGiftTypeID,
"payments.starGiftsNotModified": PaymentsStarGiftsNotModifiedTypeID,
"payments.starGifts": PaymentsStarGiftsTypeID,
"userStarGift": UserStarGiftTypeID,
"payments.userStarGifts": PaymentsUserStarGiftsTypeID,
"messageReportOption": MessageReportOptionTypeID,
"reportResultChooseOption": ReportResultChooseOptionTypeID,
"reportResultAddComment": ReportResultAddCommentTypeID,
"reportResultReported": ReportResultReportedTypeID,
"invokeAfterMsg": InvokeAfterMsgRequestTypeID,
"invokeAfterMsgs": InvokeAfterMsgsRequestTypeID,
"initConnection": InitConnectionRequestTypeID,
@ -3964,6 +3994,10 @@ func NamesMap() map[string]uint32 {
"payments.changeStarsSubscription": PaymentsChangeStarsSubscriptionRequestTypeID,
"payments.fulfillStarsSubscription": PaymentsFulfillStarsSubscriptionRequestTypeID,
"payments.getStarsGiveawayOptions": PaymentsGetStarsGiveawayOptionsRequestTypeID,
"payments.getStarGifts": PaymentsGetStarGiftsRequestTypeID,
"payments.getUserStarGifts": PaymentsGetUserStarGiftsRequestTypeID,
"payments.saveStarGift": PaymentsSaveStarGiftRequestTypeID,
"payments.convertStarGift": PaymentsConvertStarGiftRequestTypeID,
"stickers.createStickerSet": StickersCreateStickerSetRequestTypeID,
"stickers.removeStickerFromSet": StickersRemoveStickerFromSetRequestTypeID,
"stickers.changeStickerPosition": StickersChangeStickerPositionRequestTypeID,
@ -4249,6 +4283,7 @@ func TypesConstructorMap() map[uint32]func() bin.Object {
MessageActionPaymentRefundedTypeID: func() bin.Object { return &MessageActionPaymentRefunded{} },
MessageActionGiftStarsTypeID: func() bin.Object { return &MessageActionGiftStars{} },
MessageActionPrizeStarsTypeID: func() bin.Object { return &MessageActionPrizeStars{} },
MessageActionStarGiftTypeID: func() bin.Object { return &MessageActionStarGift{} },
DialogTypeID: func() bin.Object { return &Dialog{} },
DialogFolderTypeID: func() bin.Object { return &DialogFolder{} },
PhotoEmptyTypeID: func() bin.Object { return &PhotoEmpty{} },
@ -4641,6 +4676,7 @@ func TypesConstructorMap() map[uint32]func() bin.Object {
KeyboardButtonSimpleWebViewTypeID: func() bin.Object { return &KeyboardButtonSimpleWebView{} },
KeyboardButtonRequestPeerTypeID: func() bin.Object { return &KeyboardButtonRequestPeer{} },
InputKeyboardButtonRequestPeerTypeID: func() bin.Object { return &InputKeyboardButtonRequestPeer{} },
KeyboardButtonCopyTypeID: func() bin.Object { return &KeyboardButtonCopy{} },
KeyboardButtonRowTypeID: func() bin.Object { return &KeyboardButtonRow{} },
ReplyKeyboardHideTypeID: func() bin.Object { return &ReplyKeyboardHide{} },
ReplyKeyboardForceReplyTypeID: func() bin.Object { return &ReplyKeyboardForceReply{} },
@ -4843,6 +4879,7 @@ func TypesConstructorMap() map[uint32]func() bin.Object {
UploadWebFileTypeID: func() bin.Object { return &UploadWebFile{} },
PaymentsPaymentFormTypeID: func() bin.Object { return &PaymentsPaymentForm{} },
PaymentsPaymentFormStarsTypeID: func() bin.Object { return &PaymentsPaymentFormStars{} },
PaymentsPaymentFormStarGiftTypeID: func() bin.Object { return &PaymentsPaymentFormStarGift{} },
PaymentsValidatedRequestedInfoTypeID: func() bin.Object { return &PaymentsValidatedRequestedInfo{} },
PaymentsPaymentResultTypeID: func() bin.Object { return &PaymentsPaymentResult{} },
PaymentsPaymentVerificationNeededTypeID: func() bin.Object { return &PaymentsPaymentVerificationNeeded{} },
@ -5204,6 +5241,7 @@ func TypesConstructorMap() map[uint32]func() bin.Object {
InputInvoicePremiumGiftCodeTypeID: func() bin.Object { return &InputInvoicePremiumGiftCode{} },
InputInvoiceStarsTypeID: func() bin.Object { return &InputInvoiceStars{} },
InputInvoiceChatInviteSubscriptionTypeID: func() bin.Object { return &InputInvoiceChatInviteSubscription{} },
InputInvoiceStarGiftTypeID: func() bin.Object { return &InputInvoiceStarGift{} },
PaymentsExportedInvoiceTypeID: func() bin.Object { return &PaymentsExportedInvoice{} },
MessagesTranscribedAudioTypeID: func() bin.Object { return &MessagesTranscribedAudio{} },
HelpPremiumPromoTypeID: func() bin.Object { return &HelpPremiumPromo{} },
@ -5440,6 +5478,15 @@ func TypesConstructorMap() map[uint32]func() bin.Object {
MessageReactorTypeID: func() bin.Object { return &MessageReactor{} },
StarsGiveawayOptionTypeID: func() bin.Object { return &StarsGiveawayOption{} },
StarsGiveawayWinnersOptionTypeID: func() bin.Object { return &StarsGiveawayWinnersOption{} },
StarGiftTypeID: func() bin.Object { return &StarGift{} },
PaymentsStarGiftsNotModifiedTypeID: func() bin.Object { return &PaymentsStarGiftsNotModified{} },
PaymentsStarGiftsTypeID: func() bin.Object { return &PaymentsStarGifts{} },
UserStarGiftTypeID: func() bin.Object { return &UserStarGift{} },
PaymentsUserStarGiftsTypeID: func() bin.Object { return &PaymentsUserStarGifts{} },
MessageReportOptionTypeID: func() bin.Object { return &MessageReportOption{} },
ReportResultChooseOptionTypeID: func() bin.Object { return &ReportResultChooseOption{} },
ReportResultAddCommentTypeID: func() bin.Object { return &ReportResultAddComment{} },
ReportResultReportedTypeID: func() bin.Object { return &ReportResultReported{} },
InvokeAfterMsgRequestTypeID: func() bin.Object { return &InvokeAfterMsgRequest{} },
InvokeAfterMsgsRequestTypeID: func() bin.Object { return &InvokeAfterMsgsRequest{} },
InitConnectionRequestTypeID: func() bin.Object { return &InitConnectionRequest{} },
@ -5991,6 +6038,10 @@ func TypesConstructorMap() map[uint32]func() bin.Object {
PaymentsChangeStarsSubscriptionRequestTypeID: func() bin.Object { return &PaymentsChangeStarsSubscriptionRequest{} },
PaymentsFulfillStarsSubscriptionRequestTypeID: func() bin.Object { return &PaymentsFulfillStarsSubscriptionRequest{} },
PaymentsGetStarsGiveawayOptionsRequestTypeID: func() bin.Object { return &PaymentsGetStarsGiveawayOptionsRequest{} },
PaymentsGetStarGiftsRequestTypeID: func() bin.Object { return &PaymentsGetStarGiftsRequest{} },
PaymentsGetUserStarGiftsRequestTypeID: func() bin.Object { return &PaymentsGetUserStarGiftsRequest{} },
PaymentsSaveStarGiftRequestTypeID: func() bin.Object { return &PaymentsSaveStarGiftRequest{} },
PaymentsConvertStarGiftRequestTypeID: func() bin.Object { return &PaymentsConvertStarGiftRequest{} },
StickersCreateStickerSetRequestTypeID: func() bin.Object { return &StickersCreateStickerSetRequest{} },
StickersRemoveStickerFromSetRequestTypeID: func() bin.Object { return &StickersRemoveStickerFromSetRequest{} },
StickersChangeStickerPositionRequestTypeID: func() bin.Object { return &StickersChangeStickerPositionRequest{} },
@ -6616,6 +6667,7 @@ func ClassConstructorsMap() map[string][]uint32 {
InputInvoicePremiumGiftCodeTypeID,
InputInvoiceStarsTypeID,
InputInvoiceChatInviteSubscriptionTypeID,
InputInvoiceStarGiftTypeID,
},
InputMediaClassName: {
InputMediaEmptyTypeID,
@ -6778,6 +6830,7 @@ func ClassConstructorsMap() map[string][]uint32 {
KeyboardButtonSimpleWebViewTypeID,
KeyboardButtonRequestPeerTypeID,
InputKeyboardButtonRequestPeerTypeID,
KeyboardButtonCopyTypeID,
},
LangPackStringClassName: {
LangPackStringTypeID,
@ -6841,6 +6894,7 @@ func ClassConstructorsMap() map[string][]uint32 {
MessageActionPaymentRefundedTypeID,
MessageActionGiftStarsTypeID,
MessageActionPrizeStarsTypeID,
MessageActionStarGiftTypeID,
},
MessageClassName: {
MessageEmptyTypeID,
@ -7080,6 +7134,7 @@ func ClassConstructorsMap() map[string][]uint32 {
PaymentsPaymentFormClassName: {
PaymentsPaymentFormTypeID,
PaymentsPaymentFormStarsTypeID,
PaymentsPaymentFormStarGiftTypeID,
},
PaymentsPaymentReceiptClassName: {
PaymentsPaymentReceiptTypeID,
@ -7089,6 +7144,10 @@ func ClassConstructorsMap() map[string][]uint32 {
PaymentsPaymentResultTypeID,
PaymentsPaymentVerificationNeededTypeID,
},
PaymentsStarGiftsClassName: {
PaymentsStarGiftsNotModifiedTypeID,
PaymentsStarGiftsTypeID,
},
PeerClassName: {
PeerUserTypeID,
PeerChatTypeID,
@ -7204,6 +7263,11 @@ func ClassConstructorsMap() map[string][]uint32 {
InputReportReasonIllegalDrugsTypeID,
InputReportReasonPersonalDetailsTypeID,
},
ReportResultClassName: {
ReportResultChooseOptionTypeID,
ReportResultAddCommentTypeID,
ReportResultReportedTypeID,
},
RequestPeerTypeClassName: {
RequestPeerTypeUserTypeID,
RequestPeerTypeChatTypeID,

593
vendor/github.com/gotd/td/tg/tl_report_result_gen.go generated vendored Normal file
View File

@ -0,0 +1,593 @@
// Code generated by gotdgen, DO NOT EDIT.
package tg
import (
"context"
"errors"
"fmt"
"sort"
"strings"
"go.uber.org/multierr"
"github.com/gotd/td/bin"
"github.com/gotd/td/tdjson"
"github.com/gotd/td/tdp"
"github.com/gotd/td/tgerr"
)
// No-op definition for keeping imports.
var (
_ = bin.Buffer{}
_ = context.Background()
_ = fmt.Stringer(nil)
_ = strings.Builder{}
_ = errors.Is
_ = multierr.AppendInto
_ = sort.Ints
_ = tdp.Format
_ = tgerr.Error{}
_ = tdjson.Encoder{}
)
// ReportResultChooseOption represents TL type `reportResultChooseOption#f0e4e0b6`.
//
// See https://core.telegram.org/constructor/reportResultChooseOption for reference.
type ReportResultChooseOption struct {
// Title field of ReportResultChooseOption.
Title string
// Options field of ReportResultChooseOption.
Options []MessageReportOption
}
// ReportResultChooseOptionTypeID is TL type id of ReportResultChooseOption.
const ReportResultChooseOptionTypeID = 0xf0e4e0b6
// construct implements constructor of ReportResultClass.
func (r ReportResultChooseOption) construct() ReportResultClass { return &r }
// Ensuring interfaces in compile-time for ReportResultChooseOption.
var (
_ bin.Encoder = &ReportResultChooseOption{}
_ bin.Decoder = &ReportResultChooseOption{}
_ bin.BareEncoder = &ReportResultChooseOption{}
_ bin.BareDecoder = &ReportResultChooseOption{}
_ ReportResultClass = &ReportResultChooseOption{}
)
func (r *ReportResultChooseOption) Zero() bool {
if r == nil {
return true
}
if !(r.Title == "") {
return false
}
if !(r.Options == nil) {
return false
}
return true
}
// String implements fmt.Stringer.
func (r *ReportResultChooseOption) String() string {
if r == nil {
return "ReportResultChooseOption(nil)"
}
type Alias ReportResultChooseOption
return fmt.Sprintf("ReportResultChooseOption%+v", Alias(*r))
}
// FillFrom fills ReportResultChooseOption from given interface.
func (r *ReportResultChooseOption) FillFrom(from interface {
GetTitle() (value string)
GetOptions() (value []MessageReportOption)
}) {
r.Title = from.GetTitle()
r.Options = from.GetOptions()
}
// TypeID returns type id in TL schema.
//
// See https://core.telegram.org/mtproto/TL-tl#remarks.
func (*ReportResultChooseOption) TypeID() uint32 {
return ReportResultChooseOptionTypeID
}
// TypeName returns name of type in TL schema.
func (*ReportResultChooseOption) TypeName() string {
return "reportResultChooseOption"
}
// TypeInfo returns info about TL type.
func (r *ReportResultChooseOption) TypeInfo() tdp.Type {
typ := tdp.Type{
Name: "reportResultChooseOption",
ID: ReportResultChooseOptionTypeID,
}
if r == nil {
typ.Null = true
return typ
}
typ.Fields = []tdp.Field{
{
Name: "Title",
SchemaName: "title",
},
{
Name: "Options",
SchemaName: "options",
},
}
return typ
}
// Encode implements bin.Encoder.
func (r *ReportResultChooseOption) Encode(b *bin.Buffer) error {
if r == nil {
return fmt.Errorf("can't encode reportResultChooseOption#f0e4e0b6 as nil")
}
b.PutID(ReportResultChooseOptionTypeID)
return r.EncodeBare(b)
}
// EncodeBare implements bin.BareEncoder.
func (r *ReportResultChooseOption) EncodeBare(b *bin.Buffer) error {
if r == nil {
return fmt.Errorf("can't encode reportResultChooseOption#f0e4e0b6 as nil")
}
b.PutString(r.Title)
b.PutVectorHeader(len(r.Options))
for idx, v := range r.Options {
if err := v.Encode(b); err != nil {
return fmt.Errorf("unable to encode reportResultChooseOption#f0e4e0b6: field options element with index %d: %w", idx, err)
}
}
return nil
}
// Decode implements bin.Decoder.
func (r *ReportResultChooseOption) Decode(b *bin.Buffer) error {
if r == nil {
return fmt.Errorf("can't decode reportResultChooseOption#f0e4e0b6 to nil")
}
if err := b.ConsumeID(ReportResultChooseOptionTypeID); err != nil {
return fmt.Errorf("unable to decode reportResultChooseOption#f0e4e0b6: %w", err)
}
return r.DecodeBare(b)
}
// DecodeBare implements bin.BareDecoder.
func (r *ReportResultChooseOption) DecodeBare(b *bin.Buffer) error {
if r == nil {
return fmt.Errorf("can't decode reportResultChooseOption#f0e4e0b6 to nil")
}
{
value, err := b.String()
if err != nil {
return fmt.Errorf("unable to decode reportResultChooseOption#f0e4e0b6: field title: %w", err)
}
r.Title = value
}
{
headerLen, err := b.VectorHeader()
if err != nil {
return fmt.Errorf("unable to decode reportResultChooseOption#f0e4e0b6: field options: %w", err)
}
if headerLen > 0 {
r.Options = make([]MessageReportOption, 0, headerLen%bin.PreallocateLimit)
}
for idx := 0; idx < headerLen; idx++ {
var value MessageReportOption
if err := value.Decode(b); err != nil {
return fmt.Errorf("unable to decode reportResultChooseOption#f0e4e0b6: field options: %w", err)
}
r.Options = append(r.Options, value)
}
}
return nil
}
// GetTitle returns value of Title field.
func (r *ReportResultChooseOption) GetTitle() (value string) {
if r == nil {
return
}
return r.Title
}
// GetOptions returns value of Options field.
func (r *ReportResultChooseOption) GetOptions() (value []MessageReportOption) {
if r == nil {
return
}
return r.Options
}
// ReportResultAddComment represents TL type `reportResultAddComment#6f09ac31`.
//
// See https://core.telegram.org/constructor/reportResultAddComment for reference.
type ReportResultAddComment struct {
// Flags field of ReportResultAddComment.
Flags bin.Fields
// Optional field of ReportResultAddComment.
Optional bool
// Option field of ReportResultAddComment.
Option []byte
}
// ReportResultAddCommentTypeID is TL type id of ReportResultAddComment.
const ReportResultAddCommentTypeID = 0x6f09ac31
// construct implements constructor of ReportResultClass.
func (r ReportResultAddComment) construct() ReportResultClass { return &r }
// Ensuring interfaces in compile-time for ReportResultAddComment.
var (
_ bin.Encoder = &ReportResultAddComment{}
_ bin.Decoder = &ReportResultAddComment{}
_ bin.BareEncoder = &ReportResultAddComment{}
_ bin.BareDecoder = &ReportResultAddComment{}
_ ReportResultClass = &ReportResultAddComment{}
)
func (r *ReportResultAddComment) Zero() bool {
if r == nil {
return true
}
if !(r.Flags.Zero()) {
return false
}
if !(r.Optional == false) {
return false
}
if !(r.Option == nil) {
return false
}
return true
}
// String implements fmt.Stringer.
func (r *ReportResultAddComment) String() string {
if r == nil {
return "ReportResultAddComment(nil)"
}
type Alias ReportResultAddComment
return fmt.Sprintf("ReportResultAddComment%+v", Alias(*r))
}
// FillFrom fills ReportResultAddComment from given interface.
func (r *ReportResultAddComment) FillFrom(from interface {
GetOptional() (value bool)
GetOption() (value []byte)
}) {
r.Optional = from.GetOptional()
r.Option = from.GetOption()
}
// TypeID returns type id in TL schema.
//
// See https://core.telegram.org/mtproto/TL-tl#remarks.
func (*ReportResultAddComment) TypeID() uint32 {
return ReportResultAddCommentTypeID
}
// TypeName returns name of type in TL schema.
func (*ReportResultAddComment) TypeName() string {
return "reportResultAddComment"
}
// TypeInfo returns info about TL type.
func (r *ReportResultAddComment) TypeInfo() tdp.Type {
typ := tdp.Type{
Name: "reportResultAddComment",
ID: ReportResultAddCommentTypeID,
}
if r == nil {
typ.Null = true
return typ
}
typ.Fields = []tdp.Field{
{
Name: "Optional",
SchemaName: "optional",
Null: !r.Flags.Has(0),
},
{
Name: "Option",
SchemaName: "option",
},
}
return typ
}
// SetFlags sets flags for non-zero fields.
func (r *ReportResultAddComment) SetFlags() {
if !(r.Optional == false) {
r.Flags.Set(0)
}
}
// Encode implements bin.Encoder.
func (r *ReportResultAddComment) Encode(b *bin.Buffer) error {
if r == nil {
return fmt.Errorf("can't encode reportResultAddComment#6f09ac31 as nil")
}
b.PutID(ReportResultAddCommentTypeID)
return r.EncodeBare(b)
}
// EncodeBare implements bin.BareEncoder.
func (r *ReportResultAddComment) EncodeBare(b *bin.Buffer) error {
if r == nil {
return fmt.Errorf("can't encode reportResultAddComment#6f09ac31 as nil")
}
r.SetFlags()
if err := r.Flags.Encode(b); err != nil {
return fmt.Errorf("unable to encode reportResultAddComment#6f09ac31: field flags: %w", err)
}
b.PutBytes(r.Option)
return nil
}
// Decode implements bin.Decoder.
func (r *ReportResultAddComment) Decode(b *bin.Buffer) error {
if r == nil {
return fmt.Errorf("can't decode reportResultAddComment#6f09ac31 to nil")
}
if err := b.ConsumeID(ReportResultAddCommentTypeID); err != nil {
return fmt.Errorf("unable to decode reportResultAddComment#6f09ac31: %w", err)
}
return r.DecodeBare(b)
}
// DecodeBare implements bin.BareDecoder.
func (r *ReportResultAddComment) DecodeBare(b *bin.Buffer) error {
if r == nil {
return fmt.Errorf("can't decode reportResultAddComment#6f09ac31 to nil")
}
{
if err := r.Flags.Decode(b); err != nil {
return fmt.Errorf("unable to decode reportResultAddComment#6f09ac31: field flags: %w", err)
}
}
r.Optional = r.Flags.Has(0)
{
value, err := b.Bytes()
if err != nil {
return fmt.Errorf("unable to decode reportResultAddComment#6f09ac31: field option: %w", err)
}
r.Option = value
}
return nil
}
// SetOptional sets value of Optional conditional field.
func (r *ReportResultAddComment) SetOptional(value bool) {
if value {
r.Flags.Set(0)
r.Optional = true
} else {
r.Flags.Unset(0)
r.Optional = false
}
}
// GetOptional returns value of Optional conditional field.
func (r *ReportResultAddComment) GetOptional() (value bool) {
if r == nil {
return
}
return r.Flags.Has(0)
}
// GetOption returns value of Option field.
func (r *ReportResultAddComment) GetOption() (value []byte) {
if r == nil {
return
}
return r.Option
}
// ReportResultReported represents TL type `reportResultReported#8db33c4b`.
//
// See https://core.telegram.org/constructor/reportResultReported for reference.
type ReportResultReported struct {
}
// ReportResultReportedTypeID is TL type id of ReportResultReported.
const ReportResultReportedTypeID = 0x8db33c4b
// construct implements constructor of ReportResultClass.
func (r ReportResultReported) construct() ReportResultClass { return &r }
// Ensuring interfaces in compile-time for ReportResultReported.
var (
_ bin.Encoder = &ReportResultReported{}
_ bin.Decoder = &ReportResultReported{}
_ bin.BareEncoder = &ReportResultReported{}
_ bin.BareDecoder = &ReportResultReported{}
_ ReportResultClass = &ReportResultReported{}
)
func (r *ReportResultReported) Zero() bool {
if r == nil {
return true
}
return true
}
// String implements fmt.Stringer.
func (r *ReportResultReported) String() string {
if r == nil {
return "ReportResultReported(nil)"
}
type Alias ReportResultReported
return fmt.Sprintf("ReportResultReported%+v", Alias(*r))
}
// TypeID returns type id in TL schema.
//
// See https://core.telegram.org/mtproto/TL-tl#remarks.
func (*ReportResultReported) TypeID() uint32 {
return ReportResultReportedTypeID
}
// TypeName returns name of type in TL schema.
func (*ReportResultReported) TypeName() string {
return "reportResultReported"
}
// TypeInfo returns info about TL type.
func (r *ReportResultReported) TypeInfo() tdp.Type {
typ := tdp.Type{
Name: "reportResultReported",
ID: ReportResultReportedTypeID,
}
if r == nil {
typ.Null = true
return typ
}
typ.Fields = []tdp.Field{}
return typ
}
// Encode implements bin.Encoder.
func (r *ReportResultReported) Encode(b *bin.Buffer) error {
if r == nil {
return fmt.Errorf("can't encode reportResultReported#8db33c4b as nil")
}
b.PutID(ReportResultReportedTypeID)
return r.EncodeBare(b)
}
// EncodeBare implements bin.BareEncoder.
func (r *ReportResultReported) EncodeBare(b *bin.Buffer) error {
if r == nil {
return fmt.Errorf("can't encode reportResultReported#8db33c4b as nil")
}
return nil
}
// Decode implements bin.Decoder.
func (r *ReportResultReported) Decode(b *bin.Buffer) error {
if r == nil {
return fmt.Errorf("can't decode reportResultReported#8db33c4b to nil")
}
if err := b.ConsumeID(ReportResultReportedTypeID); err != nil {
return fmt.Errorf("unable to decode reportResultReported#8db33c4b: %w", err)
}
return r.DecodeBare(b)
}
// DecodeBare implements bin.BareDecoder.
func (r *ReportResultReported) DecodeBare(b *bin.Buffer) error {
if r == nil {
return fmt.Errorf("can't decode reportResultReported#8db33c4b to nil")
}
return nil
}
// ReportResultClassName is schema name of ReportResultClass.
const ReportResultClassName = "ReportResult"
// ReportResultClass represents ReportResult generic type.
//
// See https://core.telegram.org/type/ReportResult for reference.
//
// Example:
//
// g, err := tg.DecodeReportResult(buf)
// if err != nil {
// panic(err)
// }
// switch v := g.(type) {
// case *tg.ReportResultChooseOption: // reportResultChooseOption#f0e4e0b6
// case *tg.ReportResultAddComment: // reportResultAddComment#6f09ac31
// case *tg.ReportResultReported: // reportResultReported#8db33c4b
// default: panic(v)
// }
type ReportResultClass interface {
bin.Encoder
bin.Decoder
bin.BareEncoder
bin.BareDecoder
construct() ReportResultClass
// TypeID returns type id in TL schema.
//
// See https://core.telegram.org/mtproto/TL-tl#remarks.
TypeID() uint32
// TypeName returns name of type in TL schema.
TypeName() string
// String implements fmt.Stringer.
String() string
// Zero returns true if current object has a zero value.
Zero() bool
}
// DecodeReportResult implements binary de-serialization for ReportResultClass.
func DecodeReportResult(buf *bin.Buffer) (ReportResultClass, error) {
id, err := buf.PeekID()
if err != nil {
return nil, err
}
switch id {
case ReportResultChooseOptionTypeID:
// Decoding reportResultChooseOption#f0e4e0b6.
v := ReportResultChooseOption{}
if err := v.Decode(buf); err != nil {
return nil, fmt.Errorf("unable to decode ReportResultClass: %w", err)
}
return &v, nil
case ReportResultAddCommentTypeID:
// Decoding reportResultAddComment#6f09ac31.
v := ReportResultAddComment{}
if err := v.Decode(buf); err != nil {
return nil, fmt.Errorf("unable to decode ReportResultClass: %w", err)
}
return &v, nil
case ReportResultReportedTypeID:
// Decoding reportResultReported#8db33c4b.
v := ReportResultReported{}
if err := v.Decode(buf); err != nil {
return nil, fmt.Errorf("unable to decode ReportResultClass: %w", err)
}
return &v, nil
default:
return nil, fmt.Errorf("unable to decode ReportResultClass: %w", bin.NewUnexpectedID(id))
}
}
// ReportResult boxes the ReportResultClass providing a helper.
type ReportResultBox struct {
ReportResult ReportResultClass
}
// Decode implements bin.Decoder for ReportResultBox.
func (b *ReportResultBox) Decode(buf *bin.Buffer) error {
if b == nil {
return fmt.Errorf("unable to decode ReportResultBox to nil")
}
v, err := DecodeReportResult(buf)
if err != nil {
return fmt.Errorf("unable to decode boxed value: %w", err)
}
b.ReportResult = v
return nil
}
// Encode implements bin.Encode for ReportResultBox.
func (b *ReportResultBox) Encode(buf *bin.Buffer) error {
if b == nil || b.ReportResult == nil {
return fmt.Errorf("unable to encode ReportResultClass as nil")
}
return b.ReportResult.Encode(buf)
}

View File

@ -0,0 +1,307 @@
//go:build !no_gotd_slices
// +build !no_gotd_slices
// Code generated by gotdgen, DO NOT EDIT.
package tg
import (
"context"
"errors"
"fmt"
"sort"
"strings"
"go.uber.org/multierr"
"github.com/gotd/td/bin"
"github.com/gotd/td/tdjson"
"github.com/gotd/td/tdp"
"github.com/gotd/td/tgerr"
)
// No-op definition for keeping imports.
var (
_ = bin.Buffer{}
_ = context.Background()
_ = fmt.Stringer(nil)
_ = strings.Builder{}
_ = errors.Is
_ = multierr.AppendInto
_ = sort.Ints
_ = tdp.Format
_ = tgerr.Error{}
_ = tdjson.Encoder{}
)
// ReportResultClassArray is adapter for slice of ReportResultClass.
type ReportResultClassArray []ReportResultClass
// Sort sorts slice of ReportResultClass.
func (s ReportResultClassArray) Sort(less func(a, b ReportResultClass) bool) ReportResultClassArray {
sort.Slice(s, func(i, j int) bool {
return less(s[i], s[j])
})
return s
}
// SortStable sorts slice of ReportResultClass.
func (s ReportResultClassArray) SortStable(less func(a, b ReportResultClass) bool) ReportResultClassArray {
sort.SliceStable(s, func(i, j int) bool {
return less(s[i], s[j])
})
return s
}
// Retain filters in-place slice of ReportResultClass.
func (s ReportResultClassArray) Retain(keep func(x ReportResultClass) bool) ReportResultClassArray {
n := 0
for _, x := range s {
if keep(x) {
s[n] = x
n++
}
}
s = s[:n]
return s
}
// First returns first element of slice (if exists).
func (s ReportResultClassArray) First() (v ReportResultClass, ok bool) {
if len(s) < 1 {
return
}
return s[0], true
}
// Last returns last element of slice (if exists).
func (s ReportResultClassArray) Last() (v ReportResultClass, ok bool) {
if len(s) < 1 {
return
}
return s[len(s)-1], true
}
// PopFirst returns first element of slice (if exists) and deletes it.
func (s *ReportResultClassArray) PopFirst() (v ReportResultClass, ok bool) {
if s == nil || len(*s) < 1 {
return
}
a := *s
v = a[0]
// Delete by index from SliceTricks.
copy(a[0:], a[1:])
var zero ReportResultClass
a[len(a)-1] = zero
a = a[:len(a)-1]
*s = a
return v, true
}
// Pop returns last element of slice (if exists) and deletes it.
func (s *ReportResultClassArray) Pop() (v ReportResultClass, ok bool) {
if s == nil || len(*s) < 1 {
return
}
a := *s
v = a[len(a)-1]
a = a[:len(a)-1]
*s = a
return v, true
}
// AsReportResultChooseOption returns copy with only ReportResultChooseOption constructors.
func (s ReportResultClassArray) AsReportResultChooseOption() (to ReportResultChooseOptionArray) {
for _, elem := range s {
value, ok := elem.(*ReportResultChooseOption)
if !ok {
continue
}
to = append(to, *value)
}
return to
}
// AsReportResultAddComment returns copy with only ReportResultAddComment constructors.
func (s ReportResultClassArray) AsReportResultAddComment() (to ReportResultAddCommentArray) {
for _, elem := range s {
value, ok := elem.(*ReportResultAddComment)
if !ok {
continue
}
to = append(to, *value)
}
return to
}
// ReportResultChooseOptionArray is adapter for slice of ReportResultChooseOption.
type ReportResultChooseOptionArray []ReportResultChooseOption
// Sort sorts slice of ReportResultChooseOption.
func (s ReportResultChooseOptionArray) Sort(less func(a, b ReportResultChooseOption) bool) ReportResultChooseOptionArray {
sort.Slice(s, func(i, j int) bool {
return less(s[i], s[j])
})
return s
}
// SortStable sorts slice of ReportResultChooseOption.
func (s ReportResultChooseOptionArray) SortStable(less func(a, b ReportResultChooseOption) bool) ReportResultChooseOptionArray {
sort.SliceStable(s, func(i, j int) bool {
return less(s[i], s[j])
})
return s
}
// Retain filters in-place slice of ReportResultChooseOption.
func (s ReportResultChooseOptionArray) Retain(keep func(x ReportResultChooseOption) bool) ReportResultChooseOptionArray {
n := 0
for _, x := range s {
if keep(x) {
s[n] = x
n++
}
}
s = s[:n]
return s
}
// First returns first element of slice (if exists).
func (s ReportResultChooseOptionArray) First() (v ReportResultChooseOption, ok bool) {
if len(s) < 1 {
return
}
return s[0], true
}
// Last returns last element of slice (if exists).
func (s ReportResultChooseOptionArray) Last() (v ReportResultChooseOption, ok bool) {
if len(s) < 1 {
return
}
return s[len(s)-1], true
}
// PopFirst returns first element of slice (if exists) and deletes it.
func (s *ReportResultChooseOptionArray) PopFirst() (v ReportResultChooseOption, ok bool) {
if s == nil || len(*s) < 1 {
return
}
a := *s
v = a[0]
// Delete by index from SliceTricks.
copy(a[0:], a[1:])
var zero ReportResultChooseOption
a[len(a)-1] = zero
a = a[:len(a)-1]
*s = a
return v, true
}
// Pop returns last element of slice (if exists) and deletes it.
func (s *ReportResultChooseOptionArray) Pop() (v ReportResultChooseOption, ok bool) {
if s == nil || len(*s) < 1 {
return
}
a := *s
v = a[len(a)-1]
a = a[:len(a)-1]
*s = a
return v, true
}
// ReportResultAddCommentArray is adapter for slice of ReportResultAddComment.
type ReportResultAddCommentArray []ReportResultAddComment
// Sort sorts slice of ReportResultAddComment.
func (s ReportResultAddCommentArray) Sort(less func(a, b ReportResultAddComment) bool) ReportResultAddCommentArray {
sort.Slice(s, func(i, j int) bool {
return less(s[i], s[j])
})
return s
}
// SortStable sorts slice of ReportResultAddComment.
func (s ReportResultAddCommentArray) SortStable(less func(a, b ReportResultAddComment) bool) ReportResultAddCommentArray {
sort.SliceStable(s, func(i, j int) bool {
return less(s[i], s[j])
})
return s
}
// Retain filters in-place slice of ReportResultAddComment.
func (s ReportResultAddCommentArray) Retain(keep func(x ReportResultAddComment) bool) ReportResultAddCommentArray {
n := 0
for _, x := range s {
if keep(x) {
s[n] = x
n++
}
}
s = s[:n]
return s
}
// First returns first element of slice (if exists).
func (s ReportResultAddCommentArray) First() (v ReportResultAddComment, ok bool) {
if len(s) < 1 {
return
}
return s[0], true
}
// Last returns last element of slice (if exists).
func (s ReportResultAddCommentArray) Last() (v ReportResultAddComment, ok bool) {
if len(s) < 1 {
return
}
return s[len(s)-1], true
}
// PopFirst returns first element of slice (if exists) and deletes it.
func (s *ReportResultAddCommentArray) PopFirst() (v ReportResultAddComment, ok bool) {
if s == nil || len(*s) < 1 {
return
}
a := *s
v = a[0]
// Delete by index from SliceTricks.
copy(a[0:], a[1:])
var zero ReportResultAddComment
a[len(a)-1] = zero
a = a[:len(a)-1]
*s = a
return v, true
}
// Pop returns last element of slice (if exists) and deletes it.
func (s *ReportResultAddCommentArray) Pop() (v ReportResultAddComment, ok bool) {
if s == nil || len(*s) < 1 {
return
}
a := *s
v = a[len(a)-1]
a = a[:len(a)-1]
*s = a
return v, true
}

View File

@ -3388,7 +3388,7 @@ func (s *ServerDispatcher) OnMessagesGetPeerSettings(f func(ctx context.Context,
s.handlers[MessagesGetPeerSettingsRequestTypeID] = handler
}
func (s *ServerDispatcher) OnMessagesReport(f func(ctx context.Context, request *MessagesReportRequest) (bool, error)) {
func (s *ServerDispatcher) OnMessagesReport(f func(ctx context.Context, request *MessagesReportRequest) (ReportResultClass, error)) {
handler := func(ctx context.Context, b *bin.Buffer) (bin.Encoder, error) {
var request MessagesReportRequest
if err := request.Decode(b); err != nil {
@ -3399,11 +3399,7 @@ func (s *ServerDispatcher) OnMessagesReport(f func(ctx context.Context, request
if err != nil {
return nil, err
}
if response {
return &BoolBox{Bool: &BoolTrue{}}, nil
}
return &BoolBox{Bool: &BoolFalse{}}, nil
return &ReportResultBox{ReportResult: response}, nil
}
s.handlers[MessagesReportRequestTypeID] = handler
@ -9902,6 +9898,82 @@ func (s *ServerDispatcher) OnPaymentsGetStarsGiveawayOptions(f func(ctx context.
s.handlers[PaymentsGetStarsGiveawayOptionsRequestTypeID] = handler
}
func (s *ServerDispatcher) OnPaymentsGetStarGifts(f func(ctx context.Context, hash int) (PaymentsStarGiftsClass, error)) {
handler := func(ctx context.Context, b *bin.Buffer) (bin.Encoder, error) {
var request PaymentsGetStarGiftsRequest
if err := request.Decode(b); err != nil {
return nil, err
}
response, err := f(ctx, request.Hash)
if err != nil {
return nil, err
}
return &PaymentsStarGiftsBox{StarGifts: response}, nil
}
s.handlers[PaymentsGetStarGiftsRequestTypeID] = handler
}
func (s *ServerDispatcher) OnPaymentsGetUserStarGifts(f func(ctx context.Context, request *PaymentsGetUserStarGiftsRequest) (*PaymentsUserStarGifts, error)) {
handler := func(ctx context.Context, b *bin.Buffer) (bin.Encoder, error) {
var request PaymentsGetUserStarGiftsRequest
if err := request.Decode(b); err != nil {
return nil, err
}
response, err := f(ctx, &request)
if err != nil {
return nil, err
}
return response, nil
}
s.handlers[PaymentsGetUserStarGiftsRequestTypeID] = handler
}
func (s *ServerDispatcher) OnPaymentsSaveStarGift(f func(ctx context.Context, request *PaymentsSaveStarGiftRequest) (bool, error)) {
handler := func(ctx context.Context, b *bin.Buffer) (bin.Encoder, error) {
var request PaymentsSaveStarGiftRequest
if err := request.Decode(b); err != nil {
return nil, err
}
response, err := f(ctx, &request)
if err != nil {
return nil, err
}
if response {
return &BoolBox{Bool: &BoolTrue{}}, nil
}
return &BoolBox{Bool: &BoolFalse{}}, nil
}
s.handlers[PaymentsSaveStarGiftRequestTypeID] = handler
}
func (s *ServerDispatcher) OnPaymentsConvertStarGift(f func(ctx context.Context, request *PaymentsConvertStarGiftRequest) (bool, error)) {
handler := func(ctx context.Context, b *bin.Buffer) (bin.Encoder, error) {
var request PaymentsConvertStarGiftRequest
if err := request.Decode(b); err != nil {
return nil, err
}
response, err := f(ctx, &request)
if err != nil {
return nil, err
}
if response {
return &BoolBox{Bool: &BoolTrue{}}, nil
}
return &BoolBox{Bool: &BoolFalse{}}, nil
}
s.handlers[PaymentsConvertStarGiftRequestTypeID] = handler
}
func (s *ServerDispatcher) OnStickersCreateStickerSet(f func(ctx context.Context, request *StickersCreateStickerSetRequest) (MessagesStickerSetClass, error)) {
handler := func(ctx context.Context, b *bin.Buffer) (bin.Encoder, error) {
var request StickersCreateStickerSetRequest
@ -11378,7 +11450,7 @@ func (s *ServerDispatcher) OnStoriesExportStoryLink(f func(ctx context.Context,
s.handlers[StoriesExportStoryLinkRequestTypeID] = handler
}
func (s *ServerDispatcher) OnStoriesReport(f func(ctx context.Context, request *StoriesReportRequest) (bool, error)) {
func (s *ServerDispatcher) OnStoriesReport(f func(ctx context.Context, request *StoriesReportRequest) (ReportResultClass, error)) {
handler := func(ctx context.Context, b *bin.Buffer) (bin.Encoder, error) {
var request StoriesReportRequest
if err := request.Decode(b); err != nil {
@ -11389,11 +11461,7 @@ func (s *ServerDispatcher) OnStoriesReport(f func(ctx context.Context, request *
if err != nil {
return nil, err
}
if response {
return &BoolBox{Bool: &BoolTrue{}}, nil
}
return &BoolBox{Bool: &BoolFalse{}}, nil
return &ReportResultBox{ReportResult: response}, nil
}
s.handlers[StoriesReportRequestTypeID] = handler

401
vendor/github.com/gotd/td/tg/tl_star_gift_gen.go generated vendored Normal file
View File

@ -0,0 +1,401 @@
// Code generated by gotdgen, DO NOT EDIT.
package tg
import (
"context"
"errors"
"fmt"
"sort"
"strings"
"go.uber.org/multierr"
"github.com/gotd/td/bin"
"github.com/gotd/td/tdjson"
"github.com/gotd/td/tdp"
"github.com/gotd/td/tgerr"
)
// No-op definition for keeping imports.
var (
_ = bin.Buffer{}
_ = context.Background()
_ = fmt.Stringer(nil)
_ = strings.Builder{}
_ = errors.Is
_ = multierr.AppendInto
_ = sort.Ints
_ = tdp.Format
_ = tgerr.Error{}
_ = tdjson.Encoder{}
)
// StarGift represents TL type `starGift#aea174ee`.
//
// See https://core.telegram.org/constructor/starGift for reference.
type StarGift struct {
// Flags field of StarGift.
Flags bin.Fields
// Limited field of StarGift.
Limited bool
// ID field of StarGift.
ID int64
// Sticker field of StarGift.
Sticker DocumentClass
// Stars field of StarGift.
Stars int64
// AvailabilityRemains field of StarGift.
//
// Use SetAvailabilityRemains and GetAvailabilityRemains helpers.
AvailabilityRemains int
// AvailabilityTotal field of StarGift.
//
// Use SetAvailabilityTotal and GetAvailabilityTotal helpers.
AvailabilityTotal int
// ConvertStars field of StarGift.
ConvertStars int64
}
// StarGiftTypeID is TL type id of StarGift.
const StarGiftTypeID = 0xaea174ee
// Ensuring interfaces in compile-time for StarGift.
var (
_ bin.Encoder = &StarGift{}
_ bin.Decoder = &StarGift{}
_ bin.BareEncoder = &StarGift{}
_ bin.BareDecoder = &StarGift{}
)
func (s *StarGift) Zero() bool {
if s == nil {
return true
}
if !(s.Flags.Zero()) {
return false
}
if !(s.Limited == false) {
return false
}
if !(s.ID == 0) {
return false
}
if !(s.Sticker == nil) {
return false
}
if !(s.Stars == 0) {
return false
}
if !(s.AvailabilityRemains == 0) {
return false
}
if !(s.AvailabilityTotal == 0) {
return false
}
if !(s.ConvertStars == 0) {
return false
}
return true
}
// String implements fmt.Stringer.
func (s *StarGift) String() string {
if s == nil {
return "StarGift(nil)"
}
type Alias StarGift
return fmt.Sprintf("StarGift%+v", Alias(*s))
}
// FillFrom fills StarGift from given interface.
func (s *StarGift) FillFrom(from interface {
GetLimited() (value bool)
GetID() (value int64)
GetSticker() (value DocumentClass)
GetStars() (value int64)
GetAvailabilityRemains() (value int, ok bool)
GetAvailabilityTotal() (value int, ok bool)
GetConvertStars() (value int64)
}) {
s.Limited = from.GetLimited()
s.ID = from.GetID()
s.Sticker = from.GetSticker()
s.Stars = from.GetStars()
if val, ok := from.GetAvailabilityRemains(); ok {
s.AvailabilityRemains = val
}
if val, ok := from.GetAvailabilityTotal(); ok {
s.AvailabilityTotal = val
}
s.ConvertStars = from.GetConvertStars()
}
// TypeID returns type id in TL schema.
//
// See https://core.telegram.org/mtproto/TL-tl#remarks.
func (*StarGift) TypeID() uint32 {
return StarGiftTypeID
}
// TypeName returns name of type in TL schema.
func (*StarGift) TypeName() string {
return "starGift"
}
// TypeInfo returns info about TL type.
func (s *StarGift) TypeInfo() tdp.Type {
typ := tdp.Type{
Name: "starGift",
ID: StarGiftTypeID,
}
if s == nil {
typ.Null = true
return typ
}
typ.Fields = []tdp.Field{
{
Name: "Limited",
SchemaName: "limited",
Null: !s.Flags.Has(0),
},
{
Name: "ID",
SchemaName: "id",
},
{
Name: "Sticker",
SchemaName: "sticker",
},
{
Name: "Stars",
SchemaName: "stars",
},
{
Name: "AvailabilityRemains",
SchemaName: "availability_remains",
Null: !s.Flags.Has(0),
},
{
Name: "AvailabilityTotal",
SchemaName: "availability_total",
Null: !s.Flags.Has(0),
},
{
Name: "ConvertStars",
SchemaName: "convert_stars",
},
}
return typ
}
// SetFlags sets flags for non-zero fields.
func (s *StarGift) SetFlags() {
if !(s.Limited == false) {
s.Flags.Set(0)
}
if !(s.AvailabilityRemains == 0) {
s.Flags.Set(0)
}
if !(s.AvailabilityTotal == 0) {
s.Flags.Set(0)
}
}
// Encode implements bin.Encoder.
func (s *StarGift) Encode(b *bin.Buffer) error {
if s == nil {
return fmt.Errorf("can't encode starGift#aea174ee as nil")
}
b.PutID(StarGiftTypeID)
return s.EncodeBare(b)
}
// EncodeBare implements bin.BareEncoder.
func (s *StarGift) EncodeBare(b *bin.Buffer) error {
if s == nil {
return fmt.Errorf("can't encode starGift#aea174ee as nil")
}
s.SetFlags()
if err := s.Flags.Encode(b); err != nil {
return fmt.Errorf("unable to encode starGift#aea174ee: field flags: %w", err)
}
b.PutLong(s.ID)
if s.Sticker == nil {
return fmt.Errorf("unable to encode starGift#aea174ee: field sticker is nil")
}
if err := s.Sticker.Encode(b); err != nil {
return fmt.Errorf("unable to encode starGift#aea174ee: field sticker: %w", err)
}
b.PutLong(s.Stars)
if s.Flags.Has(0) {
b.PutInt(s.AvailabilityRemains)
}
if s.Flags.Has(0) {
b.PutInt(s.AvailabilityTotal)
}
b.PutLong(s.ConvertStars)
return nil
}
// Decode implements bin.Decoder.
func (s *StarGift) Decode(b *bin.Buffer) error {
if s == nil {
return fmt.Errorf("can't decode starGift#aea174ee to nil")
}
if err := b.ConsumeID(StarGiftTypeID); err != nil {
return fmt.Errorf("unable to decode starGift#aea174ee: %w", err)
}
return s.DecodeBare(b)
}
// DecodeBare implements bin.BareDecoder.
func (s *StarGift) DecodeBare(b *bin.Buffer) error {
if s == nil {
return fmt.Errorf("can't decode starGift#aea174ee to nil")
}
{
if err := s.Flags.Decode(b); err != nil {
return fmt.Errorf("unable to decode starGift#aea174ee: field flags: %w", err)
}
}
s.Limited = s.Flags.Has(0)
{
value, err := b.Long()
if err != nil {
return fmt.Errorf("unable to decode starGift#aea174ee: field id: %w", err)
}
s.ID = value
}
{
value, err := DecodeDocument(b)
if err != nil {
return fmt.Errorf("unable to decode starGift#aea174ee: field sticker: %w", err)
}
s.Sticker = value
}
{
value, err := b.Long()
if err != nil {
return fmt.Errorf("unable to decode starGift#aea174ee: field stars: %w", err)
}
s.Stars = value
}
if s.Flags.Has(0) {
value, err := b.Int()
if err != nil {
return fmt.Errorf("unable to decode starGift#aea174ee: field availability_remains: %w", err)
}
s.AvailabilityRemains = value
}
if s.Flags.Has(0) {
value, err := b.Int()
if err != nil {
return fmt.Errorf("unable to decode starGift#aea174ee: field availability_total: %w", err)
}
s.AvailabilityTotal = value
}
{
value, err := b.Long()
if err != nil {
return fmt.Errorf("unable to decode starGift#aea174ee: field convert_stars: %w", err)
}
s.ConvertStars = value
}
return nil
}
// SetLimited sets value of Limited conditional field.
func (s *StarGift) SetLimited(value bool) {
if value {
s.Flags.Set(0)
s.Limited = true
} else {
s.Flags.Unset(0)
s.Limited = false
}
}
// GetLimited returns value of Limited conditional field.
func (s *StarGift) GetLimited() (value bool) {
if s == nil {
return
}
return s.Flags.Has(0)
}
// GetID returns value of ID field.
func (s *StarGift) GetID() (value int64) {
if s == nil {
return
}
return s.ID
}
// GetSticker returns value of Sticker field.
func (s *StarGift) GetSticker() (value DocumentClass) {
if s == nil {
return
}
return s.Sticker
}
// GetStars returns value of Stars field.
func (s *StarGift) GetStars() (value int64) {
if s == nil {
return
}
return s.Stars
}
// SetAvailabilityRemains sets value of AvailabilityRemains conditional field.
func (s *StarGift) SetAvailabilityRemains(value int) {
s.Flags.Set(0)
s.AvailabilityRemains = value
}
// GetAvailabilityRemains returns value of AvailabilityRemains conditional field and
// boolean which is true if field was set.
func (s *StarGift) GetAvailabilityRemains() (value int, ok bool) {
if s == nil {
return
}
if !s.Flags.Has(0) {
return value, false
}
return s.AvailabilityRemains, true
}
// SetAvailabilityTotal sets value of AvailabilityTotal conditional field.
func (s *StarGift) SetAvailabilityTotal(value int) {
s.Flags.Set(0)
s.AvailabilityTotal = value
}
// GetAvailabilityTotal returns value of AvailabilityTotal conditional field and
// boolean which is true if field was set.
func (s *StarGift) GetAvailabilityTotal() (value int, ok bool) {
if s == nil {
return
}
if !s.Flags.Has(0) {
return value, false
}
return s.AvailabilityTotal, true
}
// GetConvertStars returns value of ConvertStars field.
func (s *StarGift) GetConvertStars() (value int64) {
if s == nil {
return
}
return s.ConvertStars
}
// GetStickerAsNotEmpty returns mapped value of Sticker field.
func (s *StarGift) GetStickerAsNotEmpty() (*Document, bool) {
return s.Sticker.AsNotEmpty()
}

View File

@ -0,0 +1,35 @@
//go:build !no_gotd_slices
// +build !no_gotd_slices
// Code generated by gotdgen, DO NOT EDIT.
package tg
import (
"context"
"errors"
"fmt"
"sort"
"strings"
"go.uber.org/multierr"
"github.com/gotd/td/bin"
"github.com/gotd/td/tdjson"
"github.com/gotd/td/tdp"
"github.com/gotd/td/tgerr"
)
// No-op definition for keeping imports.
var (
_ = bin.Buffer{}
_ = context.Background()
_ = fmt.Stringer(nil)
_ = strings.Builder{}
_ = errors.Is
_ = multierr.AppendInto
_ = sort.Ints
_ = tdp.Format
_ = tgerr.Error{}
_ = tdjson.Encoder{}
)

View File

@ -31,7 +31,7 @@ var (
_ = tdjson.Encoder{}
)
// StarsTransaction represents TL type `starsTransaction#ee7522d5`.
// StarsTransaction represents TL type `starsTransaction#a9ee4c2`.
// Represents a Telegram Stars transaction »¹.
//
// Links:
@ -118,10 +118,14 @@ type StarsTransaction struct {
//
// Use SetGiveawayPostID and GetGiveawayPostID helpers.
GiveawayPostID int
// Stargift field of StarsTransaction.
//
// Use SetStargift and GetStargift helpers.
Stargift StarGift
}
// StarsTransactionTypeID is TL type id of StarsTransaction.
const StarsTransactionTypeID = 0xee7522d5
const StarsTransactionTypeID = 0xa9ee4c2
// Ensuring interfaces in compile-time for StarsTransaction.
var (
@ -195,6 +199,9 @@ func (s *StarsTransaction) Zero() bool {
if !(s.GiveawayPostID == 0) {
return false
}
if !(s.Stargift.Zero()) {
return false
}
return true
}
@ -229,6 +236,7 @@ func (s *StarsTransaction) FillFrom(from interface {
GetExtendedMedia() (value []MessageMediaClass, ok bool)
GetSubscriptionPeriod() (value int, ok bool)
GetGiveawayPostID() (value int, ok bool)
GetStargift() (value StarGift, ok bool)
}) {
s.Refund = from.GetRefund()
s.Pending = from.GetPending()
@ -279,6 +287,10 @@ func (s *StarsTransaction) FillFrom(from interface {
s.GiveawayPostID = val
}
if val, ok := from.GetStargift(); ok {
s.Stargift = val
}
}
// TypeID returns type id in TL schema.
@ -395,6 +407,11 @@ func (s *StarsTransaction) TypeInfo() tdp.Type {
SchemaName: "giveaway_post_id",
Null: !s.Flags.Has(13),
},
{
Name: "Stargift",
SchemaName: "stargift",
Null: !s.Flags.Has(14),
},
}
return typ
}
@ -446,12 +463,15 @@ func (s *StarsTransaction) SetFlags() {
if !(s.GiveawayPostID == 0) {
s.Flags.Set(13)
}
if !(s.Stargift.Zero()) {
s.Flags.Set(14)
}
}
// Encode implements bin.Encoder.
func (s *StarsTransaction) Encode(b *bin.Buffer) error {
if s == nil {
return fmt.Errorf("can't encode starsTransaction#ee7522d5 as nil")
return fmt.Errorf("can't encode starsTransaction#a9ee4c2 as nil")
}
b.PutID(StarsTransactionTypeID)
return s.EncodeBare(b)
@ -460,20 +480,20 @@ func (s *StarsTransaction) Encode(b *bin.Buffer) error {
// EncodeBare implements bin.BareEncoder.
func (s *StarsTransaction) EncodeBare(b *bin.Buffer) error {
if s == nil {
return fmt.Errorf("can't encode starsTransaction#ee7522d5 as nil")
return fmt.Errorf("can't encode starsTransaction#a9ee4c2 as nil")
}
s.SetFlags()
if err := s.Flags.Encode(b); err != nil {
return fmt.Errorf("unable to encode starsTransaction#ee7522d5: field flags: %w", err)
return fmt.Errorf("unable to encode starsTransaction#a9ee4c2: field flags: %w", err)
}
b.PutString(s.ID)
b.PutLong(s.Stars)
b.PutInt(s.Date)
if s.Peer == nil {
return fmt.Errorf("unable to encode starsTransaction#ee7522d5: field peer is nil")
return fmt.Errorf("unable to encode starsTransaction#a9ee4c2: field peer is nil")
}
if err := s.Peer.Encode(b); err != nil {
return fmt.Errorf("unable to encode starsTransaction#ee7522d5: field peer: %w", err)
return fmt.Errorf("unable to encode starsTransaction#a9ee4c2: field peer: %w", err)
}
if s.Flags.Has(0) {
b.PutString(s.Title)
@ -483,10 +503,10 @@ func (s *StarsTransaction) EncodeBare(b *bin.Buffer) error {
}
if s.Flags.Has(2) {
if s.Photo == nil {
return fmt.Errorf("unable to encode starsTransaction#ee7522d5: field photo is nil")
return fmt.Errorf("unable to encode starsTransaction#a9ee4c2: field photo is nil")
}
if err := s.Photo.Encode(b); err != nil {
return fmt.Errorf("unable to encode starsTransaction#ee7522d5: field photo: %w", err)
return fmt.Errorf("unable to encode starsTransaction#a9ee4c2: field photo: %w", err)
}
}
if s.Flags.Has(5) {
@ -505,10 +525,10 @@ func (s *StarsTransaction) EncodeBare(b *bin.Buffer) error {
b.PutVectorHeader(len(s.ExtendedMedia))
for idx, v := range s.ExtendedMedia {
if v == nil {
return fmt.Errorf("unable to encode starsTransaction#ee7522d5: field extended_media element with index %d is nil", idx)
return fmt.Errorf("unable to encode starsTransaction#a9ee4c2: field extended_media element with index %d is nil", idx)
}
if err := v.Encode(b); err != nil {
return fmt.Errorf("unable to encode starsTransaction#ee7522d5: field extended_media element with index %d: %w", idx, err)
return fmt.Errorf("unable to encode starsTransaction#a9ee4c2: field extended_media element with index %d: %w", idx, err)
}
}
}
@ -518,16 +538,21 @@ func (s *StarsTransaction) EncodeBare(b *bin.Buffer) error {
if s.Flags.Has(13) {
b.PutInt(s.GiveawayPostID)
}
if s.Flags.Has(14) {
if err := s.Stargift.Encode(b); err != nil {
return fmt.Errorf("unable to encode starsTransaction#a9ee4c2: field stargift: %w", err)
}
}
return nil
}
// Decode implements bin.Decoder.
func (s *StarsTransaction) Decode(b *bin.Buffer) error {
if s == nil {
return fmt.Errorf("can't decode starsTransaction#ee7522d5 to nil")
return fmt.Errorf("can't decode starsTransaction#a9ee4c2 to nil")
}
if err := b.ConsumeID(StarsTransactionTypeID); err != nil {
return fmt.Errorf("unable to decode starsTransaction#ee7522d5: %w", err)
return fmt.Errorf("unable to decode starsTransaction#a9ee4c2: %w", err)
}
return s.DecodeBare(b)
}
@ -535,11 +560,11 @@ func (s *StarsTransaction) Decode(b *bin.Buffer) error {
// DecodeBare implements bin.BareDecoder.
func (s *StarsTransaction) DecodeBare(b *bin.Buffer) error {
if s == nil {
return fmt.Errorf("can't decode starsTransaction#ee7522d5 to nil")
return fmt.Errorf("can't decode starsTransaction#a9ee4c2 to nil")
}
{
if err := s.Flags.Decode(b); err != nil {
return fmt.Errorf("unable to decode starsTransaction#ee7522d5: field flags: %w", err)
return fmt.Errorf("unable to decode starsTransaction#a9ee4c2: field flags: %w", err)
}
}
s.Refund = s.Flags.Has(3)
@ -550,84 +575,84 @@ func (s *StarsTransaction) DecodeBare(b *bin.Buffer) error {
{
value, err := b.String()
if err != nil {
return fmt.Errorf("unable to decode starsTransaction#ee7522d5: field id: %w", err)
return fmt.Errorf("unable to decode starsTransaction#a9ee4c2: field id: %w", err)
}
s.ID = value
}
{
value, err := b.Long()
if err != nil {
return fmt.Errorf("unable to decode starsTransaction#ee7522d5: field stars: %w", err)
return fmt.Errorf("unable to decode starsTransaction#a9ee4c2: field stars: %w", err)
}
s.Stars = value
}
{
value, err := b.Int()
if err != nil {
return fmt.Errorf("unable to decode starsTransaction#ee7522d5: field date: %w", err)
return fmt.Errorf("unable to decode starsTransaction#a9ee4c2: field date: %w", err)
}
s.Date = value
}
{
value, err := DecodeStarsTransactionPeer(b)
if err != nil {
return fmt.Errorf("unable to decode starsTransaction#ee7522d5: field peer: %w", err)
return fmt.Errorf("unable to decode starsTransaction#a9ee4c2: field peer: %w", err)
}
s.Peer = value
}
if s.Flags.Has(0) {
value, err := b.String()
if err != nil {
return fmt.Errorf("unable to decode starsTransaction#ee7522d5: field title: %w", err)
return fmt.Errorf("unable to decode starsTransaction#a9ee4c2: field title: %w", err)
}
s.Title = value
}
if s.Flags.Has(1) {
value, err := b.String()
if err != nil {
return fmt.Errorf("unable to decode starsTransaction#ee7522d5: field description: %w", err)
return fmt.Errorf("unable to decode starsTransaction#a9ee4c2: field description: %w", err)
}
s.Description = value
}
if s.Flags.Has(2) {
value, err := DecodeWebDocument(b)
if err != nil {
return fmt.Errorf("unable to decode starsTransaction#ee7522d5: field photo: %w", err)
return fmt.Errorf("unable to decode starsTransaction#a9ee4c2: field photo: %w", err)
}
s.Photo = value
}
if s.Flags.Has(5) {
value, err := b.Int()
if err != nil {
return fmt.Errorf("unable to decode starsTransaction#ee7522d5: field transaction_date: %w", err)
return fmt.Errorf("unable to decode starsTransaction#a9ee4c2: field transaction_date: %w", err)
}
s.TransactionDate = value
}
if s.Flags.Has(5) {
value, err := b.String()
if err != nil {
return fmt.Errorf("unable to decode starsTransaction#ee7522d5: field transaction_url: %w", err)
return fmt.Errorf("unable to decode starsTransaction#a9ee4c2: field transaction_url: %w", err)
}
s.TransactionURL = value
}
if s.Flags.Has(7) {
value, err := b.Bytes()
if err != nil {
return fmt.Errorf("unable to decode starsTransaction#ee7522d5: field bot_payload: %w", err)
return fmt.Errorf("unable to decode starsTransaction#a9ee4c2: field bot_payload: %w", err)
}
s.BotPayload = value
}
if s.Flags.Has(8) {
value, err := b.Int()
if err != nil {
return fmt.Errorf("unable to decode starsTransaction#ee7522d5: field msg_id: %w", err)
return fmt.Errorf("unable to decode starsTransaction#a9ee4c2: field msg_id: %w", err)
}
s.MsgID = value
}
if s.Flags.Has(9) {
headerLen, err := b.VectorHeader()
if err != nil {
return fmt.Errorf("unable to decode starsTransaction#ee7522d5: field extended_media: %w", err)
return fmt.Errorf("unable to decode starsTransaction#a9ee4c2: field extended_media: %w", err)
}
if headerLen > 0 {
@ -636,7 +661,7 @@ func (s *StarsTransaction) DecodeBare(b *bin.Buffer) error {
for idx := 0; idx < headerLen; idx++ {
value, err := DecodeMessageMedia(b)
if err != nil {
return fmt.Errorf("unable to decode starsTransaction#ee7522d5: field extended_media: %w", err)
return fmt.Errorf("unable to decode starsTransaction#a9ee4c2: field extended_media: %w", err)
}
s.ExtendedMedia = append(s.ExtendedMedia, value)
}
@ -644,17 +669,22 @@ func (s *StarsTransaction) DecodeBare(b *bin.Buffer) error {
if s.Flags.Has(12) {
value, err := b.Int()
if err != nil {
return fmt.Errorf("unable to decode starsTransaction#ee7522d5: field subscription_period: %w", err)
return fmt.Errorf("unable to decode starsTransaction#a9ee4c2: field subscription_period: %w", err)
}
s.SubscriptionPeriod = value
}
if s.Flags.Has(13) {
value, err := b.Int()
if err != nil {
return fmt.Errorf("unable to decode starsTransaction#ee7522d5: field giveaway_post_id: %w", err)
return fmt.Errorf("unable to decode starsTransaction#a9ee4c2: field giveaway_post_id: %w", err)
}
s.GiveawayPostID = value
}
if s.Flags.Has(14) {
if err := s.Stargift.Decode(b); err != nil {
return fmt.Errorf("unable to decode starsTransaction#a9ee4c2: field stargift: %w", err)
}
}
return nil
}
@ -965,6 +995,24 @@ func (s *StarsTransaction) GetGiveawayPostID() (value int, ok bool) {
return s.GiveawayPostID, true
}
// SetStargift sets value of Stargift conditional field.
func (s *StarsTransaction) SetStargift(value StarGift) {
s.Flags.Set(14)
s.Stargift = value
}
// GetStargift returns value of Stargift conditional field and
// boolean which is true if field was set.
func (s *StarsTransaction) GetStargift() (value StarGift, ok bool) {
if s == nil {
return
}
if !s.Flags.Has(14) {
return value, false
}
return s.Stargift, true
}
// MapExtendedMedia returns field ExtendedMedia wrapped in MessageMediaClassArray helper.
func (s *StarsTransaction) MapExtendedMedia() (value MessageMediaClassArray, ok bool) {
if !s.Flags.Has(9) {

View File

@ -31,7 +31,7 @@ var (
_ = tdjson.Encoder{}
)
// StoriesReportRequest represents TL type `stories.report#1923fa8c`.
// StoriesReportRequest represents TL type `stories.report#19d8eb45`.
// Report a story.
//
// See https://core.telegram.org/method/stories.report for reference.
@ -40,14 +40,14 @@ type StoriesReportRequest struct {
Peer InputPeerClass
// IDs of the stories to report.
ID []int
// Why are these storeis being reported.
Reason ReportReasonClass
// Option field of StoriesReportRequest.
Option []byte
// Comment for report moderation
Message string
}
// StoriesReportRequestTypeID is TL type id of StoriesReportRequest.
const StoriesReportRequestTypeID = 0x1923fa8c
const StoriesReportRequestTypeID = 0x19d8eb45
// Ensuring interfaces in compile-time for StoriesReportRequest.
var (
@ -67,7 +67,7 @@ func (r *StoriesReportRequest) Zero() bool {
if !(r.ID == nil) {
return false
}
if !(r.Reason == nil) {
if !(r.Option == nil) {
return false
}
if !(r.Message == "") {
@ -90,12 +90,12 @@ func (r *StoriesReportRequest) String() string {
func (r *StoriesReportRequest) FillFrom(from interface {
GetPeer() (value InputPeerClass)
GetID() (value []int)
GetReason() (value ReportReasonClass)
GetOption() (value []byte)
GetMessage() (value string)
}) {
r.Peer = from.GetPeer()
r.ID = from.GetID()
r.Reason = from.GetReason()
r.Option = from.GetOption()
r.Message = from.GetMessage()
}
@ -131,8 +131,8 @@ func (r *StoriesReportRequest) TypeInfo() tdp.Type {
SchemaName: "id",
},
{
Name: "Reason",
SchemaName: "reason",
Name: "Option",
SchemaName: "option",
},
{
Name: "Message",
@ -145,7 +145,7 @@ func (r *StoriesReportRequest) TypeInfo() tdp.Type {
// Encode implements bin.Encoder.
func (r *StoriesReportRequest) Encode(b *bin.Buffer) error {
if r == nil {
return fmt.Errorf("can't encode stories.report#1923fa8c as nil")
return fmt.Errorf("can't encode stories.report#19d8eb45 as nil")
}
b.PutID(StoriesReportRequestTypeID)
return r.EncodeBare(b)
@ -154,24 +154,19 @@ func (r *StoriesReportRequest) Encode(b *bin.Buffer) error {
// EncodeBare implements bin.BareEncoder.
func (r *StoriesReportRequest) EncodeBare(b *bin.Buffer) error {
if r == nil {
return fmt.Errorf("can't encode stories.report#1923fa8c as nil")
return fmt.Errorf("can't encode stories.report#19d8eb45 as nil")
}
if r.Peer == nil {
return fmt.Errorf("unable to encode stories.report#1923fa8c: field peer is nil")
return fmt.Errorf("unable to encode stories.report#19d8eb45: field peer is nil")
}
if err := r.Peer.Encode(b); err != nil {
return fmt.Errorf("unable to encode stories.report#1923fa8c: field peer: %w", err)
return fmt.Errorf("unable to encode stories.report#19d8eb45: field peer: %w", err)
}
b.PutVectorHeader(len(r.ID))
for _, v := range r.ID {
b.PutInt(v)
}
if r.Reason == nil {
return fmt.Errorf("unable to encode stories.report#1923fa8c: field reason is nil")
}
if err := r.Reason.Encode(b); err != nil {
return fmt.Errorf("unable to encode stories.report#1923fa8c: field reason: %w", err)
}
b.PutBytes(r.Option)
b.PutString(r.Message)
return nil
}
@ -179,10 +174,10 @@ func (r *StoriesReportRequest) EncodeBare(b *bin.Buffer) error {
// Decode implements bin.Decoder.
func (r *StoriesReportRequest) Decode(b *bin.Buffer) error {
if r == nil {
return fmt.Errorf("can't decode stories.report#1923fa8c to nil")
return fmt.Errorf("can't decode stories.report#19d8eb45 to nil")
}
if err := b.ConsumeID(StoriesReportRequestTypeID); err != nil {
return fmt.Errorf("unable to decode stories.report#1923fa8c: %w", err)
return fmt.Errorf("unable to decode stories.report#19d8eb45: %w", err)
}
return r.DecodeBare(b)
}
@ -190,19 +185,19 @@ func (r *StoriesReportRequest) Decode(b *bin.Buffer) error {
// DecodeBare implements bin.BareDecoder.
func (r *StoriesReportRequest) DecodeBare(b *bin.Buffer) error {
if r == nil {
return fmt.Errorf("can't decode stories.report#1923fa8c to nil")
return fmt.Errorf("can't decode stories.report#19d8eb45 to nil")
}
{
value, err := DecodeInputPeer(b)
if err != nil {
return fmt.Errorf("unable to decode stories.report#1923fa8c: field peer: %w", err)
return fmt.Errorf("unable to decode stories.report#19d8eb45: field peer: %w", err)
}
r.Peer = value
}
{
headerLen, err := b.VectorHeader()
if err != nil {
return fmt.Errorf("unable to decode stories.report#1923fa8c: field id: %w", err)
return fmt.Errorf("unable to decode stories.report#19d8eb45: field id: %w", err)
}
if headerLen > 0 {
@ -211,22 +206,22 @@ func (r *StoriesReportRequest) DecodeBare(b *bin.Buffer) error {
for idx := 0; idx < headerLen; idx++ {
value, err := b.Int()
if err != nil {
return fmt.Errorf("unable to decode stories.report#1923fa8c: field id: %w", err)
return fmt.Errorf("unable to decode stories.report#19d8eb45: field id: %w", err)
}
r.ID = append(r.ID, value)
}
}
{
value, err := DecodeReportReason(b)
value, err := b.Bytes()
if err != nil {
return fmt.Errorf("unable to decode stories.report#1923fa8c: field reason: %w", err)
return fmt.Errorf("unable to decode stories.report#19d8eb45: field option: %w", err)
}
r.Reason = value
r.Option = value
}
{
value, err := b.String()
if err != nil {
return fmt.Errorf("unable to decode stories.report#1923fa8c: field message: %w", err)
return fmt.Errorf("unable to decode stories.report#19d8eb45: field message: %w", err)
}
r.Message = value
}
@ -249,12 +244,12 @@ func (r *StoriesReportRequest) GetID() (value []int) {
return r.ID
}
// GetReason returns value of Reason field.
func (r *StoriesReportRequest) GetReason() (value ReportReasonClass) {
// GetOption returns value of Option field.
func (r *StoriesReportRequest) GetOption() (value []byte) {
if r == nil {
return
}
return r.Reason
return r.Option
}
// GetMessage returns value of Message field.
@ -265,7 +260,7 @@ func (r *StoriesReportRequest) GetMessage() (value string) {
return r.Message
}
// StoriesReport invokes method stories.report#1923fa8c returning error if any.
// StoriesReport invokes method stories.report#19d8eb45 returning error if any.
// Report a story.
//
// Possible errors:
@ -273,12 +268,11 @@ func (r *StoriesReportRequest) GetMessage() (value string) {
// 400 PEER_ID_INVALID: The provided peer id is invalid.
//
// See https://core.telegram.org/method/stories.report for reference.
func (c *Client) StoriesReport(ctx context.Context, request *StoriesReportRequest) (bool, error) {
var result BoolBox
func (c *Client) StoriesReport(ctx context.Context, request *StoriesReportRequest) (ReportResultClass, error) {
var result ReportResultBox
if err := c.rpc.Invoke(ctx, request, &result); err != nil {
return false, err
return nil, err
}
_, ok := result.Bool.(*BoolTrue)
return ok, nil
return result.ReportResult, nil
}

View File

@ -31,7 +31,7 @@ var (
_ = tdjson.Encoder{}
)
// UserFull represents TL type `userFull#cc997720`.
// UserFull represents TL type `userFull#1f58e369`.
// Extended user info
// When updating the local peer database »¹, all fields from the newly received
// constructor take priority over the old constructor cached locally (including by
@ -270,10 +270,14 @@ type UserFull struct {
//
// Use SetPersonalChannelMessage and GetPersonalChannelMessage helpers.
PersonalChannelMessage int
// StargiftsCount field of UserFull.
//
// Use SetStargiftsCount and GetStargiftsCount helpers.
StargiftsCount int
}
// UserFullTypeID is TL type id of UserFull.
const UserFullTypeID = 0xcc997720
const UserFullTypeID = 0x1f58e369
// Ensuring interfaces in compile-time for UserFull.
var (
@ -416,6 +420,9 @@ func (u *UserFull) Zero() bool {
if !(u.PersonalChannelMessage == 0) {
return false
}
if !(u.StargiftsCount == 0) {
return false
}
return true
}
@ -472,6 +479,7 @@ func (u *UserFull) FillFrom(from interface {
GetBirthday() (value Birthday, ok bool)
GetPersonalChannelID() (value int64, ok bool)
GetPersonalChannelMessage() (value int, ok bool)
GetStargiftsCount() (value int, ok bool)
}) {
u.Blocked = from.GetBlocked()
u.PhoneCallsAvailable = from.GetPhoneCallsAvailable()
@ -583,6 +591,10 @@ func (u *UserFull) FillFrom(from interface {
u.PersonalChannelMessage = val
}
if val, ok := from.GetStargiftsCount(); ok {
u.StargiftsCount = val
}
}
// TypeID returns type id in TL schema.
@ -809,6 +821,11 @@ func (u *UserFull) TypeInfo() tdp.Type {
SchemaName: "personal_channel_message",
Null: !u.Flags2.Has(6),
},
{
Name: "StargiftsCount",
SchemaName: "stargifts_count",
Null: !u.Flags2.Has(8),
},
}
return typ
}
@ -926,12 +943,15 @@ func (u *UserFull) SetFlags() {
if !(u.PersonalChannelMessage == 0) {
u.Flags2.Set(6)
}
if !(u.StargiftsCount == 0) {
u.Flags2.Set(8)
}
}
// Encode implements bin.Encoder.
func (u *UserFull) Encode(b *bin.Buffer) error {
if u == nil {
return fmt.Errorf("can't encode userFull#cc997720 as nil")
return fmt.Errorf("can't encode userFull#1f58e369 as nil")
}
b.PutID(UserFullTypeID)
return u.EncodeBare(b)
@ -940,52 +960,52 @@ func (u *UserFull) Encode(b *bin.Buffer) error {
// EncodeBare implements bin.BareEncoder.
func (u *UserFull) EncodeBare(b *bin.Buffer) error {
if u == nil {
return fmt.Errorf("can't encode userFull#cc997720 as nil")
return fmt.Errorf("can't encode userFull#1f58e369 as nil")
}
u.SetFlags()
if err := u.Flags.Encode(b); err != nil {
return fmt.Errorf("unable to encode userFull#cc997720: field flags: %w", err)
return fmt.Errorf("unable to encode userFull#1f58e369: field flags: %w", err)
}
if err := u.Flags2.Encode(b); err != nil {
return fmt.Errorf("unable to encode userFull#cc997720: field flags2: %w", err)
return fmt.Errorf("unable to encode userFull#1f58e369: field flags2: %w", err)
}
b.PutLong(u.ID)
if u.Flags.Has(1) {
b.PutString(u.About)
}
if err := u.Settings.Encode(b); err != nil {
return fmt.Errorf("unable to encode userFull#cc997720: field settings: %w", err)
return fmt.Errorf("unable to encode userFull#1f58e369: field settings: %w", err)
}
if u.Flags.Has(21) {
if u.PersonalPhoto == nil {
return fmt.Errorf("unable to encode userFull#cc997720: field personal_photo is nil")
return fmt.Errorf("unable to encode userFull#1f58e369: field personal_photo is nil")
}
if err := u.PersonalPhoto.Encode(b); err != nil {
return fmt.Errorf("unable to encode userFull#cc997720: field personal_photo: %w", err)
return fmt.Errorf("unable to encode userFull#1f58e369: field personal_photo: %w", err)
}
}
if u.Flags.Has(2) {
if u.ProfilePhoto == nil {
return fmt.Errorf("unable to encode userFull#cc997720: field profile_photo is nil")
return fmt.Errorf("unable to encode userFull#1f58e369: field profile_photo is nil")
}
if err := u.ProfilePhoto.Encode(b); err != nil {
return fmt.Errorf("unable to encode userFull#cc997720: field profile_photo: %w", err)
return fmt.Errorf("unable to encode userFull#1f58e369: field profile_photo: %w", err)
}
}
if u.Flags.Has(22) {
if u.FallbackPhoto == nil {
return fmt.Errorf("unable to encode userFull#cc997720: field fallback_photo is nil")
return fmt.Errorf("unable to encode userFull#1f58e369: field fallback_photo is nil")
}
if err := u.FallbackPhoto.Encode(b); err != nil {
return fmt.Errorf("unable to encode userFull#cc997720: field fallback_photo: %w", err)
return fmt.Errorf("unable to encode userFull#1f58e369: field fallback_photo: %w", err)
}
}
if err := u.NotifySettings.Encode(b); err != nil {
return fmt.Errorf("unable to encode userFull#cc997720: field notify_settings: %w", err)
return fmt.Errorf("unable to encode userFull#1f58e369: field notify_settings: %w", err)
}
if u.Flags.Has(3) {
if err := u.BotInfo.Encode(b); err != nil {
return fmt.Errorf("unable to encode userFull#cc997720: field bot_info: %w", err)
return fmt.Errorf("unable to encode userFull#1f58e369: field bot_info: %w", err)
}
}
if u.Flags.Has(6) {
@ -1006,63 +1026,63 @@ func (u *UserFull) EncodeBare(b *bin.Buffer) error {
}
if u.Flags.Has(17) {
if err := u.BotGroupAdminRights.Encode(b); err != nil {
return fmt.Errorf("unable to encode userFull#cc997720: field bot_group_admin_rights: %w", err)
return fmt.Errorf("unable to encode userFull#1f58e369: field bot_group_admin_rights: %w", err)
}
}
if u.Flags.Has(18) {
if err := u.BotBroadcastAdminRights.Encode(b); err != nil {
return fmt.Errorf("unable to encode userFull#cc997720: field bot_broadcast_admin_rights: %w", err)
return fmt.Errorf("unable to encode userFull#1f58e369: field bot_broadcast_admin_rights: %w", err)
}
}
if u.Flags.Has(19) {
b.PutVectorHeader(len(u.PremiumGifts))
for idx, v := range u.PremiumGifts {
if err := v.Encode(b); err != nil {
return fmt.Errorf("unable to encode userFull#cc997720: field premium_gifts element with index %d: %w", idx, err)
return fmt.Errorf("unable to encode userFull#1f58e369: field premium_gifts element with index %d: %w", idx, err)
}
}
}
if u.Flags.Has(24) {
if u.Wallpaper == nil {
return fmt.Errorf("unable to encode userFull#cc997720: field wallpaper is nil")
return fmt.Errorf("unable to encode userFull#1f58e369: field wallpaper is nil")
}
if err := u.Wallpaper.Encode(b); err != nil {
return fmt.Errorf("unable to encode userFull#cc997720: field wallpaper: %w", err)
return fmt.Errorf("unable to encode userFull#1f58e369: field wallpaper: %w", err)
}
}
if u.Flags.Has(25) {
if err := u.Stories.Encode(b); err != nil {
return fmt.Errorf("unable to encode userFull#cc997720: field stories: %w", err)
return fmt.Errorf("unable to encode userFull#1f58e369: field stories: %w", err)
}
}
if u.Flags2.Has(0) {
if err := u.BusinessWorkHours.Encode(b); err != nil {
return fmt.Errorf("unable to encode userFull#cc997720: field business_work_hours: %w", err)
return fmt.Errorf("unable to encode userFull#1f58e369: field business_work_hours: %w", err)
}
}
if u.Flags2.Has(1) {
if err := u.BusinessLocation.Encode(b); err != nil {
return fmt.Errorf("unable to encode userFull#cc997720: field business_location: %w", err)
return fmt.Errorf("unable to encode userFull#1f58e369: field business_location: %w", err)
}
}
if u.Flags2.Has(2) {
if err := u.BusinessGreetingMessage.Encode(b); err != nil {
return fmt.Errorf("unable to encode userFull#cc997720: field business_greeting_message: %w", err)
return fmt.Errorf("unable to encode userFull#1f58e369: field business_greeting_message: %w", err)
}
}
if u.Flags2.Has(3) {
if err := u.BusinessAwayMessage.Encode(b); err != nil {
return fmt.Errorf("unable to encode userFull#cc997720: field business_away_message: %w", err)
return fmt.Errorf("unable to encode userFull#1f58e369: field business_away_message: %w", err)
}
}
if u.Flags2.Has(4) {
if err := u.BusinessIntro.Encode(b); err != nil {
return fmt.Errorf("unable to encode userFull#cc997720: field business_intro: %w", err)
return fmt.Errorf("unable to encode userFull#1f58e369: field business_intro: %w", err)
}
}
if u.Flags2.Has(5) {
if err := u.Birthday.Encode(b); err != nil {
return fmt.Errorf("unable to encode userFull#cc997720: field birthday: %w", err)
return fmt.Errorf("unable to encode userFull#1f58e369: field birthday: %w", err)
}
}
if u.Flags2.Has(6) {
@ -1071,16 +1091,19 @@ func (u *UserFull) EncodeBare(b *bin.Buffer) error {
if u.Flags2.Has(6) {
b.PutInt(u.PersonalChannelMessage)
}
if u.Flags2.Has(8) {
b.PutInt(u.StargiftsCount)
}
return nil
}
// Decode implements bin.Decoder.
func (u *UserFull) Decode(b *bin.Buffer) error {
if u == nil {
return fmt.Errorf("can't decode userFull#cc997720 to nil")
return fmt.Errorf("can't decode userFull#1f58e369 to nil")
}
if err := b.ConsumeID(UserFullTypeID); err != nil {
return fmt.Errorf("unable to decode userFull#cc997720: %w", err)
return fmt.Errorf("unable to decode userFull#1f58e369: %w", err)
}
return u.DecodeBare(b)
}
@ -1088,11 +1111,11 @@ func (u *UserFull) Decode(b *bin.Buffer) error {
// DecodeBare implements bin.BareDecoder.
func (u *UserFull) DecodeBare(b *bin.Buffer) error {
if u == nil {
return fmt.Errorf("can't decode userFull#cc997720 to nil")
return fmt.Errorf("can't decode userFull#1f58e369 to nil")
}
{
if err := u.Flags.Decode(b); err != nil {
return fmt.Errorf("unable to decode userFull#cc997720: field flags: %w", err)
return fmt.Errorf("unable to decode userFull#1f58e369: field flags: %w", err)
}
}
u.Blocked = u.Flags.Has(0)
@ -1110,116 +1133,116 @@ func (u *UserFull) DecodeBare(b *bin.Buffer) error {
u.ReadDatesPrivate = u.Flags.Has(30)
{
if err := u.Flags2.Decode(b); err != nil {
return fmt.Errorf("unable to decode userFull#cc997720: field flags2: %w", err)
return fmt.Errorf("unable to decode userFull#1f58e369: field flags2: %w", err)
}
}
u.SponsoredEnabled = u.Flags2.Has(7)
{
value, err := b.Long()
if err != nil {
return fmt.Errorf("unable to decode userFull#cc997720: field id: %w", err)
return fmt.Errorf("unable to decode userFull#1f58e369: field id: %w", err)
}
u.ID = value
}
if u.Flags.Has(1) {
value, err := b.String()
if err != nil {
return fmt.Errorf("unable to decode userFull#cc997720: field about: %w", err)
return fmt.Errorf("unable to decode userFull#1f58e369: field about: %w", err)
}
u.About = value
}
{
if err := u.Settings.Decode(b); err != nil {
return fmt.Errorf("unable to decode userFull#cc997720: field settings: %w", err)
return fmt.Errorf("unable to decode userFull#1f58e369: field settings: %w", err)
}
}
if u.Flags.Has(21) {
value, err := DecodePhoto(b)
if err != nil {
return fmt.Errorf("unable to decode userFull#cc997720: field personal_photo: %w", err)
return fmt.Errorf("unable to decode userFull#1f58e369: field personal_photo: %w", err)
}
u.PersonalPhoto = value
}
if u.Flags.Has(2) {
value, err := DecodePhoto(b)
if err != nil {
return fmt.Errorf("unable to decode userFull#cc997720: field profile_photo: %w", err)
return fmt.Errorf("unable to decode userFull#1f58e369: field profile_photo: %w", err)
}
u.ProfilePhoto = value
}
if u.Flags.Has(22) {
value, err := DecodePhoto(b)
if err != nil {
return fmt.Errorf("unable to decode userFull#cc997720: field fallback_photo: %w", err)
return fmt.Errorf("unable to decode userFull#1f58e369: field fallback_photo: %w", err)
}
u.FallbackPhoto = value
}
{
if err := u.NotifySettings.Decode(b); err != nil {
return fmt.Errorf("unable to decode userFull#cc997720: field notify_settings: %w", err)
return fmt.Errorf("unable to decode userFull#1f58e369: field notify_settings: %w", err)
}
}
if u.Flags.Has(3) {
if err := u.BotInfo.Decode(b); err != nil {
return fmt.Errorf("unable to decode userFull#cc997720: field bot_info: %w", err)
return fmt.Errorf("unable to decode userFull#1f58e369: field bot_info: %w", err)
}
}
if u.Flags.Has(6) {
value, err := b.Int()
if err != nil {
return fmt.Errorf("unable to decode userFull#cc997720: field pinned_msg_id: %w", err)
return fmt.Errorf("unable to decode userFull#1f58e369: field pinned_msg_id: %w", err)
}
u.PinnedMsgID = value
}
{
value, err := b.Int()
if err != nil {
return fmt.Errorf("unable to decode userFull#cc997720: field common_chats_count: %w", err)
return fmt.Errorf("unable to decode userFull#1f58e369: field common_chats_count: %w", err)
}
u.CommonChatsCount = value
}
if u.Flags.Has(11) {
value, err := b.Int()
if err != nil {
return fmt.Errorf("unable to decode userFull#cc997720: field folder_id: %w", err)
return fmt.Errorf("unable to decode userFull#1f58e369: field folder_id: %w", err)
}
u.FolderID = value
}
if u.Flags.Has(14) {
value, err := b.Int()
if err != nil {
return fmt.Errorf("unable to decode userFull#cc997720: field ttl_period: %w", err)
return fmt.Errorf("unable to decode userFull#1f58e369: field ttl_period: %w", err)
}
u.TTLPeriod = value
}
if u.Flags.Has(15) {
value, err := b.String()
if err != nil {
return fmt.Errorf("unable to decode userFull#cc997720: field theme_emoticon: %w", err)
return fmt.Errorf("unable to decode userFull#1f58e369: field theme_emoticon: %w", err)
}
u.ThemeEmoticon = value
}
if u.Flags.Has(16) {
value, err := b.String()
if err != nil {
return fmt.Errorf("unable to decode userFull#cc997720: field private_forward_name: %w", err)
return fmt.Errorf("unable to decode userFull#1f58e369: field private_forward_name: %w", err)
}
u.PrivateForwardName = value
}
if u.Flags.Has(17) {
if err := u.BotGroupAdminRights.Decode(b); err != nil {
return fmt.Errorf("unable to decode userFull#cc997720: field bot_group_admin_rights: %w", err)
return fmt.Errorf("unable to decode userFull#1f58e369: field bot_group_admin_rights: %w", err)
}
}
if u.Flags.Has(18) {
if err := u.BotBroadcastAdminRights.Decode(b); err != nil {
return fmt.Errorf("unable to decode userFull#cc997720: field bot_broadcast_admin_rights: %w", err)
return fmt.Errorf("unable to decode userFull#1f58e369: field bot_broadcast_admin_rights: %w", err)
}
}
if u.Flags.Has(19) {
headerLen, err := b.VectorHeader()
if err != nil {
return fmt.Errorf("unable to decode userFull#cc997720: field premium_gifts: %w", err)
return fmt.Errorf("unable to decode userFull#1f58e369: field premium_gifts: %w", err)
}
if headerLen > 0 {
@ -1228,7 +1251,7 @@ func (u *UserFull) DecodeBare(b *bin.Buffer) error {
for idx := 0; idx < headerLen; idx++ {
var value PremiumGiftOption
if err := value.Decode(b); err != nil {
return fmt.Errorf("unable to decode userFull#cc997720: field premium_gifts: %w", err)
return fmt.Errorf("unable to decode userFull#1f58e369: field premium_gifts: %w", err)
}
u.PremiumGifts = append(u.PremiumGifts, value)
}
@ -1236,59 +1259,66 @@ func (u *UserFull) DecodeBare(b *bin.Buffer) error {
if u.Flags.Has(24) {
value, err := DecodeWallPaper(b)
if err != nil {
return fmt.Errorf("unable to decode userFull#cc997720: field wallpaper: %w", err)
return fmt.Errorf("unable to decode userFull#1f58e369: field wallpaper: %w", err)
}
u.Wallpaper = value
}
if u.Flags.Has(25) {
if err := u.Stories.Decode(b); err != nil {
return fmt.Errorf("unable to decode userFull#cc997720: field stories: %w", err)
return fmt.Errorf("unable to decode userFull#1f58e369: field stories: %w", err)
}
}
if u.Flags2.Has(0) {
if err := u.BusinessWorkHours.Decode(b); err != nil {
return fmt.Errorf("unable to decode userFull#cc997720: field business_work_hours: %w", err)
return fmt.Errorf("unable to decode userFull#1f58e369: field business_work_hours: %w", err)
}
}
if u.Flags2.Has(1) {
if err := u.BusinessLocation.Decode(b); err != nil {
return fmt.Errorf("unable to decode userFull#cc997720: field business_location: %w", err)
return fmt.Errorf("unable to decode userFull#1f58e369: field business_location: %w", err)
}
}
if u.Flags2.Has(2) {
if err := u.BusinessGreetingMessage.Decode(b); err != nil {
return fmt.Errorf("unable to decode userFull#cc997720: field business_greeting_message: %w", err)
return fmt.Errorf("unable to decode userFull#1f58e369: field business_greeting_message: %w", err)
}
}
if u.Flags2.Has(3) {
if err := u.BusinessAwayMessage.Decode(b); err != nil {
return fmt.Errorf("unable to decode userFull#cc997720: field business_away_message: %w", err)
return fmt.Errorf("unable to decode userFull#1f58e369: field business_away_message: %w", err)
}
}
if u.Flags2.Has(4) {
if err := u.BusinessIntro.Decode(b); err != nil {
return fmt.Errorf("unable to decode userFull#cc997720: field business_intro: %w", err)
return fmt.Errorf("unable to decode userFull#1f58e369: field business_intro: %w", err)
}
}
if u.Flags2.Has(5) {
if err := u.Birthday.Decode(b); err != nil {
return fmt.Errorf("unable to decode userFull#cc997720: field birthday: %w", err)
return fmt.Errorf("unable to decode userFull#1f58e369: field birthday: %w", err)
}
}
if u.Flags2.Has(6) {
value, err := b.Long()
if err != nil {
return fmt.Errorf("unable to decode userFull#cc997720: field personal_channel_id: %w", err)
return fmt.Errorf("unable to decode userFull#1f58e369: field personal_channel_id: %w", err)
}
u.PersonalChannelID = value
}
if u.Flags2.Has(6) {
value, err := b.Int()
if err != nil {
return fmt.Errorf("unable to decode userFull#cc997720: field personal_channel_message: %w", err)
return fmt.Errorf("unable to decode userFull#1f58e369: field personal_channel_message: %w", err)
}
u.PersonalChannelMessage = value
}
if u.Flags2.Has(8) {
value, err := b.Int()
if err != nil {
return fmt.Errorf("unable to decode userFull#1f58e369: field stargifts_count: %w", err)
}
u.StargiftsCount = value
}
return nil
}
@ -2004,6 +2034,24 @@ func (u *UserFull) GetPersonalChannelMessage() (value int, ok bool) {
return u.PersonalChannelMessage, true
}
// SetStargiftsCount sets value of StargiftsCount conditional field.
func (u *UserFull) SetStargiftsCount(value int) {
u.Flags2.Set(8)
u.StargiftsCount = value
}
// GetStargiftsCount returns value of StargiftsCount conditional field and
// boolean which is true if field was set.
func (u *UserFull) GetStargiftsCount() (value int, ok bool) {
if u == nil {
return
}
if !u.Flags2.Has(8) {
return value, false
}
return u.StargiftsCount, true
}
// GetPersonalPhotoAsNotEmpty returns mapped value of PersonalPhoto conditional field and
// boolean which is true if field was set.
func (u *UserFull) GetPersonalPhotoAsNotEmpty() (*Photo, bool) {

468
vendor/github.com/gotd/td/tg/tl_user_star_gift_gen.go generated vendored Normal file
View File

@ -0,0 +1,468 @@
// Code generated by gotdgen, DO NOT EDIT.
package tg
import (
"context"
"errors"
"fmt"
"sort"
"strings"
"go.uber.org/multierr"
"github.com/gotd/td/bin"
"github.com/gotd/td/tdjson"
"github.com/gotd/td/tdp"
"github.com/gotd/td/tgerr"
)
// No-op definition for keeping imports.
var (
_ = bin.Buffer{}
_ = context.Background()
_ = fmt.Stringer(nil)
_ = strings.Builder{}
_ = errors.Is
_ = multierr.AppendInto
_ = sort.Ints
_ = tdp.Format
_ = tgerr.Error{}
_ = tdjson.Encoder{}
)
// UserStarGift represents TL type `userStarGift#eea49a6e`.
//
// See https://core.telegram.org/constructor/userStarGift for reference.
type UserStarGift struct {
// Flags field of UserStarGift.
Flags bin.Fields
// NameHidden field of UserStarGift.
NameHidden bool
// Unsaved field of UserStarGift.
Unsaved bool
// FromID field of UserStarGift.
//
// Use SetFromID and GetFromID helpers.
FromID int64
// Date field of UserStarGift.
Date int
// Gift field of UserStarGift.
Gift StarGift
// Message field of UserStarGift.
//
// Use SetMessage and GetMessage helpers.
Message TextWithEntities
// MsgID field of UserStarGift.
//
// Use SetMsgID and GetMsgID helpers.
MsgID int
// ConvertStars field of UserStarGift.
//
// Use SetConvertStars and GetConvertStars helpers.
ConvertStars int64
}
// UserStarGiftTypeID is TL type id of UserStarGift.
const UserStarGiftTypeID = 0xeea49a6e
// Ensuring interfaces in compile-time for UserStarGift.
var (
_ bin.Encoder = &UserStarGift{}
_ bin.Decoder = &UserStarGift{}
_ bin.BareEncoder = &UserStarGift{}
_ bin.BareDecoder = &UserStarGift{}
)
func (u *UserStarGift) Zero() bool {
if u == nil {
return true
}
if !(u.Flags.Zero()) {
return false
}
if !(u.NameHidden == false) {
return false
}
if !(u.Unsaved == false) {
return false
}
if !(u.FromID == 0) {
return false
}
if !(u.Date == 0) {
return false
}
if !(u.Gift.Zero()) {
return false
}
if !(u.Message.Zero()) {
return false
}
if !(u.MsgID == 0) {
return false
}
if !(u.ConvertStars == 0) {
return false
}
return true
}
// String implements fmt.Stringer.
func (u *UserStarGift) String() string {
if u == nil {
return "UserStarGift(nil)"
}
type Alias UserStarGift
return fmt.Sprintf("UserStarGift%+v", Alias(*u))
}
// FillFrom fills UserStarGift from given interface.
func (u *UserStarGift) FillFrom(from interface {
GetNameHidden() (value bool)
GetUnsaved() (value bool)
GetFromID() (value int64, ok bool)
GetDate() (value int)
GetGift() (value StarGift)
GetMessage() (value TextWithEntities, ok bool)
GetMsgID() (value int, ok bool)
GetConvertStars() (value int64, ok bool)
}) {
u.NameHidden = from.GetNameHidden()
u.Unsaved = from.GetUnsaved()
if val, ok := from.GetFromID(); ok {
u.FromID = val
}
u.Date = from.GetDate()
u.Gift = from.GetGift()
if val, ok := from.GetMessage(); ok {
u.Message = val
}
if val, ok := from.GetMsgID(); ok {
u.MsgID = val
}
if val, ok := from.GetConvertStars(); ok {
u.ConvertStars = val
}
}
// TypeID returns type id in TL schema.
//
// See https://core.telegram.org/mtproto/TL-tl#remarks.
func (*UserStarGift) TypeID() uint32 {
return UserStarGiftTypeID
}
// TypeName returns name of type in TL schema.
func (*UserStarGift) TypeName() string {
return "userStarGift"
}
// TypeInfo returns info about TL type.
func (u *UserStarGift) TypeInfo() tdp.Type {
typ := tdp.Type{
Name: "userStarGift",
ID: UserStarGiftTypeID,
}
if u == nil {
typ.Null = true
return typ
}
typ.Fields = []tdp.Field{
{
Name: "NameHidden",
SchemaName: "name_hidden",
Null: !u.Flags.Has(0),
},
{
Name: "Unsaved",
SchemaName: "unsaved",
Null: !u.Flags.Has(5),
},
{
Name: "FromID",
SchemaName: "from_id",
Null: !u.Flags.Has(1),
},
{
Name: "Date",
SchemaName: "date",
},
{
Name: "Gift",
SchemaName: "gift",
},
{
Name: "Message",
SchemaName: "message",
Null: !u.Flags.Has(2),
},
{
Name: "MsgID",
SchemaName: "msg_id",
Null: !u.Flags.Has(3),
},
{
Name: "ConvertStars",
SchemaName: "convert_stars",
Null: !u.Flags.Has(4),
},
}
return typ
}
// SetFlags sets flags for non-zero fields.
func (u *UserStarGift) SetFlags() {
if !(u.NameHidden == false) {
u.Flags.Set(0)
}
if !(u.Unsaved == false) {
u.Flags.Set(5)
}
if !(u.FromID == 0) {
u.Flags.Set(1)
}
if !(u.Message.Zero()) {
u.Flags.Set(2)
}
if !(u.MsgID == 0) {
u.Flags.Set(3)
}
if !(u.ConvertStars == 0) {
u.Flags.Set(4)
}
}
// Encode implements bin.Encoder.
func (u *UserStarGift) Encode(b *bin.Buffer) error {
if u == nil {
return fmt.Errorf("can't encode userStarGift#eea49a6e as nil")
}
b.PutID(UserStarGiftTypeID)
return u.EncodeBare(b)
}
// EncodeBare implements bin.BareEncoder.
func (u *UserStarGift) EncodeBare(b *bin.Buffer) error {
if u == nil {
return fmt.Errorf("can't encode userStarGift#eea49a6e as nil")
}
u.SetFlags()
if err := u.Flags.Encode(b); err != nil {
return fmt.Errorf("unable to encode userStarGift#eea49a6e: field flags: %w", err)
}
if u.Flags.Has(1) {
b.PutLong(u.FromID)
}
b.PutInt(u.Date)
if err := u.Gift.Encode(b); err != nil {
return fmt.Errorf("unable to encode userStarGift#eea49a6e: field gift: %w", err)
}
if u.Flags.Has(2) {
if err := u.Message.Encode(b); err != nil {
return fmt.Errorf("unable to encode userStarGift#eea49a6e: field message: %w", err)
}
}
if u.Flags.Has(3) {
b.PutInt(u.MsgID)
}
if u.Flags.Has(4) {
b.PutLong(u.ConvertStars)
}
return nil
}
// Decode implements bin.Decoder.
func (u *UserStarGift) Decode(b *bin.Buffer) error {
if u == nil {
return fmt.Errorf("can't decode userStarGift#eea49a6e to nil")
}
if err := b.ConsumeID(UserStarGiftTypeID); err != nil {
return fmt.Errorf("unable to decode userStarGift#eea49a6e: %w", err)
}
return u.DecodeBare(b)
}
// DecodeBare implements bin.BareDecoder.
func (u *UserStarGift) DecodeBare(b *bin.Buffer) error {
if u == nil {
return fmt.Errorf("can't decode userStarGift#eea49a6e to nil")
}
{
if err := u.Flags.Decode(b); err != nil {
return fmt.Errorf("unable to decode userStarGift#eea49a6e: field flags: %w", err)
}
}
u.NameHidden = u.Flags.Has(0)
u.Unsaved = u.Flags.Has(5)
if u.Flags.Has(1) {
value, err := b.Long()
if err != nil {
return fmt.Errorf("unable to decode userStarGift#eea49a6e: field from_id: %w", err)
}
u.FromID = value
}
{
value, err := b.Int()
if err != nil {
return fmt.Errorf("unable to decode userStarGift#eea49a6e: field date: %w", err)
}
u.Date = value
}
{
if err := u.Gift.Decode(b); err != nil {
return fmt.Errorf("unable to decode userStarGift#eea49a6e: field gift: %w", err)
}
}
if u.Flags.Has(2) {
if err := u.Message.Decode(b); err != nil {
return fmt.Errorf("unable to decode userStarGift#eea49a6e: field message: %w", err)
}
}
if u.Flags.Has(3) {
value, err := b.Int()
if err != nil {
return fmt.Errorf("unable to decode userStarGift#eea49a6e: field msg_id: %w", err)
}
u.MsgID = value
}
if u.Flags.Has(4) {
value, err := b.Long()
if err != nil {
return fmt.Errorf("unable to decode userStarGift#eea49a6e: field convert_stars: %w", err)
}
u.ConvertStars = value
}
return nil
}
// SetNameHidden sets value of NameHidden conditional field.
func (u *UserStarGift) SetNameHidden(value bool) {
if value {
u.Flags.Set(0)
u.NameHidden = true
} else {
u.Flags.Unset(0)
u.NameHidden = false
}
}
// GetNameHidden returns value of NameHidden conditional field.
func (u *UserStarGift) GetNameHidden() (value bool) {
if u == nil {
return
}
return u.Flags.Has(0)
}
// SetUnsaved sets value of Unsaved conditional field.
func (u *UserStarGift) SetUnsaved(value bool) {
if value {
u.Flags.Set(5)
u.Unsaved = true
} else {
u.Flags.Unset(5)
u.Unsaved = false
}
}
// GetUnsaved returns value of Unsaved conditional field.
func (u *UserStarGift) GetUnsaved() (value bool) {
if u == nil {
return
}
return u.Flags.Has(5)
}
// SetFromID sets value of FromID conditional field.
func (u *UserStarGift) SetFromID(value int64) {
u.Flags.Set(1)
u.FromID = value
}
// GetFromID returns value of FromID conditional field and
// boolean which is true if field was set.
func (u *UserStarGift) GetFromID() (value int64, ok bool) {
if u == nil {
return
}
if !u.Flags.Has(1) {
return value, false
}
return u.FromID, true
}
// GetDate returns value of Date field.
func (u *UserStarGift) GetDate() (value int) {
if u == nil {
return
}
return u.Date
}
// GetGift returns value of Gift field.
func (u *UserStarGift) GetGift() (value StarGift) {
if u == nil {
return
}
return u.Gift
}
// SetMessage sets value of Message conditional field.
func (u *UserStarGift) SetMessage(value TextWithEntities) {
u.Flags.Set(2)
u.Message = value
}
// GetMessage returns value of Message conditional field and
// boolean which is true if field was set.
func (u *UserStarGift) GetMessage() (value TextWithEntities, ok bool) {
if u == nil {
return
}
if !u.Flags.Has(2) {
return value, false
}
return u.Message, true
}
// SetMsgID sets value of MsgID conditional field.
func (u *UserStarGift) SetMsgID(value int) {
u.Flags.Set(3)
u.MsgID = value
}
// GetMsgID returns value of MsgID conditional field and
// boolean which is true if field was set.
func (u *UserStarGift) GetMsgID() (value int, ok bool) {
if u == nil {
return
}
if !u.Flags.Has(3) {
return value, false
}
return u.MsgID, true
}
// SetConvertStars sets value of ConvertStars conditional field.
func (u *UserStarGift) SetConvertStars(value int64) {
u.Flags.Set(4)
u.ConvertStars = value
}
// GetConvertStars returns value of ConvertStars conditional field and
// boolean which is true if field was set.
func (u *UserStarGift) GetConvertStars() (value int64, ok bool) {
if u == nil {
return
}
if !u.Flags.Has(4) {
return value, false
}
return u.ConvertStars, true
}

View File

@ -0,0 +1,35 @@
//go:build !no_gotd_slices
// +build !no_gotd_slices
// Code generated by gotdgen, DO NOT EDIT.
package tg
import (
"context"
"errors"
"fmt"
"sort"
"strings"
"go.uber.org/multierr"
"github.com/gotd/td/bin"
"github.com/gotd/td/tdjson"
"github.com/gotd/td/tdp"
"github.com/gotd/td/tgerr"
)
// No-op definition for keeping imports.
var (
_ = bin.Buffer{}
_ = context.Background()
_ = fmt.Stringer(nil)
_ = strings.Builder{}
_ = errors.Is
_ = multierr.AppendInto
_ = sort.Ints
_ = tdp.Format
_ = tgerr.Error{}
_ = tdjson.Encoder{}
)

View File

@ -1,5 +1,5 @@
# This is an example goreleaser.yaml file with some sane defaults.
# Make sure to check the documentation at http://goreleaser.com
version: 2
before:
hooks:
- ./gen.sh
@ -99,7 +99,7 @@ archives:
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ .Tag }}-next"
version_template: "{{ .Tag }}-next"
changelog:
sort: asc
filters:

View File

@ -16,6 +16,13 @@ This package provides various compression algorithms.
# changelog
* Sep 23rd, 2024 - [1.17.10](https://github.com/klauspost/compress/releases/tag/v1.17.10)
* gzhttp: Add TransportAlwaysDecompress option. https://github.com/klauspost/compress/pull/978
* gzhttp: Add supported decompress request body by @mirecl in https://github.com/klauspost/compress/pull/1002
* s2: Add EncodeBuffer buffer recycling callback https://github.com/klauspost/compress/pull/982
* zstd: Improve memory usage on small streaming encodes https://github.com/klauspost/compress/pull/1007
* flate: read data written with partial flush by @vajexal in https://github.com/klauspost/compress/pull/996
* Jun 12th, 2024 - [1.17.9](https://github.com/klauspost/compress/releases/tag/v1.17.9)
* s2: Reduce ReadFrom temporary allocations https://github.com/klauspost/compress/pull/949
* flate, zstd: Shave some bytes off amd64 matchLen by @greatroar in https://github.com/klauspost/compress/pull/963

View File

@ -6,6 +6,7 @@ package zstd
import (
"crypto/rand"
"errors"
"fmt"
"io"
"math"
@ -149,6 +150,9 @@ func (e *Encoder) ResetContentSize(w io.Writer, size int64) {
// and write CRC if requested.
func (e *Encoder) Write(p []byte) (n int, err error) {
s := &e.state
if s.eofWritten {
return 0, ErrEncoderClosed
}
for len(p) > 0 {
if len(p)+len(s.filling) < e.o.blockSize {
if e.o.crc {
@ -288,6 +292,9 @@ func (e *Encoder) nextBlock(final bool) error {
s.filling, s.current, s.previous = s.previous[:0], s.filling, s.current
s.nInput += int64(len(s.current))
s.wg.Add(1)
if final {
s.eofWritten = true
}
go func(src []byte) {
if debugEncoder {
println("Adding block,", len(src), "bytes, final:", final)
@ -303,9 +310,6 @@ func (e *Encoder) nextBlock(final bool) error {
blk := enc.Block()
enc.Encode(blk, src)
blk.last = final
if final {
s.eofWritten = true
}
// Wait for pending writes.
s.wWg.Wait()
if s.writeErr != nil {
@ -401,12 +405,20 @@ func (e *Encoder) Flush() error {
if len(s.filling) > 0 {
err := e.nextBlock(false)
if err != nil {
// Ignore Flush after Close.
if errors.Is(s.err, ErrEncoderClosed) {
return nil
}
return err
}
}
s.wg.Wait()
s.wWg.Wait()
if s.err != nil {
// Ignore Flush after Close.
if errors.Is(s.err, ErrEncoderClosed) {
return nil
}
return s.err
}
return s.writeErr
@ -422,6 +434,9 @@ func (e *Encoder) Close() error {
}
err := e.nextBlock(true)
if err != nil {
if errors.Is(s.err, ErrEncoderClosed) {
return nil
}
return err
}
if s.frameContentSize > 0 {
@ -459,6 +474,11 @@ func (e *Encoder) Close() error {
}
_, s.err = s.w.Write(frame)
}
if s.err == nil {
s.err = ErrEncoderClosed
return nil
}
return s.err
}

View File

@ -88,6 +88,10 @@ var (
// Close has been called.
ErrDecoderClosed = errors.New("decoder used after Close")
// ErrEncoderClosed will be returned if the Encoder was used after
// Close has been called.
ErrEncoderClosed = errors.New("encoder used after Close")
// ErrDecoderNilInput is returned when a nil Reader was provided
// and an operation other than Reset/DecodeAll/Close was attempted.
ErrDecoderNilInput = errors.New("nil input provided as reader")

View File

@ -11,8 +11,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//go:build go1.21
package model
import (

View File

@ -1,39 +0,0 @@
// Copyright 2024 The Prometheus Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//go:build !go1.21
package model
import (
"fmt"
"sort"
"strings"
)
// String was optimized using functions not available for go 1.20
// or lower. We keep the old implementation for compatibility with client_golang.
// Once client golang drops support for go 1.20 (scheduled for August 2024), this
// file can be removed.
func (l LabelSet) String() string {
labelNames := make([]string, 0, len(l))
for name := range l {
labelNames = append(labelNames, string(name))
}
sort.Strings(labelNames)
lstrs := make([]string, 0, len(l))
for _, name := range labelNames {
lstrs = append(lstrs, fmt.Sprintf("%s=%q", name, l[LabelName(name)]))
}
return fmt.Sprintf("{%s}", strings.Join(lstrs, ", "))
}

View File

@ -347,45 +347,25 @@ func computeDistinct(kvs []KeyValue) Distinct {
func computeDistinctFixed(kvs []KeyValue) interface{} {
switch len(kvs) {
case 1:
ptr := new([1]KeyValue)
copy((*ptr)[:], kvs)
return *ptr
return [1]KeyValue(kvs)
case 2:
ptr := new([2]KeyValue)
copy((*ptr)[:], kvs)
return *ptr
return [2]KeyValue(kvs)
case 3:
ptr := new([3]KeyValue)
copy((*ptr)[:], kvs)
return *ptr
return [3]KeyValue(kvs)
case 4:
ptr := new([4]KeyValue)
copy((*ptr)[:], kvs)
return *ptr
return [4]KeyValue(kvs)
case 5:
ptr := new([5]KeyValue)
copy((*ptr)[:], kvs)
return *ptr
return [5]KeyValue(kvs)
case 6:
ptr := new([6]KeyValue)
copy((*ptr)[:], kvs)
return *ptr
return [6]KeyValue(kvs)
case 7:
ptr := new([7]KeyValue)
copy((*ptr)[:], kvs)
return *ptr
return [7]KeyValue(kvs)
case 8:
ptr := new([8]KeyValue)
copy((*ptr)[:], kvs)
return *ptr
return [8]KeyValue(kvs)
case 9:
ptr := new([9]KeyValue)
copy((*ptr)[:], kvs)
return *ptr
return [9]KeyValue(kvs)
case 10:
ptr := new([10]KeyValue)
copy((*ptr)[:], kvs)
return *ptr
return [10]KeyValue(kvs)
default:
return nil
}

View File

@ -20,7 +20,8 @@ func RawToBool(r uint64) bool {
}
func Int64ToRaw(i int64) uint64 {
return uint64(i)
// Assumes original was a valid int64 (overflow not checked).
return uint64(i) // nolint: gosec
}
func RawToInt64(r uint64) int64 {

View File

@ -156,7 +156,7 @@ from the generated architecture-specific files listed below, and merge these
into a common file for each OS.
The merge is performed in the following steps:
1. Construct the set of common code that is idential in all architecture-specific files.
1. Construct the set of common code that is identical in all architecture-specific files.
2. Write this common code to the merged file.
3. Remove the common code from all architecture-specific files.

View File

@ -656,7 +656,7 @@ errors=$(
signals=$(
echo '#include <signal.h>' | $CC -x c - -E -dM $ccflags |
awk '$1=="#define" && $2 ~ /^SIG[A-Z0-9]+$/ { print $2 }' |
grep -v 'SIGSTKSIZE\|SIGSTKSZ\|SIGRT\|SIGMAX64' |
grep -E -v '(SIGSTKSIZE|SIGSTKSZ|SIGRT|SIGMAX64)' |
sort
)
@ -666,7 +666,7 @@ echo '#include <errno.h>' | $CC -x c - -E -dM $ccflags |
sort >_error.grep
echo '#include <signal.h>' | $CC -x c - -E -dM $ccflags |
awk '$1=="#define" && $2 ~ /^SIG[A-Z0-9]+$/ { print "^\t" $2 "[ \t]*=" }' |
grep -v 'SIGSTKSIZE\|SIGSTKSZ\|SIGRT\|SIGMAX64' |
grep -E -v '(SIGSTKSIZE|SIGSTKSZ|SIGRT|SIGMAX64)' |
sort >_signal.grep
echo '// mkerrors.sh' "$@"

View File

@ -360,7 +360,7 @@ func Wait4(pid int, wstatus *WaitStatus, options int, rusage *Rusage) (wpid int,
var status _C_int
var r Pid_t
err = ERESTART
// AIX wait4 may return with ERESTART errno, while the processus is still
// AIX wait4 may return with ERESTART errno, while the process is still
// active.
for err == ERESTART {
r, err = wait4(Pid_t(pid), &status, options, rusage)

View File

@ -1295,6 +1295,48 @@ func GetsockoptTCPInfo(fd, level, opt int) (*TCPInfo, error) {
return &value, err
}
// GetsockoptTCPCCVegasInfo returns algorithm specific congestion control information for a socket using the "vegas"
// algorithm.
//
// The socket's congestion control algorighm can be retrieved via [GetsockoptString] with the [TCP_CONGESTION] option:
//
// algo, err := unix.GetsockoptString(fd, unix.IPPROTO_TCP, unix.TCP_CONGESTION)
func GetsockoptTCPCCVegasInfo(fd, level, opt int) (*TCPVegasInfo, error) {
var value [SizeofTCPCCInfo / 4]uint32 // ensure proper alignment
vallen := _Socklen(SizeofTCPCCInfo)
err := getsockopt(fd, level, opt, unsafe.Pointer(&value[0]), &vallen)
out := (*TCPVegasInfo)(unsafe.Pointer(&value[0]))
return out, err
}
// GetsockoptTCPCCDCTCPInfo returns algorithm specific congestion control information for a socket using the "dctp"
// algorithm.
//
// The socket's congestion control algorighm can be retrieved via [GetsockoptString] with the [TCP_CONGESTION] option:
//
// algo, err := unix.GetsockoptString(fd, unix.IPPROTO_TCP, unix.TCP_CONGESTION)
func GetsockoptTCPCCDCTCPInfo(fd, level, opt int) (*TCPDCTCPInfo, error) {
var value [SizeofTCPCCInfo / 4]uint32 // ensure proper alignment
vallen := _Socklen(SizeofTCPCCInfo)
err := getsockopt(fd, level, opt, unsafe.Pointer(&value[0]), &vallen)
out := (*TCPDCTCPInfo)(unsafe.Pointer(&value[0]))
return out, err
}
// GetsockoptTCPCCBBRInfo returns algorithm specific congestion control information for a socket using the "bbr"
// algorithm.
//
// The socket's congestion control algorighm can be retrieved via [GetsockoptString] with the [TCP_CONGESTION] option:
//
// algo, err := unix.GetsockoptString(fd, unix.IPPROTO_TCP, unix.TCP_CONGESTION)
func GetsockoptTCPCCBBRInfo(fd, level, opt int) (*TCPBBRInfo, error) {
var value [SizeofTCPCCInfo / 4]uint32 // ensure proper alignment
vallen := _Socklen(SizeofTCPCCInfo)
err := getsockopt(fd, level, opt, unsafe.Pointer(&value[0]), &vallen)
out := (*TCPBBRInfo)(unsafe.Pointer(&value[0]))
return out, err
}
// GetsockoptString returns the string value of the socket option opt for the
// socket associated with fd at the given socket level.
func GetsockoptString(fd, level, opt int) (string, error) {
@ -1959,7 +2001,26 @@ func Getpgrp() (pid int) {
//sysnb Getpid() (pid int)
//sysnb Getppid() (ppid int)
//sys Getpriority(which int, who int) (prio int, err error)
//sys Getrandom(buf []byte, flags int) (n int, err error)
func Getrandom(buf []byte, flags int) (n int, err error) {
vdsoRet, supported := vgetrandom(buf, uint32(flags))
if supported {
if vdsoRet < 0 {
return 0, errnoErr(syscall.Errno(-vdsoRet))
}
return vdsoRet, nil
}
var p *byte
if len(buf) > 0 {
p = &buf[0]
}
r, _, e := Syscall(SYS_GETRANDOM, uintptr(unsafe.Pointer(p)), uintptr(len(buf)), uintptr(flags))
if e != 0 {
return 0, errnoErr(e)
}
return int(r), nil
}
//sysnb Getrusage(who int, rusage *Rusage) (err error)
//sysnb Getsid(pid int) (sid int, err error)
//sysnb Gettid() (tid int)

View File

@ -182,3 +182,5 @@ func KexecFileLoad(kernelFd int, initrdFd int, cmdline string, flags int) error
}
return kexecFileLoad(kernelFd, initrdFd, cmdlineLen, cmdline, flags)
}
const SYS_FSTATAT = SYS_NEWFSTATAT

View File

@ -214,3 +214,5 @@ func KexecFileLoad(kernelFd int, initrdFd int, cmdline string, flags int) error
}
return kexecFileLoad(kernelFd, initrdFd, cmdlineLen, cmdline, flags)
}
const SYS_FSTATAT = SYS_NEWFSTATAT

View File

@ -187,3 +187,5 @@ func RISCVHWProbe(pairs []RISCVHWProbePairs, set *CPUSet, flags uint) (err error
}
return riscvHWProbe(pairs, setSize, set, flags)
}
const SYS_FSTATAT = SYS_NEWFSTATAT

13
vendor/golang.org/x/sys/unix/vgetrandom_linux.go generated vendored Normal file
View File

@ -0,0 +1,13 @@
// Copyright 2024 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build linux && go1.24
package unix
import _ "unsafe"
//go:linkname vgetrandom runtime.vgetrandom
//go:noescape
func vgetrandom(p []byte, flags uint32) (ret int, supported bool)

11
vendor/golang.org/x/sys/unix/vgetrandom_unsupported.go generated vendored Normal file
View File

@ -0,0 +1,11 @@
// Copyright 2024 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build !linux || !go1.24
package unix
func vgetrandom(p []byte, flags uint32) (ret int, supported bool) {
return -1, false
}

View File

@ -495,6 +495,7 @@ const (
BPF_F_TEST_REG_INVARIANTS = 0x80
BPF_F_TEST_RND_HI32 = 0x4
BPF_F_TEST_RUN_ON_CPU = 0x1
BPF_F_TEST_SKB_CHECKSUM_COMPLETE = 0x4
BPF_F_TEST_STATE_FREQ = 0x8
BPF_F_TEST_XDP_LIVE_FRAMES = 0x2
BPF_F_XDP_DEV_BOUND_ONLY = 0x40
@ -1922,6 +1923,7 @@ const (
MNT_EXPIRE = 0x4
MNT_FORCE = 0x1
MNT_ID_REQ_SIZE_VER0 = 0x18
MNT_ID_REQ_SIZE_VER1 = 0x20
MODULE_INIT_COMPRESSED_FILE = 0x4
MODULE_INIT_IGNORE_MODVERSIONS = 0x1
MODULE_INIT_IGNORE_VERMAGIC = 0x2
@ -2187,7 +2189,7 @@ const (
NFT_REG_SIZE = 0x10
NFT_REJECT_ICMPX_MAX = 0x3
NFT_RT_MAX = 0x4
NFT_SECMARK_CTX_MAXLEN = 0x100
NFT_SECMARK_CTX_MAXLEN = 0x1000
NFT_SET_MAXNAMELEN = 0x100
NFT_SOCKET_MAX = 0x3
NFT_TABLE_F_MASK = 0x7
@ -2356,9 +2358,11 @@ const (
PERF_MEM_LVLNUM_IO = 0xa
PERF_MEM_LVLNUM_L1 = 0x1
PERF_MEM_LVLNUM_L2 = 0x2
PERF_MEM_LVLNUM_L2_MHB = 0x5
PERF_MEM_LVLNUM_L3 = 0x3
PERF_MEM_LVLNUM_L4 = 0x4
PERF_MEM_LVLNUM_LFB = 0xc
PERF_MEM_LVLNUM_MSC = 0x6
PERF_MEM_LVLNUM_NA = 0xf
PERF_MEM_LVLNUM_PMEM = 0xe
PERF_MEM_LVLNUM_RAM = 0xd
@ -2431,6 +2435,7 @@ const (
PRIO_PGRP = 0x1
PRIO_PROCESS = 0x0
PRIO_USER = 0x2
PROCFS_IOCTL_MAGIC = 'f'
PROC_SUPER_MAGIC = 0x9fa0
PROT_EXEC = 0x4
PROT_GROWSDOWN = 0x1000000
@ -2933,11 +2938,12 @@ const (
RUSAGE_SELF = 0x0
RUSAGE_THREAD = 0x1
RWF_APPEND = 0x10
RWF_ATOMIC = 0x40
RWF_DSYNC = 0x2
RWF_HIPRI = 0x1
RWF_NOAPPEND = 0x20
RWF_NOWAIT = 0x8
RWF_SUPPORTED = 0x3f
RWF_SUPPORTED = 0x7f
RWF_SYNC = 0x4
RWF_WRITE_LIFE_NOT_SET = 0x0
SCHED_BATCH = 0x3
@ -3210,6 +3216,7 @@ const (
STATX_ATTR_MOUNT_ROOT = 0x2000
STATX_ATTR_NODUMP = 0x40
STATX_ATTR_VERITY = 0x100000
STATX_ATTR_WRITE_ATOMIC = 0x400000
STATX_BASIC_STATS = 0x7ff
STATX_BLOCKS = 0x400
STATX_BTIME = 0x800
@ -3226,6 +3233,7 @@ const (
STATX_SUBVOL = 0x8000
STATX_TYPE = 0x1
STATX_UID = 0x8
STATX_WRITE_ATOMIC = 0x10000
STATX__RESERVED = 0x80000000
SYNC_FILE_RANGE_WAIT_AFTER = 0x4
SYNC_FILE_RANGE_WAIT_BEFORE = 0x1
@ -3624,6 +3632,7 @@ const (
XDP_UMEM_PGOFF_COMPLETION_RING = 0x180000000
XDP_UMEM_PGOFF_FILL_RING = 0x100000000
XDP_UMEM_REG = 0x4
XDP_UMEM_TX_METADATA_LEN = 0x4
XDP_UMEM_TX_SW_CSUM = 0x2
XDP_UMEM_UNALIGNED_CHUNK_FLAG = 0x1
XDP_USE_NEED_WAKEUP = 0x8

View File

@ -153,9 +153,14 @@ const (
NFDBITS = 0x20
NLDLY = 0x100
NOFLSH = 0x80
NS_GET_MNTNS_ID = 0x8008b705
NS_GET_NSTYPE = 0xb703
NS_GET_OWNER_UID = 0xb704
NS_GET_PARENT = 0xb702
NS_GET_PID_FROM_PIDNS = 0x8004b706
NS_GET_PID_IN_PIDNS = 0x8004b708
NS_GET_TGID_FROM_PIDNS = 0x8004b707
NS_GET_TGID_IN_PIDNS = 0x8004b709
NS_GET_USERNS = 0xb701
OLCUC = 0x2
ONLCR = 0x4

View File

@ -153,9 +153,14 @@ const (
NFDBITS = 0x40
NLDLY = 0x100
NOFLSH = 0x80
NS_GET_MNTNS_ID = 0x8008b705
NS_GET_NSTYPE = 0xb703
NS_GET_OWNER_UID = 0xb704
NS_GET_PARENT = 0xb702
NS_GET_PID_FROM_PIDNS = 0x8004b706
NS_GET_PID_IN_PIDNS = 0x8004b708
NS_GET_TGID_FROM_PIDNS = 0x8004b707
NS_GET_TGID_IN_PIDNS = 0x8004b709
NS_GET_USERNS = 0xb701
OLCUC = 0x2
ONLCR = 0x4

View File

@ -150,9 +150,14 @@ const (
NFDBITS = 0x20
NLDLY = 0x100
NOFLSH = 0x80
NS_GET_MNTNS_ID = 0x8008b705
NS_GET_NSTYPE = 0xb703
NS_GET_OWNER_UID = 0xb704
NS_GET_PARENT = 0xb702
NS_GET_PID_FROM_PIDNS = 0x8004b706
NS_GET_PID_IN_PIDNS = 0x8004b708
NS_GET_TGID_FROM_PIDNS = 0x8004b707
NS_GET_TGID_IN_PIDNS = 0x8004b709
NS_GET_USERNS = 0xb701
OLCUC = 0x2
ONLCR = 0x4

View File

@ -154,9 +154,14 @@ const (
NFDBITS = 0x40
NLDLY = 0x100
NOFLSH = 0x80
NS_GET_MNTNS_ID = 0x8008b705
NS_GET_NSTYPE = 0xb703
NS_GET_OWNER_UID = 0xb704
NS_GET_PARENT = 0xb702
NS_GET_PID_FROM_PIDNS = 0x8004b706
NS_GET_PID_IN_PIDNS = 0x8004b708
NS_GET_TGID_FROM_PIDNS = 0x8004b707
NS_GET_TGID_IN_PIDNS = 0x8004b709
NS_GET_USERNS = 0xb701
OLCUC = 0x2
ONLCR = 0x4

View File

@ -154,9 +154,14 @@ const (
NFDBITS = 0x40
NLDLY = 0x100
NOFLSH = 0x80
NS_GET_MNTNS_ID = 0x8008b705
NS_GET_NSTYPE = 0xb703
NS_GET_OWNER_UID = 0xb704
NS_GET_PARENT = 0xb702
NS_GET_PID_FROM_PIDNS = 0x8004b706
NS_GET_PID_IN_PIDNS = 0x8004b708
NS_GET_TGID_FROM_PIDNS = 0x8004b707
NS_GET_TGID_IN_PIDNS = 0x8004b709
NS_GET_USERNS = 0xb701
OLCUC = 0x2
ONLCR = 0x4

View File

@ -150,9 +150,14 @@ const (
NFDBITS = 0x20
NLDLY = 0x100
NOFLSH = 0x80
NS_GET_MNTNS_ID = 0x4008b705
NS_GET_NSTYPE = 0x2000b703
NS_GET_OWNER_UID = 0x2000b704
NS_GET_PARENT = 0x2000b702
NS_GET_PID_FROM_PIDNS = 0x4004b706
NS_GET_PID_IN_PIDNS = 0x4004b708
NS_GET_TGID_FROM_PIDNS = 0x4004b707
NS_GET_TGID_IN_PIDNS = 0x4004b709
NS_GET_USERNS = 0x2000b701
OLCUC = 0x2
ONLCR = 0x4

View File

@ -150,9 +150,14 @@ const (
NFDBITS = 0x40
NLDLY = 0x100
NOFLSH = 0x80
NS_GET_MNTNS_ID = 0x4008b705
NS_GET_NSTYPE = 0x2000b703
NS_GET_OWNER_UID = 0x2000b704
NS_GET_PARENT = 0x2000b702
NS_GET_PID_FROM_PIDNS = 0x4004b706
NS_GET_PID_IN_PIDNS = 0x4004b708
NS_GET_TGID_FROM_PIDNS = 0x4004b707
NS_GET_TGID_IN_PIDNS = 0x4004b709
NS_GET_USERNS = 0x2000b701
OLCUC = 0x2
ONLCR = 0x4

View File

@ -150,9 +150,14 @@ const (
NFDBITS = 0x40
NLDLY = 0x100
NOFLSH = 0x80
NS_GET_MNTNS_ID = 0x4008b705
NS_GET_NSTYPE = 0x2000b703
NS_GET_OWNER_UID = 0x2000b704
NS_GET_PARENT = 0x2000b702
NS_GET_PID_FROM_PIDNS = 0x4004b706
NS_GET_PID_IN_PIDNS = 0x4004b708
NS_GET_TGID_FROM_PIDNS = 0x4004b707
NS_GET_TGID_IN_PIDNS = 0x4004b709
NS_GET_USERNS = 0x2000b701
OLCUC = 0x2
ONLCR = 0x4

Some files were not shown because too many files have changed in this diff Show More