diff options
author | Wim <wim@42.be> | 2017-08-29 21:30:59 +0200 |
---|---|---|
committer | Wim <wim@42.be> | 2017-08-29 21:31:03 +0200 |
commit | e7fcb25107ff6f7676624fb3011e2bc1bede4cd0 (patch) | |
tree | eba216fa1aa9078953e40377d92c15724e6b013b /bridge/irc | |
parent | 5a85258f7423bc21c707a42c537a565a27f2fbc8 (diff) | |
download | matterbridge-msglm-e7fcb25107ff6f7676624fb3011e2bc1bede4cd0.tar.gz matterbridge-msglm-e7fcb25107ff6f7676624fb3011e2bc1bede4cd0.tar.bz2 matterbridge-msglm-e7fcb25107ff6f7676624fb3011e2bc1bede4cd0.zip |
Add a charset option (irc). Closes #247
Diffstat (limited to 'bridge/irc')
-rw-r--r-- | bridge/irc/irc.go | 29 |
1 files changed, 17 insertions, 12 deletions
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 |