strip color and formatting control codes from upstream messages
--HG-- branch : nmdc-ircfrontend
This commit is contained in:
parent
714e3b8437
commit
cac56a450a
3
TODO.txt
3
TODO.txt
@ -4,8 +4,6 @@ PRE-RELEASE
|
|||||||
|
|
||||||
- client descriptions (CTCP USERINFO)
|
- client descriptions (CTCP USERINFO)
|
||||||
|
|
||||||
- remove color code escape sequences
|
|
||||||
|
|
||||||
|
|
||||||
WISHLIST
|
WISHLIST
|
||||||
========
|
========
|
||||||
@ -58,3 +56,4 @@ https://github.com/eXeC64/Rosella AGPLv3 license
|
|||||||
|
|
||||||
https://github.com/edmund-huber/ergonomadic MIT license
|
https://github.com/edmund-huber/ergonomadic MIT license
|
||||||
|
|
||||||
|
http://en.wikichip.org/wiki/irc/colors
|
||||||
|
28
server.go
28
server.go
@ -25,6 +25,7 @@ import (
|
|||||||
"libnmdc"
|
"libnmdc"
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@ -172,6 +173,23 @@ func (s *Server) postGeneralMessageInRoom(msg string) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var rx_colorControlCode *regexp.Regexp = regexp.MustCompilePOSIX("\x03[0-9]+(,[0-9]+)?")
|
||||||
|
var rx_formattingControlCode *regexp.Regexp = regexp.MustCompile("(\x02|\x1D|\x1F|\x16|\x0F)")
|
||||||
|
|
||||||
|
func reformatOutgoingMessageBody(body string) string {
|
||||||
|
|
||||||
|
// Strip color codes
|
||||||
|
noColors := rx_colorControlCode.ReplaceAllString(body, "")
|
||||||
|
|
||||||
|
// Strip formatting codes
|
||||||
|
return rx_formattingControlCode.ReplaceAllString(noColors, "")
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func reformatIncomingMessageBody(body string) string {
|
||||||
|
return body
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Server) upstreamWorker() {
|
func (s *Server) upstreamWorker() {
|
||||||
|
|
||||||
// Read loop
|
// Read loop
|
||||||
@ -210,14 +228,14 @@ func (s *Server) upstreamWorker() {
|
|||||||
s.sendChannelTopic(hubEvent.Nick)
|
s.sendChannelTopic(hubEvent.Nick)
|
||||||
|
|
||||||
case libnmdc.EVENT_PRIVATE:
|
case libnmdc.EVENT_PRIVATE:
|
||||||
s.reply(rplMsg, hubEvent.Nick+"!"+hubEvent.Nick+"@"+hubEvent.Nick, s.upstreamLauncher.Self.Nick, hubEvent.Message)
|
s.reply(rplMsg, hubEvent.Nick+"!"+hubEvent.Nick+"@"+hubEvent.Nick, s.upstreamLauncher.Self.Nick, reformatIncomingMessageBody(hubEvent.Message))
|
||||||
|
|
||||||
case libnmdc.EVENT_PUBLIC:
|
case libnmdc.EVENT_PUBLIC:
|
||||||
if hubEvent.Nick == s.upstreamLauncher.Self.Nick {
|
if hubEvent.Nick == s.upstreamLauncher.Self.Nick {
|
||||||
// irc doesn't echo our own pubchat
|
// irc doesn't echo our own pubchat
|
||||||
} else {
|
} else {
|
||||||
// nick!username@userhost, but for us all three of those are always identical
|
// nick!username@userhost, but for us all three of those are always identical
|
||||||
s.reply(rplMsg, hubEvent.Nick+"!"+hubEvent.Nick+"@"+hubEvent.Nick, BLESSED_CHANNEL, hubEvent.Message)
|
s.reply(rplMsg, hubEvent.Nick+"!"+hubEvent.Nick+"@"+hubEvent.Nick, BLESSED_CHANNEL, reformatIncomingMessageBody(hubEvent.Message))
|
||||||
}
|
}
|
||||||
|
|
||||||
case libnmdc.EVENT_SYSTEM_MESSAGE_FROM_CONN, libnmdc.EVENT_SYSTEM_MESSAGE_FROM_HUB:
|
case libnmdc.EVENT_SYSTEM_MESSAGE_FROM_CONN, libnmdc.EVENT_SYSTEM_MESSAGE_FROM_HUB:
|
||||||
@ -411,17 +429,17 @@ func (s *Server) handleJoinedCommand(command string, args []string) {
|
|||||||
|
|
||||||
if strings.HasPrefix(message, "\x01ACTION ") {
|
if strings.HasPrefix(message, "\x01ACTION ") {
|
||||||
message = "/me " + message[8:]
|
message = "/me " + message[8:]
|
||||||
message = message[:len(message)-1]
|
message = message[:len(message)-1] // trailing \x01
|
||||||
}
|
}
|
||||||
|
|
||||||
// IRC is case-insensitive case-preserving. We can respect that for the
|
// IRC is case-insensitive case-preserving. We can respect that for the
|
||||||
// channel name, but not really for user nicks
|
// channel name, but not really for user nicks
|
||||||
|
|
||||||
if strings.ToLower(args[0]) == BLESSED_CHANNEL {
|
if strings.ToLower(args[0]) == BLESSED_CHANNEL {
|
||||||
s.upstream.SayPublic(message)
|
s.upstream.SayPublic(reformatOutgoingMessageBody(message))
|
||||||
|
|
||||||
} else if s.upstream.UserExists(args[0]) {
|
} else if s.upstream.UserExists(args[0]) {
|
||||||
s.upstream.SayPrivate(args[0], message)
|
s.upstream.SayPrivate(args[0], reformatOutgoingMessageBody(message))
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
s.reply(errNoSuchNick, args[0])
|
s.reply(errNoSuchNick, args[0])
|
||||||
|
Loading…
Reference in New Issue
Block a user