Browse Source

opers: Allow setting custom whois lines

tags/v0.4.0
Daniel Oaks 7 years ago
parent
commit
f3459830e7
4 changed files with 32 additions and 7 deletions
  1. 1
    0
      irc/client.go
  2. 25
    5
      irc/config.go
  3. 3
    2
      irc/server.go
  4. 3
    0
      oragono.yaml

+ 1
- 0
irc/client.go View File

@@ -61,6 +61,7 @@ type Client struct {
61 61
 	server             *Server
62 62
 	socket             *Socket
63 63
 	username           string
64
+	whoisLine          string
64 65
 }
65 66
 
66 67
 // NewClient returns a client with all the appropriate info setup.

+ 25
- 5
irc/config.go View File

@@ -11,6 +11,7 @@ import (
11 11
 	"fmt"
12 12
 	"io/ioutil"
13 13
 	"log"
14
+	"strings"
14 15
 
15 16
 	"gopkg.in/yaml.v2"
16 17
 )
@@ -68,14 +69,16 @@ type AccountRegistrationConfig struct {
68 69
 
69 70
 type OperClassConfig struct {
70 71
 	Title        string
72
+	WhoisLine    string
71 73
 	Extends      string
72 74
 	Capabilities []string
73 75
 }
74 76
 
75 77
 type OperConfig struct {
76
-	Class    string
77
-	Vhost    string
78
-	Password string
78
+	Class     string
79
+	Vhost     string
80
+	WhoisLine string `yaml:"whois-line"`
81
+	Password  string
79 82
 }
80 83
 
81 84
 func (conf *OperConfig) PasswordBytes() []byte {
@@ -130,6 +133,7 @@ type Config struct {
130 133
 
131 134
 type OperClass struct {
132 135
 	Title        string
136
+	WhoisLine    string          `yaml:"whois-line"`
133 137
 	Capabilities map[string]bool // map to make lookups much easier
134 138
 }
135 139
 
@@ -179,6 +183,16 @@ func (conf *Config) OperatorClasses() (*map[string]OperClass, error) {
179 183
 			for _, capab := range info.Capabilities {
180 184
 				oc.Capabilities[capab] = true
181 185
 			}
186
+			if len(info.WhoisLine) > 0 {
187
+				oc.WhoisLine = info.WhoisLine
188
+			} else {
189
+				oc.WhoisLine = "is a"
190
+				if strings.Contains(strings.ToLower(string(oc.Title[0])), "aeiou") {
191
+					oc.WhoisLine += "n"
192
+				}
193
+				oc.WhoisLine += " "
194
+				oc.WhoisLine += oc.Title
195
+			}
182 196
 
183 197
 			ocs[name] = oc
184 198
 		}
@@ -193,8 +207,9 @@ func (conf *Config) OperatorClasses() (*map[string]OperClass, error) {
193 207
 }
194 208
 
195 209
 type Oper struct {
196
-	Class *OperClass
197
-	Pass  []byte
210
+	Class     *OperClass
211
+	WhoisLine string
212
+	Pass      []byte
198 213
 }
199 214
 
200 215
 func (conf *Config) Operators(oc *map[string]OperClass) (map[string]Oper, error) {
@@ -214,6 +229,11 @@ func (conf *Config) Operators(oc *map[string]OperClass) (map[string]Oper, error)
214 229
 			return nil, fmt.Errorf("Could not load operator [%s] - they use operclass [%s] which does not exist", name, opConf.Class)
215 230
 		}
216 231
 		oper.Class = &class
232
+		if len(opConf.WhoisLine) > 0 {
233
+			oper.WhoisLine = opConf.WhoisLine
234
+		} else {
235
+			oper.WhoisLine = class.WhoisLine
236
+		}
217 237
 
218 238
 		// successful, attach to list of opers
219 239
 		operators[name] = oper

+ 3
- 2
irc/server.go View File

@@ -799,8 +799,8 @@ func (client *Client) getWhoisOf(target *Client) {
799 799
 	for _, line := range client.WhoisChannelsNames(target) {
800 800
 		client.Send(nil, client.server.name, RPL_WHOISCHANNELS, client.nick, target.nick, line)
801 801
 	}
802
-	if target.flags[Operator] {
803
-		client.Send(nil, client.server.name, RPL_WHOISOPERATOR, client.nick, target.nick, "is an IRC operator")
802
+	if target.class != nil {
803
+		client.Send(nil, client.server.name, RPL_WHOISOPERATOR, client.nick, target.nick, target.whoisLine)
804 804
 	}
805 805
 	if target.certfp != "" && (client.flags[Operator] || client == target) {
806 806
 		client.Send(nil, client.server.name, RPL_WHOISCERTFP, client.nick, target.nick, fmt.Sprintf("has client certificate fingerprint %s", target.certfp))
@@ -902,6 +902,7 @@ func operHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool {
902 902
 	client.operName = name
903 903
 	client.class = server.operators[name].Class
904 904
 	server.currentOpers[client] = true
905
+	client.whoisLine = server.operators[name].WhoisLine
905 906
 
906 907
 	//TODO(dan): push out CHGHOST if vhost is applied
907 908
 

+ 3
- 0
oragono.yaml View File

@@ -106,6 +106,9 @@ opers:
106 106
         # which capabilities this oper has access to
107 107
         class: "server-admin"
108 108
 
109
+        # custom whois line
110
+        whois-line: is a cool dude
111
+
109 112
         # custom hostname
110 113
         vhost: "n"
111 114
 

Loading…
Cancel
Save