Browse Source

Improve in-channel checking

tags/v0.2.2
Russ Garrett 7 years ago
parent
commit
864fa1b028
No account linked to committer's email address
2 changed files with 12 additions and 8 deletions
  1. 4
    0
      auth.go
  2. 8
    8
      command.go

+ 4
- 0
auth.go View File

@@ -5,6 +5,10 @@ import (
5 5
 	"strings"
6 6
 )
7 7
 
8
+func (i *IRCCat) inChannel(channel string) bool {
9
+	return i.channels.Contains(channel)
10
+}
11
+
8 12
 func (i *IRCCat) authorisedUser(nick string) bool {
9 13
 	_, exists := i.auth_users[nick]
10 14
 	return exists

+ 8
- 8
command.go View File

@@ -15,17 +15,17 @@ func (i *IRCCat) handleCommand(event *irc.Event) {
15 15
 	msg := event.Message()
16 16
 	channel := ""
17 17
 	respond_to := event.Arguments[0]
18
-	if respond_to[0] != '#' {
19
-		respond_to = event.Nick
20
-	} else {
18
+
19
+	if i.inChannel(respond_to) {
21 20
 		channel = respond_to
21
+	} else {
22
+		respond_to = event.Nick
23
+		if !i.authorisedUser(event.Nick) {
24
+			log.Infof("Unauthorised command: %s (%s) %s", event.Nick, respond_to, msg)
25
+			return
26
+		}
22 27
 	}
23 28
 
24
-	if event.Arguments[0][0] != '#' && !i.authorisedUser(event.Nick) {
25
-		// Command not in a channel, or not from an authorised user
26
-		log.Infof("Unauthorised command: %s (%s) %s", event.Nick, respond_to, msg)
27
-		return
28
-	}
29 29
 	log.Infof("Authorised command: %s (%s) %s", event.Nick, respond_to, msg)
30 30
 
31 31
 	parts := strings.SplitN(msg, " ", 2)

Loading…
Cancel
Save