Documentation ¶
Overview ¶
Package darchive contains type definitions for the darchive format as well as an encoder and decoder for the format. darchive is a gzip or zstd-compressed tar file containing JSON data.
Many of the Discord-related structs, types, and methods are taken from Arikawa's `discord` package, specifically v3.0.0-rc.2: https://pkg.go.dev/github.com/diamondburned/arikawa/v3@v3.0.0-rc.2/discord.
Index ¶
- Constants
- func DurationSinceEpoch(t time.Time) time.Duration
- type Archive
- type Attachment
- type Channel
- type ChannelType
- type CompressionType
- type Embed
- type EmbedAuthor
- type EmbedField
- type EmbedFooter
- type EmbedImage
- type EmbedProvider
- type EmbedThumbnail
- type EmbedType
- type EmbedVideo
- type Emoji
- type Encoder
- type Guild
- type ImageType
- type InvalidMessageError
- type Message
- type MessageReference
- type MessageType
- type Meta
- type Reaction
- type Role
- type Snowflake
- type User
Constants ¶
const CurrentArchiveVersion = 4
CurrentArchiveVersion is the current archive version. Other packages in this repository will output this version.
const Epoch = 1420070400000 * time.Millisecond
Epoch is the Discord epoch constant in time.Duration (nanoseconds) since Unix epoch.
const NullSnowflake = ^Snowflake(0)
NullSnowflake gets encoded into a null. This is used for optional and nullable snowflake fields.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Archive ¶
type Archive struct { Meta Meta Guild Guild Users map[uint64]User Messages map[Snowflake][]Message }
Archive is a complete archive file.
func Decode ¶
Decode decodes r into a darchive struct. If compressed is true, r is treated as a gzip-compressed tarball. If false, r is treated as an uncompressed tarball.
Decode returns (d, nil) on an io.EOF error, (d, err) on any other error.
- Files unknown to the darchive format are silently ignored. - Channels not listed in d.Meta.Channels are silently ignored.
type Attachment ¶
type Attachment struct { // ID is the attachment id. ID Snowflake `json:"id"` // Filename is the name of file attached. Filename string `json:"filename"` // ContentType is the media type of file. ContentType string `json:"content_type,omitempty"` // Size is the size of file in bytes. Size uint64 `json:"size"` // URL is the source url of file. URL string `json:"url"` // Proxy is the a proxied url of file. Proxy string `json:"proxy_url"` // Height is the height of the file, if it is an image. Height uint `json:"height,omitempty"` // Width is the width of the file, if it is an image. Width uint `json:"width,omitempty"` }
Attachment is a message attachment.
type Channel ¶
type Channel struct { ID Snowflake `json:"id"` Name string `json:"name"` Topic string `json:"topic"` Type ChannelType `json:"type"` NSFW bool `json:"nsfw"` }
Channel is a guild text channel.
type ChannelType ¶
type ChannelType uint8
ChannelType ...
const ( // GuildText is a text channel within a server. GuildText ChannelType = iota // DirectMessage is a direct message between users. DirectMessage // GuildVoice is a voice channel within a server. GuildVoice // GroupDM is a direct message between multiple users. GroupDM // GuildCategory is an organizational category that contains up to 50 // channels. GuildCategory // GuildNews is a channel that users can follow and crosspost into their // own server. GuildNews // GuildStore is a channel in which game developers can sell their game on // Discord. GuildStore // GuildNewsThread is a temporary sub-channel within a GUILD_NEWS channel GuildNewsThread // GuildPublicThread is a temporary sub-channel within a GUILD_TEXT // channel. GuildPublicThread // GuildPrivateThread isa temporary sub-channel within a GUILD_TEXT channel // that is only viewable by those invited and those with the MANAGE_THREADS // permission. GuildPrivateThread // GuildStageVoice is a voice channel for hosting events with an audience. GuildStageVoice )
https://discord.com/developers/docs/resources/channel#channel-object-channel-types
type CompressionType ¶
type CompressionType uint8
CompressionType is the compression type used for encoding/decoding.
const ( NoCompression CompressionType = 0 GzipCompression CompressionType = 1 )
Compression type constants
const DefaultCompression CompressionType = NoCompression
DefaultCompression is the default compression type.
type Embed ¶
type Embed struct { Title string `json:"title,omitempty"` Type EmbedType `json:"type,omitempty"` Description string `json:"description,omitempty"` URL string `json:"url,omitempty"` Timestamp time.Time `json:"timestamp,omitempty"` Color uint32 `json:"color,omitempty"` Image *EmbedImage `json:"image,omitempty"` Thumbnail *EmbedThumbnail `json:"thumbnail,omitempty"` Video *EmbedVideo `json:"video,omitempty"` Provider *EmbedProvider `json:"provider,omitempty"` Author *EmbedAuthor `json:"author,omitempty"` Fields []EmbedField `json:"fields,omitempty"` }
Embed ...
type EmbedAuthor ¶
type EmbedAuthor struct { Name string `json:"name,omitempty"` URL string `json:"url,omitempty"` Icon string `json:"icon_url,omitempty"` ProxyIcon string `json:"proxy_icon_url,omitempty"` }
EmbedAuthor ...
type EmbedField ¶
type EmbedField struct { Name string `json:"name"` Value string `json:"value"` Inline bool `json:"inline,omitempty"` }
EmbedField ...
type EmbedImage ¶
type EmbedImage struct { URL string `json:"url"` Proxy string `json:"proxy_url"` Height uint `json:"height,omitempty"` Width uint `json:"width,omitempty"` }
EmbedImage ...
type EmbedProvider ¶
EmbedProvider ...
type EmbedThumbnail ¶
type EmbedThumbnail struct { URL string `json:"url,omitempty"` Proxy string `json:"proxy_url,omitempty"` Height uint `json:"height,omitempty"` Width uint `json:"width,omitempty"` }
EmbedThumbnail ...
type EmbedVideo ¶
type EmbedVideo struct { URL string `json:"url"` Height uint `json:"height"` Width uint `json:"width"` }
EmbedVideo ...
type Emoji ¶
type Emoji struct { // ID is the ID of the Emoji. // The ID will be NullSnowflake, if the Emoji is a Unicode emoji. ID Snowflake `json:"id"` // Name is the name of the emoji. Name string `json:"name"` // RoleIDs are the roles the emoji is whitelisted to. // // This field is only available for custom emojis. RoleIDs []Snowflake `json:"roles,omitempty"` // User is the user that created the emoji. // // This field is only available for custom emojis. User User `json:"user,omitempty"` // RequireColons specifies whether the emoji must be wrapped in colons. // // This field is only available for custom emojis. RequireColons bool `json:"require_colons,omitempty"` // Managed specifies whether the emoji is managed. // // This field is only available for custom emojis. Managed bool `json:"managed,omitempty"` // Animated specifies whether the emoji is animated. // // This field is only available for custom emojis. Animated bool `json:"animated,omitempty"` // Available specifies whether the emoji can be used. // This may be false due to loss of Server Boosts. // // This field is only available for custom emojis. Available bool `json:"available,omitempty"` }
Emoji ...
func (Emoji) EmojiURL ¶
EmojiURL returns the URL of the emoji and auto-detects a suitable type.
This will only work for custom emojis.
func (Emoji) EmojiURLWithType ¶
EmojiURLWithType returns the URL to the emoji's image.
This will only work for custom emojis.
Supported ImageTypes: PNG, GIF
type Encoder ¶
type Encoder struct { sync.RWMutex CompressionType CompressionType // contains filtered or unexported fields }
Encoder creates darchive files.
func (*Encoder) AddMessages ¶
AddMessages adds the given messages to the encoder. Messages should be in reverse order, i.e. oldest first.
func (*Encoder) AddUsers ¶
AddUsers adds the given users to the encoder. Existing values will be overwritten if they have the same key, so be careful! Ensuring unique keys, and ensuring that they match messages, is left to the caller.
type Guild ¶
type Guild struct { Name string `json:"name"` ID Snowflake `json:"id"` Channels []Channel `json:"channels"` Roles []Role `json:"roles"` }
Guild is stored in guild.json
type ImageType ¶
type ImageType string
ImageType ...
const ( // AutoImage chooses automatically between a PNG and GIF. AutoImage ImageType = "auto" // JPEGImage is the JPEG image type. JPEGImage ImageType = ".jpeg" // PNGImage is the PNG image type. PNGImage ImageType = ".png" // WebPImage is the WebP image type. WebPImage ImageType = ".webp" // GIFImage is the GIF image type. GIFImage ImageType = ".gif" )
type InvalidMessageError ¶
type InvalidMessageError struct {
// contains filtered or unexported fields
}
InvalidMessageError can be returned by Encoder.AddMessages
func (*InvalidMessageError) Error ¶
func (e *InvalidMessageError) Error() string
type Message ¶
type Message struct { ID Snowflake `json:"id,omitempty"` Content string `json:"content,omitempty"` Timestamp time.Time `json:"timestamp,omitempty"` EditedTimestamp time.Time `json:"edited_timestamp,omitempty"` Pinned bool `json:"pinned"` MentionRoles []Snowflake `json:"mention_roles,omitempty"` MentionEveryone bool `json:"mention_everyone"` // Reference to users.json/Archive.Users MentionUsers []uint64 `json:"mention_users,omitempty"` // Reference to users.json/Archive.Users Author uint64 `json:"author"` Attachments []Attachment `json:"attachments,omitempty"` Embeds []Embed `json:"embeds,omitempty"` Reactions []Reaction `json:"reactions,omitempty"` Type MessageType `json:"type"` WebhookID Snowflake `json:"webhook_id,omitempty"` Reference *MessageReference `json:"message_reference,omitempty"` }
Message is a single message.
type MessageReference ¶
type MessageReference struct { // MessageID is the id of the originating message. MessageID Snowflake `json:"message_id,omitempty"` // ChannelID is the id of the originating message's channel. ChannelID Snowflake `json:"channel_id,omitempty"` // GuildID is the id of the originating message's guild. GuildID Snowflake `json:"guild_id,omitempty"` }
MessageReference ...
type MessageType ¶
type MessageType int
MessageType ...
const ( MessageTypeDefault MessageType = 0 MessageTypeRecipientAdd MessageType = 1 MessageTypeRecipientRemove MessageType = 2 MessageTypeCall MessageType = 3 MessageTypeChannelNameChange MessageType = 4 MessageTypeChannelIconChange MessageType = 5 MessageTypeChannelPinnedMessage MessageType = 6 MessageTypeGuildMemberJoin MessageType = 7 MessageTypeUserPremiumGuildSubscription MessageType = 8 MessageTypeUserPremiumGuildSubscriptionTierOne MessageType = 9 MessageTypeUserPremiumGuildSubscriptionTierTwo MessageType = 10 MessageTypeUserPremiumGuildSubscriptionTierThree MessageType = 11 MessageTypeChannelFollowAdd MessageType = 12 MessageTypeGuildDiscoveryDisqualified MessageType = 14 MessageTypeGuildDiscoveryRequalified MessageType = 15 MessageTypeReply MessageType = 19 MessageTypeChatInputCommand MessageType = 20 MessageTypeContextMenuCommand MessageType = 23 )
MessageType constants
type Meta ¶
type Meta struct { ArchiveVersion int `json:"archive_version"` Timestamp time.Time `json:"timestamp"` Channels []Snowflake `json:"channels"` User *User `json:"user,omitempty"` }
Meta is the structure of the meta file.
type Reaction ¶
type Reaction struct { // Count is the amount of times the emoji has been used to react. Count int `json:"count"` // Me specifies whether the current user reacted using this emoji. Me bool `json:"me"` // Emoji contains emoji information. Emoji Emoji `json:"emoji"` }
Reaction ...
type Role ¶
type Role struct { // ID is the role id. ID Snowflake `json:"id"` // Name is the role name. Name string `json:"name"` // Position is the position of this role. Position int `json:"position"` // Color is the integer representation of hexadecimal color code. Color uint32 `json:"color"` }
Role is a guild role.
type Snowflake ¶
type Snowflake uint64
Snowflake is a snowflake ID
func NewSnowflake ¶
NewSnowflake creates a new Snowflake with just the time component set.
func ParseSnowflake ¶
ParseSnowflake parses a Snowflake from a string.
func (*Snowflake) UnmarshalJSON ¶
UnmarshalJSON ...
type User ¶
type User struct { ID Snowflake `json:"id"` Username string `json:"username"` Avatar string `json:"avatar"` Discriminator string `json:"discriminator"` Bot bool `json:"bot"` // Empty if the user doesn't have a nickname in the guild, or if the message was sent by a webhook, or if the archive creator didn't fill it. Nick string `json:"nick,omitempty"` // List of role IDs the user has Roles []Snowflake `json:"roles,omitempty"` }
User is the author of a message. Also borrows two fields from guild members.