structures

package
v2.5.6 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2024 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Overview

Package structures provides functions to parse Slack data types.

Index

Constants

This section is empty.

Variables

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")
)

Functions

func FixMpIMmembers added in v2.2.0

func FixMpIMmembers(ch *slack.Channel, users []slack.User) (*slack.Channel, error)

FixMpIMmembers verifies Channel.Members to contain all channel members, if not, it attempts to populate it by parsing out the usernames from name_normalized, and populating Channel.Members with IDs of the users discovered. usernameIDs is a mapping of username -> user_id.

func FormatSlackTS

func FormatSlackTS(ts time.Time) string

func HasExcludePrefix added in v2.0.1

func HasExcludePrefix(s string) bool

func IsURL added in v2.0.1

func IsURL(s string) bool

func IsValidSlackURL added in v2.0.1

func IsValidSlackURL(s string) bool

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

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 added in v2.0.1

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.

Types

type EntityList added in v2.0.1

type EntityList struct {
	Include []string
	Exclude []string
}

EntityList is an Inclusion/Exclusion list

func LoadEntityList added in v2.0.1

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

MakeEntityList creates an EntityList from a slice of IDs or URLs (entities).

func NewEntityList added in v2.5.0

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

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

func (*EntityList) HasExcludes added in v2.0.1

func (el *EntityList) HasExcludes() bool

func (*EntityList) HasIncludes added in v2.0.1

func (el *EntityList) HasIncludes() bool

func (*EntityList) Index added in v2.0.1

func (el *EntityList) Index() map[string]bool

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

func (*EntityList) IsEmpty added in v2.0.1

func (el *EntityList) IsEmpty() bool
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 added in v2.0.1

func (u SlackLink) IsThread() bool

func (SlackLink) IsValid added in v2.0.1

func (u SlackLink) IsValid() bool

func (SlackLink) String added in v2.0.1

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(channel *slack.Channel) (who string)

ChannelName return the "beautified" name of the channel.

func (UserIndex) DisplayName added in v2.2.0

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