logic

package
v0.0.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 23, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DropInBlockType            = "dropin"
	DropInOptionTargetWord     = "targetWord"     // required
	DropInOptionCancelWord     = "cancelWord"     // optional
	DropInOptionIgnoreWord     = "ignoreWord"     // optional
	DropInOptionExpireDuration = "expireDuration" // optional
)
View Source
const (
	LimiterBlockType         = "limiter"
	LimiterOptionCount       = "count"       //required
	LimiterOptionTimeWindow  = "timeWindow"  //required
	LimiterOptionCleanupFreq = "cleanupFreq" //optional
)
View Source
const (
	RegexBlockType           = "regex"
	RegexOptionValue         = "value"         // required
	RegexOptionInvert        = "invert"        // required
	RegexOptionCaseSensitive = "caseSensitive" // required
)
View Source
const (
	RemoveBlockType       = "remove"
	RemoveOptionSubject   = "subject"
	RemoveOptionValue     = "value"
	RemoveOptionLanguage  = "language"
	RemoveOptionOperator  = "operator"
	RemoveSubjectItem     = "item"
	RemoveSubjectLanguage = "language"
	RemoveValueReply      = "reply"
	RemoveValueRepost     = "repost"
	RemoveOperatorEq      = "=="
	RemoveOperatorNe      = "!="
)
View Source
const (
	UserListBlockType        = "userlist"
	UserListOptionUri        = "listUri"    //required
	UserListOptionAllow      = "allow"      //required
	UserListOptionApiBaseURL = "apiBaseURL" //optional
)

Variables

