Documentation
¶
Index ¶
- Constants
- type AuditLog
- type AuditLogConfig
- type AuditLogConfigEntityManager
- func (alcem *AuditLogConfigEntityManager) Create(auditLogConfig *AuditLogConfig) error
- func (alcem *AuditLogConfigEntityManager) GetByGuildId(guildId uint) (*AuditLogConfig, error)
- func (alcem *AuditLogConfigEntityManager) Save(auditLogConfig *AuditLogConfig) error
- func (alcem *AuditLogConfigEntityManager) Update(auditLogConfig *AuditLogConfig, column string, value interface{}) error
- type AuditLogEntityManager
- type ComponentCode
- type EntityManager
- type GlobalComponentStatus
- type GlobalComponentStatusEntityManager
- func (gem *GlobalComponentStatusEntityManager) Create(globalComponentStatus *GlobalComponentStatus) error
- func (gem *GlobalComponentStatusEntityManager) Get(registeredComponentStatusId uint) (*GlobalComponentStatus, error)
- func (gem *GlobalComponentStatusEntityManager) GetDisplayString(globalComponentStatusId uint) (string, error)
- func (gem *GlobalComponentStatusEntityManager) Save(globalComponentStatus *GlobalComponentStatus) error
- func (gem *GlobalComponentStatusEntityManager) Update(globalComponentStatus *GlobalComponentStatus, column string, value interface{}) error
- type Guild
- type GuildComponentStatus
- type GuildComponentStatusEntityManager
- func (gcsem *GuildComponentStatusEntityManager) Create(guildComponentStatus *GuildComponentStatus) error
- func (gcsem *GuildComponentStatusEntityManager) Get(guildId uint, componentId uint) (*GuildComponentStatus, error)
- func (gcsem *GuildComponentStatusEntityManager) GetDisplay(guildId uint, componentId uint) (string, error)
- func (gcsem *GuildComponentStatusEntityManager) Save(guildComponentStatus *GuildComponentStatus) error
- func (gcsem *GuildComponentStatusEntityManager) Update(guildComponentStatus *GuildComponentStatus, column string, value interface{}) error
- type GuildEntityManager
- func (gem *GuildEntityManager) Count() (int64, error)
- func (gem *GuildEntityManager) Create(guild *Guild) error
- func (gem *GuildEntityManager) Get(guildId string) (*Guild, error)
- func (gem *GuildEntityManager) Save(guild *Guild) error
- func (gem *GuildEntityManager) Update(guild *Guild, column string, value interface{}) error
- type RegisteredComponent
- type RegisteredComponentEntityManager
- func (rgem *RegisteredComponentEntityManager) Create(regComp *RegisteredComponent) error
- func (rgem *RegisteredComponentEntityManager) Get(registeredComponentCode ComponentCode) (*RegisteredComponent, error)
- func (rgem *RegisteredComponentEntityManager) GetAvailable() []*RegisteredComponent
- func (rgem *RegisteredComponentEntityManager) MarkAsAvailable(code ComponentCode)
- func (rgem *RegisteredComponentEntityManager) Save(regComp *RegisteredComponent) error
- func (rgem *RegisteredComponentEntityManager) Update(regComp *RegisteredComponent, column string, value interface{}) error
Constants ¶
const ColumnCode = "code"
const ColumnComponent = "component_id"
const ColumnEnabled = "enabled"
const ColumnGuild = "guild_id"
const ColumnGuildId = "guild_id"
const ColumnName = "name"
const CoreComponentPrefix = "bot_"
CoreComponentPrefix is the prefix put in front of components that cannot be managed by server owners, as they are important core components
const GlobalComponentStatusDisabledDisplay = ":no_entry:"
const GlobalComponentStatusEnabledDisplay = ":white_check_mark:"
const GuildComponentStatusDisabledDisplay = ":x:"
const GuildComponentStatusEnabledDisplay = ":white_check_mark:"
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AuditLog ¶ added in v0.2.0
type AuditLog struct { gorm.Model GuildID uint `gorm:"index:idx_audit_log_guild_id;index:idx_audit_log_guild_id_user_id;index:idx_audit_log_guild_id_component_id_user_id;"` Guild Guild `gorm:"constraint:OnDelete:CASCADE;"` RegisteredComponentID uint `gorm:"index:idx_audit_log_guild_id;index:idx_audit_log_guild_id_user_id;index:idx_audit_log_guild_id_component_id_user_id;"` RegisteredComponent RegisteredComponent `gorm:"constraint:OnDelete:CASCADE;"` UserID uint64 `gorm:"index:idx_audit_log_user_id;index:idx_audit_log_guild_id_user_id;index:idx_audit_log_guild_id_component_id_user_id;"` Message string }
AuditLog holds the audit log of the bot. The audit log contains information about different administrative actions. The most important purpose of the audit log is to ensure that any change done to the bots configuration done by the users of the bot can be tracked. This can be actions on guilds or actions performed in private messages.
type AuditLogConfig ¶ added in v0.2.0
type AuditLogConfig struct { gorm.Model GuildID uint `gorm:"uniqueIndex;"` Guild Guild `gorm:"constraint:OnDelete:CASCADE;"` ChannelId *uint64 Enabled bool }
AuditLogConfig holds the guild specific configuration for audit logging.
type AuditLogConfigEntityManager ¶ added in v0.2.0
type AuditLogConfigEntityManager struct {
EntityManager
}
AuditLogConfigEntityManager is the audit log config specific entity manager that allows easy access to audit log configurations.
func NewAuditLogConfigEntityManager ¶ added in v0.2.0
func NewAuditLogConfigEntityManager(entityManager EntityManager) *AuditLogConfigEntityManager
NewAuditLogConfigEntityManager creates a new AuditLogConfigEntityManager.
func (*AuditLogConfigEntityManager) Create ¶ added in v0.2.0
func (alcem *AuditLogConfigEntityManager) Create(auditLogConfig *AuditLogConfig) error
Create saves the passed AuditLogConfig in the database. Use Update or Save to update an already existing AuditLogConfig.
func (*AuditLogConfigEntityManager) GetByGuildId ¶ added in v0.2.0
func (alcem *AuditLogConfigEntityManager) GetByGuildId(guildId uint) (*AuditLogConfig, error)
GetByGuildId tries to get a AuditLogConfig by its guild ID. The function uses a cache and first tries to resolve a value from it. If no cache entry is present, a request to the entities will be made. If no AuditLogConfig can be found, the function returns a new empty AuditLogConfig.
func (*AuditLogConfigEntityManager) Save ¶ added in v0.2.0
func (alcem *AuditLogConfigEntityManager) Save(auditLogConfig *AuditLogConfig) error
Save updates the passed Guild in the database. This does a generic update, use Update to do a precise and more performant update of the entity when only updating a single field!
func (*AuditLogConfigEntityManager) Update ¶ added in v0.2.0
func (alcem *AuditLogConfigEntityManager) Update(auditLogConfig *AuditLogConfig, column string, value interface{}) error
Update updates the defined field on the entity and saves it in the database.
type AuditLogEntityManager ¶ added in v0.2.0
type AuditLogEntityManager struct {
EntityManager
}
AuditLogEntityManager is the audit log specific entity manager that allows easy access to guilds in the entities.
func NewAuditLogEntityManager ¶ added in v0.2.0
func NewAuditLogEntityManager(entityManager EntityManager) *AuditLogEntityManager
NewAuditLogEntityManager creates a new AuditLogEntityManager.
func (*AuditLogEntityManager) Create ¶ added in v0.2.0
func (alem *AuditLogEntityManager) Create(guild *AuditLog) error
Create saves the passed AuditLog in the database. Use Update or Save to update an already existing AuditLog.
func (*AuditLogEntityManager) Save ¶ added in v0.2.0
func (alem *AuditLogEntityManager) Save(guild *AuditLog) error
Save updates the passed AuditLog in the database. This does a generic update, use Update to do a precise and more performant update of the entity when only updating a single field!
type ComponentCode ¶ added in v0.2.0
type ComponentCode string
ComponentCode is the code of a specific component. It is used as a unique identifier across all components.
type EntityManager ¶
type EntityManager interface { // RegisterEntity registers a new entity (struct) and runs its automated // migration to ensure the entities schema is up-to-date. RegisterEntity(entityType interface{}) error // DB returns the current services.DatabaseAccess instance that // wraps gorm.DB and allows lower level db access. // Note that it is highly recommended to depend on methods of the // entity specific managers instead of services.DatabaseAccess. DB() services.DatabaseAccess // Logger returns the services.Logger of the EntityManager. Logger() services.Logger }
EntityManager contains methods that allow to retrieve entity specific entity managers that provide caching and dedicated functions to work with specific entities. The entity specific managers allow to perform CRUD operations.
Additionally, the main entity manager allows to register (auto migrate)
type GlobalComponentStatus ¶
type GlobalComponentStatus struct { gorm.Model ComponentID uint `gorm:"index:idx_global_component_status_component_id;"` Component RegisteredComponent `gorm:"constraint:OnDelete:CASCADE;"` Enabled bool }
GlobalComponentStatus holds the status of a component in the global context. This allows disabling a bugging component globally if necessary.
type GlobalComponentStatusEntityManager ¶
type GlobalComponentStatusEntityManager struct {
EntityManager
}
GlobalComponentStatusEntityManager is the GlobalComponentStatus specific entity manager that allows easy access to global component status in the entities.
func NewGlobalComponentStatusEntityManager ¶
func NewGlobalComponentStatusEntityManager(entityManager EntityManager) *GlobalComponentStatusEntityManager
NewGlobalComponentStatusEntityManager creates a new GlobalComponentStatusEntityManager.
func (*GlobalComponentStatusEntityManager) Create ¶
func (gem *GlobalComponentStatusEntityManager) Create(globalComponentStatus *GlobalComponentStatus) error
Create saves the passed GlobalComponentStatus in the database. Use Update or Save to update an already existing GlobalComponentStatus.
func (*GlobalComponentStatusEntityManager) Get ¶
func (gem *GlobalComponentStatusEntityManager) Get(registeredComponentStatusId uint) (*GlobalComponentStatus, error)
Get tries to get a GlobalComponentStatus from the cache. If no cache entry is present, a request to the entities will be made. If no GlobalComponentStatus can be found, the function returns a new empty GlobalComponentStatus.
func (*GlobalComponentStatusEntityManager) GetDisplayString ¶
func (gem *GlobalComponentStatusEntityManager) GetDisplayString(globalComponentStatusId uint) (string, error)
GetDisplayString returns the string that indicates whether a component is enabled or disabled globally. The string can directly being used to print out messages in Discord.
func (*GlobalComponentStatusEntityManager) Save ¶
func (gem *GlobalComponentStatusEntityManager) Save(globalComponentStatus *GlobalComponentStatus) error
Save updates the passed GlobalComponentStatus in the database. This does a generic update, use Update to do a precise and more performant update of the entity when only updating a single field!
func (*GlobalComponentStatusEntityManager) Update ¶
func (gem *GlobalComponentStatusEntityManager) Update( globalComponentStatus *GlobalComponentStatus, column string, value interface{}, ) error
Update updates the defined field on the entity and saves it in the database.
type Guild ¶
Guild represents a single Discord guild that the bot is currently on.
Note that the guild name is just stored for convenience when manually searching the DB for a guild.
type GuildComponentStatus ¶
type GuildComponentStatus struct { gorm.Model GuildID uint `gorm:"index:idx_guild_component_status_guild_id;index:idx_guild_component_status_guild_id_component_id;"` Guild Guild `gorm:"constraint:OnDelete:CASCADE;"` ComponentID uint `gorm:"index:idx_guild_component_status_component_id;index:idx_guild_component_status_guild_id_component_id;"` Component RegisteredComponent `gorm:"constraint:OnDelete:CASCADE;"` Enabled bool }
GuildComponentStatus holds the status of a component on a specific server
type GuildComponentStatusEntityManager ¶
type GuildComponentStatusEntityManager struct {
EntityManager
}
GuildComponentStatusEntityManager is the guild component specific entity manager that allows easy access to guilds in the entities.
func NewGuildComponentStatusEntityManager ¶
func NewGuildComponentStatusEntityManager(entityManager EntityManager) *GuildComponentStatusEntityManager
NewGuildComponentStatusEntityManager creates a new GuildComponentStatusEntityManager.
func (*GuildComponentStatusEntityManager) Create ¶
func (gcsem *GuildComponentStatusEntityManager) Create(guildComponentStatus *GuildComponentStatus) error
Create saves the passed Guild in the database. Use Update or Save to update an already existing Guild.
func (*GuildComponentStatusEntityManager) Get ¶
func (gcsem *GuildComponentStatusEntityManager) Get(guildId uint, componentId uint) (*GuildComponentStatus, error)
Get tries to get a GuildComponentStatus from the cache. If no cache entry is present, a request to the entities will be made. If no GuildComponentStatus can be found, the function returns a new empty GuildComponentStatus.
func (*GuildComponentStatusEntityManager) GetDisplay ¶
func (gcsem *GuildComponentStatusEntityManager) GetDisplay(guildId uint, componentId uint) (string, error)
GetDisplay returns the status of a component in a form that can be directly displayed in Discord.
func (*GuildComponentStatusEntityManager) Save ¶
func (gcsem *GuildComponentStatusEntityManager) Save(guildComponentStatus *GuildComponentStatus) error
Save updates the passed Guild in the database. This does a generic update, use Update to do a precise and more performant update of the entity when only updating a single field!
func (*GuildComponentStatusEntityManager) Update ¶
func (gcsem *GuildComponentStatusEntityManager) Update( guildComponentStatus *GuildComponentStatus, column string, value interface{}, ) error
Update updates the defined field on the entity and saves it in the database.
type GuildEntityManager ¶
type GuildEntityManager struct {
EntityManager
}
GuildEntityManager is the Guild specific entity manager that allows easy access to guilds in the entities.
func NewGuildEntityManager ¶
func NewGuildEntityManager(em EntityManager) *GuildEntityManager
NewGuildEntityManager creates a new GuildEntityManager with the given EntityManager.
func (*GuildEntityManager) Count ¶
func (gem *GuildEntityManager) Count() (int64, error)
Count returns the number of all guilds stored in the entities
func (*GuildEntityManager) Create ¶
func (gem *GuildEntityManager) Create(guild *Guild) error
Create saves the passed Guild in the database. Use Update or Save to update an already existing Guild.
func (*GuildEntityManager) Get ¶
func (gem *GuildEntityManager) Get(guildId string) (*Guild, error)
Get tries to get a Guild from the cache. If no cache entry is present, a request to the entities will be made. If no Guild can be found, the function returns a new empty Guild.
func (*GuildEntityManager) Save ¶
func (gem *GuildEntityManager) Save(guild *Guild) error
Save updates the passed Guild in the database. This does a generic update, use Update to do a precise and more performant update of the entity when only updating a single field!
type RegisteredComponent ¶
type RegisteredComponent struct { gorm.Model Code ComponentCode `gorm:"uniqueIndex"` Name string Description string DefaultEnabled bool }
RegisteredComponent represents a single component that is or was known to the system.
Single purpose of this struct is to provide a entities table with which relations can be build to ensure integrity of the GuildComponentStatus and GlobalComponentStatus tables.
func (*RegisteredComponent) IsCoreComponent ¶
func (regComp *RegisteredComponent) IsCoreComponent() bool
IsCoreComponent checks whether the passed RegisteredComponent is a core component or not.
Core components are components which are prefixed with the CoreComponentPrefix.
type RegisteredComponentEntityManager ¶
type RegisteredComponentEntityManager struct { EntityManager // contains filtered or unexported fields }
RegisteredComponentEntityManager is the RegisteredComponent specific entity manager that allows easy access to global component status in the database.
func NewRegisteredComponentEntityManager ¶
func NewRegisteredComponentEntityManager(entityManager EntityManager) *RegisteredComponentEntityManager
NewRegisteredComponentEntityManager creates a new RegisteredComponentEntityManager.
func (*RegisteredComponentEntityManager) Create ¶
func (rgem *RegisteredComponentEntityManager) Create(regComp *RegisteredComponent) error
Create saves the passed RegisteredComponent in the database. Use Update or Save to update an already existing RegisteredComponent.
func (*RegisteredComponentEntityManager) Get ¶
func (rgem *RegisteredComponentEntityManager) Get(registeredComponentCode ComponentCode) (*RegisteredComponent, error)
Get tries to get a RegisteredComponent from the cache. If no cache entry is present, a request to the database will be made. If no RegisteredComponent can be found, the function returns a new empty RegisteredComponent.
func (*RegisteredComponentEntityManager) GetAvailable ¶
func (rgem *RegisteredComponentEntityManager) GetAvailable() []*RegisteredComponent
GetAvailable returns all components that have been registered during application bootstrap.
func (*RegisteredComponentEntityManager) MarkAsAvailable ¶
func (rgem *RegisteredComponentEntityManager) MarkAsAvailable(code ComponentCode)
MarkAsAvailable marks the passed component as available, by putting the codes into an array. Note that duplicates will be filtered.
func (*RegisteredComponentEntityManager) Save ¶
func (rgem *RegisteredComponentEntityManager) Save(regComp *RegisteredComponent) error
Save updates the passed RegisteredComponent in the database. This does a generic update, use Update to do a precise and more performant update of the entity when only updating a single field!
func (*RegisteredComponentEntityManager) Update ¶
func (rgem *RegisteredComponentEntityManager) Update(regComp *RegisteredComponent, column string, value interface{}) error
Update updates the defined field on the entity and saves it in the database.