Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions holobot.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"regexp"
"strings"
"time"
"math/rand"
)

type Config struct {
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down