logs

package
v1.19.9 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2019 License: MIT Imports: 26 Imported by: 0

README

Logs

The logs plugin logs certain information from servers.

  • Can store a subset of the message history with deleted messages
  • Username changes

Documentation

Index

Constants

View Source
const CacheKeyConfig bot.GSCacheKey = "logs_config"

Variables

View Source
var AuthorColors = []string{
	"7c7cff",
	"529fb7",
	"4aa085",
	"7ea04a",
	"a0824a",
	"a04a4a",
	"a04a89",
}
View Source
var DBSchemas = []string{
	`CREATE TABLE IF NOT EXISTS message_logs (
	id SERIAL PRIMARY KEY,
	created_at TIMESTAMP WITH TIME ZONE,
	updated_at TIMESTAMP WITH TIME ZONE,
	deleted_at TIMESTAMP WITH TIME ZONE,

	channel_name TEXT,
	channel_id TEXT,
	guild_id TEXT,
	author TEXT,
	author_id TEXT
);`,

	`CREATE INDEX IF NOT EXISTS idx_message_logs_deleted_at ON message_logs(deleted_at);`,

	`CREATE TABLE IF NOT EXISTS messages (
	id SERIAL PRIMARY KEY,

	created_at TIMESTAMP WITH TIME ZONE,
	updated_at TIMESTAMP WITH TIME ZONE,
	-- deleted_at TIMESTAMP WITH TIME ZONE, Note: this column exists in setups from below 1.15, but during the upgrade to sqlboiler i deemed it useless and don't include it in the schema anymore

	message_log_id INT REFERENCES message_logs(id) ON DELETE CASCADE,
	message_id TEXT,

	author_username TEXT,
	author_discrim TEXT,
	author_id TEXT,
	deleted BOOLEAN,

	content TEXT,
	timestamp TEXT
);`,

	`CREATE INDEX IF NOT EXISTS idx_messages_message_id ON messages(message_id);`,
	`CREATE INDEX IF NOT EXISTS idx_messages_message_log_id ON messages(message_log_id);`,

	`CREATE TABLE IF NOT EXISTS guild_logging_configs (
	guild_id BIGINT PRIMARY KEY,

	created_at TIMESTAMP WITH TIME ZONE,
	updated_at TIMESTAMP WITH TIME ZONE,

	username_logging_enabled BOOLEAN,
	nickname_logging_enabled BOOLEAN,

	blacklisted_channels TEXT,
	manage_messages_can_view_deleted BOOLEAN,
	everyone_can_view_deleted BOOLEAN
);`,

	`ALTER TABLE guild_logging_configs ADD COLUMN IF NOT EXISTS message_logs_allowed_roles BIGINT[];`,

	`CREATE TABLE IF NOT EXISTS username_listings (
	id SERIAL PRIMARY KEY,

	created_at TIMESTAMP WITH TIME ZONE,
	updated_at TIMESTAMP WITH TIME ZONE,
	deleted_at TIMESTAMP WITH TIME ZONE,

	user_id BIGINT,
	username TEXT
);`,

	`CREATE INDEX IF NOT EXISTS idx_username_listings_user_id ON username_listings(user_id);`,

	`CREATE TABLE IF NOT EXISTS nickname_listings (
	id SERIAL PRIMARY KEY,

	created_at TIMESTAMP WITH TIME ZONE,
	updated_at TIMESTAMP WITH TIME ZONE,
	deleted_at TIMESTAMP WITH TIME ZONE,

	user_id BIGINT,
	guild_id TEXT,
	nickname TEXT
);`,

	`CREATE INDEX IF NOT EXISTS idx_nickname_listings_deleted_at ON nickname_listings(deleted_at);`,

	`DROP INDEX IF EXISTS idx_nickname_listings_user_id;`,
	`DROP INDEX IF EXISTS nickname_listings_user_id_guild_idx;`,

	`CREATE INDEX IF NOT EXISTS nickname_listings_user_id_guild_id_id_idx ON nickname_listings(user_id, guild_id, id);`,
}
View Source
var (
	ErrChannelBlacklisted = errors.New("Channel blacklisted from creating message logs")
)

Functions

func CheckNickname

