slacker

package module
v9.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2020 License: Apache-2.0 Imports: 4 Imported by: 0

README

TravisCI

slacker is simple go package for bootstraping Slack bots.

Installation

Before the initial install allows git to use redirects for pkg.re service (reason why you should do this described here):

git config --global http.https://pkg.re.followRedirects true

Make sure you have a working Go 1.12+ workspace (instructions), then:

go get pkg.re/essentialkaos/slacker.v9

For update to latest stable release, do:

go get -u pkg.re/essentialkaos/slacker.v9

Build Status

Branch Status
master Build Status
develop Build Status

Contributing

Before contributing to this project please read our Contributing Guidelines.

License

Apache License, Version 2.0

Documentation

Overview

Package slacker provides methods for for bootstraping Slack bots

Index

Constants

View Source
const (
	STATUS_NONE   uint = 0
	STATUS_TYPING      = 1
	STATUS_EMOJI       = 2
)

Status types

View Source
const VERSION = "9.0.0"

VERSION is current package version

Variables

This section is empty.

Functions

func GetMention

func GetMention(u User) string

GetMention generates user mention link

Types

type Bot

type Bot struct {
	Token                string // Auth token
	BotName              string // Bot name
	AllowDM              bool   // Allow direct messages
	StatusType           uint8  // Processing status mark type
	Started              int64  // Bot start timestamp
	UserListUpdatePeriod int    // User list update period in seconds

	ErrorHandler          func(err error)
	ConnectHandler        func()
	HelloHandler          func() string
	UnknownCommandHandler func(user User, cmd string, args []string) string

	CommandHandlers map[string]CommandHandler
	// contains filtered or unexported fields
}

Bot is basic bot struct

func NewBot

func NewBot(name, token string) *Bot

NewBot creates new bot

func (*Bot) FetchUsers

func (b *Bot) FetchUsers() error

fetchUsers fetches users and creates map id->name

func (*Bot) GetUser

func (b *Bot) GetUser(nameOrID string) User

GetUser tries to find user info by user name or ID

func (*Bot) NormalizeInput

func (b *Bot) NormalizeInput(input string) string

NormalizeInput normalizes links and usernames in a message

func (*Bot) PostMessage

func (b *Bot) PostMessage(channel, message string, options ...slack.MsgOption) error

PostMessage posts mesasge

func (*Bot) Run

func (b *Bot) Run() error

Run starts bot

func (*Bot) SendMessage

func (b *Bot) SendMessage(to, message string) error

SendMessage sends simple message to some user

type CommandHandler

type CommandHandler func(user User, args []string) []string

CommandHandler is command handler

type User

type User = slack.User

User is alias for slack.User struct

type UsersInfo

type UsersInfo struct {
	Users map[string]User
	// contains filtered or unexported fields
}

Basic users info

Jump to

Keyboard shortcuts

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