discspy

package module
v0.0.0-...-b19cdf9 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2022 License: AGPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Deleted    = Deletable{true}
	NotDeleted = Deletable{false}
)

Convenient variables for Deletables.

Functions

This section is empty.

Types

type Channel

type Channel struct {
	// ID is the ID of the channel.
	ID discord.ChannelID
	// ParentID is the ID of the parent channel, if any.
	ParentID discord.ChannelID
	// Name is the name of the channel.
	Name string
	// Type is the type of the channel.
	Type discord.ChannelType
	// Position is the position of the role.
	Position int
}

Channel is metadata for a channel.

func ChannelFromDiscord

func ChannelFromDiscord(dc discord.Channel) Channel

ChannelFromDiscord returns a Channel from a discord.Channel.

type Deletable

type Deletable struct {
	Deleted bool
}

Deletable is a structure for an entity that can be deleted.

type FetchedChannel

type FetchedChannel struct {
	Channel
	Deletable
}

FetchedChannel is a Channel fetched from the store.

type FetchedGuild

type FetchedGuild struct {
	Guild
	// Channels is the list of channels in the guild.
	Channels []FetchedChannel
	Deletable
}

FetchedGuild is a Guild fetched from the store.

type FetchedMessage

type FetchedMessage struct {
	Message
	Deletable
}

FetchedMessage is a message that is fetched from the store.

type FetchedMessages

type FetchedMessages struct {
	// Messages is a slice of messages. The messages are sorted latest first.
	Messages []FetchedMessage
	// ExtraRepliedTo is a map of message IDs to the message that they are
	// replying to. It does not contain messages that are already in Messages,
	// so that should be searched first.
	ExtraRepliedTo map[discord.MessageID]FetchedMessage
	// Authors is a map of author IDs to author metadata. The map should contain
	// all known authors of the messages, but some authors may be missing.
	Authors map[discord.UserID]Member
	// Roles is a map of role IDs to role metadata. The map should contain all
	// known roles of the authors, but some roles may be missing.
	Roles map[discord.RoleID]Role
	// HasMore is whether there are more messages that could be fetched.
	HasMore bool
}

FetchedMessages is a slice of messages that are fetched from the store.

func (FetchedMessages) AuthorColor

func (m FetchedMessages) AuthorColor(uID discord.UserID) discord.Color

AuthorColor returns the color of the author of the message. If the author doesn't have a color, then false is returned.

func (FetchedMessages) EarliestID

func (m FetchedMessages) EarliestID() discord.MessageID

EarliestID returns the earliest message ID in the slice. If the slice is empty, then 0 is returned.

func (FetchedMessages) Message

Message looks up both the Messages list and the ExtraRepliedTo map for the message with the given ID.

type Guild

type Guild struct {
	// ID is the ID of the guild.
	ID discord.GuildID
	// OwnerID is the ID of the owner of the guild.
	OwnerID discord.UserID
	// Name is the name of the guild.
	Name string
	// Icon is the icon of the guild.
	Icon string
	Deletable
}

Guild is metadata for a guild.

func GuildFromDiscord

func GuildFromDiscord(dg discord.Guild) Guild

GuildFromDiscord returns a Guild from a discord.Guild.

func (Guild) IconURL

func (g Guild) IconURL() string

IconURL returns the icon URL of the guild. If the guild has no icon, then an empty string is returned.

type GuildStorer

type GuildStorer interface {
	// Guilds returns all guilds.
	Guilds(context.Context) ([]Guild, error)
	// Guild returns a guild by its ID. This method returns more data than
	// Guilds does.
	Guild(context.Context, discord.GuildID) (*FetchedGuild, error)
	// UpdateGuild updates the metadata of a guild. The store must replace all
	// existing channels and roles within each guild with the new ones.
	UpdateGuild(context.Context, GuildUpdateData) error
	// DeleteGuild deletes the given guild.
	DeleteGuild(context.Context, discord.GuildID) error
	// UpdateMember updates the metadata of a guild member. If the members'
	// guilds are not found, then the store is permitted to ignore them. The
	// store should persistently store all members.
	UpdateMember(context.Context, discord.GuildID, Member) error
	// UnknownMembers returns all unknown member IDs within the guild. This is
	// obtained by going over messages and checking if they have a member in the
	// record.
	UnknownMembers(context.Context, discord.GuildID) ([]discord.UserID, error)
}

GuildStorer stores guilds.

type GuildUpdateData

type GuildUpdateData struct {
	Guild
	// Channels is the list of channels in the guild.
	Channels []Channel
	// Role is the list of roles in the guild.
	Roles []Role
}

GuildUpdateData contains more data for updating a Guild's state.

