search

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package search provides composable chat message matchers that can be combined to build structured search queries.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AndMatcher

type AndMatcher struct {
	Matchers []Matcher
}

AndMatcher requires all child matchers to match. Short-circuits on first failure.

func NewAndMatcher

func NewAndMatcher(matchers ...Matcher) *AndMatcher

func (*AndMatcher) Match

func (m *AndMatcher) Match(msg *twitchirc.PrivateMessage) bool

type BadgeMatcher

type BadgeMatcher struct {
	// contains filtered or unexported fields
}

BadgeMatcher matches when the user has a badge whose name contains the term.

func NewBadgeMatcher

func NewBadgeMatcher(name string) *BadgeMatcher

func (*BadgeMatcher) Match

func (m *BadgeMatcher) Match(msg *twitchirc.PrivateMessage) bool

type ContentMatcher

type ContentMatcher struct {
	// contains filtered or unexported fields
}

ContentMatcher matches case-insensitive substrings in message content.

func NewContentMatcher

func NewContentMatcher(term string) *ContentMatcher

func (*ContentMatcher) Match

type DefaultMatcher

type DefaultMatcher struct {
	// contains filtered or unexported fields
}

DefaultMatcher matches when either content or username contains the term. Preserves backward-compatible behavior with the old search.

func NewDefaultMatcher

func NewDefaultMatcher(term string) *DefaultMatcher

func (*DefaultMatcher) Match

type Field

type Field int

Field selects which message fields a matcher operates on.

const (
	FieldAny     Field = iota // match content OR username
	FieldContent              // match message content only
	FieldUser                 // match username only
)

type Matcher

type Matcher interface {
	Match(msg *twitchirc.PrivateMessage) bool
}

Matcher tests whether a PrivateMessage satisfies a search criterion.

func Parse

func Parse(query string) (Matcher, error)

Parse converts a query string into a Matcher tree.

Syntax:

content:term        message content substring
msg:term            alias for content:
user:term           username substring
from:term           alias for user:
badge:name          badge name substring
is:mod|sub|vip|first boolean property
regex:pattern       regex on content + username
/pattern/           shorthand for regex:
-prefix:value       negation
bare term           default (content OR username)
"quoted value"      treated as single bare term

Multiple tokens are combined with implicit AND. Returns nil when the query is empty.

type NotMatcher

type NotMatcher struct {
	Inner Matcher
}

NotMatcher inverts the result of the inner matcher.

func NewNotMatcher

func NewNotMatcher(inner Matcher) *NotMatcher

func (*NotMatcher) Match

func (m *NotMatcher) Match(msg *twitchirc.PrivateMessage) bool

type Property

type Property int

Property identifies a boolean field on PrivateMessage for property matching.

const (
	PropertyMod   Property = iota // Mod field
	PropertySub                   // Subscriber field
	PropertyVIP                   // VIP field
	PropertyFirst                 // FirstMsg field
)

type PropertyMatcher

type PropertyMatcher struct {
	// contains filtered or unexported fields
}

PropertyMatcher matches a boolean property on the message.

func NewPropertyMatcher

func NewPropertyMatcher(prop Property) *PropertyMatcher

func (*PropertyMatcher) Match

type RegexMatcher

type RegexMatcher struct {
	// contains filtered or unexported fields
}

RegexMatcher matches a compiled regular expression against selected fields.

func NewRegexMatcher

func NewRegexMatcher(pattern string) (*RegexMatcher, error)

NewRegexMatcher compiles the pattern into a case-insensitive regex matching both content and username. Returns an error if the pattern is invalid.

func NewRegexMatcherField

func NewRegexMatcherField(pattern string, field Field) (*RegexMatcher, error)

NewRegexMatcherField compiles the pattern into a case-insensitive regex scoped to the given field.

func (*RegexMatcher) Match

func (m *RegexMatcher) Match(msg *twitchirc.PrivateMessage) bool

type UserMatcher

type UserMatcher struct {
	// contains filtered or unexported fields
}

UserMatcher matches case-insensitive substrings in the display name.

func NewUserMatcher

func NewUserMatcher(term string) *UserMatcher

func (*UserMatcher) Match

func (m *UserMatcher) Match(msg *twitchirc.PrivateMessage) bool

Jump to

Keyboard shortcuts

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