Documentation ¶
Index ¶
- Constants
- Variables
- func AdminOrPerm(guildID int64, channelID int64, userID int64, needed int64) (bool, error)
- func AdminOrPermMS(guildID int64, channelID int64, ms *dstate.MemberState, needed int64) (bool, error)
- func BotHasPermission(guildID int64, channelID int64, permission int64) (bool, error)
- func BotHasPermissionGS(gs *dstate.GuildSet, channelID int64, permission int64) (bool, error)
- func BotPermissions(gs *dstate.GuildSet, channelID int64) (int64, error)
- func CheckDiscordErrRetry(err error) bool
- func ConcurrentEventHandler(inner eventsystem.HandlerFuncLegacy) eventsystem.HandlerFuncLegacy
- func ContextSession(ctx context.Context) *discordgo.Session
- func GenNonce() int
- func GetMember(guildID, userID int64) (*dstate.MemberState, error)
- func GetMembers(guildID int64, userIDs ...int64) ([]*dstate.MemberState, error)
- func GetMessages(guildID int64, channelID int64, limit int, deleted bool) ([]*dstate.MessageState, error)
- func GetUsers(guildID int64, ids ...int64) []*discordgo.User
- func GuildCountsFunc() []int
- func GuildShardID(totalShards, guildID int64) int
- func HandleGuildCreate(evt *eventsystem.EventData) (retry bool, err error)
- func HandleGuildDelete(evt *eventsystem.EventData) (retry bool, err error)
- func HandleGuildMemberAdd(evt *eventsystem.EventData) (retry bool, err error)
- func HandleGuildMemberRemove(evt *eventsystem.EventData) (retry bool, err error)
- func HandleGuildMembersChunk(data *eventsystem.EventData)
- func HandleGuildUpdate(evt *eventsystem.EventData) (retry bool, err error)
- func HandleMessageCreate(evt *eventsystem.EventData)
- func HandleMessageCreateUpdateFirst(evt *eventsystem.EventData)
- func HandleRatelimit(evt *eventsystem.EventData)
- func HandleReactionAdd(evt *eventsystem.EventData)
- func HandleReady(data *eventsystem.EventData)
- func HasReadOnlyAccess(userID int64) (hasAccess bool, err error)
- func InvalidateCache(guildID, userID int64)
- func IsBotAdmin(userID int64) (isAdmin bool, err error)
- func IsMemberAbove(gs *dstate.GuildSet, ms1 *dstate.MemberState, ms2 *dstate.MemberState) bool
- func IsMemberAboveRole(gs *dstate.GuildSet, ms1 *dstate.MemberState, role *discordgo.Role) bool
- func IsNormalUserMessage(msg *discordgo.Message) bool
- func LimitedConcurrentEventHandler(inner eventsystem.HandlerFuncLegacy, limit int64, sleepDur time.Duration) eventsystem.HandlerFuncLegacy
- func MemberHighestRole(gs *dstate.GuildSet, ms *dstate.MemberState) *discordgo.Role
- func NodeID() string
- func QueueMergedMessage(channelID int64, message string, allowedMentions discordgo.AllowedMentions)
- func RefreshStatus(session *discordgo.Session)
- func Run(nodeID string)
- func SendDM(user int64, msg string) error
- func SendDMEmbed(user int64, embed *discordgo.MessageEmbed) error
- func SendMessage(guildID int64, channelID int64, msg string) (permsOK bool, resp *discordgo.Message, err error)
- func SendMessageEmbed(guildID int64, channelID int64, msg *discordgo.MessageEmbed) (permsOK bool, resp *discordgo.Message, err error)
- func SendMessageEmbedGS(gs *dstate.GuildSet, channelID int64, msg *discordgo.MessageEmbed) (permsOK bool, resp *discordgo.Message, err error)
- func SendMessageGS(gs *dstate.GuildSet, channelID int64, msg string) (permsOK bool, resp *discordgo.Message, err error)
- func SetStatus(streaming, status string)
- func SnowflakeToTime(i int64) time.Time
- func StateHandler(evt *eventsystem.EventData)
- func Stop(wg *sync.WaitGroup)
- func StopAllPlugins(wg *sync.WaitGroup)
- type BotInitHandler
- type BotStopperHandler
- type GSCacheKey
- type LateBotInitHandler
- type MemWatcher
- type NewGuildHandler
- type NodeImpl
- func (n *NodeImpl) AddNewShards(shards ...int)
- func (n *NodeImpl) HandleUserEvent(evt dshardorchestrator.EventType, data interface{})
- func (n *NodeImpl) InitializeShardTransferFrom(shard int) (sessionID string, sequence int64)
- func (n *NodeImpl) InitializeShardTransferTo(shard int, sessionID string, sequence int64)
- func (n *NodeImpl) ResumeShard(shard int, sessionID string, sequence int64)
- func (n *NodeImpl) SendGuilds(shard int) int
- func (n *NodeImpl) SessionEstablished(info node.SessionInfo)
- func (n *NodeImpl) Shutdown()
- func (n *NodeImpl) StartShardTransferFrom(shard int) (numEventsSent int)
- func (n *NodeImpl) StopShard(shard int) (sessionID string, sequence int64)
- type QueuedMergedMessage
- type RemoveGuildHandler
- type ShardMigrationHandler
- type ShardMigrationReceiver
- type ShardMigrationSender
Constants ¶
const ( EvtGuildState dshardorchestrator.EventType = 102 EvtMember dshardorchestrator.EventType = 103 )
const DBSchema = `` /* 253-byte string literal not displayed */
const EventLoggerPeriodDuration = time.Second * 10
const ( // How long after removing a guild the config for it gets cleared GuildRemoveConfigExpire = 60 * 60 * 24 // <- 1 day )
const MemFreeThreshold = 90
Variables ¶
var ( // Set of redis admins RedisKeyAdmins = "yagpdb_admins" // Set of users with read only access RedisKeyReadOnlyAccess = "yagpdb_ro_access" )
var ( // When the bot was started Started = time.Now() Enabled bool // wether the bot is set to run at some point in this process Running bool // wether the bot is currently running State dstate.StateTracker ShardManager *dshardmanager.Manager NodeConn *node.Conn UsingOrchestrator bool )
var ( ErrStartingUp = errors.New("Starting up, caches are being filled...") ErrGuildNotFound = errors.New("Guild not found") ErrChannelNotFound = errors.New("Channel not found") )
var (
BatchMemberJobManager = newBatchMemberJobManager()
)
var BotPlugin = new(botPlugin)
bot plugin
var (
Cache = cache.New(time.Minute, time.Minute)
)
var (
ErrGuildNotOnProcess = errors.New("guild not on process")
)
var ErrTimeoutWaitingForMember = errors.New("timeout waiting for members")
var (
EventLogger = &eventLogger{}
)
var MessageDeleteQueue = &messageDeleteQueue{ channels: make(map[int64]*messageDeleteQueueChannel), }
var ReadyTracker = &readyTracker{}
ReadyTracker tracks process shards and initial readies/resumes, aswell as sending out events
Functions ¶
func AdminOrPerm ¶
AdminOrPerm is the same as AdminOrPermMS but only required a member ID
func AdminOrPermMS ¶ added in v1.11.5
func AdminOrPermMS(guildID int64, channelID int64, ms *dstate.MemberState, needed int64) (bool, error)
AdminOrPermMS checks if the provided member has all of the needed permissions or is a admin
func BotHasPermission ¶ added in v1.31.10
BotProbablyHasPermission returns true if its possible that the bot has the following permission, it also returns true if the bot member could not be found or if the guild is not in state (hence, probably)
func BotHasPermissionGS ¶ added in v1.31.10
BotProbablyHasPermissionGS is the same as BotProbablyHasPermission but with a guildstate instead of guildid
func BotPermissions ¶ added in v1.31.10
func CheckDiscordErrRetry ¶ added in v1.20.0
func ConcurrentEventHandler ¶
func ConcurrentEventHandler(inner eventsystem.HandlerFuncLegacy) eventsystem.HandlerFuncLegacy
func ContextSession ¶
func GetMember ¶
GetMember will either return a member from state or fetch one from the member fetcher and then put it in state
func GetMembers ¶
GetMembers is the same as GetMember but with multiple members
func GetMessages ¶
func GetMessages(guildID int64, channelID int64, limit int, deleted bool) ([]*dstate.MessageState, error)
GetMessages Gets messages from state if possible, if not then it retrieves from the discord api
func GuildCountsFunc ¶
func GuildCountsFunc() []int
func GuildShardID ¶ added in v1.11.0
GuildShardID returns the shard id for the provided guild id
func HandleGuildCreate ¶
func HandleGuildCreate(evt *eventsystem.EventData) (retry bool, err error)
func HandleGuildDelete ¶
func HandleGuildDelete(evt *eventsystem.EventData) (retry bool, err error)
func HandleGuildMemberAdd ¶ added in v1.7.0
func HandleGuildMemberAdd(evt *eventsystem.EventData) (retry bool, err error)
func HandleGuildMemberRemove ¶ added in v1.11.6
func HandleGuildMemberRemove(evt *eventsystem.EventData) (retry bool, err error)
func HandleGuildMembersChunk ¶ added in v1.6.0
func HandleGuildMembersChunk(data *eventsystem.EventData)
func HandleGuildUpdate ¶
func HandleGuildUpdate(evt *eventsystem.EventData) (retry bool, err error)
func HandleMessageCreate ¶ added in v1.11.1
func HandleMessageCreate(evt *eventsystem.EventData)
func HandleMessageCreateUpdateFirst ¶ added in v1.31.10
func HandleMessageCreateUpdateFirst(evt *eventsystem.EventData)
HandleMessageCreateUpdateFirst transforms the message events a little to make them easier to deal with Message.Member.User is null from the api, so we assign it to Message.Author
func HandleRatelimit ¶ added in v1.19.19
func HandleRatelimit(evt *eventsystem.EventData)
func HandleReactionAdd ¶ added in v1.11.1
func HandleReactionAdd(evt *eventsystem.EventData)
func HandleReady ¶
func HandleReady(data *eventsystem.EventData)
func HasReadOnlyAccess ¶ added in v1.6.0
func InvalidateCache ¶
func InvalidateCache(guildID, userID int64)
func IsBotAdmin ¶ added in v1.6.0
func IsMemberAbove ¶ added in v1.11.5
func IsMemberAbove(gs *dstate.GuildSet, ms1 *dstate.MemberState, ms2 *dstate.MemberState) bool
IsMemberAbove returns wether ms1 is above ms2 in terms of roles (e.g the highest role of ms1 is higher than the highest role of ms2) assumes gs is locked, otherwise race conditions will occur
func IsMemberAboveRole ¶ added in v1.16.0
func IsMemberAboveRole(gs *dstate.GuildSet, ms1 *dstate.MemberState, role *discordgo.Role) bool
IsMemberAboveRole returns wether ms is above role assumes gs is locked, otherwise race conditions will occur
func IsNormalUserMessage ¶ added in v1.31.10
func IsNormalUserMessage(msg *discordgo.Message) bool
func LimitedConcurrentEventHandler ¶ added in v1.31.10
func LimitedConcurrentEventHandler(inner eventsystem.HandlerFuncLegacy, limit int64, sleepDur time.Duration) eventsystem.HandlerFuncLegacy
func MemberHighestRole ¶ added in v1.11.5
func MemberHighestRole(gs *dstate.GuildSet, ms *dstate.MemberState) *discordgo.Role
MemberHighestRole returns the highest role for ms, assumes gs is rlocked, otherwise race conditions will occur
func NodeID ¶ added in v1.11.2
func NodeID() string
NodeID returns this node's ID if using the orchestrator system
func QueueMergedMessage ¶
func RefreshStatus ¶ added in v1.11.4
func RefreshStatus(session *discordgo.Session)
RefreshStatus updates the provided sessions status according to the current status set
func SendDMEmbed ¶ added in v1.4.1
func SendMessage ¶ added in v1.4.12
func SendMessageEmbed ¶ added in v1.4.12
func SendMessageEmbedGS ¶ added in v1.4.12
func SendMessageGS ¶ added in v1.4.12
func SnowflakeToTime ¶ added in v1.4.1
func StateHandler ¶
func StateHandler(evt *eventsystem.EventData)
StateHandler updates the world state use AddHandlerBefore to add handler before this one, otherwise they will alwyas be after
func StopAllPlugins ¶ added in v1.4.1
Types ¶
type BotInitHandler ¶ added in v1.4.1
type BotInitHandler interface {
BotInit()
}
Fired when the bot it starting up, not for the webserver
type BotStopperHandler ¶
BotStopperHandler runs when the bot is shuttdown down you need to call wg.Done when you have completed your plugin shutdown (stopped background workers)
type GSCacheKey ¶ added in v1.18.3
type GSCacheKey string
type LateBotInitHandler ¶ added in v1.11.5
type LateBotInitHandler interface {
LateBotInit()
}
Fired when the bot it starting up, after BotInit
type MemWatcher ¶ added in v1.16.0
type MemWatcher struct {
// contains filtered or unexported fields
}
func (*MemWatcher) Check ¶ added in v1.16.0
func (mw *MemWatcher) Check()
func (*MemWatcher) Run ¶ added in v1.16.0
func (mw *MemWatcher) Run()
type NewGuildHandler ¶
type NewGuildHandler interface {
NewGuild(guild *discordgo.Guild) error
}
Used for intializing stuff for new servers
type NodeImpl ¶ added in v1.11.0
type NodeImpl struct {
// contains filtered or unexported fields
}
func (*NodeImpl) AddNewShards ¶ added in v1.31.10
func (*NodeImpl) HandleUserEvent ¶ added in v1.11.0
func (n *NodeImpl) HandleUserEvent(evt dshardorchestrator.EventType, data interface{})
func (*NodeImpl) InitializeShardTransferFrom ¶ added in v1.11.0
func (*NodeImpl) InitializeShardTransferTo ¶ added in v1.11.0
func (*NodeImpl) ResumeShard ¶ added in v1.31.10
func (*NodeImpl) SendGuilds ¶ added in v1.11.0
func (*NodeImpl) SessionEstablished ¶ added in v1.11.0
func (n *NodeImpl) SessionEstablished(info node.SessionInfo)
func (*NodeImpl) Shutdown ¶ added in v1.11.0
func (n *NodeImpl) Shutdown()
called when the bot should shut down, make sure to send EvtShutdown when completed
func (*NodeImpl) StartShardTransferFrom ¶ added in v1.11.0
this should return when all user events has been sent, with the number of user events sent
type QueuedMergedMessage ¶ added in v1.31.10
type QueuedMergedMessage struct { Content string AllowedMentions discordgo.AllowedMentions }
type RemoveGuildHandler ¶
Used for deleting configuration about servers
type ShardMigrationHandler ¶ added in v1.4.1
type ShardMigrationHandler interface {
GuildMigrated(guild *dstate.GuildSet, toThisSlave bool)
}
type ShardMigrationReceiver ¶ added in v1.11.5
type ShardMigrationReceiver interface {
ShardMigrationReceive(evt dshardorchestrator.EventType, data interface{})
}