This repository has been archived by the owner on Oct 21, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
welcome.go
68 lines (57 loc) · 1.9 KB
/
welcome.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package welcome
import (
"fmt"
"github.com/nlopes/slack"
"github.com/ubclaunchpad/rocket/bot"
"github.com/ubclaunchpad/rocket/cmd"
)
// Plugin stores the bot that is used to access the Slack API.
type Plugin struct {
Bot *bot.Bot
}
// New reutrns a new instance of the WelcomePlugin
func New(b *bot.Bot) *Plugin {
return &Plugin{
Bot: b,
}
}
// Start starts the welcome plugin.
func (wp *Plugin) Start() error {
wp.Bot.Log.Info("Running WelcomePlugin")
return nil
}
// Commands returns an empty list of commands, because this plugin has no
// commands.
func (wp *Plugin) Commands() []*cmd.Command {
return []*cmd.Command{}
}
// EventHandlers returns a map from event type to event handler.
func (wp *Plugin) EventHandlers() map[string]bot.EventHandler {
return map[string]bot.EventHandler{
"team_join": wp.handleTeamJoin,
}
}
// handleTeamJoin welcomes a user to our Slack when they join be messaging
// them in the general channel.
func (wp *Plugin) handleTeamJoin(evt slack.RTMEvent) {
user := evt.Data.(*slack.TeamJoinEvent).User
userMention := cmd.ToMention(user.ID)
// Post a welcome message in #general
msg := fmt.Sprintf("Welcome to the team, %s! :rocket:", userMention)
noParams := slack.PostMessageParameters{}
wp.Bot.API.PostMessage("general", msg, noParams)
// Send the user a private message asking them to update their info
msg = fmt.Sprintf("Hi %s, please update your profile information with "+
"the `set` command:\n"+
"`@rocket set github={myGitHubUsername} position={a fun position} "+
"major={myUBCMajor}`\n"+
"If you need help using Rocket commands, try `@rocket help`", userMention)
_, _, channelID, err := wp.Bot.API.OpenIMChannel(user.ID)
if err != nil {
// If this fails it's not the end of the world - just log an error
wp.Bot.Log.WithError(err).Errorf(
"failed to send %s a private message", user.Name)
return
}
wp.Bot.API.PostMessage(channelID, msg, noParams)
}