-
-
Notifications
You must be signed in to change notification settings - Fork 135
/
report.go
97 lines (79 loc) · 2.55 KB
/
report.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package message
import (
"context"
"golang.org/x/xerrors"
"github.com/gotd/td/tg"
)
// ReportBuilder is a reporting messages helper.
type ReportBuilder struct {
sender *Sender
peer peerPromise
ids []int
message string
}
// Message sets additional comment for report.
func (b *ReportBuilder) Message(msg string) *ReportBuilder {
b.message = msg
return b
}
func (b *ReportBuilder) send(ctx context.Context, reason tg.ReportReasonClass) (bool, error) {
p, err := b.peer(ctx)
if err != nil {
return false, xerrors.Errorf("peer: %w", err)
}
return b.sender.report(ctx, &tg.MessagesReportRequest{
Peer: p,
ID: b.ids,
Reason: reason,
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{})
}
// Report reports messages in a chat for violation of Telegram's Terms of Service.
func (b *RequestBuilder) Report(id int, ids ...int) *ReportBuilder {
return &ReportBuilder{
sender: b.sender,
peer: b.peer,
ids: append([]int{id}, ids...),
}
}
// ReportSpam reports peer for spam.
// NB: You should check that the peer settings of the chat allow us to do that.
func (b *RequestBuilder) ReportSpam(ctx context.Context) (bool, error) {
p, err := b.peer(ctx)
if err != nil {
return false, xerrors.Errorf("peer: %w", err)
}
return b.sender.reportSpam(ctx, p)
}