type Member

type Member struct {
	User
	// Nick is the nickname of the member.
	Nick string
	// RoleIDs is a list of role IDs that the member has.
	RoleIDs []discord.RoleID
}

Member is metadata for a member.

func MemberFromDiscord

func MemberFromDiscord(dmember discord.Member) Member

MemberFromDiscord returns a Member from a discord.Member.

type Message

type Message struct {
	// ID is the ID of the message.
	ID discord.MessageID
	// ReplyingTo is the ID of the message that this message is replying to, if
	// any.
	ReplyingTo discord.MessageID
	// AuthorID is the ID of the author of the message.
	AuthorID discord.UserID
	// LastEditedAt is the timestamp of the last update to the message. If 0,
	// then the message has never been edited.
	LastEditedAt discord.Timestamp
	// Content is the content of the message.
	Content MessageContent
}

Message is metadata for a message.

func MessageFromDiscord

func MessageFromDiscord(dmsg discord.Message) Message

MessageFromDiscord returns a Message from a discord.Message.

func (Message) IsEdited

func (m Message) IsEdited() bool

IsEdited returns whether the message has been edited.

type MessageContent

type MessageContent struct {
	Body              string                      `json:"content"`
	Embeds            []discord.Embed             `json:"embeds"`
	Attachments       []discord.Attachment        `json:"attachments"`
	Reactions         []discord.Reaction          `json:"reactions,omitempty"`
	Components        discord.ContainerComponents `json:"components,omitempty"`
	Stickers          []discord.StickerItem       `json:"sticker_items,omitempty"`
	MentionEveryone   bool                        `json:"mention_everyone"`
	MentionUserIDs    []discord.UserID            `json:"mention_user_ids"`
	MentionRoleIDs    []discord.RoleID            `json:"mention_role_ids"`
	MentionChannelIDs []discord.ChannelID         `json:"mention_channel_ids,omitempty"`
}

MessageContent is the content of a message. This specific structure is JSON-encodable; it is recommended to store this as JSON to be faithful to the API.

type MessageStorer

type MessageStorer interface {
	// Messages returns messages in the given channel. Messages must be returned
	// latest first.
	//
	// The store determines how many messages to paginate, and the client must
	// handle that by using the beforeID parameter. If beforeID is 0, then the
	// store must return the latest messages. The returned messages should not
	// fetch beforeID again.
	Messages(ctx context.Context, chID discord.ChannelID, beforeID discord.MessageID) (*FetchedMessages, error)
	// UpdateMessages adds or updates a slice of messages to the store. The
	// messages shall be persisted permanently unless deleted later.
	UpdateMessages(ctx context.Context, chID discord.ChannelID, msgs []MessageUpdateData) error
	// DeleteMessages deletes a slice of messages from the store. The messages
	// don't have to be permanently deleted from the store.
	DeleteMessages(ctx context.Context, chID discord.ChannelID, msgIDs []discord.MessageID) error
}

MessageStorer stores messages.

type MessageUpdateData

type MessageUpdateData struct {
	Message
	Author User
}

MessageUpdateData contains more data for updating a Message's state.

type Role

type Role struct {
	// ID is the ID of the role.
	ID discord.RoleID
	// Name is the name of the role.
	Name string
	// Position is the position of the role.
	Position int
	// Color is the color of the role.
	Color discord.Color
	// Permissions is the permissions of the role.
	Permissions discord.Permissions
}

Role is metadata for a role.

func RoleFromDiscord

func RoleFromDiscord(drole discord.Role) Role

RoleFromDiscord returns a Role from a discord.Role.

type Storer

type Storer interface {
	GuildStorer
	MessageStorer

	// Me returns the current user that the store has been tracking as.
	Me(context.Context) (*User, error)
	// SetMe sets the current user.
	SetMe(context.Context, User) error
}

Storer describes a store for all tracked states.

type User

type User struct {
	// ID is the ID of the user.
	ID discord.UserID
	// Username is the username of the user.
	Username string
	// Discriminator is the discriminator of the member.
	Discriminator string
	// Avatar is the avatar of the member.
	Avatar discord.Hash
	// Bot is whether the member is a bot.
	Bot bool
}

User is a user that is tracked by the store.

func UserFromDiscord

func UserFromDiscord(duser discord.User) User

UserFromDiscord returns a User from a discord.User.

func (User) AvatarURL

func (u User) AvatarURL() string

AvatarURL returns the avatar URL of the user.

func (User) StaticAvatarURL

func (u User) StaticAvatarURL() string

StaticAvatarURL always returns a PNG avatar URL of the user.

Jump to

Keyboard shortcuts

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