diff --git a/holobot.go b/holobot.go index 1441d5b..262cdb5 100644 --- a/holobot.go +++ b/holobot.go @@ -12,6 +12,7 @@ import ( "regexp" "strings" "time" + "math/rand" ) type Config struct { @@ -148,6 +149,16 @@ func main() { }, }, */ + Command{ + Name: "randombuddy", + Description: "Invites a random member of the privateTeam to chat with you.", + Handler: func(event *model.WebSocketEvent, post *model.Post) error { + user := GetRandomUserInTeam(privateTeam) + client.AddChannelMember(event.Broadcast.ChannelId, user.Id) + SendMsgToChannel(event.Broadcast.ChannelId, "Have a happy buddy chat!", post.Id) + return nil + } + }, // time command Command{ Name: "time", @@ -192,6 +203,8 @@ func main() { loc = "Asia/Kolkata" case "ADT", "AEDT", "ASDT", "AUSTRALIA", "MELBOURNE": loc = "Australia/Melbourne" + case "BRT", "BRST", "BRASIL", "BRAZILLIAN": + loc = "America/Sao_Paulo" default: loc = m[4] //default } @@ -250,12 +263,14 @@ func main() { ist := t.In(istl).Format("3:04 PM") adtl, _ := time.LoadLocation("Australia/Melbourne") adt := t.In(adtl).Format("3:04 PM") + brtl, _ := time.LoadLocation("America/Sao Paulo") + brt := t.In(brtl).Format("3:04 PM") // and prints them in a table timeZoneText = fmt.Sprintf(`"%s" is: -| PT | MT | CT | ET | GMT | CET | IST | ADT | +| PT | MT | CT | ET | GMT | CET | IST | ADT | BRT | |:--------:|:---------:|:--------:|:--------:|:-------:|:------:|:--------:|:--------:| -| %s | %s | %s | %s | %s | %s | %s | %s |`, m[0], pt, mt, ct, et, gmt, cet, ist, adt) +| %s | %s | %s | %s | %s | %s | %s | %s |`, m[0], pt, mt, ct, et, gmt, cet, ist, adt, brt) // make a debugging message with extra info about the above processes debuggingTimeZoneText = fmt.Sprintf("➚ **Debugging Info:**\n(%v)\nTime zone I heard (m[4]) was: %v\nLocation (l): %v\nPost.Id: %v\npost.RootId: %v", t, m[4], l, post.Id, post.RootId) @@ -341,6 +356,21 @@ func UpdateTheBotUserIfNeeded() { } } +func GetRandomUserInTeam(team *model.Team) *model.User { + userList, resp := client.GetUsersInTeam(team, 0, 200, "") + if rest.Error != nil { + println("We failed list users") + PrintError(resp.Error) + os.Exit(1) + return nil + } + if config.Debugging { + fmt.Printf("Trying to get a random user in team %v", team) + } + selectedPos := rand.Intn(len(userList)) + return userList[selectedPos] +} + func FindTeam(name string) *model.Team { team, resp := client.GetTeamByName(name, "") if resp.Error != nil {