View Source
var DropInConfigElements = map[string]types.ConfigElementDefinition{
	DropInOptionTargetWord: {
		Type:         types.ElementTypeStringArray,
		Key:          DropInOptionTargetWord,
		DefaultValue: nil,
		Required:     true,
		Validator: func(value interface{}) error {
			words, err := types.ConvertStringArray(value)
			if err != nil {
				return errors.NewValidationError(DropInOptionTargetWord, value, "must be a string array")
			}
			if len(words) == 0 {
				return errors.NewValidationError(DropInOptionTargetWord, value, "must not be empty")
			}
			return nil
		},
	},
	DropInOptionCancelWord: {
		Type:         types.ElementTypeStringArray,
		Key:          DropInOptionCancelWord,
		DefaultValue: []string{},
		Required:     false,
		Validator: func(value interface{}) error {
			words, err := types.ConvertStringArray(value)
			if err != nil {
				return errors.NewValidationError(DropInOptionCancelWord, value, "must be a string array")
			}
			if len(words) == 0 {
				return errors.NewValidationError(DropInOptionCancelWord, value, "must not be empty")
			}
			return nil
		},
	},
	DropInOptionIgnoreWord: {
		Type:         types.ElementTypeStringArray,
		Key:          DropInOptionIgnoreWord,
		DefaultValue: []string{},
		Required:     false,
		Validator: func(value interface{}) error {
			words, err := types.ConvertStringArray(value)
			if err != nil {
				return errors.NewValidationError(DropInOptionIgnoreWord, value, "must be a string array")
			}
			if len(words) == 0 {
				return errors.NewValidationError(DropInOptionIgnoreWord, value, "must not be empty")
			}
			return nil
		},
	},
	DropInOptionExpireDuration: {
		Type:         types.ElementTypeDuration,
		Key:          DropInOptionExpireDuration,
		DefaultValue: time.Duration(0),
		Required:     false,
		Validator: func(value interface{}) error {
			_, ok := value.(time.Duration)
			if !ok {
				return errors.NewValidationError(DropInOptionExpireDuration, value, "must be a duration")
			}
			return nil
		},
	},
}
View Source
var LimiterConfigElements = map[string]types.ConfigElementDefinition{
	LimiterOptionCount: {
		Type:         types.ElementTypeInt,
		Key:          LimiterOptionCount,
		DefaultValue: nil,
		Required:     true,
		Validator: func(value interface{}) error {
			var count int
			var ok bool
			if count, ok = value.(int); !ok {
				if v, ok := value.(uint64); ok {
					count = int(v)
				} else if v, ok := value.(float64); ok {
					count = int(v)
				} else {
					return errors.NewValidationError(LimiterOptionCount, value, "must be an integer")
				}
			}
			if count <= 0 {
				return errors.NewValidationError(LimiterOptionCount, value, "must be positive")
			}
			return nil
		},
	},
	LimiterOptionTimeWindow: {
		Type:         types.ElementTypeDuration,
		Key:          LimiterOptionTimeWindow,
		DefaultValue: nil,
		Required:     true,
		Validator: func(value interface{}) error {
			duration, ok := value.(time.Duration)
			if !ok {
				return errors.NewValidationError(LimiterOptionTimeWindow, value, "must be a duration")
			}
			if duration <= 0 {
				return errors.NewValidationError(LimiterOptionTimeWindow, value, "must be positive")
			}
			return nil
		},
	},
	LimiterOptionCleanupFreq: {
		Type:         types.ElementTypeDuration,
		Key:          LimiterOptionCleanupFreq,
		DefaultValue: 10 * time.Minute,
		Required:     false,
		Validator: func(value interface{}) error {
			duration, ok := value.(time.Duration)
			if !ok {
				return errors.NewValidationError(LimiterOptionCleanupFreq, value, "must be a duration")
			}
			if duration <= 0 {
				return errors.NewValidationError(LimiterOptionCleanupFreq, value, "must be positive")
			}
			return nil
		},
	},
}
View Source
var RegexConfigElements = map[string]types.ConfigElementDefinition{
	RegexOptionValue: {
		Type:         types.ElementTypeString,
		Key:          RegexOptionValue,
		DefaultValue: "",
		Required:     true,
		Validator: func(value interface{}) error {
			if _, ok := value.(string); !ok {
				return errors.NewValidationError(RegexOptionValue, value, "must be a string")
			}
			if _, err := regexp2.Compile(value.(string), 0); err != nil {
				return errors.NewValidationError(RegexOptionValue, value, fmt.Sprintf("invalid regex pattern: %v", err))
			}
			if value == "" {
				return errors.NewValidationError(RegexOptionValue, value, "must not be empty")
			}
			return nil
		},
	},
	RegexOptionInvert: {
		Type:         types.ElementTypeBool,
		Key:          RegexOptionInvert,
		DefaultValue: false,
		Required:     true,
		Validator: func(value interface{}) error {
			if _, ok := value.(bool); !ok {
				return errors.NewValidationError(RegexOptionInvert, value, "must be a boolean")
			}
			return nil
		},
	},
	RegexOptionCaseSensitive: {
		Type:         types.ElementTypeBool,
		Key:          RegexOptionCaseSensitive,
		DefaultValue: true,
		Required:     true,
		Validator: func(value interface{}) error {
			if _, ok := value.(bool); !ok {
				return errors.NewValidationError(RegexOptionCaseSensitive, value, "must be a boolean")
			}
			return nil
		},
	},
}
View Source
var RemoveItemConfigElements = map[string]types.ConfigElementDefinition{
	RemoveOptionSubject: elementDefinitionSubject,
	RemoveOptionValue: {
		Type:         types.ElementTypeString,
		Key:          RemoveOptionValue,
		DefaultValue: "",
		Required:     true,
		Validator: func(value interface{}) error {
			arr := []string{RemoveValueReply, RemoveValueRepost}
			if !slices.Contains(arr, value.(string)) {
				return errors.NewValidationError(RemoveOptionValue, value, "value must be one of the following: "+strings.Join(arr, ", "))
			}
			return nil
		},
	},
}
View Source
var RemoveSubjectConfigElements = map[string]types.ConfigElementDefinition{
	RemoveOptionSubject: elementDefinitionSubject,
	RemoveOptionLanguage: {
		Type:         types.ElementTypeString,
		Key:          RemoveOptionLanguage,
		DefaultValue: "",
		Required:     true,
		Validator: func(value interface{}) error {
			if value == "" {
				return errors.NewValidationError(RemoveOptionLanguage, value, "language cannot be empty")
			}
			return nil
		},
	},
	RemoveOptionOperator: {
		Type:         types.ElementTypeString,
		Key:          RemoveOptionOperator,
		DefaultValue: "",
		Required:     true,
		Validator: func(value interface{}) error {
			if value == "" {
				return errors.NewValidationError(RemoveOptionOperator, value, "operator cannot be empty")
			}
			arr := []string{RemoveOperatorEq, RemoveOperatorNe}
			if !slices.Contains(arr, value.(string)) {
				return errors.NewValidationError(RemoveOptionOperator, value, "operator must be one of the following: "+strings.Join(arr, ", "))
			}
			return nil
		},
	},
}
View Source
var UserListConfigElements = map[string]types.ConfigElementDefinition{
	UserListOptionUri: {
		Type:         types.ElementTypeString,
		Key:          UserListOptionUri,
		DefaultValue: "",
		Required:     true,
		Validator: func(value interface{}) error {
			if _, ok := value.(string); !ok {
				return errors.NewValidationError(UserListOptionUri, value, "must be a string")
			}
			parsedUri, err := util.ParseAtUri(value.(string))
			if err != nil {
				return errors.NewValidationError(UserListOptionUri, value, "must be a valid uri")
			}
			if parsedUri.Collection != "app.bsky.graph.list" {
				return errors.NewValidationError(UserListOptionUri, value, "must be a valid user list uri")
			}
			return nil
		},
	},
	UserListOptionAllow: {
		Type:         types.ElementTypeBool,
		Key:          UserListOptionAllow,
		DefaultValue: false,
		Required:     true,
		Validator: func(value interface{}) error {
			if _, ok := value.(bool); !ok {
				return errors.NewValidationError(UserListOptionAllow, value, "must be a boolean")
			}
			return nil
		},
	},
	UserListOptionApiBaseURL: {
		Type:         types.ElementTypeString,
		Key:          UserListOptionApiBaseURL,
		DefaultValue: "https://public.api.bsky.app",
		Required:     false,
		Validator: func(value interface{}) error {
			if _, ok := value.(string); !ok {
				return errors.NewValidationError(UserListOptionApiBaseURL, value, "must be a string")
			}
			if value == "" {
				return errors.NewValidationError(UserListOptionApiBaseURL, value, "must not be empty")
			}
			return nil
		},
	},
}

