From 7e2285bb2e90d839b796b1e708f64961c8faa6e1 Mon Sep 17 00:00:00 2001 From: Edward Jones Date: Mon, 14 Aug 2017 18:22:43 +0100 Subject: [PATCH 1/3] Add a note about how to install optional charset converter dependencies Fixes part of #252 and #237. --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index b8585fa8..d3c51070 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,10 @@ import config from './config.json'; discordIRC(config); ``` +When installing the library, you may encounter an error relating to the installation of `iconv` or `node-icu-charset-detector`. +These are optional dependencies which allow you to set the target encoding of messages sent to Discord, as detailed below in the README. +Without these dependencies and the relevant setting, messages that aren't sent in UTF-8 may be corrupted when copied to Discord. + ## Configuration First you need to create a Discord bot user, which you can do by following the instructions [here](https://github.com/reactiflux/discord-irc/wiki/Creating-a-discord-bot-&-getting-a-token). @@ -94,6 +98,12 @@ The `ircOptions` object is passed directly to irc-upd ([available options](https To retrieve a discord channel ID, write `\#channel` on the relevant server – it should produce something of the form `<#1234567890>`, which you can then use in the `channelMapping` config. +### Encodings + +If you encounter trouble with some characters being corrupted from some clients (particularly umlauted characters, such as `ä` or `ö`), try installing the optional dependencies `iconv` and `node-icu-charset-detector`, then adding `"encoding": "utf-8"` to your `ircOptions` object. + +Further information can be found in [the installation section of irc-upd](https://github.com/Throne3d/node-irc#character-set-detection). + ## Tests Run the tests with: ```bash From ec56ecaa913d603e9b70672f1ae62998ff3014e6 Mon Sep 17 00:00:00 2001 From: Edward Jones Date: Mon, 14 Aug 2017 19:52:41 +0100 Subject: [PATCH 2/3] Default ircOptions.encoding to utf-8 if node-irc can convert encodings Also warn when started if the IRC library cannot convert between encodings, in case users rely on this behavior. --- README.md | 3 ++- lib/bot.js | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d3c51070..92081453 100644 --- a/README.md +++ b/README.md @@ -100,7 +100,8 @@ To retrieve a discord channel ID, write `\#channel` on the relevant server – i ### Encodings -If you encounter trouble with some characters being corrupted from some clients (particularly umlauted characters, such as `ä` or `ö`), try installing the optional dependencies `iconv` and `node-icu-charset-detector`, then adding `"encoding": "utf-8"` to your `ircOptions` object. +If you encounter trouble with some characters being corrupted from some clients (particularly umlauted characters, such as `ä` or `ö`), try installing the optional dependencies `iconv` and `node-icu-charset-detector`. +The bot will produce a warning when started if the IRC library is unable to convert between encodings. Further information can be found in [the installation section of irc-upd](https://github.com/Throne3d/node-irc#character-set-detection). diff --git a/lib/bot.js b/lib/bot.js index 31402db0..d78e592f 100644 --- a/lib/bot.js +++ b/lib/bot.js @@ -91,6 +91,15 @@ class Bot { ...this.ircOptions }; + // default encoding to UTF-8 so messages to Discord aren't corrupted + if (!('encoding' in ircOptions)) { + if (irc.canConvertEncoding()) { + ircOptions.encoding = 'utf-8'; + } else { + logger.warn('Cannot convert message encoding; you may encounter corrupted characters with non-English text.'); + } + } + this.ircClient = new irc.Client(this.server, this.nickname, ircOptions); this.attachListeners(); } From 0ef0f098a93f7e0d1de55c72211d0d57338e23a7 Mon Sep 17 00:00:00 2001 From: Edward Jones Date: Sat, 30 Sep 2017 15:20:59 +0100 Subject: [PATCH 3/3] Improve config check and warning message around encodings --- lib/bot.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/bot.js b/lib/bot.js index d78e592f..7555b198 100644 --- a/lib/bot.js +++ b/lib/bot.js @@ -92,11 +92,12 @@ class Bot { }; // default encoding to UTF-8 so messages to Discord aren't corrupted - if (!('encoding' in ircOptions)) { + if (!Object.prototype.hasOwnProperty.call(ircOptions, 'encoding')) { if (irc.canConvertEncoding()) { ircOptions.encoding = 'utf-8'; } else { - logger.warn('Cannot convert message encoding; you may encounter corrupted characters with non-English text.'); + logger.warn('Cannot convert message encoding; you may encounter corrupted characters with non-English text.\n' + + 'For information on how to fix this, please see: https://github.com/Throne3d/node-irc#character-set-detection'); } }