message

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2026 License: MIT Imports: 58 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrNonceAlreadyBeingProcessed = "message with this nonce is already being created"
	ErrReplyMustBeInSameChannel   = "reply target must exist in the same channel"
)
View Source
const (
	ErrUnableToGetUserToken         = "unable to get user token"
	ErrUnableToParseBody            = "unable to parse body"
	ErrPermissionsRequired          = "permissions required"
	ErrUnableToCreateAttachment     = "unable to create attachment"
	ErrUnableToCreateUploadURL      = "unable to create upload url"
	ErrIncorrectChannelID           = "incorrect channel ID"
	ErrIncorrectMessageID           = "incorrect message ID"
	ErrFileIsTooBig                 = "file is too big"
	ErrUnableToSendMessage          = "unable to send message"
	ErrUnableToUpdateMessage        = "unable to update message"
	ErrUnableToGetUser              = "unable to get user"
	ErrUnableToGetGuild             = "unable to get guild"
	ErrUnableToGetUserDiscriminator = "unable to get discriminator"
	ErrUnableToGetAttachements      = "unable to get attachments"
	ErrUnableToSentToThisChannel    = "unable to send to this channel"
	ErrUnableToReadFromThisChannel  = "unable to read from this channel"
	ErrUnableToGetMessage           = "unable to get message"
	ErrUnableToSetReadState         = "unable to set read state"
	ErrUnableToSendTypingEvent      = "unable to send typing event"
	ErrInvalidAttachments           = "invalid attachments"
	ErrUnableToCreateThread         = "unable to create thread"
	ErrThreadClosed                 = "thread is closed"
	ErrThreadSourceInvalid          = "threads can only be created from guild text channel messages"
	ErrThreadNestingForbidden       = "cannot create a thread inside a thread"
	ErrThreadAlreadyExists          = "thread already exists for this message"
	ErrThreadNameTooLong            = "thread name must be 256 characters or fewer"
	ErrMessageNotEditable           = "message type cannot be edited"
	ErrNonceRequiredWithEnforce     = "nonce is required when enforce_nonce is true"
	ErrReferenceIdInvalid           = "reference ID must be positive"
	ErrIncorrectReactionName        = "incorrect reaction name"
	ErrAfterIdInvalid               = "after ID must be positive"

	// Validation error messages
	ErrMessagePayloadRequired = "message content, attachments, or embeds are required"
	ErrMessageUpdateRequired  = "message content, embeds, or flags update is required"
	ErrMessageContentTooLong  = "message content must be less than 2000 characters"
	ErrAttachmentIdInvalid    = "attachment ID must be positive"
	ErrMentionIdInvalid       = "mention ID must be positive"
	ErrFilenameRequired       = "filename is required"
	ErrFilenameTooLong        = "filename must be less than 255 characters"
	ErrFileSizeInvalid        = "file size must be positive"
	ErrFileSizeTooBig         = "file size must be less than 100MB"
	ErrDimensionsInvalid      = "width and height must be non-negative"
	ErrLimitInvalid           = "limit must be between 1 and 100"
	ErrFromIdInvalid          = "from ID must be positive"
	ErrDirectionInvalid       = "direction must be 'before' or 'after'"
	ErrFlagsInvalid           = "flags must be non-negative"
)
View Source
const (
	DirectionBefore = Direction("before")
	DirectionAfter  = Direction("after")
	DirectionAround = Direction("around")
)
View Source
const (
	DefaultLimit = int(50)
)
View Source
const MaxBatchSize = 50

Variables

This section is empty.

Functions

func GetAttachmentType

func GetAttachmentType(contentType string) string

func HasURL

func HasURL(text string) bool

HasURL returns true if the input string contains at least one URL.

func MentionsExtractor added in v1.5.0

func MentionsExtractor(content string) (users, roles []int64, everyone, here bool)

MentionsExtractor extract mentions from the text message <@2226021950625415168> - extracts all as user ids <@&2226021950625415168> - extracts all as role ids

@here		- if present in content returns true for here mentions
@everyone	- if present in content returns true for everyone mentions

Example: "Hello <@2226021950625415168> and <@2229920912390488064>" returns slice if users [2226021950625415168, 2229920912390488064]

func New

func New(cql *db.CQLCon, pg *pgdb.DB, t mq.SendTransporter, imq *indexmq.IndexMQ, emq embedQueue, uploadLimit int64, attachTTLSeconds int64, cache cache.Cache, log *slog.Logger) server.Entity

func UniqueAttachmentTypes

func UniqueAttachmentTypes(types []string) []string

Types

type CreateThreadRequest added in v1.8.0

type CreateThreadRequest struct {
	Name        string                  `json:"name,omitempty" example:"Thread title"`                  // Optional explicit thread name.
	Content     string                  `json:"content" example:"Hello from thread!"`                   // First thread message content.
	Nonce       *helper.MessageNonce    `json:"nonce,omitempty" swaggertype:"string" example:"draft-1"` // Optional client correlation token for the starter message event.
	Attachments helper.StringInt64Array `json:"attachments" example:"2230469276416868352"`              // IDs of attached files uploaded to the parent channel before thread creation.
	Mentions    helper.StringInt64Array `json:"mentions" example:"2230469276416868352"`                 // IDs of mentioned users.
	Embeds      []embed.Embed           `json:"embeds,omitempty"`                                       // Manual embeds for the first thread message.
}

func (CreateThreadRequest) MessageRequest added in v1.8.0

func (r CreateThreadRequest) MessageRequest(attachmentIDs []int64) *SendMessageRequest

func (CreateThreadRequest) Validate added in v1.8.0

func (r CreateThreadRequest) Validate() error

type Direction

type Direction string

type GetMessagesRequest

type GetMessagesRequest struct {
	From      *int64     `query:"from" json:"from" example:"2230469276416868352"`                          // ID of the message whe start to look from
	Limit     *int       `query:"limit" json:"limit" example:"30"`                                         // Number of messages to return.
	Direction *Direction `query:"direction" json:"direction" enums:"before,after,around" example:"before"` // Direction to look for messages
}

func (GetMessagesRequest) Validate

func (r GetMessagesRequest) Validate() error

type GetReactionUsersRequest added in v1.10.0

type GetReactionUsersRequest struct {
	After *int64 `query:"after" json:"after" example:"2230469276416868352"`
	Limit *int   `query:"limit" json:"limit" example:"30"`
}

func (GetReactionUsersRequest) Validate added in v1.10.0

func (r GetReactionUsersRequest) Validate() error

type SendMessageRequest

type SendMessageRequest struct {
	Content      string                  `json:"content" example:"Hello world!"`                                          // Message content
	Nonce        *helper.MessageNonce    `json:"nonce,omitempty" swaggertype:"string" example:"draft-1"`                  // Optional client correlation token echoed back to the author.
	EnforceNonce bool                    `json:"enforce_nonce,omitempty"`                                                 // When true, deduplicates sends with the same nonce in the same channel for a short window.
	Reference    *helper.StringInt64     `json:"reference,omitempty" swaggertype:"integer" example:"2230469276416868352"` // Referenced message ID in the same channel. When set, the new message is stored as type 1 (Reply).
	Attachments  helper.StringInt64Array `json:"attachments" example:"2230469276416868352"`                               // IDs of attached files
	Mentions     helper.StringInt64Array `json:"mentions" example:"2230469276416868352"`                                  // IDs of mentioned users
	Embeds       []embed.Embed           `json:"embeds,omitempty"`                                                        // Manual embeds supplied by the client. These are stored separately from generated URL embeds.
}

func (SendMessageRequest) Validate

func (r SendMessageRequest) Validate() error

type UpdateMessageRequest

type UpdateMessageRequest struct {
	Content *string        `json:"content,omitempty" example:"Hello world!"` // Message content
	Embeds  *[]embed.Embed `json:"embeds,omitempty"`                         // Full replacement for the manual embed array. Generated embeds are managed by the embedder service.
	Flags   *int           `json:"flags,omitempty" example:"4"`              // Message flags bitmask. Use 4 to suppress URL embed generation and clear generated embeds.
}

func (UpdateMessageRequest) Validate

func (r UpdateMessageRequest) Validate() error

type UploadAttachmentRequest

type UploadAttachmentRequest struct {
	Filename    string `json:"filename" example:"image.png"`     // File name
	FileSize    int64  `json:"file_size" example:"100000"`       // File size in bytes
	Width       int64  `json:"width" example:"800"`              // Image width in pixels
	Height      int64  `json:"height" example:"600"`             // Image height in pixels
	ContentType string `json:"content_type" example:"image/png"` // File content-type meta data
}

func (UploadAttachmentRequest) Validate

func (r UploadAttachmentRequest) Validate() error

Jump to

Keyboard shortcuts

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