From e7fcb25107ff6f7676624fb3011e2bc1bede4cd0 Mon Sep 17 00:00:00 2001 From: Wim Date: Tue, 29 Aug 2017 21:30:59 +0200 Subject: Add a charset option (irc). Closes #247 --- bridge/irc/irc.go | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) (limited to 'bridge/irc') diff --git a/bridge/irc/irc.go b/bridge/irc/irc.go index 36b01b6c..5176389b 100644 --- a/bridge/irc/irc.go +++ b/bridge/irc/irc.go @@ -265,20 +265,25 @@ func (b *Birc) handlePrivMsg(event *irc.Event) { re := regexp.MustCompile(`[[:cntrl:]](\d+,|)\d+`) msg = re.ReplaceAllString(msg, "") - // detect what were sending so that we convert it to utf-8 - detector := chardet.NewTextDetector() - result, err := detector.DetectBest([]byte(msg)) - if err != nil { - flog.Infof("detection failed for msg: %#v", msg) - return - } - flog.Debugf("detected %s confidence %#v", result.Charset, result.Confidence) var r io.Reader - r, err = charset.NewReader(result.Charset, strings.NewReader(msg)) - // if we're not sure, just pick ISO-8859-1 - if result.Confidence < 80 { - r, err = charset.NewReader("ISO-8859-1", strings.NewReader(msg)) + var err error + mycharset := b.Config.Charset + if mycharset == "" { + // detect what were sending so that we convert it to utf-8 + detector := chardet.NewTextDetector() + result, err := detector.DetectBest([]byte(msg)) + if err != nil { + flog.Infof("detection failed for msg: %#v", msg) + return + } + flog.Debugf("detected %s confidence %#v", result.Charset, result.Confidence) + r, err = charset.NewReader(result.Charset, strings.NewReader(msg)) + // if we're not sure, just pick ISO-8859-1 + if result.Confidence < 80 { + mycharset = "ISO-8859-1" + } } + r, err = charset.NewReader(mycharset, strings.NewReader(msg)) if err != nil { flog.Errorf("charset to utf-8 conversion failed: %s", err) return -- cgit v1.2.3