slk

package
v0.0.0-...-5db7531 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2018 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// UserPresenceActive represents the active presence.
	UserPresenceActive UserPresence = "active"
	// UserPresenceAway represents the away presence.
	UserPresenceAway UserPresence = "away"

	// TypeChannel identifies the channel-type
	TypeChannel EntityType = "channel"
	// TypeUser identifies the user-type
	TypeUser EntityType = "user"
)
View Source
const (
	// ListItemStatusNone should not receive special treatment
	ListItemStatusNone = iota
	// ListItemStatusGood should indicate a positive status
	// (e.g.: user online, ...)
	ListItemStatusGood
	// ListItemStatusBad should indicate a negative status
	// (e.g.: user set to DND)
	ListItemStatusBad
	// ListItemStatusNormal should indicate a neutral status
	// (e.g.: channel exists but user is not a member)
	ListItemStatusNormal
	// ListItemStatusTitle can be used to section a list with titles.
	ListItemStatusTitle
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Entity

type Entity interface {
	ID() string
	Name() string
	QualifiedName() string
	Type() EntityType
	UnreadCount() int
	IsActive() bool
	IsAway() bool
	IsNil() bool
	Is(Entity) bool
	// contains filtered or unexported methods
}

Entity abstracts users, groups and channels

type EntityType

type EntityType string

EntityType represents a slack entity-type (i.e.: channel, user, ...)

type ListItem

type ListItem struct {
	Status int
	Value  string
}

ListItem represens a single ListItems entry with a ListItemsStatus and text.

type ListItemStatus

type ListItemStatus string

ListItemStatus allows Output implementations to differentiate between diffent types of ListItems.

type ListItems

type ListItems []*ListItem

ListItems is a collection items that should be rendered as a list by the implementation of the output interface.

func (ListItems) Len

func (a ListItems) Len() int

func (ListItems) Less

func (a ListItems) Less(i, j int) bool

func (ListItems) Swap

func (a ListItems) Swap(i, j int)

type Output

type Output interface {
	// Notify should do something that stands out relative to the rest of
	// the methods and represens a message event.
	Notify(channel, from, text string, force bool)

	// Info will be called when a 'positive' event occurs.
	Info(msg string)
	// Notice will be called when a 'neutral' event occurs.
	Notice(msg string)
	// Warn will be called when an errors occurs.
	Warn(msg string)
	// Msg should render a slack message.
	Msg(channel, from, msg string, ts time.Time, newSection bool)
	// Debug will be called with dev info.
	Debug(msg ...string)
	// Typing should notify the user of another user's typing status.
	Typing(channel, user string, timeout time.Duration)
	// File should render a file.
	File(channel, from, title, url string)
	// List should render the given list.
	List(items ListItems, reverse bool)
}

Output allows for different implementations of the slk ui.

type Slk

type Slk struct {
	// contains filtered or unexported fields
}

Slk abstracts a bunch of nlopes/slack calls and writes all output to the given Output interface.

Handling of errors returned by Slk exposed methods is optional. Except for Init and Run.

func NewSlk

func NewSlk(token, timeFormat string, output Output) *Slk

NewSlk returns a new Slk 'engine'.

func (*Slk) Active

func (s *Slk) Active() (Entity, error)

Active returns the active entity.

func (*Slk) Fuzzy

func (s *Slk) Fuzzy(entityType EntityType, query string) []Entity

Fuzzy returns a list of entities of type entityType whose names fuzzy match the given query.

func (*Slk) History

func (s *Slk) History(e Entity, amount int) error

History like Unread writes a set of messages to the Output interface but takes an amount of messages argument instead of looking up unread messages.

func (*Slk) IMs

func (s *Slk) IMs() []Entity

IMs returns a list of users you have intiated an IM channel with.

func (*Slk) Init

func (s *Slk) Init() error

Init establishes the rtm connection and returns once we have all channel / group / im / user information. Should be called before Run().

func (*Slk) Invite

func (s *Slk) Invite(channel, user Entity) error

Invite a user to a channel or group.

func (*Slk) Join

func (s *Slk) Join(e Entity) error

Join makes your user join the given channel or group.

func (*Slk) Joined

func (s *Slk) Joined() []Entity

Joined returns a list of channels and groups you are a member of.

func (*Slk) Leave

func (s *Slk) Leave(e Entity) error

Leave makes your user leave the given channel or group.

func (*Slk) List

func (s *Slk) List(entityType EntityType, relevantOnly bool) error

List writes a list of entities of type entityType to the Output interface.

func (*Slk) ListUnread

func (s *Slk) ListUnread() error

ListUnread writes a list of entities with unread messages to the Output.

func (*Slk) Members

func (s *Slk) Members(e Entity, relevantOnly bool) error

Members writes a list of members of the given channel or group to the Output interface.

func (*Slk) NextUnread

func (s *Slk) NextUnread() (Entity, error)

NextUnread returns a random entity (ims first) with unread messages.

func (*Slk) Pins

func (s *Slk) Pins(e Entity) error

Pins writes the last 100 (?) pins of a channel or group to the Output interface.

func (*Slk) Post

func (s *Slk) Post(e Entity, msg string) error

Post a message to the given user, channel or group.

func (*Slk) Quit

func (s *Slk) Quit()

Quit closes the slack RTM connection.

func (*Slk) Run

func (s *Slk) Run() error

Run starts handling events. Should only be called once.

func (*Slk) SetPresence

func (s *Slk) SetPresence(presence UserPresence) error

SetPresence updates your presence.

func (*Slk) Switch

func (s *Slk) Switch(e Entity) error

Switch to the given entity and fetch unread history.

func (*Slk) Unread

func (s *Slk) Unread(e Entity) error

Unread writes all unread mesages of the given user, channel or group to the Output interface and marks the last message as read.

func (*Slk) Upload

func (s *Slk) Upload(e Entity, filepath, title, comment string) chan error

Upload a file to the given entity.

func (*Slk) Uploads

func (s *Slk) Uploads(e Entity) error

Uploads lists the first api page of uploads of the given entity.

func (*Slk) Username

func (s *Slk) Username() string

Username returns the name of the user whose api key we are using. Will be populated after Init.

type UserPresence

type UserPresence string

UserPresence represent a slack userpresence string

Jump to

Keyboard shortcuts

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