Add a list of color code pairs for foreground and background IRC usernames

This commit is contained in:
Yuval Langer
2018-05-26 20:47:21 +03:00
parent ab1670e2ce
commit 1872c1898e
2 changed files with 55 additions and 2 deletions

View File

@@ -242,6 +242,25 @@ func (b *Birc) Send(msg config.Message) (string, error) {
return "", nil
}
func colorizeString(s string, foreground int64, background int64) string {
return fmt.Sprintf("\x03%02d,%02d%s\x03", foreground, background, s)
}
func (b *Birc) colorizeUsername(username string) string {
ircNickColors := b.GetStringSlice2D("ColorNicksList")
checksum := int(crc32.ChecksumIEEE([]byte(username)))
selectedColorPair := ircNickColors[checksum%len(ircNickColors)]
foreground, err := strconv.ParseInt(selectedColorPair[0], 16, 64)
if err == nil {
panic(fmt.Sprintf("Bad IRC color code: %v", selectedColorPair[0]))
}
background, err := strconv.ParseInt(selectedColorPair[1], 16, 64)
if err == nil {
panic(fmt.Sprintf("Bad IRC color code: %v", selectedColorPair[1]))
}
return colorizeString(username, foreground, background)
}
func (b *Birc) doSend() {
rate := time.Millisecond * time.Duration(b.MessageDelay)
throttle := time.NewTicker(rate)
@@ -249,8 +268,7 @@ func (b *Birc) doSend() {
<-throttle.C
username := msg.Username
if b.GetBool("Colornicks") {
checksum := crc32.ChecksumIEEE([]byte(msg.Username))
username = fmt.Sprintf("\x03%02d%s\x0F", checksum%0x10, msg.Username)
username = b.colorizeUsername(msg.Username)
}
if msg.Event == config.EVENT_USER_ACTION {
b.i.Cmd.Action(msg.Channel, username+msg.Text)

View File

@@ -96,6 +96,41 @@ RejoinDelay=0
#Only works in IRC right now.
ColorNicks=false
#ColorNicksList holds a list of pairs of [foreground, background] colors.
#Colors are represented by these numbers:
# White 0x0
# Black 0x1
# Blue 0x2
# Green 0x3
# Light Red 0x4
# Brown 0x5
# Purple 0x6
# Orange 0x7
# Yellow 0x8
# Light Green 0x9
# Cyan 0xa
# Light Cyan 0xb
# Light Blue 0xc
# Pink 0xd
# Grey 0xe
# Light Grey 0xf
ColorNicksList=[
[0x2, 0x1]
[0x3, 0x1]
[0x4, 0x1]
[0x5, 0x1]
[0x6, 0x1]
[0x7, 0x1]
[0x8, 0x1]
[0x9, 0x1]
[0xa, 0x1]
[0xb, 0x1]
[0xc, 0x1]
[0xd, 0x1]
[0xe, 0x1]
[0xf, 0x1]
]
#Nicks you want to ignore.
#Messages from those users will not be sent to other bridges.
#OPTIONAL