Documentation
¶
Index ¶
- Variables
- func NewReactionEmojiEngineTask(e engine.Engine, channel, emoji, timestamp string) *reactionEmojiEngineTask
- func NewReloadEngineTask(e engine.Engine) reloadEngineTask
- func NewReplyEngineTask(e engine.Engine, channel, text string) *replyEngineTask
- func NewReplyThreadEngineTask(e engine.Engine, channel, text, timestamp string) *replyThreadEngineTask
- func NewUploadEngineTask(e engine.Engine, channel string, file io.Reader, filename string) *uploadEngineTask
- type BasicCommandTemplate
- type Command
- type CommandData
- type CommandSet
- type CommandTemplate
- type Task
Constants ¶
This section is empty.
Variables ¶
var GoodMorningCommand = BasicCommandTemplate{ Help: "reply Good morning in thread", Regexp: regexp.MustCompile("(?i)Good Morning"), GenerateFn: func(d CommandData) Command { c := Command{} text := fmt.Sprintf("Good Morning <@%s>", d.SenderID) task := NewReplyThreadEngineTask(d.Engine, d.Channel, text, d.ThreadTimestamp) c.Add(task) return c }, }
GoodMorningCommand is an example command. This command reply greeting to a thread.
var HelpCommand = BasicCommandTemplate{ Help: "show command list and usages", MentionCommand: "help", GenerateFn: func(d CommandData) Command { c := Command{} mentionMap := d.GetMentionMap() mentions := make([]string, 0, len(mentionMap)) for key, c := range mentionMap { if !c.HasHelp() { continue } str := fmt.Sprintf("- %s\t\t%s", key, c.GetHelp()) mentions = append(mentions, str) } regexpList := d.GetRegexpList() freewords := make([]string, len(regexpList)) for i, c := range regexpList { if !c.HasHelp() { continue } freewords[i] = fmt.Sprintf("- %s\t\t%s", c.GetRegexp().String(), c.GetHelp()) } text := fmt.Sprintf("```Command:\n%s\n\nFreeword:\n%s```", strings.Join(mentions, "\n"), strings.Join(freewords, "\n")) task := NewReplyEngineTask(d.Engine, d.Channel, text) c.Add(task) return c }, }
HelpCommand is an example command. This command shows all of the commands help text.
var ParrotCommand = BasicCommandTemplate{ Help: "reply text between :parrot: Emoji", MentionCommand: "parrot", GenerateFn: func(d CommandData) Command { c := Command{} text := fmt.Sprintf(":parrot: %s :parrot:", d.TextOther) task := NewReplyEngineTask(d.Engine, d.Channel, text) c.Add(task) return c }, }
ParrotCommand is an example command. This command puts :parrot: emoji both side.
var PingCommand = BasicCommandTemplate{ Help: "reply PONG", MentionCommand: "ping", GenerateFn: func(d CommandData) Command { c := Command{} task := NewReplyEngineTask(d.Engine, d.Channel, "PONG") c.Add(task) return c }, }
PingCommand is an example command. This command sais "PONG".
var ReactEmojiCommand = BasicCommandTemplate{ Help: "add reaction to message", Regexp: regexp.MustCompile("^"), GenerateFn: func(d CommandData) Command { c := Command{} if !isRandValid(20) { return c } emoji, err := d.Engine.GetEmojiByRandom() if err != nil { task := NewReplyEngineTask(d.Engine, d.Channel, fmt.Sprintf("Error on Slack!\nErr: `%s`", err.Error())) c.Add(task) return c } task := NewReactionEmojiEngineTask(d.Engine, d.Channel, emoji, d.ThreadTimestamp) c.Add(task) return c }, }
ReactEmojiCommand is an example command. This command add emoji reaction 20% chance.
var ReloadCommand = BasicCommandTemplate{ Help: "Reload Bot Engine", MentionCommand: "reload", GenerateFn: func(d CommandData) Command { c := Command{} c.Add(NewReplyEngineTask(d.Engine, d.Channel, "Reloading...")) c.Add(NewReloadEngineTask(d.Engine)) return c }, }
ReloadCommand is an example command. This command reloads bot engine.
Functions ¶
func NewReactionEmojiEngineTask ¶
func NewReactionEmojiEngineTask(e engine.Engine, channel, emoji, timestamp string) *reactionEmojiEngineTask
NewReactionEmojiEngineTask is a task to add reaction to a message.
func NewReloadEngineTask ¶ added in v0.0.2
NewReloadEngineTask is a task to reload engine.
func NewReplyEngineTask ¶
NewReplyEngineTask is a task to reply text.
func NewReplyThreadEngineTask ¶
func NewReplyThreadEngineTask(e engine.Engine, channel, text, timestamp string) *replyThreadEngineTask
NewReplyThreadEngineTask is a task to reply text on a thread.
Types ¶
type BasicCommandTemplate ¶
type BasicCommandTemplate struct { MentionCommand string Regexp *regexp.Regexp GenerateFn func(CommandData) Command Help string // usage text NoHelp bool // don't show usage text }
BasicCommandTemplate is a basic command template.
func (BasicCommandTemplate) Exec ¶
func (c BasicCommandTemplate) Exec(d CommandData)
func (BasicCommandTemplate) GetHelp ¶
func (c BasicCommandTemplate) GetHelp() string
func (BasicCommandTemplate) GetMentionCommand ¶
func (c BasicCommandTemplate) GetMentionCommand() string
func (BasicCommandTemplate) GetRegexp ¶
func (c BasicCommandTemplate) GetRegexp() *regexp.Regexp
func (BasicCommandTemplate) HasHelp ¶
func (c BasicCommandTemplate) HasHelp() bool
type Command ¶
type Command struct {
// contains filtered or unexported fields
}
Command contains task list to execute.
type CommandData ¶
type CommandData struct { Engine engine.Engine RawText string // "@bot <command> <other>" or "<command> <other>" Text string // "@bot <command> <other>" TextMention string // @bot TextCommand string // <command> TextOther string // <other> IsDM bool // it's on DM or not BotID string SenderID string SenderName string // Engine's data Channel string ThreadTimestamp string // for help usecase CommandSet *CommandSet }
CommandData is used to create and execute command.
func (CommandData) GetMentionMap ¶
func (d CommandData) GetMentionMap() map[string]CommandTemplate
func (CommandData) GetRegexpList ¶
func (d CommandData) GetRegexpList() []CommandTemplate
func (CommandData) HasMyMention ¶
func (d CommandData) HasMyMention() bool
type CommandSet ¶
type CommandSet struct { List []CommandTemplate // contains filtered or unexported fields }
CommandSet is a collection of bot commands.
func NewCommandSet ¶
func NewCommandSet(templateList ...CommandTemplate) *CommandSet
func (*CommandSet) Exec ¶
func (s *CommandSet) Exec(d CommandData)
func (*CommandSet) Init ¶
func (s *CommandSet) Init()
type CommandTemplate ¶
Source Files
¶
- command__data.go
- command__set.go
- command__template.go
- example_command_goodmorning.go
- example_command_help.go
- example_command_parrot.go
- example_command_ping.go
- example_command_react_emoji.go
- example_command_reload.go
- task.go
- task_reaction_emoji_engine.go
- task_reload_engine.go
- task_reply_engine.go
- task_reply_thread_engine.go
- task_upload_engine.go