• 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
/helper/tg/interfaces.go
1
package tg
2

3
import (
4
        "bytes"
5
        "errors"
6
        "strings"
7

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

11
        "github.com/Civil/tg-simple-regex-antispam/helper/stateful"
12
)
13

14
type AdminCMDHandlerFunc func(logger *zap.Logger, bot *telego.Bot, message *telego.Message, tokens []string) error
15

16
type AdminCMDHelpFunc func() string
17

18
type TGHaveAdminCommands struct {
19
        Handlers map[string]AdminCMDHandlerFunc
20
}
21

22
var (
23
        ErrCommandArgsInvalid = errors.New("not enough arguments for command")
24
)
25

26
func (r *TGHaveAdminCommands) HandleTGCommands(logger *zap.Logger, bot *telego.Bot, message *telego.Message, tokens []string) error {
×
27
        supportedCommands := make([]string, 0, len(r.Handlers))
×
28
        for cmd := range r.Handlers {
×
29
                supportedCommands = append(supportedCommands, cmd)
×
30
        }
×
NEW
31
        logger.Debug("handling tg command", zap.Any("message", message), zap.Strings("supported_commands", supportedCommands))
×
32
        if tokens == nil {
×
33
                logger.Warn("empty tokens for tg command")
×
34
                buf := bytes.NewBuffer([]byte{})
×
35
                buf.WriteString("Sub-command was not specified.\nAvailable subcommands:\n\n")
×
36
                for _, prefix := range supportedCommands {
×
37
                        buf.WriteString("   " + prefix + "\n")
×
38
                }
×
39
                _ = SendMessage(bot, message.Chat.ChatID(), &message.MessageID, buf.String())
×
40
                return ErrCommandArgsInvalid
×
41
        }
42
        logger.Debug("handling tg command", zap.String("command", tokens[0]))
×
43
        if h, ok := r.Handlers[strings.ToLower(tokens[0])]; ok {
×
44
                if len(tokens) > 1 {
×
45
                        return h(logger, bot, message, tokens[1:])
×
46
                } else {
×
47
                        return h(logger, bot, message, nil)
×
48
                }
×
49
        }
50
        logger.Warn("unsupported command", zap.Strings("tokens", tokens), zap.Strings("supported_commands", supportedCommands))
×
51
        return stateful.ErrNotSupported
×
52
}
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