bot

package
v1.7.3 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2018 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StateRunningNoMaster   int = iota
	StateRunningWithMaster     // Fully started

	StateWaitingHelloMaster
	StateSoftStarting
	StateShardMigrationTo
	StateShardMigrationFrom
)
View Source
const EventLoggerPeriodDuration = time.Second * 10
View Source
const (
	// How long after removing a guild the config for it gets cleared
	GuildRemoveConfigExpire = 60 * 60 * 24 // <- 1 day
)

Variables

View Source
var (

	// Set of redis admins
	RedisKeyAdmins = "yagpdb_admins"

	// Set of users with read only access
	RedisKeyReadOnlyAccess = "yagpdb_ro_access"
)
View Source
var (
	// When the bot was started
	Started      = time.Now()
	Running      bool
	State        *dstate.State
	ShardManager *dshardmanager.Manager

	StateHandlerPtr *eventsystem.Handler

	SlaveClient *slave.Conn

	MessageDeleteQueue = deletequeue.NewQueue()
)
View Source
var (
	ErrStartingUp    = errors.New("Starting up, caches are being filled...")
	ErrGuildNotFound = errors.New("Guild not found")
)
View Source
var (
	Cache = cache.New(time.Minute, time.Minute)
)
View Source
var (
	EventLogger = &eventLogger{}
)
View Source
var (
	MemberFetcher = &memberFetcher{
		fetching:    make(map[int64]*MemberFetchGuildQueue),
		notFetching: make(map[int64]*MemberFetchGuildQueue),
	}
)

Functions

func AdminOrPerm

func AdminOrPerm(needed int, userID, channelID int64) (bool, error)

func BotProbablyHasPermission added in v1.4.12

func BotProbablyHasPermission(guildID int64, channelID int64, permission int) bool

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 ContextSession

func ContextSession(ctx context.Context) *discordgo.Session

func EmitGuildRemoved

func EmitGuildRemoved(guildID int64)

func GetMember

func GetMember(guildID, userID int64) (*dstate.MemberState, error)

func GetMembers

func GetMembers(guildID int64, userIDs ...int64) ([]*dstate.MemberState, error)

func GuildCountsFunc

func GuildCountsFunc() []int

func GuildName added in v0.29.1

func GuildName(gID int64) (name string)

GuildName is a convenience function for getting the name of a guild

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 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 HandleReady

func HandleReady(data *eventsystem.EventData)

func HasReadOnlyAccess added in v1.6.0

func HasReadOnlyAccess(userID int64) (hasAccess bool, err error)

func InitPlugins added in v1.4.1

func InitPlugins()

func InvalidateCache

func InvalidateCache(guildID, userID int64)

func IsBotAdmin added in v1.6.0

func IsBotAdmin(userID int64) (isAdmin bool, err error)

func MonitorLoading

func MonitorLoading()

func QueueMergedMessage

func QueueMergedMessage(channelID int64, message string)

func Run

func Run()

func SendDM

func SendDM(user int64, msg string) error

func SendDMEmbed added in v1.4.1

func SendDMEmbed(user int64, embed *discordgo.MessageEmbed) error

func SendMessage added in v1.4.12

func SendMessage(guildID int64, channelID int64, msg string) (permsOK bool, resp *discordgo.Message, err error)

func SendMessageEmbed added in v1.4.12

func SendMessageEmbed(guildID int64, channelID int64, msg *discordgo.MessageEmbed) (permsOK bool, resp *discordgo.Message, err error)

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 SendMessageGS(gs *dstate.GuildState, channelID int64, msg string) (permsOK bool, resp *discordgo.Message, err error)

func SetStatus added in v1.4.7

func SetStatus(status string)

func SetStreaming added in v1.4.7

func SetStreaming(streaming, status string)

func SnowflakeToTime added in v1.4.1

func SnowflakeToTime(i int64) time.Time

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 Stop

func Stop(wg *sync.WaitGroup)

func StopAllPlugins added in v1.4.1

func StopAllPlugins(wg *sync.WaitGroup)

Types

type BotInitHandler added in v1.4.1

type BotInitHandler interface {
	BotInit()
}

Fired when the bot it starting up, not for the webserver

type BotStartedHandler

type BotStartedHandler interface {
	BotStarted()
}

Fired after the bot has connected all shards

type BotStopperHandler

type BotStopperHandler interface {
	StopBot(wg *sync.WaitGroup)
}

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 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

type NewGuildHandler interface {
	NewGuild(guild *discordgo.Guild) error
}

Used for intializing stuff for new servers

type RemoveGuildHandler

type RemoveGuildHandler interface {
	RemoveGuild(guildID int64) error
}

Used for deleting configuration about servers

type ShardMigrationHandler added in v1.4.1

type ShardMigrationHandler interface {
	GuildMigrated(guild *dstate.GuildState, toThisSlave bool)
}

type SlaveImpl added in v1.4.1

type SlaveImpl struct {
	// contains filtered or unexported fields
}

Slave implementation

func (*SlaveImpl) FullStart added in v1.4.1

func (s *SlaveImpl) FullStart()

func (*SlaveImpl) LoadGuildState added in v1.4.1

func (s *SlaveImpl) LoadGuildState(gs *master.GuildStateData)

func (*SlaveImpl) SendGuilds added in v1.4.1

func (s *SlaveImpl) SendGuilds(shard int)

func (*SlaveImpl) Shutdown added in v1.4.1

func (s *SlaveImpl) Shutdown()

func (*SlaveImpl) SoftStart added in v1.4.1

func (s *SlaveImpl) SoftStart()

func (*SlaveImpl) StartShard added in v1.4.1

func (s *SlaveImpl) StartShard(shard int, sessionID string, sequence int64)

func (*SlaveImpl) StartShardTransferFrom added in v1.4.1

func (s *SlaveImpl) StartShardTransferFrom() int

func (*SlaveImpl) StartShardTransferTo added in v1.4.1

func (s *SlaveImpl) StartShardTransferTo(numShards int)

func (*SlaveImpl) StopShard added in v1.4.1

func (s *SlaveImpl) StopShard(shard int) (sessionID string, sequence int64)

type WrappedMessage

type WrappedMessage struct {
	*discordgo.Message
	Deleted bool
}

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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