store

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2025 License: AGPL-3.0 Imports: 12 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	ConfigFilePath = "configs/config.json"
	CacheFilePath  = "configs/cache.json"
)

## Path Constants These constants define the file paths used for configuration, cache, and logs.

View Source
const (
	// Avatar cache errors
	ErrReadCacheFile        = "error reading cache file: %w"
	ErrUnmarshalCache       = "error unmarshalling cache: %w"
	ErrCreateCacheDirectory = "error creating cache directory: %w"
	ErrMarshalCache         = "error marshalling cache: %w"
	ErrSaveCacheFile        = "error saving cache file: %w"
	WarnNoGuildCache        = "ClearForGuild called, but guild has no cache"

	// Configuration and File System errors
	ErrFailedLoadConfig           = "failed to load config: %w"
	ErrCreateConfigDir            = "error creating config directory: %w"
	ErrCreateLogsDir              = "error creating logs directory: %w"
	ErrFailedCheckPerms           = "failed to check permissions: %w"
	ErrCreateConfigFile           = "error creating config file: %w"
	ErrCreateCacheFile            = "error creating cache file: %w"
	ErrFailedResolveConfigPath    = "failed to resolve config path: %w"
	ErrCannotSaveNilConfig        = "cannot save nil config"
	ErrFailedMarshalConfig        = "failed to marshal config: %w"
	ErrProjectRootPathNotFoundMsg = "project root path not found"
	ErrInvalidPath                = "invalid path: %w"
	ErrCreateCacheDir             = "error creating cache directory: %w"

	// Discord API and Guild-related errors
	ErrGuildsNotAccessible  = "%d configured guild(s) could not be accessed"
	ErrGuildInfoFetchMsg    = "error fetching guild info %s: %w"
	ErrNoSuitableChannelMsg = "no suitable channel found in guild %s"
	ErrChannelNotFound      = "channel not found"
	ErrChannelWrongGuild    = "channel does not belong to this guild"
	ErrChannelWrongType     = "channel must be a text channel"
	ErrChannelNoPermissions = "bot lacks permissions to send messages in channel"
	ErrWriteAvatarCache     = "error writing avatar cache file: %w"
	ErrMarshalAvatarCache   = "error marshalling avatar cache: %w"
	ErrRemoveAvatarCache    = "error removing avatar cache file: %w"
)

## Error Constants These constants define a consistent set of error messages used throughout the application. They are used to wrap underlying errors with more descriptive context, which helps in debugging and logging.

View Source
const (
	// Configuration and startup logs
	LogCouldNotFetchGuild     = "Could not fetch guild details: %v"
	LogNoSuitableChannel      = "No suitable channel found in guild %s"
	LogGuildAdded             = "Guild added"
	LogGuildAlreadyConfigured = "Guild already configured, skipping"
	LogMonitorGuild           = "Will monitor this guild"
	LogConfigFileNotFound     = "Config file not found, creating: %s"
	LogCacheFileNotFound      = "Cache file not found, creating: %s"
	LogNoConfiguredGuilds     = "No configured guilds. Use /setup to configure."
	LogGuildNotAccessible     = "Guild not accessible; skipping"
	LogFoundConfiguredGuilds  = "%d configured guild(s) found"

	// Specific loading and saving logs
	LogLoadConfigFailedJoinPaths   = "Failed to join paths: %s, error: %v"
	LogLoadConfigFileNotFound      = "Config file not found at path: %s, initializing default config"
	LogLoadConfigFailedReadFile    = "Failed to read config file at path: %s, error: %v"
	LogLoadConfigFailedUnmarshal   = "Failed to unmarshal config data from path: %s, error: %v"
	LogLoadConfigNoGuilds          = "Loaded config has no guilds defined, path: %s"
	LogLoadConfigSuccess           = "Successfully loaded config from path: %s"
	LogSaveConfigNilConfig         = "Attempted to save nil config"
	LogSaveConfigFailedResolvePath = "Failed to resolve config path: %s, error: %v"
	LogSaveConfigFailedMarshal     = "Failed to marshal config, error: %v"
	LogSaveConfigFailedWriteFile   = "Failed to write config to path: %s, error: %v"
	LogSaveConfigSuccess           = "Successfully saved config to path: %s"
)

## Log Constants These constants define consistent log messages to be used for informational, warning, and error logging. They help maintain a uniform and easily searchable log output.

View Source
const (
	RuleTypeNative = "native"
	RuleTypeCustom = "custom"
)