Functions

func RegisterFactory

func RegisterFactory(blockType string, factory LogicBlockFactory)

RegisterFactory registers a factory for a specific block type.

Types

type BaseLogicBlockConfig

type BaseLogicBlockConfig struct {
	BlockName string                 `yaml:"name,omitempty" json:"name,omitempty"`
	BlockType string                 `yaml:"type" json:"type"`
	Options   map[string]interface{} `yaml:"options,omitempty" json:"options,omitempty"`
	// contains filtered or unexported fields
}

func (*BaseLogicBlockConfig) Create

func (*BaseLogicBlockConfig) DeepCopy

func (*BaseLogicBlockConfig) GetBlockName

func (c *BaseLogicBlockConfig) GetBlockName() string

func (*BaseLogicBlockConfig) GetBlockType

func (c *BaseLogicBlockConfig) GetBlockType() string

func (*BaseLogicBlockConfig) GetBoolOption

func (c *BaseLogicBlockConfig) GetBoolOption(key string) (val bool, exists bool)

func (*BaseLogicBlockConfig) GetDurationOption

func (c *BaseLogicBlockConfig) GetDurationOption(key string) (val time.Duration, exists bool)

func (*BaseLogicBlockConfig) GetIntOption

func (c *BaseLogicBlockConfig) GetIntOption(key string) (val int, exists bool)

func (*BaseLogicBlockConfig) GetOption

func (c *BaseLogicBlockConfig) GetOption(key string) interface{}

Helper methods for type-safe value retrieval

func (*BaseLogicBlockConfig) GetOptions

func (c *BaseLogicBlockConfig) GetOptions() map[string]interface{}

func (*BaseLogicBlockConfig) GetStringArrayOption

func (c *BaseLogicBlockConfig) GetStringArrayOption(key string) (val []string, exists bool)

func (*BaseLogicBlockConfig) GetStringOption

func (c *BaseLogicBlockConfig) GetStringOption(key string) (val string, exists bool)

func (*BaseLogicBlockConfig) Update

func (l *BaseLogicBlockConfig) Update(key string, value interface{}) error

func (*BaseLogicBlockConfig) Validate

func (l *BaseLogicBlockConfig) Validate(key string, value interface{}) error

func (*BaseLogicBlockConfig) ValidateAll

func (l *BaseLogicBlockConfig) ValidateAll() error

type CustomLogicBlockConfig

type CustomLogicBlockConfig struct {
	BaseLogicBlockConfig
}

CustomLogicBlockConfig don't have validation funcs

func (*CustomLogicBlockConfig) Update

func (c *CustomLogicBlockConfig) Update(key string, value interface{}) error

func (*CustomLogicBlockConfig) Validate

func (l *CustomLogicBlockConfig) Validate(key string, value interface{}) error

