sample

package
v0.0.0-...-821ef61 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2017 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package sample is a sample implementation of a plugin. Use this as a place to start to build a plugin

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Plugin

type Plugin struct{}

Plugin initializes the interface

func (*Plugin) Command

func (p *Plugin) Command() []string

Command returns a list of commands the plugin provides

func (*Plugin) HandleMessage

func (p *Plugin) HandleMessage(in message.Basic) (out message.Basic)

HandleMessage is responsible for handling the incoming message and returning a response based on the message provided

Example
package main

import (
	"fmt"

	"github.com/handwritingio/deckard-bot/message"
)

func main() {
	p := new(Plugin)
	fmt.Println(p.HandleMessage(format("!sample")).Text)
	fmt.Println(rePluginRegexp.MatchString("!sample"))
}

func format(text string) message.Basic {
	return message.Basic{
		ID:       1,
		Text:     text,
		Finished: true,
	}
}
Output:

Sample Plugin Output
true

func (*Plugin) Name

func (p *Plugin) Name() string

Name returns the name of the plugin

func (*Plugin) OnInit

func (p *Plugin) OnInit() error

OnInit returns an error if the plugin could not be started OnInit doesn't do anything here as nothing needs to be initialized for this plugin

func (Plugin) Regexp

func (p Plugin) Regexp() *regexp.Regexp

Regexp returns the regexp of a message that should be handled by this plugin

func (*Plugin) Usage

func (p *Plugin) Usage() string

Usage prints detailed usage instructions

Jump to

Keyboard shortcuts

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