RuleType distinguishes between native Discord rules and custom bot rules

Variables

View Source
var (
	DiscordBotName         string = "Alice Bot"
	DiscordBotToken        string
	ApplicationSupportPath string
	ApplicationConfigPath  string
	CurrentGitBranch       string
)

Functions

func EnsureConfigFiles

func EnsureConfigFiles() error

func FindAdminRoles

func FindAdminRoles(session *discordgo.Session, guildID, ownerID string) []string

func FindSuitableChannel

func FindSuitableChannel(session *discordgo.Session, guildID string) string

func GetTextChannels

func GetTextChannels(session *discordgo.Session, guildID string) ([]*discordgo.Channel, error)

func LogConfiguredGuilds

func LogConfiguredGuilds(configManager *ConfigManager, session *discordgo.Session) error

LogConfiguredGuilds logs a summary of configured guilds. Returns error if any guilds are inaccessible.

func ShowConfiguredGuilds

func ShowConfiguredGuilds(s *discordgo.Session, configManager *ConfigManager)

ShowConfiguredGuilds logs the configured guilds (no active guild concept).

func ValidateChannel

func ValidateChannel(session *discordgo.Session, guildID, channelID string) error

Types

type AvatarCache

type AvatarCache struct {
	Avatars     map[string]string `json:"avatars"`
	LastUpdated time.Time         `json:"last_updated"`
	GuildID     string            `json:"guild_id"`
}

AvatarCache holds the cached avatars for a guild.

type AvatarCacheManager

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

func NewAvatarCacheManager

func NewAvatarCacheManager() *AvatarCacheManager

func (*AvatarCacheManager) AvatarChanged

func (m *AvatarCacheManager) AvatarChanged(guildID, userID, currentAvatarHash string) bool

func (*AvatarCacheManager) AvatarHash

func (m *AvatarCacheManager) AvatarHash(guildID, userID string) string

AvatarHash retrieves the avatar hash for a user in a specific guild.

func (*AvatarCacheManager) ClearForGuild

func (m *AvatarCacheManager) ClearForGuild(guildID string) error

ClearForGuild removes the cache of a specific guild

func (*AvatarCacheManager) GuildCache

func (m *AvatarCacheManager) GuildCache(guildID string) *AvatarCache

GuildCache retrieves or initializes the cache for a specific guild.

func (*AvatarCacheManager) GuildIDs

func (m *AvatarCacheManager) GuildIDs() []string

GuildIDs returns a list of guilds that have cache

func (*AvatarCacheManager) Load

func (m *AvatarCacheManager) Load() error

Load loads the cache from the file.

func (*AvatarCacheManager) Save

func (m *AvatarCacheManager) Save() error

Save saves the avatar cache to the configured file path.

func (*AvatarCacheManager) SaveForGuild

func (m *AvatarCacheManager) SaveForGuild(guildID string) error

SaveForGuild saves only a specific guild (keeps compatibility)

func (*AvatarCacheManager) SaveThrottled

func (m *AvatarCacheManager) SaveThrottled(minInterval time.Duration) error

SaveThrottled performs coalesced persistence respecting the minimum interval.

func (*AvatarCacheManager) UpdateAvatar

func (m *AvatarCacheManager) UpdateAvatar(guildID, userID, avatarHash string)

UpdateAvatar updates the avatar hash for a user in a specific guild.

type AvatarChange

type AvatarChange struct {
	UserID    string
	Username  string
	OldAvatar string
	NewAvatar string
	Timestamp time.Time
}

AvatarChange holds information about a user's avatar change.

type AvatarMultiGuildCache

type AvatarMultiGuildCache struct {
	Guilds      map[string]*AvatarCache `json:"guilds"`
	LastUpdated time.Time               `json:"last_updated"`
	Version     string                  `json:"version"`
}

AvatarMultiGuildCache represents the cache file containing all guilds

type BotConfig

type BotConfig struct {
	Guilds      []GuildConfig `json:"guilds"`
	ActiveGuild string        `json:"active_guild,omitempty"`
}

BotConfig holds the configuration for the bot.

type ConfigManager

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

Manager handles bot configuration management.

func NewConfigManager

func NewConfigManager() *ConfigManager

func NewConfigManagerWithPath

func NewConfigManagerWithPath(configPath string) *ConfigManager

NewManager creates a new configuration manager.

func (*ConfigManager) AddGuildConfig

func (mgr *ConfigManager) AddGuildConfig(guildCfg GuildConfig) error

