Skip to content

Commit

Permalink
[WIP] Colorize username sent to IRC using its crc32 IEEE checksum (#423)
Browse files Browse the repository at this point in the history
* Colorize username sent to IRC using its crc32 IEEE checksum

* Add `ColorNicks` configuration variable

* Add `ColorNicks` setting
  • Loading branch information
yuvallanger authored and 42wim committed May 11, 2018
1 parent 75381c2 commit f0738a9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions bridge/config/config.go
Expand Up @@ -62,6 +62,7 @@ type Protocol struct {
BindAddress string // mattermost, slack // DEPRECATED
Buffer int // api
Charset string // irc
ColorNicks bool // only irc for now
Debug bool // general
DebugLevel int // only for irc now
EditSuffix string // mattermost, slack, discord, telegram, gitter
Expand Down
10 changes: 8 additions & 2 deletions bridge/irc/irc.go
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/paulrosania/go-charset/charset"
_ "github.com/paulrosania/go-charset/data"
"github.com/saintfish/chardet"
"hash/crc32"
"io"
"io/ioutil"
"net"
Expand Down Expand Up @@ -246,11 +247,16 @@ func (b *Birc) doSend() {
throttle := time.NewTicker(rate)
for msg := range b.Local {
<-throttle.C
username := msg.Username
if b.GetBool("Colornicks") {
checksum := crc32.ChecksumIEEE([]byte(msg.Username))
username = fmt.Sprintf("\x03%d%s\x03", checksum%0x10, msg.Username)
}
if msg.Event == config.EVENT_USER_ACTION {
b.i.Cmd.Action(msg.Channel, msg.Username+msg.Text)
b.i.Cmd.Action(msg.Channel, username+msg.Text)
} else {
b.Log.Debugf("Sending to channel %s", msg.Channel)
b.i.Cmd.Message(msg.Channel, msg.Username+msg.Text)
b.i.Cmd.Message(msg.Channel, username+msg.Text)
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions matterbridge.toml.sample
Expand Up @@ -92,6 +92,10 @@ MessageSplit=false
#OPTIONAL (default 0)
RejoinDelay=0

#ColorNicks will show each nickname in a different color.
#Only works in IRC right now.
ColorNicks=false

#Nicks you want to ignore.
#Messages from those users will not be sent to other bridges.
#OPTIONAL
Expand Down

0 comments on commit f0738a9

Please sign in to comment.