func (*CustomLogicBlockConfig) ValidateAll

func (l *CustomLogicBlockConfig) ValidateAll() error

type DropInLogicBlockConfig

type DropInLogicBlockConfig struct {
	BaseLogicBlockConfig
	ExpireDuration time.Duration
	TargetWord     []string
	CancelWord     []string
	IgnoreWord     []string
}

type DropInLogicBlockFactory

type DropInLogicBlockFactory struct{}

DropInLogicBlockFactory is a factory for creating DropInLogicBlockConfig

func (*DropInLogicBlockFactory) Create

type FeedLogicConfigimpl

type FeedLogicConfigimpl struct {
	LogicBlocks []types.LogicBlockConfig `yaml:"blocks" json:"blocks"`
}

func DefaultFeedLogicConfig

func DefaultFeedLogicConfig() *FeedLogicConfigimpl

func (*FeedLogicConfigimpl) DeepCopy

func (*FeedLogicConfigimpl) GetLogicBlockConfigs

func (f *FeedLogicConfigimpl) GetLogicBlockConfigs() []types.LogicBlockConfig

func (*FeedLogicConfigimpl) MarshalYAML

func (f *FeedLogicConfigimpl) MarshalYAML() (interface{}, error)

func (*FeedLogicConfigimpl) UnmarshalJSON

func (f *FeedLogicConfigimpl) UnmarshalJSON(data []byte) error

func (*FeedLogicConfigimpl) UnmarshalYAML

func (f *FeedLogicConfigimpl) UnmarshalYAML(unmarshal func(interface{}) error) error

func (*FeedLogicConfigimpl) Validate

func (f *FeedLogicConfigimpl) Validate(key string, value interface{}) error

func (*FeedLogicConfigimpl) ValidateAll

func (f *FeedLogicConfigimpl) ValidateAll() error

type LimiterLogicBlockConfig

type LimiterLogicBlockConfig struct {
	BaseLogicBlockConfig
}

listUri: stringユーザーリストのURI 例: at://did:plc:xxx/app.bsky.graph.list/xxx allow: bool trueの場合リスト内のDidのみを通過する。falseの場合リスト内のDidを遮断する

type LimiterLogicBlockFactory

type LimiterLogicBlockFactory struct{}

LimiterLogicBlockFactory is a factory for creating LimiterLogicBlockConfig

func (*LimiterLogicBlockFactory) Create

type LogicBlockFactory

type LogicBlockFactory interface {
	Create(base BaseLogicBlockConfig) (types.LogicBlockConfig, error)
}

type RegexLogicBlockConfig

type RegexLogicBlockConfig struct {
	BaseLogicBlockConfig
}

RegexLogicBlockConfig defines a filtering logic block based on regular expressions. It allows filtering posts based on regex pattern matching against post content. The matching can be configured in several ways: - value: The regex pattern to match against - invert: If true, inverts the match result (keeps non-matching posts) - caseSensitive: If true, performs case-sensitive regex matching

type RegexLogicBlockFactory

type RegexLogicBlockFactory struct{}

RegexLogicBlockFactory is a factory for creating RegexLogicBlockConfig

func (*RegexLogicBlockFactory) Create

type RemoveLogicBlockConfig

type RemoveLogicBlockConfig struct {
	BaseLogicBlockConfig
}

RemoveLogicBlockConfig defines a logic block for removing by specific elements The following values are available for subject: - "item": post type (reply, repost) - "language": post language with operator (== or !=) For validation, see Validate() method

func (*RemoveLogicBlockConfig) ValidateAll

func (l *RemoveLogicBlockConfig) ValidateAll() error

type RemoveLogicBlockFactory

type RemoveLogicBlockFactory struct{}

RemoveLogicBlockFactory is a factory for creating RemoveLogicBlockConfig

func (*RemoveLogicBlockFactory) Create

type UserListLogicBlockConfig

type UserListLogicBlockConfig struct {
	BaseLogicBlockConfig
}

listUri: string uri of the user list example: at://did:plc:xxx/app.bsky.graph.list/xxx allow: bool if true, only DIDs in the list will pass. if false, DIDs in the list will be blocked apiBaseURL: string base url of the user list api

type UserListLogicBlockFactory

type UserListLogicBlockFactory struct{}

UserListLogicBlockFactory is a factory for creating UserListLogicBlockConfig

func (*UserListLogicBlockFactory) Create

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL