DB is an interface to the database used by plugins. This allows plugins to avoid importing pgx and its dependencies redundantly.
type DB interface {
// Config.
HaveConfig(key string) bool
GetString(key string) string
SaveString(key string, value string)
GetMultiString(key string) []string
SaveMultiString(key string, value []string)
GetBool(key string) bool
SaveBool(key string, value bool)
GetInt(key string) int
SaveInt(key string, value int)
GetMultiInt(key string) []int
SaveMultiInt(key string, values []int)
GetInt64(key string) int64
SaveInt64(key string, value int64)
GetFloat(key string) float64
SaveFloat(key string, value float64)
// Account.
AddAccount(a *Account, password string)
AccountByID(id int) *Account
AccountByUsername(username string) *Account
AccountBySessionKey(sessionKey string) *Account
AllAccounts() []*Account
UpdateAccountUsername(a *Account)
UpdateAccountRole(a *Account)
UpdateAccountPassword(id int, password string)
UpdateAccountLastActive(id int)
UpdateAccountStyle(id int, style string)
UpdateAccountLocale(id int, locale string)
LoginAccount(username string, password string) *Account
// Ban.
AddBan(b *Ban)
BanByID(id int) *Ban
BanByIP(ip string) *Ban
AllBans(rangeOnly bool) []*Ban
UpdateBan(b *Ban)
DeleteExpiredBans() int
DeleteBan(id int)
// File ban.
AddFileBan(fileHash string)
FileBanned(fileHash string) bool
LiftFileBan(fileHash string)
// Board.
AddBoard(b *Board)
BoardByID(id int) *Board
BoardByDir(dir string) *Board
UniqueUserPosts(b *Board) int
AllBoards() []*Board
DeleteBoard(id int)
UpdateBoard(b *Board)
// CAPTCHA.
AddCAPTCHA(c *CAPTCHA)
GetCAPTCHA(ip string) *CAPTCHA
UpdateCAPTCHA(c *CAPTCHA)
ExpiredCAPTCHAs() []*CAPTCHA
DeleteCAPTCHA(ip string)
NewCAPTCHAImage() string
// Keyword.
AddKeyword(k *Keyword)
KeywordByID(id int) *Keyword
KeywordByText(text string) *Keyword
AllKeywords() []*Keyword
UpdateKeyword(k *Keyword)
DeleteKeyword(id int)
// Log.
AddLog(l *Log)
LogCount() int
LogsByPage(page int) []*Log
// News.
AddNews(n *News)
NewsByID(id int) *News
AllNews(onlyPublished bool) []*News
UpdateNews(n *News)
DeleteNews(id int)
// Post.
AddPost(p *Post)
AllThreads(board *Board, moderated bool) [][2]int
TrimThreads(board *Board) []*Post
AllPostsInThread(postID int, moderated bool) []*Post
AllReplies(threadID int, limit int, moderated bool) []*Post
PendingPosts() []*Post
PostByID(postID int) *Post
PostsByIP(hash string) []*Post
PostsByFileHash(hash string, filterBoard *Board) []*Post
PostByField(b *Board, field string, value any) *Post
LastPostByIP(board *Board, ip string) *Post
ReplyCount(threadID int) int
BumpThread(threadID int, timestamp int64)
ModeratePost(postID int, moderated PostModerated)
StickyPost(postID int, sticky bool)
LockPost(postID int, lock bool)
UpdatePostNameblock(postID int, nameblock string)
UpdatePostMessage(postID int, message string)
DeletePost(postID int)
// Report.
AddReport(r *Report)
AllReports() []*Report
NumReports(p *Post) int
DeleteReports(p *Post)
}
Plugin describes the required methods for a plugin.
type Plugin interface {
// About returns the plugin description.
About() string
}
PluginConfig represents a plugin configuration option.
type PluginConfig struct {
Type PluginConfigType
Multiple bool
Name string
Info string
Value string
Default string
}
func (c PluginConfig) HaveInt(i int) bool
HaveInt returns whether an integer value is selected.
func (c PluginConfig) Options() []string
Options returns the options of the provided configuration option as a collection of strings.
func (c PluginConfig) Validate() error
func (c PluginConfig) Values() []string
Values returns the value of the provided configuration option as a collection of strings.
PluginConfigType represents the type of a plugin configuration option.
type PluginConfigType int
Plugin config types.
const (
TypeBoolean PluginConfigType = 0
TypeInteger PluginConfigType = 1
TypeFloat PluginConfigType = 2
TypeEnum PluginConfigType = 3
TypeString PluginConfigType = 4
TypeBoard PluginConfigType = 5
)
PluginWithAttach describes the required methods for a plugin subscribing to attach events.
type PluginWithAttach interface {
Plugin
// Attach events are sent when a file is attached to a post. FileOriginal contains
// the original file name and FileMIME contains the detected MIME type. When a
// file attachment is handled, return true to stop propagating events.
Attach(db DB, post *Post, file []byte) (handled bool, err error)
}
PluginWithAudit describes the required methods for a plugin subscribing to audit events.
type PluginWithAudit interface {
Plugin
// Audit events are sent when a new message is added to the audit log.
// Based on the source of the event, user is "system", "admin" or "mod".
Audit(db DB, user string, action string, info string) error
}
PluginWithConfig describes the required methods for a plugin with configuration options.
type PluginWithConfig interface {
Plugin
// Config returns the available configuration options.
Config() []PluginConfig
}
PluginWithCreate describes the required methods for a plugin subscribing to create events.
type PluginWithCreate interface {
Plugin
// Create events are sent when a new post is created and inserted into the
// database, after Post and Insert events have been processed. The post may
// not be modified during this event. Modify posts during a Post event instead.
Create(db DB, post *Post) error
}
PluginWithHelp describes the required methods for a plugin with help text.
type PluginWithHelp interface {
// Help returns the text displayed above the available configuration options.
Help() template.HTML
}
PluginWithInsert describes the required methods for a plugin subscribing to insert events.
type PluginWithInsert interface {
Plugin
// Insert events are sent after Post events have been processed, before a
// new post is inserted. The post may not be modified during this event.
// Modify new posts during a Post event instead. Return an error to cancel
// the post, or nil to continue processing.
Insert(db DB, post *Post) error
}
PluginWithPost describes the required methods for a plugin subscribing to post events.
type PluginWithPost interface {
Plugin
// Post events are sent when a new post is being created. Message is the
// only HTML-escaped field. Newlines are conveted into line break tags
// after all plugins have finished processing the post.
Post(db DB, post *Post) error
}
PluginWithReport describes the required methods for a plugin subscribing to report events.
type PluginWithReport interface {
Plugin
// Report events are sent when a post is reported.
Report(db DB, post *Post) error
}
PluginWithServe describes the required methods for a plugin with a web interface.
type PluginWithServe interface {
Plugin
// Serve handles plugin web requests. Only administrators and super-administrators
// may access this page. When serving HTML responses, return the HTML and a
// nil error. When serving any other content type, set the Conent-Type header,
// write to the http.ResponseWriter directly and return a blank string.
Serve(db DB, a *Account, w http.ResponseWriter, r *http.Request) (string, error)
}
PluginWithUpdate describes the required methods for a plugin subscribing to configuration updates.
type PluginWithUpdate interface {
Plugin
// Update events are sent when a configuration option is modified. Update events
// are also sent for each configuration option when the server initializes.
Update(db DB, key string) error
}