• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Civil / tg-simple-regex-antispam / 13070263183

31 Jan 2025 09:45AM UTC coverage: 0.0%. Remained the same
13070263183

Pull #5

github

Civil
Refactor and improve bot

 * Fixed small bug in forward action
 * package statefulFilters renamed to chains
 * generic badgerdb interface
 * add filter that counts repeated messages
 * add filter that checks if message is a story
 * add filter that checks if message was marked as spam
Pull Request #5: some improvements

0 of 1422 new or added lines in 20 files covered. (0.0%)

21 existing lines in 3 files now uncovered.

0 of 3756 relevant lines covered (0.0%)

0.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/filters/filteringRules/isInSpam/rule.go
1
package isInSpam
2

3
import (
4
        "bytes"
5
        "crypto/sha256"
6

7
        "github.com/mymmrac/telego"
8
        "go.uber.org/zap"
9

10
        "github.com/Civil/tg-simple-regex-antispam/filters/interfaces"
11
        "github.com/Civil/tg-simple-regex-antispam/filters/types/scoringResult"
12
        config2 "github.com/Civil/tg-simple-regex-antispam/helper/config"
13
        "github.com/Civil/tg-simple-regex-antispam/sharedDBs/messages"
14
)
15

16
type Filter struct {
17
        messageDB *messages.MessageDB
18
        logger    *zap.Logger
19
        chainName string
20
        isFinal   bool
21
}
22

NEW
23
func New(logger *zap.Logger, config map[string]any, chainName string) (interfaces.FilteringRule, error) {
×
NEW
24
        logger = logger.With(zap.String("filter", chainName), zap.String("filter_type", "isInSpam"))
×
NEW
25
        isFinal, err := config2.GetOptionBoolWithDefault(config, "isFinal", true)
×
NEW
26
        if err != nil {
×
NEW
27
                return nil, err
×
NEW
28
        }
×
29

NEW
30
        messageDB, err := messages.Get(logger, "spamMessages")
×
NEW
31
        if err != nil {
×
NEW
32
                return nil, err
×
NEW
33
        }
×
34

NEW
35
        return &Filter{
×
NEW
36
                logger:    logger,
×
NEW
37
                chainName: chainName,
×
NEW
38
                isFinal:   isFinal,
×
NEW
39
                messageDB: messageDB,
×
NEW
40
        }, nil
×
41
}
42

NEW
43
func Help() string {
×
NEW
44
        return "isInSpam checks if the message is forwarded"
×
NEW
45
}
×
46

NEW
47
func (r *Filter) Score(_ *telego.Bot, msg *telego.Message) *scoringResult.ScoringResult {
×
NEW
48
        res := &scoringResult.ScoringResult{
×
NEW
49
                Score: 0,
×
NEW
50
        }
×
NEW
51
        msgByte := []byte(msg.Text)
×
NEW
52
        key := sha256.Sum256(msgByte)
×
NEW
53
        data, err := r.messageDB.LoadValue(key[:])
×
NEW
54
        if err != nil {
×
NEW
55
                return res
×
NEW
56
        }
×
NEW
57
        if bytes.Compare(data, msgByte) == 0 {
×
NEW
58
                res.Reason = "this message matches one that was marked as spam before"
×
NEW
59
                res.Score = 100
×
NEW
60
        } else {
×
NEW
61
                r.logger.Error("key collision found",
×
NEW
62
                        zap.ByteString("current_message", msgByte),
×
NEW
63
                        zap.ByteString("collided_with", data),
×
NEW
64
                )
×
NEW
65
        }
×
NEW
66
        return res
×
67
}
68

NEW
69
func (r *Filter) IsStateful() bool {
×
NEW
70
        return false
×
NEW
71
}
×
72

NEW
73
func (r *Filter) GetName() string {
×
NEW
74
        return "isInSpam"
×
NEW
75
}
×
76

NEW
77
func (r *Filter) GetFilterName() string {
×
NEW
78
        return ""
×
NEW
79
}
×
80

NEW
81
func (r *Filter) IsFinal() bool {
×
NEW
82
        return r.isFinal
×
NEW
83
}
×
84

NEW
85
func (r *Filter) TGAdminPrefix() string {
×
NEW
86
        return ""
×
NEW
87
}
×
88

NEW
89
func (r *Filter) HandleTGCommands(_ *zap.Logger, _ *telego.Bot, _ *telego.Message, _ []string) error {
×
NEW
90
        return nil
×
NEW
91
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc