structures

package
v3.0.0-pre-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2024 License: GPL-3.0 Imports: 19 Imported by: 0

Documentation

Overview

Package structures provides functions to parse Slack data types.

Index

Constants

View Source
const (
	CUnknown = iota
	CIM
	CMPIM
	CPrivate
	CPublic
)
View Source
const (
	LatestReplyNoReplies = "0000000000.000000"
)
View Source
const LinkSep = ":"
View Source
const (
	SubTypeThreadBroadcast = "thread_broadcast"
)

Variables

View Source
var (
	ErrMaxFileSize = errors.New("maximum file size exceeded")
	ErrEmptyList   = errors.New("empty list")
)
View Source
var (
	ErrNoChannel = errors.New("empty channel data base")
	ErrNoUsers   = errors.New("empty users data base")
	ErrNoIdent   = errors.New("empty user identity")
)
View Source
var (
	ErrUnsupportedURL = errors.New("unsupported URL type")
	ErrNoURL          = errors.New("no url provided")
	ErrNotSlackURL    = errors.New("not a slack URL")
	ErrInvalidLink    = errors.New("invalid link")
)
View Source
var ErrInvalidDomain = errors.New("invalid domain")

Functions

func ChannelType

func ChannelType(ch slack.Channel) int

func ExtractWorkspace

func ExtractWorkspace(workspace string) (string, error)

ExtractWorkspace takes a workspace name or URL and returns the workspace name.

func FormatSlackTS

func FormatSlackTS(ts time.Time) string

func HasExcludePrefix

func HasExcludePrefix(s string) bool

func IsThreadStart

func IsThreadStart(m *slack.Message) bool

func IsURL

func IsURL(s string) bool

func IsValidSlackURL

func IsValidSlackURL(s string) bool

IsValidSlackURL returns true if the value looks like valid Slack URL, false if not.

func NVL

func NVL(s string, ss ...string) string

func ParseSlackTS

func ParseSlackTS(timestamp string) (time.Time, error)

ParseSlackTS parses the slack timestamp.

func ParseThreadID

func ParseThreadID(threadID string) (time.Time, error)

ParseThreadID parses the thread id (ie. p1577694990000400) and returns time.Time.

func ResolveURLs

func ResolveURLs(idsOrURLs []string) ([]string, error)

ResolveURLs normalises all channels to ID form. If the idsOrURLs[i] is a channel ID, it is unmodified, if it is URL - it is parsed and replaced with the channel ID. If the channel is marked for exclusion in the list it will retain this status.

func SplitEntryList

func SplitEntryList(s string) []string

SplitEntryList splits the string by space.

func ValidateEntityList

func ValidateEntityList(s string) error

ValidateEntityList validates a space-separated list of entities.

func ValidateToken

func ValidateToken(token string) error

Types

type DM

type DM struct {
	ID      string   `json:"id"`
	Created int64    `json:"created"`
	Members []string `json:"members"`
}

DM respresents a direct Message entry in dms.json. Structure is based on this post:

https://github.com/RocketChat/Rocket.Chat/issues/13905#issuecomment-477500022

type EntityIndex

type EntityIndex map[string]bool

func (EntityIndex) IsExcluded

func (ei EntityIndex) IsExcluded(ent string) bool

IsExcluded returns true if the entity is excluded (is in the list, and has value false).

func (EntityIndex) IsIncluded

func (ei EntityIndex) IsIncluded(ent string) bool

IsIncluded returns true if the entity is included (is in the list, and has value true).

type EntityList

type EntityList struct {
	Include []string
	Exclude []string
	// contains filtered or unexported fields
}

EntityList is an Inclusion/Exclusion list

func LoadEntityList

func LoadEntityList(filename string) (*EntityList, error)

LoadEntityList creates an EntityList from a slice of IDs or URLs (entites).

func NewEntityList

func NewEntityList(entities []string) (*EntityList, error)

NewEntityList creates an EntityList from a slice of IDs or URLs (entites).

func NewEntityListFromString

func NewEntityListFromString(s string) (*EntityList, error)

NewEntityListFromString creates an EntityList from a space-separated list of entities.

func (*EntityList) C

func (el *EntityList) C(ctx context.Context) <-chan string

