From 695faefd93746b5e4ecc0bd8abffe6111c317cf7 Mon Sep 17 00:00:00 2001 From: Daniel Oaks Date: Sun, 8 Oct 2017 20:17:49 +1000 Subject: [PATCH] Allow formatting codes in the MOTD --- Makefile | 1 + docs/FORMATTING.md | 56 ++++++++++++++++++++++++++++++++++++++++++++++ irc/config.go | 1 + irc/server.go | 9 ++++++-- oragono.motd | 13 +++++++++++ oragono.yaml | 4 ++++ 6 files changed, 82 insertions(+), 2 deletions(-) create mode 100644 docs/FORMATTING.md diff --git a/Makefile b/Makefile index f4da7f6b..36e76fcd 100644 --- a/Makefile +++ b/Makefile @@ -15,6 +15,7 @@ add-files = mkdir -p $1; \ cp ./docs/README $1; \ mkdir -p $1/docs; \ cp ./CHANGELOG.md $1/docs/; \ + cp ./docs/*.md $1/docs/; \ cp ./docs/logo* $1/docs/; all: clean windows osx linux arm6 diff --git a/docs/FORMATTING.md b/docs/FORMATTING.md new file mode 100644 index 00000000..8b9b86d4 --- /dev/null +++ b/docs/FORMATTING.md @@ -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 + -------------------- diff --git a/irc/config.go b/irc/config.go index 825a68b9..be5b3d37 100644 --- a/irc/config.go +++ b/irc/config.go @@ -180,6 +180,7 @@ type Config struct { STS STSConfig CheckIdent bool `yaml:"check-ident"` MOTD string + MOTDFormatting bool `yaml:"motd-formatting"` ProxyAllowedFrom []string `yaml:"proxy-allowed-from"` MaxSendQString string `yaml:"max-sendq"` MaxSendQBytes uint64 diff --git a/irc/server.go b/irc/server.go index 51048d01..e3f3c704 100644 --- a/irc/server.go +++ b/irc/server.go @@ -1423,7 +1423,7 @@ func (server *Server) applyConfig(config *Config, initial bool) error { newISupportReplies = oldISupportList.GetDifference(server.isupport) } - server.loadMOTD(config.Server.MOTD) + server.loadMOTD(config.Server.MOTD, config.Server.MOTDFormatting) // reload logging config err = server.logger.ApplyConfig(config.Logging) @@ -1462,7 +1462,7 @@ func (server *Server) applyConfig(config *Config, initial bool) error { return nil } -func (server *Server) loadMOTD(motdPath string) error { +func (server *Server) loadMOTD(motdPath string, useFormatting bool) error { server.logger.Debug("rehash", "Loading MOTD") motdLines := make([]string, 0) if motdPath != "" { @@ -1477,6 +1477,11 @@ func (server *Server) loadMOTD(motdPath string) error { break } 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 // bursting it out to clients easier line = fmt.Sprintf("- %s", line) diff --git a/oragono.motd b/oragono.motd index 4c08868f..14d88974 100644 --- a/oragono.motd +++ b/oragono.motd @@ -7,3 +7,16 @@ 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 diff --git a/oragono.yaml b/oragono.yaml index b759cece..55f566b6 100644 --- a/oragono.yaml +++ b/oragono.yaml @@ -54,6 +54,10 @@ server: # if you change the motd, you should move it to ircd.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 # 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