Allow formatting codes in the MOTD

This commit is contained in:
Daniel Oaks 2017-10-08 20:17:49 +10:00
parent 095e71b2fe
commit 695faefd93
6 changed files with 82 additions and 2 deletions

View File

@ -15,6 +15,7 @@ add-files = mkdir -p $1; \
cp ./docs/README $1; \ cp ./docs/README $1; \
mkdir -p $1/docs; \ mkdir -p $1/docs; \
cp ./CHANGELOG.md $1/docs/; \ cp ./CHANGELOG.md $1/docs/; \
cp ./docs/*.md $1/docs/; \
cp ./docs/logo* $1/docs/; cp ./docs/logo* $1/docs/;
all: clean windows osx linux arm6 all: clean windows osx linux arm6

56
docs/FORMATTING.md Normal file
View File

@ -0,0 +1,56 @@
# MOTD Formatting Codes
If `motd-formatting` is enabled in the config file, you can use special escape codes to
easily get bold, coloured, italic, and other types of specially-formatted text.
Our formatting character is '$', and this followed by specific letters means that the text
after it is formatted in the given way. Here are the character pairs and what they output:
--------------------------
Escape | Output
--------------------------
$$ | Dollar sign ($)
$b | Bold
$c | Color code
$i | Italics
$u | Underscore
$r | Reset
--------------------------
## Color codes
After the color code (`$c`), you can use square brackets to specify which foreground and
background colors to output. For example:
This line outputs red text:
`This is $c[red]really cool text!`
This line outputs red text with a light blue background:
`This is $c[red,light blue]22% cooler!`
If you're familiar with IRC colors you can also use the raw numbers you're used to:
`This is $c13pink text`
Here are the color names we support, and which IRC colors they map to:
--------------------
Code | Name
--------------------
00 | white
01 | black
02 | blue
03 | green
04 | red
05 | brown
06 | magenta
07 | orange
08 | yellow
09 | light green
10 | cyan
11 | light cyan
12 | light blue
13 | pink
14 | grey
15 | light grey
--------------------

View File

@ -180,6 +180,7 @@ type Config struct {
STS STSConfig STS STSConfig
CheckIdent bool `yaml:"check-ident"` CheckIdent bool `yaml:"check-ident"`
MOTD string MOTD string
MOTDFormatting bool `yaml:"motd-formatting"`
ProxyAllowedFrom []string `yaml:"proxy-allowed-from"` ProxyAllowedFrom []string `yaml:"proxy-allowed-from"`
MaxSendQString string `yaml:"max-sendq"` MaxSendQString string `yaml:"max-sendq"`
MaxSendQBytes uint64 MaxSendQBytes uint64

View File

@ -1423,7 +1423,7 @@ func (server *Server) applyConfig(config *Config, initial bool) error {
newISupportReplies = oldISupportList.GetDifference(server.isupport) newISupportReplies = oldISupportList.GetDifference(server.isupport)
} }
server.loadMOTD(config.Server.MOTD) server.loadMOTD(config.Server.MOTD, config.Server.MOTDFormatting)
// reload logging config // reload logging config
err = server.logger.ApplyConfig(config.Logging) err = server.logger.ApplyConfig(config.Logging)
@ -1462,7 +1462,7 @@ func (server *Server) applyConfig(config *Config, initial bool) error {
return nil return nil
} }
func (server *Server) loadMOTD(motdPath string) error { func (server *Server) loadMOTD(motdPath string, useFormatting bool) error {
server.logger.Debug("rehash", "Loading MOTD") server.logger.Debug("rehash", "Loading MOTD")
motdLines := make([]string, 0) motdLines := make([]string, 0)
if motdPath != "" { if motdPath != "" {
@ -1477,6 +1477,11 @@ func (server *Server) loadMOTD(motdPath string) error {
break break
} }
line = strings.TrimRight(line, "\r\n") line = strings.TrimRight(line, "\r\n")
if useFormatting {
line = ircfmt.Unescape(line)
}
// "- " is the required prefix for MOTD, we just add it here to make // "- " is the required prefix for MOTD, we just add it here to make
// bursting it out to clients easier // bursting it out to clients easier
line = fmt.Sprintf("- %s", line) line = fmt.Sprintf("- %s", line)

View File

@ -7,3 +7,16 @@
This is the default Oragono MOTD. This is the default Oragono MOTD.
If motd-formatting is enabled in the config file, you can use the dollarsign character to
create special formatting such as bold, italics and color codes.
For example, here are a few formatted lines (enable motd-formatting to see these in action):
- this is $bbold text$r.
- this is $iitalics text$r.
- this is $c[red]red$c and $c[blue]blue$c text.
- this is $c[red,light blue]red text with a light blue background$c.
- this is a normal escaped dollarsign: $$
For more information on using these, see MOTDFORMATTING.md

View File

@ -54,6 +54,10 @@ server:
# if you change the motd, you should move it to ircd.motd # if you change the motd, you should move it to ircd.motd
motd: oragono.motd motd: oragono.motd
# motd formatting codes
# if this is true, the motd is escaped using formatting codes like $c, $b, and $i
#motd-formatting: true
# addresses/hostnames the PROXY command can be used from # addresses/hostnames the PROXY command can be used from
# this should be restricted to 127.0.0.1 and localhost at most # this should be restricted to 127.0.0.1 and localhost at most
# you should also add these addresses to the connection limits and throttling exemption lists # you should also add these addresses to the connection limits and throttling exemption lists