-
Notifications
You must be signed in to change notification settings - Fork 291
Set default encoding to UTF-8 #315
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ekmartin
merged 3 commits into
reactiflux:master
from
Throne3d:fix/237-default-utf8-encoding
Sep 30, 2017
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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.'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You might want to link to the section in your node-irc README here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good idea! Done. |
||
} | ||
} | ||
|
||
this.ircClient = new irc.Client(this.server, this.nickname, ircOptions); | ||
this.attachListeners(); | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (!ircOptions.encoding)
or if you really want to explicitly check that the property isn't set:!ircOptions.hasOwnProperty('encoding')
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The linter seems to complain about
ircOptions.hasOwnProperty('encoding')
:I've made it use
Object.prototype.hasOwnProperty.call(ircOptions, 'encoding')
instead.I think I decided to check for the property because if
encoding
is set without support for translating encodings, it will output errors for each message it attempts (and fails) to convert the encoding of. So, if the library erroneously says it can convert an encoding, and sodiscord-irc
sets the encoding, (or if something else goes wrong along the way) it could be useful for people to manually disable the option by setting it to null.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also – what's the difference between
'encoding' in ircOptions
andircOptions.hasOwnProperty('encoding')
? Whether the objectircOptions
implements it itself, versus whether some superclass of it does?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep: https://stackoverflow.com/questions/13632999/if-key-in-object-or-ifobject-hasownpropertykey
Probably doesn't really matter here though, but I think in general
hasOwnProperty
is considered a bit more hygienic.