commit dcb9f84fba9c98e2a0497072336eb906f90fde30 parent 9a92b967b37bcebc802e15c5cd46a04b10c4d2d4 Author: Natasha Kerensikova <natgh@instinctive.eu> Date: Wed, 13 Aug 2025 17:52:10 +0000 Base-64 fallback when hexadecimal output is too long Diffstat:
M | main.go | | | 8 | ++++++-- |
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/main.go b/main.go @@ -91,6 +91,7 @@ type IrcConfig struct { BlockCmd []string BlockSend []string MaxQuoteRatio float32 + MaxHex int } type LogConfig struct { @@ -671,10 +672,13 @@ func (natsim *NatsIM) ircQuoteData(data []byte) string { } quoted.WriteString(strings.Repeat("\\n", suffix)) - if quoted.Len() >= int(natsim.Irc.MaxQuoteRatio*float32(len(data))) { + if quoted.Len() < int(natsim.Irc.MaxQuoteRatio*float32(len(data))) { + return quoted.String() + } else if 2*len(data) <= natsim.Irc.MaxHex { return "#" + hex.EncodeToString(data) + "#" + } else { + return "|" + base64.StdEncoding.EncodeToString(data) + "|" } - return quoted.String() } func (natsim *NatsIM) ircReceive(e *irc.Event) {