Browse Source

minor: Only execute command when commands.handler is defined

tags/v0.3.0
Harry Reeder 6 years ago
parent
commit
f5e16b9b6b
1 changed files with 16 additions and 12 deletions
  1. 16
    12
      command.go

+ 16
- 12
command.go View File

@@ -3,12 +3,13 @@ package main
3 3
 import (
4 4
 	"bytes"
5 5
 	"fmt"
6
-	"github.com/irccloud/go-ircevent"
7
-	"github.com/spf13/viper"
8 6
 	"os"
9 7
 	"os/exec"
10 8
 	"strings"
11 9
 	"time"
10
+
11
+	"github.com/irccloud/go-ircevent"
12
+	"github.com/spf13/viper"
12 13
 )
13 14
 
14 15
 func (i *IRCCat) handleCommand(event *irc.Event) {
@@ -35,17 +36,20 @@ func (i *IRCCat) handleCommand(event *irc.Event) {
35 36
 		args = parts[1]
36 37
 	}
37 38
 
38
-	cmd := exec.Command(viper.GetString("commands.handler"))
39
-	cmd.Env = append(os.Environ(), fmt.Sprintf("IRCCAT_NICK=%s", event.Nick),
40
-		fmt.Sprintf("IRCCAT_USER=%s", event.User),
41
-		fmt.Sprintf("IRCCAT_HOST=%s", event.Host),
42
-		fmt.Sprintf("IRCCAT_CHANNEL=%s", channel),
43
-		fmt.Sprintf("IRCCAT_RESPOND_TO=%s", respond_to),
44
-		fmt.Sprintf("IRCCAT_COMMAND=%s", parts[0][1:]),
45
-		fmt.Sprintf("IRCCAT_ARGS=%s", args),
46
-		fmt.Sprintf("IRCCAT_RAW=%s", event.Raw))
39
+	handler := viper.GetString("commands.handler")
40
+	if handler != "" {
41
+		cmd := exec.Command(handler)
42
+		cmd.Env = append(os.Environ(), fmt.Sprintf("IRCCAT_NICK=%s", event.Nick),
43
+			fmt.Sprintf("IRCCAT_USER=%s", event.User),
44
+			fmt.Sprintf("IRCCAT_HOST=%s", event.Host),
45
+			fmt.Sprintf("IRCCAT_CHANNEL=%s", channel),
46
+			fmt.Sprintf("IRCCAT_RESPOND_TO=%s", respond_to),
47
+			fmt.Sprintf("IRCCAT_COMMAND=%s", parts[0][1:]),
48
+			fmt.Sprintf("IRCCAT_ARGS=%s", args),
49
+			fmt.Sprintf("IRCCAT_RAW=%s", event.Raw))
47 50
 
48
-	i.runCommand(cmd, respond_to)
51
+		i.runCommand(cmd, respond_to)
52
+	}
49 53
 }
50 54
 
51 55
 // Run a command with the output going to the nick/channel identified by respond_to

Loading…
Cancel
Save