C returns a channel where all included entries are streamed. The channel is closed when all entries have been sent, or when the context is cancelled.

func (*EntityList) HasExcludes

func (el *EntityList) HasExcludes() bool

HasExcludes returns true if there's any excluded entities.

func (*EntityList) HasIncludes

func (el *EntityList) HasIncludes() bool

HasIncludes returns true if there's any included entities.

func (*EntityList) Index

func (el *EntityList) Index() EntityIndex

Index returns a map where key is entity, and value show if the entity should be processed (true) or not (false).

func (*EntityList) IsEmpty

func (el *EntityList) IsEmpty() bool

IsEmpty returns true if there's no entries in the list.

type ExportIndex

type ExportIndex struct {
	Channels []slack.Channel `filename:"channels.json"`
	Groups   []slack.Channel `filename:"groups.json,omitempty"`
	MPIMs    []slack.Channel `filename:"mpims.json,omitempty"`
	DMs      []DM            `filename:"dms.json,omitempty"`
	Users    []slack.User    `filename:"users.json"`
}

ExportIndex is the ExportIndex of the export archive. filename tags are used to serialize the structure to JSON files.

func MakeExportIndex

func MakeExportIndex(channels []slack.Channel, users []slack.User, currentUserID string) (*ExportIndex, error)

MakeExportIndex creates a channels and users index for export archive, splitting channels in group/mpims/dms/public channels. currentUserID should contain the current user ID.

func (*ExportIndex) Marshal

func (idx *ExportIndex) Marshal(fs fsadapter.FS) error

Marshal writes the index to the filesystem in a set of files specified in `filename` tags of the structure.

func (*ExportIndex) Restore

func (idx *ExportIndex) Restore() []slack.Channel

Restore restores the index to the original channels slice (minus the lost data from DMs).

func (*ExportIndex) Unmarshal

func (idx *ExportIndex) Unmarshal(fsys fs.FS) error

Unmarshal reads the index from the filesystem in a set of files specified in `filename` tags of the structure.

type SlackLink struct {
	Channel  string
	ThreadTS string
}
func ParseLink(link string) (SlackLink, error)

ParseLink parses the slack link string. It supports the following formats:

  • XXXXXXX - channel ID
  • XXXXXXX:99999999.99999 - channel ID and thread ID
  • https://<valid slack URL> - slack URL link.

It returns the SlackLink or error.

func ParseURL

func ParseURL(slackURL string) (*SlackLink, error)

ParseURL parses the slack link in the format of https://xxxx.slack.com/archives/XXXXX[/p99999999]

func (SlackLink) IsThread

func (u SlackLink) IsThread() bool

func (SlackLink) IsValid

func (u SlackLink) IsValid() bool

func (SlackLink) LogValue

func (u SlackLink) LogValue() slog.Value

func (SlackLink) String

func (u SlackLink) String() string

type UserIndex

type UserIndex map[string]*slack.User

UserIndex is a mapping of user ID to the *slack.User.

func NewUserIndex

func NewUserIndex(us []slack.User) UserIndex

NewUserIndex creates a new UserIndex from slack Users slice

func (UserIndex) ChannelName

func (idx UserIndex) ChannelName(ch slack.Channel) (who string)

ChannelName return the "beautified" name of the channel.

func (UserIndex) DisplayName

func (idx UserIndex) DisplayName(id string) string

DisplayName tries to resolve the display name by ID. if the index is empty, it returns the user ID. If the user is not found in index, is assumes that it is an external user and returns ID with "external" prefix. If it does find the user and display name is unavailble, it returns the Real Name.

func (UserIndex) IsDeleted

func (idx UserIndex) IsDeleted(id string) bool

IsDeleted checks if the user is deleted and returns appropriate value. It will assume user is not deleted, if it's not present in the user index.

func (UserIndex) Sender

func (idx UserIndex) Sender(msg *slack.Message) string

Sender returns username for the message

func (UserIndex) Username

func (idx UserIndex) Username(id string) string

Username tries to resolve the username by ID. If it fails, it returns the user ID. If the user is not found in index, is assumes that it is an external user and returns ID with "external" prefix.

Directories

Path Synopsis
Package files contains some additional file logic.
Package files contains some additional file logic.
dl

Jump to

Keyboard shortcuts

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