bot

package
v2.33.1 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2024 License: MIT Imports: 36 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EvtGuildState dshardorchestrator.EventType = 102
	EvtMember     dshardorchestrator.EventType = 103
)
View Source
const DBSchema = `` /* 253-byte string literal not displayed */
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
)
View Source
const MemFreeThreshold = 90

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()
	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
)
View Source
var (
	ErrStartingUp      = errors.New("Starting up, caches are being filled...")
	ErrGuildNotFound   = errors.New("Guild not found")
	ErrChannelNotFound = errors.New("Channel not found")
)
View Source
var (
	BatchMemberJobManager = newBatchMemberJobManager()
)
View Source
var BotPlugin = new(botPlugin)

bot plugin

View Source
var (
	Cache = cache.New(time.Minute, time.Minute)
)
View Source
var (
	ErrGuildNotOnProcess = errors.New("guild not on process")
)
View Source
var ErrTimeoutWaitingForMember = errors.New("timeout waiting for members")
View Source
var (
	EventLogger = &eventLogger{}
)
View Source
var MessageDeleteQueue = &messageDeleteQueue{
	channels: make(map[int64]*messageDeleteQueueChannel),
}
View Source
var ReadyTracker = &readyTracker{}

ReadyTracker tracks process shards and initial readies/resumes, aswell as sending out events

View Source
var StateLimitsF func(guildID int64) (int, time.Duration) = func(guildID int64) (int, time.Duration) {
	return 1000, time.Hour
}

Functions

func AdminOrPerm

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

AdminOrPerm is the same as AdminOrPermMS but only required a member ID

func AdminOrPermMS

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

func BotHasPermission(guildID int64, channelID int64, permission int64) (bool, error)

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

func BotHasPermissionGS(gs *dstate.GuildSet, channelID int64, permission int64) (bool, error)

BotProbablyHasPermissionGS is the same as BotProbablyHasPermission but with a guildstate instead of guildid

func BotPermissions

func BotPermissions(gs *dstate.GuildSet, channelID int64) (int64, error)

func CheckDiscordErrRetry

func CheckDiscordErrRetry(err error) bool

func ContextSession

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

func GenNonce

func GenNonce() int

func GetMainServer added in v2.3.4

func GetMainServer() int64

func GetMember

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

GetMember will either return a member from state or fetch one from the member fetcher and then put it in state

func GetMembers

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

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 GetUsers

func GetUsers(guildID int64, ids ...int64) []*discordgo.User

func GuildCountsFunc

func GuildCountsFunc() []int

func GuildShardID

func GuildShardID(totalShards, guildID int64) int

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

func HandleGuildMemberAdd(evt *eventsystem.EventData) (retry bool, err error)

func HandleGuildMemberRemove

func HandleGuildMemberRemove(evt *eventsystem.EventData) (retry bool, err error)

func HandleGuildMembersChunk

func HandleGuildMembersChunk(data *eventsystem.EventData)

func HandleGuildUpdate

func HandleGuildUpdate(evt *eventsystem.EventData) (retry bool, err error)

func HandleInteractionCreate added in v2.5.0

func HandleInteractionCreate(evt *eventsystem.EventData)

func HandleMessageCreate

func HandleMessageCreate(evt *eventsystem.EventData)

func HandleMessageCreateUpdateFirst

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

func HandleRatelimit(evt *eventsystem.EventData)

func HandleReactionAdd

func HandleReactionAdd(evt *eventsystem.EventData)

func HandleReady

func HandleReady(data *eventsystem.EventData)

func HasReadOnlyAccess

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

func InvalidateCache

func InvalidateCache(guildID, userID int64)

func IsBotAdmin

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

func IsMemberAbove

func IsMemberAbove(gs *dstate.GuildSet, ms1 *dstate.MemberState, ms2 *dstate.MemberState) bool

IsMemberAbove returns whether 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

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

func IsNormalUserMessage(msg *discordgo.Message) bool

func LimitedConcurrentEventHandler

func LimitedConcurrentEventHandler(inner eventsystem.HandlerFuncLegacy, limit int64, sleepDur time.Duration) eventsystem.HandlerFuncLegacy

