Documentation ¶
Index ¶
- Constants
- Variables
- func AdminOrPerm(needed int, userID, channelID int64) (bool, error)
- func AdminOrPermMS(ms *dstate.MemberState, channelID int64, needed int) (bool, error)
- func BotProbablyHasPermission(guildID int64, channelID int64, permission int) bool
- func BotProbablyHasPermissionGS(lock bool, gs *dstate.GuildState, channelID int64, permission int) bool
- func BotStarted()
- func ConcurrentEventHandler(inner eventsystem.Handler) eventsystem.Handler
- func ContextSession(ctx context.Context) *discordgo.Session
- func EmitGuildRemoved(guildID int64)
- func GetMember(guildID, userID int64) (*dstate.MemberState, error)
- func GetMembers(guildID int64, userIDs ...int64) ([]*dstate.MemberState, error)
- func GetProcessShards() []int
- func GetTotalShards() int64
- func GuildCountsFunc() []int
- func GuildName(gID int64) (name string)
- func GuildShardID(guildID int64) int
- func HandleChannelCreate(evt *eventsystem.EventData)
- func HandleChannelDelete(evt *eventsystem.EventData)
- func HandleChannelUpdate(evt *eventsystem.EventData)
- func HandleGuildCreate(evt *eventsystem.EventData)
- func HandleGuildDelete(evt *eventsystem.EventData)
- func HandleGuildMemberAdd(evt *eventsystem.EventData)
- func HandleGuildMemberRemove(evt *eventsystem.EventData)
- func HandleGuildMemberUpdate(evt *eventsystem.EventData)
- func HandleGuildMembersChunk(data *eventsystem.EventData)
- func HandleGuildRoleCreate(evt *eventsystem.EventData)
- func HandleGuildRoleRemove(evt *eventsystem.EventData)
- func HandleGuildRoleUpdate(evt *eventsystem.EventData)
- func HandleGuildUpdate(evt *eventsystem.EventData)
- func HandleMessageCreate(evt *eventsystem.EventData)
- func HandleReactionAdd(evt *eventsystem.EventData)
- func HandleReady(data *eventsystem.EventData)
- func HandleResumed(evt *eventsystem.EventData)
- func HasReadOnlyAccess(userID int64) (hasAccess bool, err error)
- func InitPlugins()
- func InvalidateCache(guildID, userID int64)
- func IsBotAdmin(userID int64) (isAdmin bool, err error)
- func IsGuildOnCurrentProcess(guildID int64) bool
- func IsMemberAbove(gs *dstate.GuildState, ms1 *dstate.MemberState, ms2 *dstate.MemberState) bool
- func MemberHighestRole(gs *dstate.GuildState, ms *dstate.MemberState) *discordgo.Role
- func NodeID() string
- func QueueMergedMessage(channelID int64, message string)
- func RefreshStatus(session *discordgo.Session)
- func Run()
- 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.GuildState, channelID int64, msg *discordgo.MessageEmbed) (permsOK bool, resp *discordgo.Message, err error)
- func SendMessageGS(gs *dstate.GuildState, channelID int64, msg string) (permsOK bool, resp *discordgo.Message, err error)
- func SetStatus(streaming, status string)
- func SetupStandalone()
- 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 DiscordMessages
- type LateBotInitHandler
- type MemberFetchGuildQueue
- type MemberFetchRequest
- type MemberFetchResult
- type NewGuildHandler
- type NodeImpl
- 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) LoadGuildState(gs *dstate.GuildState)
- func (n *NodeImpl) SendGuilds(shard int) int
- func (n *NodeImpl) SessionEstablished(info node.SessionInfo)
- func (n *NodeImpl) Shutdown()
- func (n *NodeImpl) StartShard(shard int, sessionID string, sequence int64)
- func (n *NodeImpl) StartShardTransferFrom(shard int) (numEventsSent int)
- func (n *NodeImpl) StopShard(shard int) (sessionID string, sequence int64)
- type RemoveGuildHandler
- type ShardMigrationHandler
- type ShardMigrationReceiver
- type ShardMigrationSender
- type WrappedMessage
Constants ¶
const DBSchema = `` /* 253-byte string literal not displayed */
const EventLoggerPeriodDuration = time.Second * 10
const (
EvtGuildState dshardorchestrator.EventType = 101
)
const ( // How long after removing a guild the config for it gets cleared GuildRemoveConfigExpire = 60 * 60 * 24 // <- 1 day )
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.State ShardManager *dshardmanager.Manager StateHandlerPtr *eventsystem.Handler NodeConn *node.Conn UsingOrchestrator bool MessageDeleteQueue = deletequeue.NewQueue() )
var ( ErrStartingUp = errors.New("Starting up, caches are being filled...") ErrGuildNotFound = errors.New("Guild not found") )
var (
Cache = cache.New(time.Minute, time.Minute)
)
var (
EventLogger = &eventLogger{}
)
var ( MemberFetcher = &memberFetcher{ fetching: make(map[int64]*MemberFetchGuildQueue), notFetching: make(map[int64]*MemberFetchGuildQueue), } )
Functions ¶
func AdminOrPerm ¶
AdminOrPerm returns the permissions for the userID in the specified channel returns an error if the user or channel is not found
func AdminOrPermMS ¶ added in v1.11.5
AdminOrPermMS is the same as AdminOrPerm but with a provided member state
func BotProbablyHasPermission ¶ added in v1.4.12
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 BotProbablyHasPermissionGS ¶ added in v1.4.12
func BotProbablyHasPermissionGS(lock bool, gs *dstate.GuildState, channelID int64, permission int) bool
BotProbablyHasPermissionGS is the same as BotProbablyHasPermission but with a guildstate instead of guildid
func BotStarted ¶ added in v1.4.1
func BotStarted()
func ConcurrentEventHandler ¶
func ConcurrentEventHandler(inner eventsystem.Handler) eventsystem.Handler
func EmitGuildRemoved ¶
func EmitGuildRemoved(guildID int64)
func GetMembers ¶
func GetMembers(guildID int64, userIDs ...int64) ([]*dstate.MemberState, error)
func GetProcessShards ¶ added in v1.11.0
func GetProcessShards() []int
func GetTotalShards ¶ added in v1.11.0
func GetTotalShards() int64
GetTotalShards either retrieves the total shards from passed command line if the bot is set to run in the same process or it starts a background poller to poll redis for it every second
func GuildCountsFunc ¶
func GuildCountsFunc() []int
func GuildName ¶ added in v0.29.1
GuildName is a convenience function for getting the name of a guild
func GuildShardID ¶ added in v1.11.0
GuildShardID returns the shard id for the provided guild id
func HandleChannelCreate ¶
func HandleChannelCreate(evt *eventsystem.EventData)
func HandleChannelDelete ¶
func HandleChannelDelete(evt *eventsystem.EventData)
func HandleChannelUpdate ¶
func HandleChannelUpdate(evt *eventsystem.EventData)
func HandleGuildCreate ¶
func HandleGuildCreate(evt *eventsystem.EventData)
func HandleGuildDelete ¶
func HandleGuildDelete(evt *eventsystem.EventData)
func HandleGuildMemberAdd ¶ added in v1.7.0
func HandleGuildMemberAdd(evt *eventsystem.EventData)
func HandleGuildMemberRemove ¶ added in v1.11.6
func HandleGuildMemberRemove(evt *eventsystem.EventData)
func HandleGuildMemberUpdate ¶
func HandleGuildMemberUpdate(evt *eventsystem.EventData)
func HandleGuildMembersChunk ¶ added in v1.6.0
func HandleGuildMembersChunk(data *eventsystem.EventData)
func HandleGuildRoleCreate ¶
func HandleGuildRoleCreate(evt *eventsystem.EventData)
func HandleGuildRoleRemove ¶
func HandleGuildRoleRemove(evt *eventsystem.EventData)
func HandleGuildRoleUpdate ¶
func HandleGuildRoleUpdate(evt *eventsystem.EventData)
func HandleGuildUpdate ¶
func HandleGuildUpdate(evt *eventsystem.EventData)
func HandleMessageCreate ¶ added in v1.11.1
func HandleMessageCreate(evt *eventsystem.EventData)
func HandleReactionAdd ¶ added in v1.11.1
func HandleReactionAdd(evt *eventsystem.EventData)
func HandleReady ¶
func HandleReady(data *eventsystem.EventData)
func HandleResumed ¶ added in v1.11.6
func HandleResumed(evt *eventsystem.EventData)
func HasReadOnlyAccess ¶ added in v1.6.0
func InitPlugins ¶ added in v1.4.1
func InitPlugins()
func InvalidateCache ¶
func InvalidateCache(guildID, userID int64)
func IsBotAdmin ¶ added in v1.6.0
func IsGuildOnCurrentProcess ¶ added in v1.9.0
IsGuildOnCurrentProcess returns whether the guild is on one of the shards for this process
func IsMemberAbove ¶ added in v1.11.5
func IsMemberAbove(gs *dstate.GuildState, 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 MemberHighestRole ¶ added in v1.11.5
func MemberHighestRole(gs *dstate.GuildState, ms *dstate.MemberState) *discordgo.Role
MemberHighestRole returns the highest role for ms, assumes gs is rlocked, otherwise race conditions will occur
func QueueMergedMessage ¶
func RefreshStatus ¶ added in v1.11.4
func SendDMEmbed ¶ added in v1.4.1
func SendDMEmbed(user int64, embed *discordgo.MessageEmbed) error
func SendMessage ¶ added in v1.4.12
func SendMessageEmbed ¶ added in v1.4.12
func SendMessageEmbedGS ¶ added in v1.4.12
func SendMessageEmbedGS(gs *dstate.GuildState, channelID int64, msg *discordgo.MessageEmbed) (permsOK bool, resp *discordgo.Message, err error)
func SendMessageGS ¶ added in v1.4.12
func SetupStandalone ¶ added in v1.11.0
func SetupStandalone()
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 DiscordMessages ¶
type DiscordMessages []*dstate.MessageState
func (DiscordMessages) Len ¶
func (d DiscordMessages) Len() int
Len is the number of elements in the collection.
func (DiscordMessages) Less ¶
func (d DiscordMessages) Less(i, j int) bool
Less reports whether the element with index i should sort before the element with index j.
func (DiscordMessages) Swap ¶
func (d DiscordMessages) Swap(i, j int)
Swap swaps the elements with indexes i and j.
type LateBotInitHandler ¶ added in v1.11.5
type LateBotInitHandler interface {
LateBotInit()
}
Fired when the bot it starting up, after BotInit
type MemberFetchGuildQueue ¶
type MemberFetchGuildQueue struct {
Queue []*MemberFetchRequest
}
type MemberFetchRequest ¶
type MemberFetchRequest struct { Member int64 Guild int64 WaitingChannels []chan MemberFetchResult }
type MemberFetchResult ¶
type MemberFetchResult struct { Err error Member *dstate.MemberState }
type NewGuildHandler ¶
Used for intializing stuff for new servers
type NodeImpl ¶ added in v1.11.0
type NodeImpl struct {
// contains filtered or unexported fields
}
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) LoadGuildState ¶ added in v1.11.0
func (n *NodeImpl) LoadGuildState(gs *dstate.GuildState)
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) StartShard ¶ added in v1.11.0
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 RemoveGuildHandler ¶
Used for deleting configuration about servers
type ShardMigrationHandler ¶ added in v1.4.1
type ShardMigrationHandler interface {
GuildMigrated(guild *dstate.GuildState, toThisSlave bool)
}
type ShardMigrationReceiver ¶ added in v1.11.5
type ShardMigrationReceiver interface {
ShardMigrationReceive(evt dshardorchestrator.EventType, data interface{})
}
type ShardMigrationSender ¶ added in v1.11.5
type WrappedMessage ¶
func GetMessages ¶
func GetMessages(channelID int64, limit int, deleted bool) ([]*WrappedMessage, error)
GetMessages Gets messages from state if possible, if not then it retrieves from the discord api Puts the messages in the state aswell