diff options
Diffstat (limited to 'api')
-rw-r--r-- | api/auto_environment.go (renamed from api/auto_enviroment.go) | 30 | ||||
-rw-r--r-- | api/auto_teams.go | 2 | ||||
-rw-r--r-- | api/command.go | 48 |
3 files changed, 55 insertions, 25 deletions
diff --git a/api/auto_enviroment.go b/api/auto_environment.go index c6453f5da..68186ec6c 100644 --- a/api/auto_enviroment.go +++ b/api/auto_environment.go @@ -10,42 +10,42 @@ import ( "time" ) -type TestEnviroment struct { - Teams []*model.Team - Enviroments []TeamEnviroment +type TestEnvironment struct { + Teams []*model.Team + Environments []TeamEnvironment } -func CreateTestEnviromentWithTeams(client *model.Client, rangeTeams utils.Range, rangeChannels utils.Range, rangeUsers utils.Range, rangePosts utils.Range, fuzzy bool) (TestEnviroment, bool) { +func CreateTestEnvironmentWithTeams(client *model.Client, rangeTeams utils.Range, rangeChannels utils.Range, rangeUsers utils.Range, rangePosts utils.Range, fuzzy bool) (TestEnvironment, bool) { rand.Seed(time.Now().UTC().UnixNano()) teamCreator := NewAutoTeamCreator(client) teamCreator.Fuzzy = fuzzy teams, err := teamCreator.CreateTestTeams(rangeTeams) if err != true { - return TestEnviroment{}, false + return TestEnvironment{}, false } - enviroment := TestEnviroment{teams, make([]TeamEnviroment, len(teams))} + environment := TestEnvironment{teams, make([]TeamEnvironment, len(teams))} for i, team := range teams { userCreator := NewAutoUserCreator(client, team.Id) userCreator.Fuzzy = fuzzy randomUser, err := userCreator.createRandomUser() if err != true { - return TestEnviroment{}, false + return TestEnvironment{}, false } client.LoginById(randomUser.Id, USER_PASSWORD) - teamEnviroment, err := CreateTestEnviromentInTeam(client, team.Id, rangeChannels, rangeUsers, rangePosts, fuzzy) + teamEnvironment, err := CreateTestEnvironmentInTeam(client, team.Id, rangeChannels, rangeUsers, rangePosts, fuzzy) if err != true { - return TestEnviroment{}, false + return TestEnvironment{}, false } - enviroment.Enviroments[i] = teamEnviroment + environment.Environments[i] = teamEnvironment } - return enviroment, true + return environment, true } -func CreateTestEnviromentInTeam(client *model.Client, teamID string, rangeChannels utils.Range, rangeUsers utils.Range, rangePosts utils.Range, fuzzy bool) (TeamEnviroment, bool) { +func CreateTestEnvironmentInTeam(client *model.Client, teamID string, rangeChannels utils.Range, rangeUsers utils.Range, rangePosts utils.Range, fuzzy bool) (TeamEnvironment, bool) { rand.Seed(time.Now().UTC().UnixNano()) // We need to create at least one user @@ -57,7 +57,7 @@ func CreateTestEnviromentInTeam(client *model.Client, teamID string, rangeChanne userCreator.Fuzzy = fuzzy users, err := userCreator.CreateTestUsers(rangeUsers) if err != true { - return TeamEnviroment{}, false + return TeamEnvironment{}, false } usernames := make([]string, len(users)) for i, user := range users { @@ -77,7 +77,7 @@ func CreateTestEnviromentInTeam(client *model.Client, teamID string, rangeChanne } if err != true { - return TeamEnviroment{}, false + return TeamEnvironment{}, false } numPosts := utils.RandIntFromRange(rangePosts) numImages := utils.RandIntFromRange(rangePosts) / 4 @@ -93,5 +93,5 @@ func CreateTestEnviromentInTeam(client *model.Client, teamID string, rangeChanne } } - return TeamEnviroment{users, channels}, true + return TeamEnvironment{users, channels}, true } diff --git a/api/auto_teams.go b/api/auto_teams.go index 6677ac9bf..082415d32 100644 --- a/api/auto_teams.go +++ b/api/auto_teams.go @@ -8,7 +8,7 @@ import ( "github.com/mattermost/platform/utils" ) -type TeamEnviroment struct { +type TeamEnvironment struct { Users []*model.User Channels []*model.Channel } diff --git a/api/command.go b/api/command.go index b2a4f4a0b..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"] @@ -381,11 +411,11 @@ func loadTestSetupCommand(c *Context, command *model.Command) bool { if doTeams { if err := CreateBasicUser(client); err != nil { - l4g.Error("Failed to create testing enviroment") + l4g.Error("Failed to create testing environment") return true } client.LoginByEmail(BTEST_TEAM_NAME, BTEST_USER_EMAIL, BTEST_USER_PASSWORD) - enviroment, err := CreateTestEnviromentWithTeams( + environment, err := CreateTestEnvironmentWithTeams( client, utils.Range{numTeams, numTeams}, utils.Range{numChannels, numChannels}, @@ -393,18 +423,18 @@ func loadTestSetupCommand(c *Context, command *model.Command) bool { utils.Range{numPosts, numPosts}, doFuzz) if err != true { - l4g.Error("Failed to create testing enviroment") + l4g.Error("Failed to create testing environment") return true } else { - l4g.Info("Testing enviroment created") - for i := 0; i < len(enviroment.Teams); i++ { - l4g.Info("Team Created: " + enviroment.Teams[i].Name) - l4g.Info("\t User to login: " + enviroment.Enviroments[i].Users[0].Email + ", " + USER_PASSWORD) + l4g.Info("Testing environment created") + for i := 0; i < len(environment.Teams); i++ { + l4g.Info("Team Created: " + environment.Teams[i].Name) + l4g.Info("\t User to login: " + environment.Environments[i].Users[0].Email + ", " + USER_PASSWORD) } } } else { client.MockSession(c.Session.Token) - CreateTestEnviromentInTeam( + CreateTestEnvironmentInTeam( client, c.Session.TeamId, utils.Range{numChannels, numChannels}, @@ -416,7 +446,7 @@ func loadTestSetupCommand(c *Context, command *model.Command) bool { } else if strings.Index(cmd, command.Command) == 0 { command.AddSuggestion(&model.SuggestCommand{ Suggestion: cmd, - Description: "Creates a testing enviroment in current team. [teams] [fuzz] <Num Channels> <Num Users> <NumPosts>"}) + Description: "Creates a testing environment in current team. [teams] [fuzz] <Num Channels> <Num Users> <NumPosts>"}) } return false |