Skip to content

Commit

Permalink
Merge pull request #22 from infracloudio/develop
Browse files Browse the repository at this point in the history
Merge develop to master
  • Loading branch information
sanketsudake authored Jan 22, 2019
2 parents 1c9f0a4 + 92c83d5 commit 2999903
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 13 deletions.
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

0 comments on commit 2999903

Please sign in to comment.