Code Monkey home page Code Monkey logo

slasher's Introduction

slasher

-- import "github.com/autom8ter/slasher"

Usage

func ExampleHandler

func ExampleHandler()

type HandlerFunc

type HandlerFunc func(s *Slasher, client *slack.Client, command *slack.SlashCommand) (interface{}, error)

A handler func is run against an incoming slack slash command. It is up to the user of this library to define their own handlers

type Slasher

type Slasher struct {
}

Slasher holds a slack client, a map of functions map[string]HandlerFunc and an array of allowed users

func NewSlasher

func NewSlasher(token string) *Slasher

Creates a newe slasher instance

func (*Slasher) AddHandler

func (s *Slasher) AddHandler(command string, function HandlerFunc)

Adds a slack slash command handler

func (*Slasher) BashScipt

func (s *Slasher) BashScipt(script string) ([]byte, error)

runs exec.Command("/bin/sh", "-c", script)

func (*Slasher) CommandHandlers

func (s *Slasher) CommandHandlers() []string

Names of all supported slash commands

func (*Slasher) DeleteHandler

func (s *Slasher) DeleteHandler(command string)

Deletes a handler delete(s.functions, command)

func (*Slasher) Error

func (s *Slasher) Error(w http.ResponseWriter, err error)

Writes a wrapped Slasher error to the response

func (*Slasher) Exec

func (s *Slasher) Exec(args ...string) ([]byte, error)

runs exec.Command(args[0], args[1:]...)

func (*Slasher) Exists

func (s *Slasher) Exists(command string) bool

Checks if a function exists for the command

func (*Slasher) HandlerFunc

func (s *Slasher) HandlerFunc() http.HandlerFunc

func (*Slasher) JSON

func (s *Slasher) JSON(w http.ResponseWriter, obj interface{})

Writes pretty json to the response

func (*Slasher) Python3Script

func (s *Slasher) Python3Script(cmd string) ([]byte, error)

runs exec.Command("python3", "-c", cmd)

func (*Slasher) ShellScript

func (s *Slasher) ShellScript(script string) ([]byte, error)

exec.Command("/bin/sh", "-c", script)

func (*Slasher) String

func (s *Slasher) String(w http.ResponseWriter, response string)

Writes the string to the response

slasher's People

Contributors

autom8ter avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.