state

package
v0.0.0-...-a30b172 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2022 License: MIT Imports: 11 Imported by: 41

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrPresenceStateNotFound    = errors.New("presence not found in state cache")
	ErrRoleStateNotFound        = errors.New("role not found in state cache")
	ErrEmojiStateNotFound       = errors.New("emoji not found in state cache")
	ErrBotForGuildStateNotFound = errors.New("bot for guild not found in state cache")

	ErrTargetWrongServer = errors.New("target is on wrong server")
	ErrTargetWrongType   = errors.New("target is of wrong type")

	ErrUserNotFound    = errors.New("user not found")
	ErrChannelNotFound = errors.New("channel not found")
	ErrRoleNotFound    = errors.New("role not found")
)

defines various errors used

View Source
var (
	// MentionRegex matches Discord User Mentions
	// Source: https://github.com/b1naryth1ef/disco/blob/master/disco/bot/command.py#L15, modified to accept IDs
	MentionRegex = regexp.MustCompile("(<@!?)?([0-9]+)(>)?")

	// RoleRegex matches Discord Role Mentions
	// Source: https://github.com/b1naryth1ef/disco/blob/master/disco/bot/command.py#L16, modified to accept IDs
	RoleRegex = regexp.MustCompile("(<@&)?([0-9]+)(>)?")

	// ChannelRegex matches Discord Channel Mentions
	// Source: https://github.com/b1naryth1ef/disco/blob/master/disco/bot/command.py#L17, modified to accept IDs
	ChannelRegex = regexp.MustCompile("(<#)?([0-9]+)(>)?")
)

Functions

This section is empty.

Types

type State

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

func NewState

func NewState(client *redis.Client, db *gorm.DB) *State

func (*State) AllChannelIDs

func (s *State) AllChannelIDs() (guildIDs []string, err error)

AllChannelIDs returns a list of all Channel IDs from the shared state

func (*State) AllChannelsCount

func (s *State) AllChannelsCount() (int, error)

func (*State) AllGuildIDs

func (s *State) AllGuildIDs() (guildIDs []string, err error)

AllGuildIDs returns a list of all Guild IDs from the shared state

func (*State) AllGuildsCount

func (s *State) AllGuildsCount() (int, error)

func (*State) AllUserIDs

func (s *State) AllUserIDs() (userIDs []string, err error)

AllUserIDs returns a list of all User IDs from the shared state

func (*State) AllUsersCount

func (s *State) AllUsersCount() (int, error)

func (*State) BotForChannel

func (s *State) BotForChannel(
	channelID string,
	permissions ...interfaces.Permission,
) (
	botID string,
	err error,
)

BotForChannel returns a Bot User ID for the given Channel ID matches the Permissions if specified

func (*State) BotForGuild

func (s *State) BotForGuild(
	guildID string,
	permissions ...int64,
) (
	botID string,
	err error,
)

BotForGuild returns a Bot User ID for the given Guild ID matches the Discord Permissions if specified if possible one should use BotForChannel with the specific permissions

func (*State) Channel

func (s *State) Channel(channelID string) (channel *discordgo.Channel, err error)

Channel returns the specified Channel from the shard state, returns ErrStateNotFound if not found

func (*State) ChannelFromMention

func (s *State) ChannelFromMention(guildID, mention string) (*discordgo.Channel, error)

ChannelFromMention finds a text channel on the same server in an mention, can be direct ID input

func (*State) ChannelFromMentionTypes

func (s *State) ChannelFromMentionTypes(
	guildID, mention string, types ...discordgo.ChannelType,
) (*discordgo.Channel, error)

ChannelFromMention finds a channel on the same server in an mention, can be direct ID input

func (*State) ChannelFromMentionTypesEverywhere

func (s *State) ChannelFromMentionTypesEverywhere(
	mention string, types ...discordgo.ChannelType,
) (*discordgo.Channel, error)

ChannelFromMentionTypesEverywhere finds a channel on any server in an mention, can be direct ID input

func (*State) ChannelMessages

func (s *State) ChannelMessages(channelID string) (messages []discordgo.Message, err error)

ChannelMessages returns the messages of a channel

func (*State) Emoji

func (s *State) Emoji(guildID, emojiID string) (emoji *discordgo.Emoji, err error)

Emoji returns the specified Emoji from the shard state, returns ErrStateNotFound if not found

func (*State) Guild

func (s *State) Guild(guildID string) (guild *discordgo.Guild, err error)

Guild returns the specified Guild from the shard state, returns ErrStateNotFound if not found

func (*State) GuildBans

func (s *State) GuildBans(guildID string) (userIDs []string, err error)

GuildBans returns the banned user IDs of a server only contains items if the bot has the Ban Members or Administrator permission

func (*State) GuildInvites

func (s *State) GuildInvites(guildID string) (invites []*discordgo.Invite, err error)

func (*State) GuildInvitesWithRefresh

func (s *State) GuildInvitesWithRefresh(guildID string, session *discordgo.Session) (invites []*discordgo.Invite, err error)

func (*State) GuildMembers

func (s *State) GuildMembers(guildID string) (userIDs []string, err error)

GuildUserIDs returns a list of all User IDs in a specific Guild from the shared state

func (*State) GuildWebhooks

func (s *State) GuildWebhooks(guildID string) (webhooks []*discordgo.Webhook, err error)

func (*State) IsMember

func (s *State) IsMember(guildID, userID string) (isMember bool, err error)

IsMember true if the User is a member of the specified Guild

func (*State) Member

func (s *State) Member(guildID, userID string) (member *discordgo.Member, err error)

Member returns the specified Member from the shard state, returns ErrStateNotFound if not found

func (*State) Presence

func (s *State) Presence(guildID, userID string) (presence *discordgo.Presence, err error)

Presence returns the specified Presence from the shard state, returns ErrStateNotFound if not found

func (*State) Role

func (s *State) Role(guildID, roleID string) (role *discordgo.Role, err error)

Role returns the specified Role from the shard state, returns ErrStateNotFound if not found

func (*State) RoleFromMention

func (s *State) RoleFromMention(guildID string, mention string) (*discordgo.Role, error)

RoleFromMention finds a role in the mention, can be direct ID input

func (*State) SharedStateEventHandler

func (s *State) SharedStateEventHandler(session *discordgo.Session, i interface{}) error

SharedStateEventHandler receives events from a discordgo Websocket and updates the shared state with them

func (*State) User

func (s *State) User(userID string) (user *discordgo.User, err error)

User returns the specified User from the shard state, returns ErrStateNotFound if not found

func (*State) UserChannelPermissions

func (s *State) UserChannelPermissions(userID, channelID string) (apermissions int64, err error)

UserChannelPermissions returns the permission of a user in a channel

func (*State) UserFromMention

func (s *State) UserFromMention(mention string) (*discordgo.User, error)

UserFromMention finds an user in a mention, can be direct ID input

func (*State) UserPermissions

func (s *State) UserPermissions(userID, guildID string) (apermissions int64, err error)

UserPermissions returns the permissions of a user in a guild

func (*State) Webhook

func (s *State) Webhook(id string) (webhook *discordgo.Webhook, err error)

Jump to

Keyboard shortcuts

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