• 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
/actions/storeAsSpam/action.go
1
package storeAsSpam
2

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

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

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

16
type Action struct {
17
        logger *zap.Logger
18
        bot    *telego.Bot
19

20
        messageDB *messages.MessageDB
21
}
22

23
func (r *Action) Apply(_ interfaces2.StatefulFilter, _ *scoringResult.ScoringResult, _ telego.ChatID, _ []int64,
NEW
24
        _ int64, _ any) error {
×
NEW
25
        return ErrNotSupported
×
NEW
26
}
×
27

28
var ErrNotSupported = errors.New("not supported")
29

NEW
30
func (r *Action) GetName() string {
×
NEW
31
        return "storeAsSpam"
×
NEW
32
}
×
33

NEW
34
func (r *Action) PerMessage() bool {
×
NEW
35
        return true
×
NEW
36
}
×
37

38
func (r *Action) ApplyToMessage(_ interfaces2.StatefulFilter, _ *scoringResult.ScoringResult,
NEW
39
        msg *telego.Message, _ any) error {
×
NEW
40

×
NEW
41
        r.messageDB.Lock()
×
NEW
42
        defer r.messageDB.Unlock()
×
NEW
43

×
NEW
44
        data := []byte(msg.Text)
×
NEW
45
        key := sha256.Sum256(data)
×
NEW
46

×
NEW
47
        err := r.messageDB.StoreValue(key[:], data)
×
NEW
48
        if err != nil {
×
NEW
49
                return err
×
NEW
50
        }
×
51

NEW
52
        return nil
×
53
}
54

NEW
55
func New(logger *zap.Logger, bot *telego.Bot, _ map[string]any) (interfaces.Action, error) {
×
NEW
56
        messageDB, err := messages.Get(logger, "spamMessages")
×
NEW
57
        if err != nil {
×
NEW
58
                return nil, err
×
NEW
59
        }
×
60

NEW
61
        return &Action{
×
NEW
62
                logger:    logger,
×
NEW
63
                bot:       bot,
×
NEW
64
                messageDB: messageDB,
×
NEW
65
        }, nil
×
66
}
67

NEW
68
func Help() string {
×
NEW
69
        return "storeAsSpam doesn't require any parameter"
×
NEW
70
}
×
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