Skip to content

Commit ec56eca

Browse files
committed
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.
1 parent 7e2285b commit ec56eca

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ To retrieve a discord channel ID, write `\#channel` on the relevant server – i
100100

101101
### Encodings
102102

103-
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.
103+
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`.
104+
The bot will produce a warning when started if the IRC library is unable to convert between encodings.
104105

105106
Further information can be found in [the installation section of irc-upd](https://github.com/Throne3d/node-irc#character-set-detection).
106107

lib/bot.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,15 @@ class Bot {
9191
...this.ircOptions
9292
};
9393

94+
// default encoding to UTF-8 so messages to Discord aren't corrupted
95+
if (!('encoding' in ircOptions)) {
96+
if (irc.canConvertEncoding()) {
97+
ircOptions.encoding = 'utf-8';
98+
} else {
99+
logger.warn('Cannot convert message encoding; you may encounter corrupted characters with non-English text.');
100+
}
101+
}
102+
94103
this.ircClient = new irc.Client(this.server, this.nickname, ircOptions);
95104
this.attachListeners();
96105
}

0 commit comments

Comments
 (0)