func CheckNickname(exec boil.ContextExecutor, ctx context.Context, nicknameStmt *sql.Stmt, userID, guildID int64, nickname string) error

func CheckUsername

func CheckUsername(exec boil.ContextExecutor, ctx context.Context, usernameStmt *sql.Stmt, user *discordgo.User) error

func CreateChannelLog

func CreateChannelLog(ctx context.Context, config *models.GuildLoggingConfig, guildID, channelID int64, author string, authorID int64, count int) (*models.MessageLog, error)
func CreateLink(guildID int64, id int) string

func EvtProcesser

func EvtProcesser()

Queue up all the events and process them one by one, because of limited connections

func EvtProcesserGCs

func EvtProcesserGCs()

func GetChannelLogs

func GetChannelLogs(ctx context.Context, id, guildID int64) (*models.MessageLog, error)

func GetConfig

func GetConfig(exec boil.ContextExecutor, ctx context.Context, guildID int64) (*models.GuildLoggingConfig, error)

Returns either stored config, err or a default config

func GetConfigCached added in v1.18.3

func GetConfigCached(exec boil.ContextExecutor, gID int64) (*models.GuildLoggingConfig, error)

func GetGuilLogs

func GetGuilLogs(ctx context.Context, guildID int64, before, after, limit int) ([]*models.MessageLog, error)

func GetNicknames

func GetNicknames(ctx context.Context, userID, guildID int64, limit int) ([]*models.NicknameListing, error)

func GetUsernames

func GetUsernames(ctx context.Context, userID int64, limit int) ([]*models.UsernameListing, error)

func HandleDeleteMessageJson

func HandleDeleteMessageJson(w http.ResponseWriter, r *http.Request) interface{}

func HandleGC

func HandleGC(evt *eventsystem.EventData)

func HandleLogsCP

func HandleLogsCP(w http.ResponseWriter, r *http.Request) (web.TemplateData, error)

func HandleLogsCPDelete

func HandleLogsCPDelete(w http.ResponseWriter, r *http.Request) (web.TemplateData, error)

func HandleLogsCPSaveGeneral

func HandleLogsCPSaveGeneral(w http.ResponseWriter, r *http.Request) (web.TemplateData, error)

func HandleLogsHTML

func HandleLogsHTML(w http.ResponseWriter, r *http.Request) interface{}

func HandleMsgDelete

func HandleMsgDelete(evt *eventsystem.EventData)

Mark all log messages with this id as deleted

func HandlePresenceUpdate

func HandlePresenceUpdate(evt *eventsystem.EventData)

func HandleQueueEvt

func HandleQueueEvt(evt *eventsystem.EventData)

While presence update is sent when user changes username.... MAKES NO SENSE IMO BUT WHATEVER Also check nickname incase the user came online

func ProcessBatch added in v1.19.6

func ProcessBatch(users []*UserGuildPair, members []*discordgo.Member) error

func RegisterPlugin added in v1.4.1

func RegisterPlugin()

Types

type ConfigFormData added in v1.15.1

type ConfigFormData struct {
	UsernameLoggingEnabled       bool
	NicknameLoggingEnabled       bool
	ManageMessagesCanViewDeleted bool
	EveryoneCanViewDeleted       bool
	BlacklistedChannels          []string
	MessageLogsAllowedRoles      []int64
}

type DeleteData

type DeleteData struct {
	ID int64
}

type LightGC added in v1.4.1

type LightGC struct {
	GuildID int64
	Members []*discordgo.Member
}

type Plugin

type Plugin struct{}

func (*Plugin) AddCommands added in v1.4.1

func (p *Plugin) AddCommands()

func (*Plugin) BotInit added in v1.4.1

func (p *Plugin) BotInit()

func (*Plugin) InitWeb

func (lp *Plugin) InitWeb()

func (*Plugin) LoadServerHomeWidget added in v1.17.0

func (p *Plugin) LoadServerHomeWidget(w http.ResponseWriter, r *http.Request) (web.TemplateData, error)

func (*Plugin) PluginInfo added in v1.17.0

func (p *Plugin) PluginInfo() *common.PluginInfo

type UserGuildPair added in v1.19.6

type UserGuildPair struct {
	GuildID int64
	User    *discordgo.User
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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