Documentation
¶
Overview ¶
Package webapi provides a web API spam detection service.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenerateRandomPassword ¶
GenerateRandomPassword generates a random password of a given length
Types ¶
type Config ¶
type Config struct {
Version string // version to show in /ping
ListenAddr string // listen address
Detector Detector // spam detector
SpamFilter SpamFilter // spam filter (bot)
DetectedSpam DetectedSpam // detected spam accessor
Locator Locator // locator for user info
Dictionary Dictionary // dictionary for stop phrases and ignored words
StorageEngine StorageEngine // database engine access for backups
AuthPasswd string // basic auth password for user "tg-spam"
AuthHash string // basic auth hash for user "tg-spam". If both AuthPasswd and AuthHash are provided, AuthHash is used
Dbg bool // debug mode
Settings Settings // application settings
}
Config defines server parameters
type DetectedSpam ¶ added in v1.10.0
type DetectedSpam interface {
Read(ctx context.Context) ([]storage.DetectedSpamInfo, error)
SetAddedToSamplesFlag(ctx context.Context, id int64) error
FindByUserID(ctx context.Context, userID int64) (*storage.DetectedSpamInfo, error)
}
DetectedSpam is a storage interface used to get detected spam messages and set added flag.
type Detector ¶ added in v1.5.0
type Detector interface {
Check(req spamcheck.Request) (spam bool, cr []spamcheck.Response)
ApprovedUsers() []approved.UserInfo
AddApprovedUser(user approved.UserInfo) error
RemoveApprovedUser(id string) error
GetLuaPluginNames() []string // Returns the list of available Lua plugin names
}
Detector is a spam detector interface.
type Dictionary ¶ added in v1.21.0
type Dictionary interface {
Add(ctx context.Context, t storage.DictionaryType, data string) error
Delete(ctx context.Context, id int64) error
Read(ctx context.Context, t storage.DictionaryType) ([]string, error)
ReadWithIDs(ctx context.Context, t storage.DictionaryType) ([]storage.DictionaryEntry, error)
Stats(ctx context.Context) (*storage.DictionaryStats, error)
}
Dictionary is a storage interface for managing stop phrases and ignored words
type Locator ¶ added in v1.5.0
type Locator interface {
UserIDByName(ctx context.Context, userName string) int64
UserNameByID(ctx context.Context, userID int64) string
}
Locator is a storage interface used to get user id by name and vice versa.
type Settings ¶ added in v1.9.0
type Settings struct {
InstanceID string `json:"instance_id"`
PrimaryGroup string `json:"primary_group"`
AdminGroup string `json:"admin_group"`
DisableAdminSpamForward bool `json:"disable_admin_spam_forward"`
LoggerEnabled bool `json:"logger_enabled"`
SuperUsers []string `json:"super_users"`
NoSpamReply bool `json:"no_spam_reply"`
CasEnabled bool `json:"cas_enabled"`
MetaEnabled bool `json:"meta_enabled"`
MetaLinksLimit int `json:"meta_links_limit"`
MetaMentionsLimit int `json:"meta_mentions_limit"`
MetaLinksOnly bool `json:"meta_links_only"`
MetaImageOnly bool `json:"meta_image_only"`
MetaVideoOnly bool `json:"meta_video_only"`
MetaAudioOnly bool `json:"meta_audio_only"`
MetaForwarded bool `json:"meta_forwarded"`
MetaKeyboard bool `json:"meta_keyboard"`
MetaContactOnly bool `json:"meta_contact_only"`
MetaUsernameSymbols string `json:"meta_username_symbols"`
MetaGiveaway bool `json:"meta_giveaway"`
MultiLangLimit int `json:"multi_lang_limit"`
OpenAIEnabled bool `json:"openai_enabled"`
OpenAIVeto bool `json:"openai_veto"`
OpenAIHistorySize int `json:"openai_history_size"`
OpenAIModel string `json:"openai_model"`
OpenAICheckShortMessages bool `json:"openai_check_short_messages"`
OpenAICustomPrompts []string `json:"openai_custom_prompts"`
LuaPluginsEnabled bool `json:"lua_plugins_enabled"`
LuaPluginsDir string `json:"lua_plugins_dir"`
LuaEnabledPlugins []string `json:"lua_enabled_plugins"`
LuaDynamicReload bool `json:"lua_dynamic_reload"`
LuaAvailablePlugins []string `json:"lua_available_plugins"` // the list of all available Lua plugins
SamplesDataPath string `json:"samples_data_path"`
DynamicDataPath string `json:"dynamic_data_path"`
WatchIntervalSecs int `json:"watch_interval_secs"`
SimilarityThreshold float64 `json:"similarity_threshold"`
MinMsgLen int `json:"min_msg_len"`
MaxEmoji int `json:"max_emoji"`
MinSpamProbability float64 `json:"min_spam_probability"`
ParanoidMode bool `json:"paranoid_mode"`
FirstMessagesCount int `json:"first_messages_count"`
StartupMessageEnabled bool `json:"startup_message_enabled"`
TrainingEnabled bool `json:"training_enabled"`
StorageTimeout time.Duration `json:"storage_timeout"`
SoftBanEnabled bool `json:"soft_ban_enabled"`
AbnormalSpacingEnabled bool `json:"abnormal_spacing_enabled"`
HistorySize int `json:"history_size"`
DebugModeEnabled bool `json:"debug_mode_enabled"`
DryModeEnabled bool `json:"dry_mode_enabled"`
TGDebugModeEnabled bool `json:"tg_debug_mode_enabled"`
}
Settings contains all application settings
type SpamFilter ¶
type SpamFilter interface {
UpdateSpam(msg string) error
UpdateHam(msg string) error
ReloadSamples() (err error)
DynamicSamples() (spam, ham []string, err error)
RemoveDynamicSpamSample(sample string) error
RemoveDynamicHamSample(sample string) error
}
SpamFilter is a spam filter, bot interface.
Click to show internal directories.
Click to hide internal directories.