func MemberHighestRole

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

func NodeID() string

NodeID returns this node's ID if using the orchestrator system

func ParseActivityType added in v2.33.1

func ParseActivityType(activityType string) (discordgo.ActivityType, error)

ParseActivityType parses the activity type from a string

func QueueMergedMessage

func QueueMergedMessage(channelID int64, message string, allowedMentions discordgo.AllowedMentions)

func RefreshStatus

func RefreshStatus(session *discordgo.Session)

RefreshStatus updates the provided sessions status according to the current status set

func Run

func Run(nodeID string)

Run intializes and starts the discord bot component of yagpdb

func SendDM

func SendDM(user int64, msg string) error

func SendDMEmbed

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

func SendDMEmbedList added in v2.3.0

func SendDMEmbedList(user int64, embeds []*discordgo.MessageEmbed) error

func SendMessage

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

func SendMessageEmbed

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

func SendMessageEmbedList added in v2.3.0

func SendMessageEmbedList(guildID int64, channelID int64, embeds []*discordgo.MessageEmbed) (permsOK bool, resp *discordgo.Message, err error)

func SendMessageGS

func SendMessageGS(gs *dstate.GuildSet, channelID int64, msg string) (permsOK bool, resp *discordgo.Message, err error)

func SetStatus

func SetStatus(activityType, statusType, statusText, streamingUrl string)

func SnowflakeToTime

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

func StopAllPlugins(wg *sync.WaitGroup)

Types

type BotInitHandler

type BotInitHandler interface {
	BotInit()
}

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

type BotStopperHandler

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

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

type GSCacheKey string

type LateBotInitHandler

type LateBotInitHandler interface {
	LateBotInit()
}

Fired when the bot it starting up, after BotInit

type MemWatcher

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

func (*MemWatcher) Check

func (mw *MemWatcher) Check()

func (*MemWatcher) Run

func (mw *MemWatcher) Run()

type NewGuildHandler

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

Used for intializing stuff for new servers

type NodeImpl

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

func (*NodeImpl) AddNewShards

func (n *NodeImpl) AddNewShards(shards ...int)

func (*NodeImpl) HandleUserEvent

func (n *NodeImpl) HandleUserEvent(evt dshardorchestrator.EventType, data interface{})

func (*NodeImpl) InitializeShardTransferFrom

func (n *NodeImpl) InitializeShardTransferFrom(shard int) (sessionID string, sequence int64, resumeGatewayUrl string)

func (*NodeImpl) InitializeShardTransferTo

func (n *NodeImpl) InitializeShardTransferTo(shard int, sessionID string, sequence int64, resumeGatewayUrl string)

func (*NodeImpl) ResumeShard

func (n *NodeImpl) ResumeShard(shard int, sessionID string, sequence int64, resumeGatewayUrl string)

func (*NodeImpl) SendGuilds

func (n *NodeImpl) SendGuilds(shard int) int

func (*NodeImpl) SessionEstablished

func (n *NodeImpl) SessionEstablished(info node.SessionInfo)

func (*NodeImpl) Shutdown

func (n *NodeImpl) Shutdown()

called when the bot should shut down, make sure to send EvtShutdown when completed

func (*NodeImpl) StartShardTransferFrom

func (n *NodeImpl) StartShardTransferFrom(shard int) (numEventsSent int)

this should return when all user events has been sent, with the number of user events sent

func (*NodeImpl) StopShard

func (n *NodeImpl) StopShard(shard int) (sessionID string, sequence int64, resumeGatewayUrl string)

type QueuedMergedMessage

type QueuedMergedMessage struct {
	Content         string
	AllowedMentions discordgo.AllowedMentions
}

type RemoveGuildHandler

type RemoveGuildHandler interface {
	RemoveGuild(guildID int64) error
}

Used for deleting configuration about servers

type ShardMigrationHandler

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

type ShardMigrationReceiver

type ShardMigrationReceiver interface {
	ShardMigrationReceive(evt dshardorchestrator.EventType, data interface{})
}

type ShardMigrationSender

type ShardMigrationSender interface {
	ShardMigrationSend(shard int) int
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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