structures

package
v2.1.2 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2022 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 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 (entites).

func MakeEntityList added in v2.0.1

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

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

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) 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 the user index is not initialised, it will return the ID, otherwise, if the user is not found in cache, it will assume that the user is external, and return the ID with "external" prefix.

Directories

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

Jump to

Keyboard shortcuts

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