AddGuildConfig adds or replaces a guild configuration.

func (*ConfigManager) AddList

func (mgr *ConfigManager) AddList(guildID string, list List) error

Adicionar métodos para gerenciar lists, rules e rulesets no ConfigManager

func (*ConfigManager) AddListToRule

func (mgr *ConfigManager) AddListToRule(guildID string, ruleID string, list List) error

Corrigir lógica para adicionar lists a rules

func (*ConfigManager) AddRule

func (mgr *ConfigManager) AddRule(guildID string, rule Rule) error

func (*ConfigManager) AddRuleset

func (mgr *ConfigManager) AddRuleset(guildID string, ruleset Ruleset) error

func (*ConfigManager) Config

func (mgr *ConfigManager) Config() *BotConfig

GetConfig returns the current configuration.

func (*ConfigManager) ConfigPath

func (mgr *ConfigManager) ConfigPath() string

GetConfigPath returns the config file path.

func (*ConfigManager) DetectGuilds

func (mgr *ConfigManager) DetectGuilds(session *discordgo.Session) error

AutoDetectGuilds automatically detects guilds where the bot is present.

func (*ConfigManager) GuildConfig

func (mgr *ConfigManager) GuildConfig(guildID string) *GuildConfig

GuildConfig returns the configuration for a specific guild.

func (*ConfigManager) HasAnyGuilds

func (mgr *ConfigManager) HasAnyGuilds() bool

HasGuilds checks if there are configured guilds.

func (*ConfigManager) LoadConfig

func (mgr *ConfigManager) LoadConfig() error

Load loads the configuration from file.

func (*ConfigManager) RegisterGuild

func (mgr *ConfigManager) RegisterGuild(session *discordgo.Session, guildID string) error

AddGuildToConfig adds a new guild to the configuration.

func (*ConfigManager) RemoveGuildConfig

func (mgr *ConfigManager) RemoveGuildConfig(guildID string)

RemoveGuildConfig removes a guild configuration.

func (*ConfigManager) SaveConfig

func (mgr *ConfigManager) SaveConfig() error

Save saves the current configuration to file.

type GuildConfig

type GuildConfig struct {
	GuildID             string    `json:"guild_id"`
	CommandChannelID    string    `json:"command_channel_id"`
	UserLogChannelID    string    `json:"user_log_channel_id"` // Renamed from AvatarLogChannelID
	AutomodLogChannelID string    `json:"automod_log_channel_id"`
	AllowedRoles        []string  `json:"allowed_roles"`
	Rulesets            []Ruleset `json:"rulesets,omitempty"`
	LooseLists          []Rule    `json:"loose_rules,omitempty"` // Regras soltas, não associadas a nenhuma ruleset
	Blocklist           []string  `json:"blocklist,omitempty"`
}

GuildConfig holds the configuration for a specific guild.

func (*GuildConfig) FindListByName

func (gc *GuildConfig) FindListByName(name string) *List

FindListByName searches for a list by its name in LooseLists.

func (*GuildConfig) FindRulesetByID

func (cfg *GuildConfig) FindRulesetByID(id string) (*Ruleset, int)

FindRulesetByID searches for a ruleset by its ID in the guild configuration.

func (*GuildConfig) ListExists

func (gc *GuildConfig) ListExists(name string) bool

ListExists checks if a list with the given name already exists in LooseLists.

type List

type List struct {
	ID          string `json:"id"`
	Type        string `json:"type"` // "native" or "custom"
	Name        string `json:"name"`
	Description string `json:"description,omitempty"`
	// Native list fields
	NativeID string `json:"native_id,omitempty"`
	// Custom list fields
	BlockedKeywords []string `json:"blocked_keywords,omitempty"`
}

List represents a single list in the system.

type Rule

type Rule struct {
	ID      string `json:"id"`
	Name    string `json:"name"`
	Lists   []List `json:"lists"` // Conjunto de listas associadas à regra
	Enabled bool   `json:"enabled"`
}

Rule representa uma regra que pode carregar um conjunto de listas.

type Ruleset

type Ruleset struct {
	ID      string `json:"id"`
	Name    string `json:"name"`
	Rules   []Rule `json:"rules"`
	Enabled bool   `json:"enabled"`
}

Ruleset holds a collection of rules.

func (Ruleset) StatusString

func (r Ruleset) StatusString() string

StatusString returns a human-readable status for the ruleset (Enabled/Disabled)

Jump to

Keyboard shortcuts

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