3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-25 13:29:27 +01:00

opers: Allow setting custom whois lines

This commit is contained in:
Daniel Oaks 2016-10-23 11:01:05 +10:00
parent 64bdedaee2
commit f3459830e7
4 changed files with 32 additions and 7 deletions

View File

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

View File

@ -11,6 +11,7 @@ import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"log" "log"
"strings"
"gopkg.in/yaml.v2" "gopkg.in/yaml.v2"
) )
@ -68,6 +69,7 @@ type AccountRegistrationConfig struct {
type OperClassConfig struct { type OperClassConfig struct {
Title string Title string
WhoisLine string
Extends string Extends string
Capabilities []string Capabilities []string
} }
@ -75,6 +77,7 @@ type OperClassConfig struct {
type OperConfig struct { type OperConfig struct {
Class string Class string
Vhost string Vhost string
WhoisLine string `yaml:"whois-line"`
Password string Password string
} }
@ -130,6 +133,7 @@ type Config struct {
type OperClass struct { type OperClass struct {
Title string Title string
WhoisLine string `yaml:"whois-line"`
Capabilities map[string]bool // map to make lookups much easier Capabilities map[string]bool // map to make lookups much easier
} }
@ -179,6 +183,16 @@ func (conf *Config) OperatorClasses() (*map[string]OperClass, error) {
for _, capab := range info.Capabilities { for _, capab := range info.Capabilities {
oc.Capabilities[capab] = true oc.Capabilities[capab] = true
} }
if len(info.WhoisLine) > 0 {
oc.WhoisLine = info.WhoisLine
} else {
oc.WhoisLine = "is a"
if strings.Contains(strings.ToLower(string(oc.Title[0])), "aeiou") {
oc.WhoisLine += "n"
}
oc.WhoisLine += " "
oc.WhoisLine += oc.Title
}
ocs[name] = oc ocs[name] = oc
} }
@ -194,6 +208,7 @@ func (conf *Config) OperatorClasses() (*map[string]OperClass, error) {
type Oper struct { type Oper struct {
Class *OperClass Class *OperClass
WhoisLine string
Pass []byte Pass []byte
} }
@ -214,6 +229,11 @@ func (conf *Config) Operators(oc *map[string]OperClass) (map[string]Oper, error)
return nil, fmt.Errorf("Could not load operator [%s] - they use operclass [%s] which does not exist", name, opConf.Class) return nil, fmt.Errorf("Could not load operator [%s] - they use operclass [%s] which does not exist", name, opConf.Class)
} }
oper.Class = &class oper.Class = &class
if len(opConf.WhoisLine) > 0 {
oper.WhoisLine = opConf.WhoisLine
} else {
oper.WhoisLine = class.WhoisLine
}
// successful, attach to list of opers // successful, attach to list of opers
operators[name] = oper operators[name] = oper

View File

@ -799,8 +799,8 @@ func (client *Client) getWhoisOf(target *Client) {
for _, line := range client.WhoisChannelsNames(target) { for _, line := range client.WhoisChannelsNames(target) {
client.Send(nil, client.server.name, RPL_WHOISCHANNELS, client.nick, target.nick, line) client.Send(nil, client.server.name, RPL_WHOISCHANNELS, client.nick, target.nick, line)
} }
if target.flags[Operator] { if target.class != nil {
client.Send(nil, client.server.name, RPL_WHOISOPERATOR, client.nick, target.nick, "is an IRC operator") client.Send(nil, client.server.name, RPL_WHOISOPERATOR, client.nick, target.nick, target.whoisLine)
} }
if target.certfp != "" && (client.flags[Operator] || client == target) { if target.certfp != "" && (client.flags[Operator] || client == target) {
client.Send(nil, client.server.name, RPL_WHOISCERTFP, client.nick, target.nick, fmt.Sprintf("has client certificate fingerprint %s", target.certfp)) 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 {
client.operName = name client.operName = name
client.class = server.operators[name].Class client.class = server.operators[name].Class
server.currentOpers[client] = true server.currentOpers[client] = true
client.whoisLine = server.operators[name].WhoisLine
//TODO(dan): push out CHGHOST if vhost is applied //TODO(dan): push out CHGHOST if vhost is applied

View File

@ -106,6 +106,9 @@ opers:
# which capabilities this oper has access to # which capabilities this oper has access to
class: "server-admin" class: "server-admin"
# custom whois line
whois-line: is a cool dude
# custom hostname # custom hostname
vhost: "n" vhost: "n"