summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCorey Hulen <corey@hulen.com>2015-11-02 09:02:46 -0800
committerCorey Hulen <corey@hulen.com>2015-11-02 09:02:46 -0800
commit16171468dd51bb60216b5b9fa26866ec0c38d81c (patch)
treeca6afebef0debf28291ed1f51b083643c03861d9
parent120d68fa4b74eb8abcd3ad9be53e723ba56648c7 (diff)
parent47fcb79e998040ca83ba9a08cbe87bbf376db114 (diff)
downloadchat-16171468dd51bb60216b5b9fa26866ec0c38d81c.tar.gz
chat-16171468dd51bb60216b5b9fa26866ec0c38d81c.tar.bz2
chat-16171468dd51bb60216b5b9fa26866ec0c38d81c.zip
Merge pull request #1263 from yuvipanda/add-me
Add a /me command
-rw-r--r--api/command.go30
1 files changed, 30 insertions, 0 deletions
diff --git a/api/command.go b/api/command.go
index e22a05a5f..50ca41155 100644
--- a/api/command.go
+++ b/api/command.go
@@ -24,6 +24,7 @@ var (
"loadTestCommand": "/loadtest",
"echoCommand": "/echo",
"shrugCommand": "/shrug",
+ "meCommand": "/me",
}
commands = []commandHandler{
logoutCommand,
@@ -31,6 +32,7 @@ var (
loadTestCommand,
echoCommand,
shrugCommand,
+ meCommand,
}
commandNotImplementedErr = model.NewAppError("checkCommand", "Command not implemented", "")
)
@@ -194,6 +196,34 @@ func echoCommand(c *Context, command *model.Command) bool {
return false
}
+func meCommand(c *Context, command *model.Command) bool {
+ cmd := cmds["meCommand"]
+
+ if !command.Suggest && strings.Index(command.Command, cmd) == 0 {
+ message := ""
+
+ parameters := strings.SplitN(command.Command, " ", 2)
+ if len(parameters) > 1 {
+ message += "*" + parameters[1] + "*"
+ }
+
+ post := &model.Post{}
+ post.Message = message
+ post.ChannelId = command.ChannelId
+ if _, err := CreatePost(c, post, false); err != nil {
+ l4g.Error("Unable to create /me post post, err=%v", err)
+ return false
+ }
+ command.Response = model.RESP_EXECUTED
+ return true
+
+ } else if strings.Index(cmd, command.Command) == 0 {
+ command.AddSuggestion(&model.SuggestCommand{Suggestion: cmd, Description: "Do an action, /me [message]"})
+ }
+
+ return false
+}
+
func shrugCommand(c *Context, command *model.Command) bool {
cmd := cmds["shrugCommand"]