mirror of
https://github.com/krau/SaveAny-Bot.git
synced 2026-05-10 17:52:44 +08:00
* refactor: a big refactor. wip * refactor: port handle file * refactor: place all handlers * fix: task info nil pointer * feat: enhance task progress tracking and context management * feat: cancel task * feat: stream mode * feat: silent mode * feat: dir cmd * refactor: remove unused old file * feat: rule cmd * feat: handle silent mode * feat: batch task * fix: batch task progress and temp file cleanup * refactor: update file creation and cleanup methods for better resource management * feat: add save command with silent mode handling * feat: message link * feat: update message prompts to include file count in storage selection * feat: slient save links * refactor: reduce dup code * feat: rule type * feat: chose dir * feat: refactor file handling and storage rules, improve error handling and logging * feat: rule mode * feat: telegraph pics * fix: tphpics nil pointer and inaccurate dirpath * feat: silent save telegraph * feat: add suffix to avoid file overwrite * feat: new storage telegram * chore: tidy go mod
44 lines
837 B
Go
44 lines
837 B
Go
package rule
|
|
|
|
import (
|
|
"regexp"
|
|
|
|
ruleenum "github.com/krau/SaveAny-Bot/pkg/enums/rule"
|
|
)
|
|
|
|
var _ RuleClass[string] = (*RuleMessageRegex)(nil)
|
|
|
|
type RuleMessageRegex struct {
|
|
storInfo
|
|
regex *regexp.Regexp
|
|
}
|
|
|
|
func (r RuleMessageRegex) Type() ruleenum.RuleType {
|
|
return ruleenum.MessageRegex
|
|
}
|
|
|
|
func (r RuleMessageRegex) Match(input string) (bool, error) {
|
|
return r.regex.MatchString(input), nil
|
|
}
|
|
|
|
func (r RuleMessageRegex) StorageName() string {
|
|
return r.storName
|
|
}
|
|
func (r RuleMessageRegex) StoragePath() string {
|
|
return r.storPath
|
|
}
|
|
|
|
func NewRuleMessageRegex(storName, storPath, regexStr string) (*RuleMessageRegex, error) {
|
|
regex, err := regexp.Compile(regexStr)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &RuleMessageRegex{
|
|
storInfo: storInfo{
|
|
storName: storName,
|
|
storPath: storPath,
|
|
},
|
|
regex: regex,
|
|
}, nil
|
|
}
|