Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge develop to master #22

Merged
merged 9 commits into from
Jan 22, 2019
2 changes: 1 addition & 1 deletion helm/botkube/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ replicaCount: 1

image:
repository: infracloud/botkube
tag: "0.2"
tag: "0.4"
pullPolicy: Always

nameOverride: ""
Expand Down
16 changes: 8 additions & 8 deletions pkg/execute/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var kubectlBinary = "/usr/local/bin/kubectl"
const (
notifierStartMsg = "Brace yourselves, notifications are coming."
notifierStopMsg = "Sure! I won't send you notifications anymore."
unsupportedCmdMsg = "Command not supported. Please run '@botkube help' to see supported commands."
unsupportedCmdMsg = "Command not supported. Please run '@BotKube help' to see supported commands."
kubectlDisabledMsg = "Sorry, the admin hasn't given me the permission to execute kubectl command."
)

Expand Down Expand Up @@ -79,19 +79,19 @@ func printHelp() string {
for k := range validKubectlCommands {
allowedKubectl = allowedKubectl + k + ", "
}
helpMsg := "botkube executes kubectl commands on k8s cluster and returns output.\n" +
helpMsg := "BotKube executes kubectl commands on k8s cluster and returns output.\n" +
"Usages:\n" +
" @botkube <kubectl command without `kubectl` prefix>\n" +
" @BotKube <kubectl command without `kubectl` prefix>\n" +
"e.g:\n" +
" @botkube get pods\n" +
" @botkube logs podname -n namespace\n" +
" @BotKube get pods\n" +
" @BotKube logs podname -n namespace\n" +
"Allowed kubectl commands:\n" +
" " + allowedKubectl + "\n\n" +
"Commands to manage notifier:\n" +
"notifier stop Stop sending k8s event notifications to slack (started by default)\n" +
"notifier start Start sending k8s event notifications to slack\n" +
"notifier stop Stop sending k8s event notifications to Slack (started by default)\n" +
"notifier start Start sending k8s event notifications to Slack\n" +
"notifier status Show running status of event notifier\n" +
"notifier showconfig Show botkube configuration for event notifier\n\n" +
"notifier showconfig Show BotKube configuration for event notifier\n\n" +
"Other Commands:\n" +
"help Show help\n" +
"ping Check connection health\n"
Expand Down
35 changes: 31 additions & 4 deletions pkg/slack/slack.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,43 @@ func (b *Bot) Start() {
logging.Logger.Debug("Connection Info: ", ev.Info)

case *slack.MessageEvent:
// Serve only if mentioned
if !strings.HasPrefix(ev.Text, "<@"+botID+"> ") {
// Skip if message posted by BotKube
if ev.User == botID {
continue
}

// Check if message posted in a channel
_, err := api.GetChannelInfo(ev.Channel)
if err == nil {
// Message posted in a channel
// Serve only if starts with mention
if !strings.HasPrefix(ev.Text, "<@"+botID+"> ") {
continue
}
} else {
// Check if message posted in a group
_, err := api.GetGroupInfo(ev.Channel)
if err == nil {
// Message posted in a group
// Serve only if starts with mention
if !strings.HasPrefix(ev.Text, "<@"+botID+"> ") {
continue
}
}
}

// Message posted as a DM
logging.Logger.Debugf("Slack incoming message: %+v", ev)
msg := strings.TrimPrefix(ev.Text, "<@"+botID+"> ")
inMessage := ev.Text

// Trim @BotKube prefix if exists
if strings.HasPrefix(ev.Text, "<@"+botID+"> ") {
inMessage = strings.TrimPrefix(ev.Text, "<@"+botID+"> ")
}
sm := slackMessage{
ChannelID: ev.Channel,
BotID: botID,
InMessage: msg,
InMessage: inMessage,
RTM: rtm,
}
sm.HandleMessage(b.AllowKubectl)
Expand Down